Browse Source

* Add CheckAllRTL

Michaël Van Canneyt 4 tháng trước cách đây
mục cha
commit
523c4486aa

+ 77 - 0
tests/utils/tsdb.pp

@@ -79,6 +79,7 @@ Type
 
     // create and open a query, return in Res.
     Function  OpenQuery (Qry : String; Out Res : TSQLQuery; Silent : Boolean) : Boolean ;
+
   Public
     { ---------------------------------------------------------------------
       High-level access
@@ -96,6 +97,8 @@ Type
     // Execute a query, return true if it executed without error.
     Function  ExecuteQuery (Qry : String; Silent : Boolean) : Boolean ;
     // Run query, return first field as integer. -1 on error or no data.
+    function GetIDQueryResult(Qry: TSQLQuery): Int64;
+    // Run SQL, return first field as integer. -1 on error or no data.
     Function  IDQuery(Qry : String) : Integer;
     // Run query, return first field as int64. -1 on error or no data.
     Function  ID64Query(Qry : String) : Int64;
@@ -123,6 +126,10 @@ Type
     function AddLastResult(TestID, PlatformID: Integer; ResultID: Int64): Boolean;
     // Add previousTestResult. If it exists already with given platform/test, update result ID.
     function AddPreviousResult(TestID, PlatformID: Integer; ResultID: Int64): Boolean;
+    // Add Check-All-RTL results
+    Function AddCheckAllRtl(aData : TCheckAllRTL) : Int64;
+    // Add Check-All-RTL failed run log
+    function AddCheckAllRtlLog(aCheckAllRTLID: int64; aStep: Byte; const aLog: String): Int64;
     //
     // Get ID based on key. All keys are case sensitive. If a key does not exist, -1 is returned.
     //
@@ -369,6 +376,17 @@ begin
   FreeAndNil(aQry);
 end;
 
+function TTestSQL.GetIDQueryResult(Qry: TSQLQuery): Int64;
+
+
+begin
+  Result:=-1;
+  Qry.Open;
+  if Not Qry.IsEmpty then
+    Result:=Qry.Fields[0].AsLargeInt;
+  Qry.SQLTransaction.Commit;
+end;
+
 function TTestSQL.IDQuery(Qry: String): Integer;
 
 Var
@@ -1086,6 +1104,65 @@ begin
   Result:=ExecuteQuery(Format(SQLInsert,[TestId,PlatFormID,ResultID]),False);
 end;
 
+function TTestSQL.AddCheckAllRtlLog(aCheckAllRTLID : int64; aStep : Byte; const aLog : String): Int64;
+
+const
+  SQLInsertLog = 'INSERT INTO public.checkallrtllog '+
+	'  (cal_checkallrtl_fk, cal_step, cal_log) '+
+	'VALUES '+
+        '  (:cal_checkallrtl_fk, :cal_step, :cal_log) '+
+	'returning cal_id';
+
+var
+  Qry : TSQLQuery;
+begin
+  Qry:=CreateQuery(SQLInsertLog);
+  try
+    Qry.ParamByName('cal_checkallrtl_fk').AsLargeInt:=aCheckAllRTLID;
+    Qry.ParamByName('cal_step').AsInteger:=aStep;
+    Qry.ParamByName('cal_log').AsString:=aLog;
+    Result:=GetIDQueryResult(Qry);
+  finally
+    Qry.Free;
+  end;
+end;
+
+function TTestSQL.AddCheckAllRtl(aData: TCheckAllRTL): Int64;
+
+const
+  SQLInsertCAR =
+             'INSERT INTO public.checkallrtl( '+
+             '  ca_platform_fk, ca_date, ca_step1, ca_step2, ca_step3, ca_step4, ca_step5, ca_step6)'+
+             'VALUES (:ca_platform_fk, :ca_date, :ca_step1, :ca_step2, :ca_step3, :ca_step4, :ca_step5, :ca_step6) '+
+             '  returning ca_id';
+var
+  Qry : TSQLQuery;
+  i : TCheckStage;
+
+begin
+  Qry:=CreateQuery(SQLInsertCar);
+  try
+    Qry.ParamByName('ca_platform_fk').AsInteger:=aData.Platform;
+    Qry.ParamByName('ca_date').AsDateTime:=aData.Date;
+    Qry.ParamByName('ca_step1').AsBoolean:=aData.Steps[1];
+    Qry.ParamByName('ca_step2').AsBoolean:=aData.Steps[2];
+    Qry.ParamByName('ca_step3').AsBoolean:=aData.Steps[3];
+    Qry.ParamByName('ca_step4').AsBoolean:=aData.Steps[4];
+    Qry.ParamByName('ca_step5').AsBoolean:=aData.Steps[5];
+    Qry.ParamByName('ca_step6').AsBoolean:=aData.Steps[6];
+    Qry.Open;
+    Result:=GetIDQueryResult(Qry);
+    if Result<>-1 then
+      begin
+      For I in TCheckStage do
+        if (not aData.Steps[i]) and (aData.Logs[i]<>'') then
+          AddCheckAllRtlLog(Result,i,aData.Logs[i]);
+      end;
+  finally
+    Qry.Free;
+  end;
+end;
+
 function TTestSQL.UpdateTestRun(aData: TTestRunData): Boolean;
 var
   Qry : string;

+ 12 - 0
tests/utils/tstypes.pp

@@ -305,6 +305,18 @@ Type
     function ResultDiffers(aResult : TTestResultData; CompareLog : Boolean = False) : Boolean;
   end;
 
+  TCheckStage = 1..6;
+  TStageResults = Array[TCheckStage] of Boolean;
+  TFailLogs = Array[TCheckStage] of String;
+
+  TCheckAllRTL = record
+    ID : Int64;
+    Platform : Integer;
+    Date : TDateTime;
+    Steps : TStageResults;
+    Logs : TFailLogs;
+  end;
+
 implementation
 
 uses sysutils;

+ 2 - 0
tests/utils/unittests/tcsetup.pas

@@ -172,6 +172,8 @@ begin
   ClearTable('TESTLASTRESULTS');
   ClearTable('TESTRESULTS');
   ClearTable('TESTRUN');
+  ClearTable('CHECKALLRTLLOG');
+  ClearTable('CHECKALLRTL');
   ClearTable('TESTPLATFORM');
   ClearTable('TESTOS');
   ClearTable('TESTCPU');

+ 26 - 2
tests/utils/unittests/tctestsql.pas

@@ -62,6 +62,7 @@ type
     procedure TestHistoryWithHistory;
     Procedure TestGetPreviousTestRun;
     Procedure TestGetNextTestRun;
+    procedure TestAddCheckAllRtl;
   end;
 
 
@@ -133,7 +134,7 @@ begin
     AssertEquals('Date',DATE,FieldByName('TU_DATE').AsDateTime);
     AssertEquals('Platform',PlatformID,FieldByName('TU_PLATFORM_FK').AsInteger);
     AssertEquals('Submitter',Submitter,FieldByName('TU_SUBMITTER').AsString);
-    For St in TTestStatus do
+    For St in TValidTestStatus do
       AssertEquals(StatusText[St],StatusCount[st],FieldByName(SQLField[ST]).AsInteger);
     AssertEquals('CompilerDate',CompilerDate,FieldByName('TU_COMPILERDATE').AsString);
     AssertEquals('CompilerFullVersion',CompilerFullVersion,FieldByName('TU_COMPILERFULLVERSION').AsString);
@@ -526,7 +527,7 @@ begin
   lData:=Default(TTestRunData);
   lData.PlatformID:=PreparePlatform(lData);
   lData.RunID:=SQL.AddRun(lData);
-  for St in TTestStatus do
+  for St in TValidTestStatus do
     lData.StatusCount[st]:=(Ord(st)+1)*100;
   AssertTrue('Update',SQL.UpdateTestRun(lData));
   Qry:=TDBHelper.CreateQuery(Format('Select * from testrun where (tu_id=%d)',[lData.RunID]));
@@ -682,6 +683,29 @@ begin
   AssertEquals('last',-1,SQL.GetNextRunID(4));
 end;
 
+procedure TTestSQLCase.TestAddCheckAllRtl;
+
+var
+  lData : TCheckAllRTL;
+  lTestRunData: TTestRunData;
+  I : integer;
+
+begin
+  lTestRunData:=Default(TTestRunData);
+  lData:=Default(TCheckAllRTL);
+  lData.Platform:=PreparePlatform(lTestRunData);
+  lData.Date:=Date;
+  for I:=Low(TCheckStage) to High(TCheckStage) do
+    begin
+    lData.Steps[i]:=(I mod 2)=0;
+    lData.Logs[i]:='Step '+IntToStr(i)+' log';
+    end;
+  lData.ID:=SQL.AddCheckAllRtl(lData);
+  AssertEquals('count CheckAllRTL', 1, TDBHelper.CountRecords('CHECKALLRTL',Format('(CA_ID=%d)',[lData.ID])));
+  AssertEquals('count CheckAllRTLLog', 3, TDBHelper.CountRecords('CHECKALLRTLLOG',Format('CAL_CHECKALLRTL_FK=%d',[lData.ID])));
+
+end;
+
 
 initialization
   RegisterTestDecorator(TDBDecorator,TTestSQLCase);