dbdigest.pp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. {
  2. This file is part of the Free Pascal test suite.
  3. Copyright (c) 2002 by the Free Pascal development team.
  4. This program inserts the last tests run
  5. into TESTSUITE database.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$mode objfpc}
  13. {$h+}
  14. {$ifndef win32}
  15. {$linklib pthread}
  16. {$endif}
  17. program dbdigest;
  18. uses
  19. sysutils,teststr,testu,tresults,dbtests;
  20. Var
  21. StatusCount : Array[TTestStatus] of Integer;
  22. UnknownLines : integer;
  23. Procedure ExtractTestFileName(Var Line : string);
  24. Var I : integer;
  25. begin
  26. I:=Pos(' ',Line);
  27. If (I<>0) then
  28. Line:=Copy(Line,1,I-1);
  29. end;
  30. Function Analyse(Var Line : string; Var Status : TTestStatus) : Boolean;
  31. Var
  32. TS : TTestStatus;
  33. begin
  34. Result:=False;
  35. For TS:=FirstStatus to LastStatus do
  36. begin
  37. Result:=Pos(StatusText[TS],Line)=1;
  38. If Result then
  39. begin
  40. Status:=TS;
  41. Delete(Line,1,Length(StatusText[TS]));
  42. ExtractTestFileName(Line);
  43. Break;
  44. end;
  45. end;
  46. end;
  47. Type
  48. TConfigOpt = (
  49. coDatabaseName,
  50. coHost,
  51. coUserName,
  52. coPassword,
  53. coPort,
  54. coLogFile,
  55. coLongLogFile,
  56. coOS,
  57. coCPU,
  58. coCategory,
  59. coVersion,
  60. coDate,
  61. coSubmitter,
  62. coMachine,
  63. coComment,
  64. coTestSrcDir,
  65. coRelSrcDir,
  66. coVerbose
  67. );
  68. { Additional options only for dbdigest.cfg file }
  69. TConfigAddOpt = (
  70. coCompilerDate,
  71. coCompilerFullVersion,
  72. coSvnCompilerRevision,
  73. coSvnTestsRevision,
  74. coSvnRTLRevision,
  75. coSvnPackagesRevision
  76. );
  77. Const
  78. ConfigStrings : Array [TConfigOpt] of string = (
  79. 'databasename',
  80. 'host',
  81. 'username',
  82. 'password',
  83. 'port',
  84. 'logfile',
  85. 'longlogfile',
  86. 'os',
  87. 'cpu',
  88. 'category',
  89. 'version',
  90. 'date',
  91. 'submitter',
  92. 'machine',
  93. 'comment',
  94. 'testsrcdir',
  95. 'relsrcdir',
  96. 'verbose'
  97. );
  98. ConfigOpts : Array[TConfigOpt] of char =(
  99. 'd', { coDatabaseName }
  100. 'h', { coHost }
  101. 'u', { coUserName }
  102. 'p', { coPassword }
  103. 'P', { coPort }
  104. 'l', { coLogFile }
  105. 'L', { coLongLogFile }
  106. 'o', { coOS }
  107. 'c', { coCPU }
  108. 'a', { coCategory }
  109. 'v', { coVersion }
  110. 't', { coDate }
  111. 's', { coSubmitter }
  112. 'm', { coMachine }
  113. 'C', { coComment }
  114. 'S', { coTestSrcDir }
  115. 'r', { coRelSrcDir }
  116. 'V' { coVerbose }
  117. );
  118. ConfigAddStrings : Array [TConfigAddOpt] of string = (
  119. 'compilerdate',
  120. 'compilerfullversion',
  121. 'svncompilerrevision',
  122. 'svntestsrevision',
  123. 'svnrtlrevision',
  124. 'svnpackagesrevision'
  125. );
  126. ConfigAddCols : Array [TConfigAddOpt] of string = (
  127. 'TU_COMPILERDATE',
  128. 'TU_COMPILERFULLVERSION',
  129. 'TU_SVNCOMPILERREVISION',
  130. 'TU_SVNTESTSREVISION',
  131. 'TU_SVNRTLREVISION',
  132. 'TU_SVNPACKAGESREVISION'
  133. );
  134. Var
  135. TestOS,
  136. TestCPU,
  137. TestVersion,
  138. TestCategory,
  139. DatabaseName,
  140. HostName,
  141. UserName,
  142. Password,
  143. Port,
  144. LongLogFileName,
  145. LogFileName,
  146. Submitter,
  147. Machine,
  148. Comment : String;
  149. TestDate : TDateTime;
  150. TestCompilerDate,
  151. TestCompilerFullVersion,
  152. TestSvnCompilerRevision,
  153. TestSvnTestsRevision,
  154. TestSvnRTLRevision,
  155. TestSvnPackagesRevision : String;
  156. Procedure SetAddOpt (O : TConfigAddOpt; Value : string);
  157. begin
  158. Case O of
  159. coCompilerDate:
  160. TestCompilerDate:=Value;
  161. coCompilerFullVersion:
  162. TestCompilerFullVersion:=Value;
  163. coSvnCompilerRevision:
  164. TestSvnCompilerRevision:=Value;
  165. coSvnTestsRevision:
  166. TestSvnTestsRevision:=Value;
  167. coSvnRTLRevision:
  168. TestSvnRTLRevision:=Value;
  169. coSvnPackagesRevision:
  170. TestSvnPackagesRevision:=Value;
  171. end;
  172. end;
  173. Procedure SetOpt (O : TConfigOpt; Value : string);
  174. var
  175. year,month,day,min,hour : word;
  176. begin
  177. Case O of
  178. coDatabaseName : DatabaseName:=Value;
  179. coHost : HostName:=Value;
  180. coUserName : UserName:=Value;
  181. coPassword : Password:=Value;
  182. coPort : Port:=Value;
  183. coLogFile : LogFileName:=Value;
  184. coLongLogFile : LongLogFileName:=Value;
  185. coOS : TestOS:=Value;
  186. coCPU : TestCPU:=Value;
  187. coCategory : TestCategory:=Value;
  188. coVersion : TestVersion:=Value;
  189. coDate :
  190. begin
  191. { Formated like YYYYMMDDhhmm }
  192. if Length(value)=12 then
  193. begin
  194. year:=StrToInt(Copy(value,1,4));
  195. month:=StrToInt(Copy(value,5,2));
  196. day:=StrToInt(Copy(Value,7,2));
  197. hour:=StrToInt(Copy(Value,9,2));
  198. min:=StrToInt(Copy(Value,11,2));
  199. TestDate:=EncodeDate(year,month,day)+EncodeTime(hour,min,0,0);
  200. end
  201. else
  202. Verbose(V_Error,'Error in date format, use YYYYMMDDhhmm');
  203. end;
  204. coSubmitter : Submitter:=Value;
  205. coMachine : Machine:=Value;
  206. coComment : Comment:=Value;
  207. coVerbose : DoVerbose:=true;
  208. coTestSrcDir :
  209. begin
  210. TestSrcDir:=Value;
  211. if (TestSrcDir<>'') and (TestSrcDir[length(TestSrcDir)]<>'/') then
  212. TestSrcDir:=TestSrcDir+'/';
  213. end;
  214. coRelSrcDir :
  215. begin
  216. RelSrcDir:=Value;
  217. if (RelSrcDir<>'') and (RelSrcDir[length(RelSrcDir)]<>'/') then
  218. RelSrcDir:=RelSrcDir+'/';
  219. if (RelSrcDir<>'') and (RelSrcDir[1]='/') then
  220. RelSrcDir:=copy(RelSrcDir,2,length(RelSrcDir)-1);
  221. end;
  222. end;
  223. end;
  224. Function ProcessOption(S: String) : Boolean;
  225. Var
  226. N : String;
  227. I : Integer;
  228. co : TConfigOpt;
  229. coa : TConfigAddOpt;
  230. begin
  231. Verbose(V_DEBUG,'Processing option: '+S);
  232. I:=Pos('=',S);
  233. Result:=(I<>0);
  234. If Result then
  235. begin
  236. N:=Copy(S,1,I-1);
  237. Delete(S,1,I);
  238. For co:=low(TConfigOpt) to high(TConfigOpt) do
  239. begin
  240. Result:=CompareText(ConfigStrings[co],N)=0;
  241. If Result then
  242. begin
  243. SetOpt(co,S);
  244. Exit;
  245. end;
  246. end;
  247. For coa:=low(TConfigAddOpt) to high(TConfigAddOpt) do
  248. begin
  249. Result:=CompareText(ConfigAddStrings[coa],N)=0;
  250. If Result then
  251. begin
  252. SetAddOpt(coa,S);
  253. Exit;
  254. end;
  255. end;
  256. end;
  257. Verbose(V_ERROR,'Unknown option : '+n+S);
  258. end;
  259. Procedure ProcessConfigfile(FN : String);
  260. Var
  261. F : Text;
  262. S : String;
  263. I : Integer;
  264. begin
  265. // Set the default value for old digests without RelSrcDir to the rtl/compiler
  266. // testsuite
  267. RelSrcDir:='tests/';
  268. If Not FileExists(FN) Then
  269. Exit;
  270. Verbose(V_DEBUG,'Parsing config file: '+FN);
  271. Assign(F,FN);
  272. {$i-}
  273. Reset(F);
  274. If IOResult<>0 then
  275. Exit;
  276. {$I+}
  277. While not(EOF(F)) do
  278. begin
  279. ReadLn(F,S);
  280. S:=trim(S);
  281. I:=Pos('#',S);
  282. If I<>0 then
  283. S:=Copy(S,1,I-1);
  284. If (S<>'') then
  285. ProcessOption(S);
  286. end;
  287. Close(F);
  288. end;
  289. Procedure ProcessCommandLine;
  290. Var
  291. I : Integer;
  292. O : String;
  293. c,co : TConfigOpt;
  294. ShortOptFound, Found : Boolean;
  295. begin
  296. I:=1;
  297. While I<=ParamCount do
  298. begin
  299. O:=Paramstr(I);
  300. ShortOptFound:=(Length(O)=2) and (O[1]='-');
  301. If ShortOptFound then
  302. For co:=low(TConfigOpt) to high(TConfigOpt) do
  303. begin
  304. Found:=(O[2]=ConfigOpts[co]);
  305. If Found then
  306. begin
  307. c:=co;
  308. Break;
  309. end;
  310. end;
  311. If not ShortOptFound then
  312. begin
  313. Found:=false;
  314. { accept long options }
  315. if (copy(O,1,2)='--') then
  316. begin
  317. { remove -- }
  318. O:=copy(O,3,length(O));
  319. For co:=low(TConfigOpt) to high(TConfigOpt) do
  320. begin
  321. Found:=(O=ConfigStrings[co]);
  322. If Found then
  323. begin
  324. c:=co;
  325. Break;
  326. end;
  327. end;
  328. end
  329. end;
  330. if not Found then
  331. Verbose(V_ERROR,'Illegal command-line option : '+O)
  332. else
  333. begin
  334. Found:=(I<ParamCount);
  335. If Not found then
  336. Verbose(V_ERROR,'Option requires argument : '+O)
  337. else
  338. begin
  339. inc(I);
  340. O:=Paramstr(I);
  341. SetOpt(c,o);
  342. end;
  343. end;
  344. Inc(I);
  345. end;
  346. end;
  347. Var
  348. TestCPUID : Integer;
  349. TestOSID : Integer;
  350. TestVersionID : Integer;
  351. TestCategoryID : Integer;
  352. TestRunID : Integer;
  353. ConfigID : Integer;
  354. Procedure GetIDs;
  355. begin
  356. TestCPUID := GetCPUId(TestCPU);
  357. If TestCPUID=-1 then
  358. Verbose(V_Error,'NO ID for CPU "'+TestCPU+'" found.');
  359. TestOSID := GetOSID(TestOS);
  360. If TestOSID=-1 then
  361. Verbose(V_Error,'NO ID for OS "'+TestOS+'" found.');
  362. TestCategoryID := GetCategoryID(TestCategory);
  363. If TestCategoryID=-1 then
  364. begin
  365. // Verbose(V_Error,'NO ID for Category "'+TestCategory+'" found.');
  366. TestCategoryID:=1;
  367. end;
  368. TestVersionID := GetVersionID(TestVersion);
  369. If TestVersionID=-1 then
  370. Verbose(V_Error,'NO ID for version "'+TestVersion+'" found.');
  371. If (Round(TestDate)=0) then
  372. Testdate:=Now;
  373. TestRunID:=GetRunID(TestOSID,TestCPUID,TestVersionID,TestDate);
  374. If (TestRunID=-1) then
  375. begin
  376. TestRunID:=AddRun(TestOSID,TestCPUID,TestVersionID,TestCategoryID,TestDate);
  377. If TestRUnID=-1 then
  378. Verbose(V_Error,'Could not insert new testrun record!');
  379. end
  380. else
  381. CleanTestRun(TestRunID);
  382. end;
  383. var
  384. LongLogFile : Text;
  385. const
  386. UseLongLog : boolean = false;
  387. LongLogOpenCount : longint = 0;
  388. FirstLongLogLine : boolean = true;
  389. Function GetContentsFromLongLog(Line : String) : String;
  390. var
  391. S : String;
  392. IsFirst, IsFound : boolean;
  393. begin
  394. Result:='';
  395. IsFirst:=true;
  396. IsFound:=false;
  397. While Not(EOF(LongLogFile)) do
  398. begin
  399. ReadLn(LongLogFile,S);
  400. if FirstLongLogLine then
  401. begin
  402. { At start of file there is a separation line }
  403. if (pos('>>>>>>>>>>>',S)=1) then
  404. Readln(LongLogFile,S);
  405. FirstLongLogLine:=false;
  406. end;
  407. if pos(Line,S)=1 then
  408. begin
  409. IsFound:=true;
  410. while not eof(LongLogFile) do
  411. begin
  412. ReadLn(LongLogFile,S);
  413. { End of file marker }
  414. if eof(LongLogFile) or (pos('>>>>>>>>>>>',S)=1) then
  415. exit;
  416. Result:=Result+S+LineEnding;
  417. end;
  418. end
  419. else if IsFirst then
  420. begin
  421. Verbose(V_Warning,'Line "'+Line+'" not found as next "'+S+'"');
  422. IsFirst:=false;
  423. end;
  424. end;
  425. if not IsFound then
  426. begin
  427. Verbose(V_Warning,'Line "'+Line+'" not found');
  428. { Restart to get a chance to find others }
  429. if eof(LongLogFile) then
  430. begin
  431. Close(LongLogFile);
  432. Reset(LongLogFile);
  433. inc(LongLogOpenCount);
  434. end;
  435. end;
  436. end;
  437. Function GetLog(Line, FN : String) : String;
  438. begin
  439. if UseLongLog then
  440. begin
  441. Result:=GetContentsFromLongLog(Line);
  442. exit;
  443. end;
  444. FN:=ChangeFileExt(FN,'.log');
  445. If FileExists(FN) then
  446. Result:=GetFileContents(FN)
  447. else
  448. Result:='';
  449. end;
  450. Function GetExecuteLog(Line, FN : String) : String;
  451. begin
  452. if UseLongLog then
  453. begin
  454. Result:=GetContentsFromLongLog(Line);
  455. exit;
  456. end;
  457. FN:=ChangeFileExt(FN,'.elg');
  458. If FileExists(FN) then
  459. Result:=GetFileContents(FN)
  460. else
  461. Result:='';
  462. end;
  463. Procedure Processfile (FN: String);
  464. var
  465. logfile : text;
  466. fullline,line,prevLine : string;
  467. TS,PrevTS : TTestStatus;
  468. ID,PrevID : integer;
  469. Testlog : string;
  470. is_new : boolean;
  471. begin
  472. Assign(logfile,FN);
  473. PrevId:=-1;
  474. PrevLine:='';
  475. is_new:=false;
  476. PrevTS:=low(TTestStatus);
  477. {$i-}
  478. reset(logfile);
  479. if ioresult<>0 then
  480. Verbose(V_Error,'Unable to open log file'+FN);
  481. {$i+}
  482. while not eof(logfile) do
  483. begin
  484. readln(logfile,line);
  485. fullline:=line;
  486. ts:=stFailedToCompile;
  487. If analyse(line,TS) then
  488. begin
  489. Verbose(V_NORMAL,'Analysing result for test '+Line);
  490. If Not ExpectRun[TS] then
  491. begin
  492. ID:=RequireTestID(Line);
  493. if (PrevID<>-1) and (PrevID<>ID) then
  494. begin
  495. { This can only happen if a Successfully compiled message
  496. is not followed by any other line about the same test }
  497. TestLog:='';
  498. AddTestResult(PrevID,TestRunId,ord(PrevTS),
  499. TestOK[PrevTS],TestSkipped[PrevTS],TestLog,is_new);
  500. Verbose(V_Warning,'Orphaned test: "'+prevline+'"');
  501. end;
  502. PrevID:=-1;
  503. If (ID<>-1) then
  504. begin
  505. If Not (TestOK[TS] or TestSkipped[TS]) then
  506. begin
  507. TestLog:=GetExecuteLog(Fullline,Line);
  508. if pos(failed_to_compile,TestLog)=1 then
  509. TestLog:=GetLog(Fullline,Line);
  510. end
  511. else
  512. TestLog:='';
  513. { AddTestResult can fail for test that contain %recompile
  514. as the same }
  515. if AddTestResult(ID,TestRunID,Ord(TS),TestOK[TS],
  516. TestSkipped[TS],TestLog,is_new) <> -1 then
  517. begin
  518. if is_new then
  519. Inc(StatusCount[TS])
  520. else
  521. Verbose(V_Debug,'Test: "'+line+'" was updated');
  522. end
  523. else
  524. begin
  525. Verbose(V_Warning,'Test: "'+line+'" already registered');
  526. end;
  527. end;
  528. end
  529. else
  530. begin
  531. Inc(StatusCount[TS]);
  532. PrevTS:=TS;
  533. PrevID:=RequireTestID(line);
  534. PrevLine:=line;
  535. end;
  536. end
  537. else
  538. begin
  539. Inc(UnknownLines);
  540. Verbose(V_Warning,'Unknown line: "'+line+'"');
  541. end;
  542. end;
  543. close(logfile);
  544. end;
  545. procedure UpdateTestRun;
  546. var
  547. i : TTestStatus;
  548. qry : string;
  549. begin
  550. qry:='UPDATE TESTRUN SET ';
  551. for i:=low(TTestStatus) to high(TTestStatus) do
  552. qry:=qry+format('%s=%d, ',[SQLField[i],StatusCount[i]]);
  553. if TestCompilerDate<>'' then
  554. qry:=qry+format('%s="%s", ',[ConfigAddCols[coCompilerDate],EscapeSQL(TestCompilerDate)]);
  555. if TestCompilerFullVersion<>'' then
  556. qry:=qry+format('%s="%s", ',[ConfigAddCols[coCompilerFullVersion],EscapeSQL(TestCompilerFullVersion)]);
  557. if TestSvnCompilerRevision<>'' then
  558. qry:=qry+format('%s="%s", ',[ConfigAddCols[coSvnCompilerRevision],EscapeSQL(TestSvnCompilerRevision)]);
  559. if TestSvnTestsRevision<>'' then
  560. qry:=qry+format('%s="%s", ',[ConfigAddCols[coSvnTestsRevision],EscapeSQL(TestSvnTestsRevision)]);
  561. if TestSvnRTLRevision<>'' then
  562. qry:=qry+format('%s="%s", ',[ConfigAddCols[coSvnRTLRevision],EscapeSQL(TestSvnRTLRevision)]);
  563. if TestSvnPackagesRevision<>'' then
  564. qry:=qry+format('%s="%s", ',[ConfigAddCols[coSvnPackagesRevision],EscapeSQL(TestSvnPackagesRevision)]);
  565. qry:=qry+format('TU_SUBMITTER="%s", TU_MACHINE="%s", TU_COMMENT="%s", TU_DATE="%s"',[Submitter,Machine,Comment,SqlDate(TestDate)]);
  566. qry:=qry+' WHERE TU_ID='+format('%d',[TestRunID]);
  567. ExecuteQuery(Qry,False);
  568. end;
  569. function GetTestConfigId : Integer;
  570. var
  571. qry : string;
  572. begin
  573. qry:='SELECT TCONF_ID FROM TESTCONFIG WHERE ' +
  574. 'TCONF_CPU_FK=%d AND ' +
  575. 'TCONF_OS_FK=%d AND ' +
  576. 'TCONF_VERSION_FK=%d AND ' +
  577. 'TCONF_CATEGORY_FK=%d AND ' +
  578. 'TCONF_SUBMITTER="%s" AND ' +
  579. 'TCONF_MACHINE="%s" AND ' +
  580. 'TCONF_COMMENT="%s" ';
  581. ConfigID:=IDQuery(format(qry,[TestCPUID, TestOSID, TestVersionID, TestCategoryID,
  582. Submitter, Machine, Comment]));
  583. GetTestConfigID:=ConfigID;
  584. end;
  585. function UpdateTestConfigID : boolean;
  586. var
  587. qry : string;
  588. firstRunID, lastRunID,PrevRunID : Integer;
  589. RunCount : Integer;
  590. AddCount : boolean;
  591. begin
  592. AddCount:=false;
  593. UpdateTestConfigID:=false;
  594. qry:=format('SELECT TCONF_FIRST_RUN_FK FROM TESTCONFIG WHERE TCONF_ID=%d',[ConfigID]);
  595. FirstRunID:=IDQuery(qry);
  596. if TestRunID<FirstRunID then
  597. begin
  598. Verbose(V_Warning,format('FirstRunID changed from %d to %d',[FirstRunID,TestRunID]));
  599. qry:=format('UPDATE TESTCONFIG SET TCONF_FIRST_RUN_FK=%d WHERE TCONF_ID=%d',
  600. [TestRunID,ConfigID]);
  601. if Not ExecuteQuery(qry,False) then
  602. Verbose(V_Warning,'Update of LastRunID failed');
  603. end;
  604. qry:=format('SELECT TCONF_LAST_RUN_FK FROM TESTCONFIG WHERE TCONF_ID=%d',[ConfigID]);
  605. LastRunID:=IDQuery(qry);
  606. if TestRunID>LastRunID then
  607. begin
  608. qry:=format('UPDATE TESTCONFIG SET TCONF_LAST_RUN_FK=%d WHERE TCONF_ID=%d',
  609. [TestRunID,ConfigID]);
  610. if not ExecuteQuery(qry,False) then
  611. Verbose(V_Warning,'Update of LastRunID failed');
  612. end
  613. else
  614. Verbose(V_Warning,format('LastRunID %di,new %d',[LastRunID,TestRunID]));
  615. qry:=format('SELECT TCONF_NEW_RUN_FK FROM TESTCONFIG WHERE TCONF_ID=%d',[ConfigID]);
  616. PrevRunID:=IDQuery(qry);
  617. if TestRunID<>PrevRunID then
  618. begin
  619. qry:=format('UPDATE TESTCONFIG SET TCONF_NEW_RUN_FK=%d WHERE TCONF_ID=%d',
  620. [TestRunID,ConfigID]);
  621. if not ExecuteQuery(qry,False) then
  622. Verbose(V_Warning,'Update of LastRunID failed');
  623. AddTestHistoryEntry(TestRunID,PrevRunID);
  624. AddCount:=true;
  625. end
  626. else
  627. Verbose(V_Warning,'TestRunID is equal to last!');
  628. qry:=format('SELECT TCONF_COUNT_RUNS FROM TESTCONFIG WHERE TCONF_ID=%d',[ConfigID]);
  629. RunCount:=IDQuery(qry);
  630. { Add one to run count }
  631. if AddCount then
  632. begin
  633. Inc(RunCount);
  634. qry:=format('UPDATE TESTCONFIG SET TCONF_COUNT_RUNS=%d WHERE TCONF_ID=%d',
  635. [RunCount,ConfigID]);
  636. if not ExecuteQuery(qry,False) then
  637. Verbose(V_Warning,'Update of TU_COUNT_RUNS failed');
  638. end;
  639. UpdateTestConfigID:=true;
  640. end;
  641. function InsertNewTestConfigId : longint;
  642. var
  643. qry : string;
  644. begin
  645. qry:='INSERT INTO TESTCONFIG '+
  646. '(TCONF_NEW_RUN_FK,TCONF_FIRST_RUN_FK,TCONF_LAST_RUN_FK,' +
  647. 'TCONF_CPU_FK,TCONF_OS_FK,TCONF_VERSION_FK,TCONF_CATEGORY_FK,'+
  648. 'TCONF_SUBMITTER,TCONF_MACHINE,TCONF_COMMENT,'+
  649. 'TCONF_NEW_DATE,TCONF_FIRST_DATE,TCONF_LAST_DATE) ';
  650. qry:=qry+format(' VALUES(%d,%d,%d,%d,%d,%d,%d,"%s","%s","%s","%s","%s","%s") ',
  651. [TestRunID, TestRunID, TestRunID, TestCPUID,
  652. TestOSID, TestVersionID, TestCategoryID,
  653. Submitter, Machine, Comment,
  654. SqlDate(TestDate), SqlDate(TestDate), SqlDate(TestDate)]);
  655. qry:=qry+' RETURNING TCONF_ID';
  656. Result:=InsertQuery(qry);
  657. AddTestHistoryEntry(TestRunID,0);
  658. end;
  659. procedure UpdateTestConfig;
  660. begin
  661. if GetTestPreviousRunHistoryID(TestRunID) <> -1 then
  662. begin
  663. Verbose(V_DEBUG,format('TestRun %d already in TestHistory table',[TestRunID]));
  664. exit;
  665. end;
  666. if GetTestConfigID >= 0 then
  667. begin
  668. if not UpdateTestConfigID then
  669. Verbose(V_Warning, ' Update of TESTCONFIG table failed');
  670. end
  671. else
  672. begin
  673. if InsertNewTestConfigID = -1 then
  674. Verbose(V_Warning, ' Insert of new entry into TESTCONFIG table failed');
  675. end;
  676. end;
  677. begin
  678. ProcessConfigFile('dbdigest.cfg');
  679. ProcessCommandLine;
  680. If LogFileName<>'' then
  681. begin
  682. ConnectToDatabase(DatabaseName,HostName,UserName,Password,Port);
  683. if LongLogFileName<>'' then
  684. begin
  685. {$I-}
  686. Assign(LongLogFile,LongLogFileName);
  687. Reset(LongLogFile);
  688. If IOResult=0 then
  689. begin
  690. UseLongLog:=true;
  691. inc(LongLogOpenCount);
  692. end;
  693. {$I+}
  694. end;
  695. GetIDs;
  696. ProcessFile(LogFileName);
  697. UpdateTestRun;
  698. UpdateTestConfig;
  699. if UseLongLog then
  700. begin
  701. Close(LongLogFile);
  702. if LongLogOpenCount>1 then
  703. Verbose(V_Warning,format('LongLog file was read %d times.',[LongLogOpenCount]));
  704. end
  705. end
  706. else
  707. Verbose(V_ERROR,'Missing log file name');
  708. end.