dbdigest.pp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  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. If analyse(line,TS) then
  487. begin
  488. Verbose(V_NORMAL,'Analysing result for test '+Line);
  489. If Not ExpectRun[TS] then
  490. begin
  491. ID:=RequireTestID(Line);
  492. if (PrevID<>-1) and (PrevID<>ID) then
  493. begin
  494. { This can only happen if a Successfully compiled message
  495. is not followed by any other line about the same test }
  496. TestLog:='';
  497. AddTestResult(PrevID,TestRunId,ord(PrevTS),
  498. TestOK[PrevTS],TestSkipped[PrevTS],TestLog,is_new);
  499. Verbose(V_Warning,'Orphaned test: "'+prevline+'"');
  500. end;
  501. PrevID:=-1;
  502. If (ID<>-1) then
  503. begin
  504. If Not (TestOK[TS] or TestSkipped[TS]) then
  505. begin
  506. TestLog:=GetExecuteLog(Fullline,Line);
  507. if pos(failed_to_compile,TestLog)=1 then
  508. TestLog:=GetLog(Fullline,Line);
  509. end
  510. else
  511. TestLog:='';
  512. { AddTestResult can fail for test that contain %recompile
  513. as the same }
  514. if AddTestResult(ID,TestRunID,Ord(TS),TestOK[TS],
  515. TestSkipped[TS],TestLog,is_new) <> -1 then
  516. begin
  517. if is_new then
  518. Inc(StatusCount[TS])
  519. else
  520. Verbose(V_Debug,'Test: "'+line+'" was updated');
  521. end
  522. else
  523. begin
  524. Verbose(V_Warning,'Test: "'+line+'" already registered');
  525. end;
  526. end;
  527. end
  528. else
  529. begin
  530. Inc(StatusCount[TS]);
  531. PrevTS:=TS;
  532. PrevID:=RequireTestID(line);
  533. PrevLine:=line;
  534. end;
  535. end
  536. else
  537. begin
  538. Inc(UnknownLines);
  539. Verbose(V_Warning,'Unknown line: "'+line+'"');
  540. end;
  541. end;
  542. close(logfile);
  543. end;
  544. procedure UpdateTestRun;
  545. var
  546. i : TTestStatus;
  547. qry : string;
  548. res : TQueryResult;
  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. if RunQuery(Qry,res) then
  568. FreeQueryResult(Res);
  569. end;
  570. function GetTestConfigId : Integer;
  571. var
  572. qry : string;
  573. begin
  574. qry:='SELECT TCONF_ID FROM TESTCONFIG WHERE ' +
  575. 'TCONF_CPU_FK=%d AND ' +
  576. 'TCONF_OS_FK=%d AND ' +
  577. 'TCONF_VERSION_FK=%d AND ' +
  578. 'TCONF_CATEGORY_FK=%d AND ' +
  579. 'TCONF_SUBMITTER="%s" AND ' +
  580. 'TCONF_MACHINE="%s" AND ' +
  581. 'TCONF_COMMENT="%s" ';
  582. ConfigID:=IDQuery(format(qry,[TestCPUID, TestOSID, TestVersionID, TestCategoryID,
  583. Submitter, Machine, Comment]));
  584. GetTestConfigID:=ConfigID;
  585. end;
  586. function UpdateTestConfigID : boolean;
  587. var
  588. qry : string;
  589. firstRunID, lastRunID,PrevRunID : Integer;
  590. RunCount : Integer;
  591. res : TQueryResult;
  592. AddCount : boolean;
  593. begin
  594. AddCount:=false;
  595. UpdateTestConfigID:=false;
  596. qry:=format('SELECT TCONF_FIRST_RUN_FK FROM TESTCONFIG WHERE TCONF_ID=%d',[ConfigID]);
  597. FirstRunID:=IDQuery(qry);
  598. if TestRunID<FirstRunID then
  599. begin
  600. Verbose(V_Warning,format('FirstRunID changed from %d to %d',[FirstRunID,TestRunID]));
  601. qry:=format('UPDATE TESTCONFIG SET TCONF_FIRST_RUN_FK=%d WHERE TCONF_ID=%d',
  602. [TestRunID,ConfigID]);
  603. if RunQuery(qry,res) then
  604. FreeQueryResult(res)
  605. else
  606. Verbose(V_Warning,'Update of LastRunID failed');
  607. end;
  608. qry:=format('SELECT TCONF_LAST_RUN_FK FROM TESTCONFIG WHERE TCONF_ID=%d',[ConfigID]);
  609. LastRunID:=IDQuery(qry);
  610. if TestRunID>LastRunID then
  611. begin
  612. qry:=format('UPDATE TESTCONFIG SET TCONF_LAST_RUN_FK=%d WHERE TCONF_ID=%d',
  613. [TestRunID,ConfigID]);
  614. if RunQuery(qry,res) then
  615. FreeQueryResult(res)
  616. else
  617. Verbose(V_Warning,'Update of LastRunID failed');
  618. end
  619. else
  620. Verbose(V_Warning,format('LastRunID %di,new %d',[LastRunID,TestRunID]));
  621. qry:=format('SELECT TCONF_NEW_RUN_FK FROM TESTCONFIG WHERE TCONF_ID=%d',[ConfigID]);
  622. PrevRunID:=IDQuery(qry);
  623. if TestRunID<>PrevRunID then
  624. begin
  625. qry:=format('UPDATE TESTCONFIG SET TCONF_NEW_RUN_FK=%d WHERE TCONF_ID=%d',
  626. [TestRunID,ConfigID]);
  627. if RunQuery(qry,res) then
  628. FreeQueryResult(res)
  629. else
  630. Verbose(V_Warning,'Update of LastRunID failed');
  631. AddTestHistoryEntry(TestRunID,PrevRunID);
  632. AddCount:=true;
  633. end
  634. else
  635. Verbose(V_Warning,'TestRunID is equal to last!');
  636. qry:=format('SELECT TCONF_COUNT_RUNS FROM TESTCONFIG WHERE TCONF_ID=%d',[ConfigID]);
  637. RunCount:=IDQuery(qry);
  638. { Add one to run count }
  639. if AddCount then
  640. begin
  641. Inc(RunCount);
  642. qry:=format('UPDATE TESTCONFIG SET TCONF_COUNT_RUNS=%d WHERE TCONF_ID=%d',
  643. [RunCount,ConfigID]);
  644. if RunQuery(qry,res) then
  645. FreeQueryResult(res)
  646. else
  647. Verbose(V_Warning,'Update of TU_COUNT_RUNS failed');
  648. end;
  649. UpdateTestConfigID:=true;
  650. end;
  651. function InsertNewTestConfigId : longint;
  652. var
  653. qry : string;
  654. begin
  655. qry:='INSERT INTO TESTCONFIG '+
  656. '(TCONF_NEW_RUN_FK,TCONF_FIRST_RUN_FK,TCONF_LAST_RUN_FK,' +
  657. 'TCONF_CPU_FK,TCONF_OS_FK,TCONF_VERSION_FK,TCONF_CATEGORY_FK,'+
  658. 'TCONF_SUBMITTER,TCONF_MACHINE,TCONF_COMMENT,'+
  659. 'TCONF_NEW_DATE,TCONF_FIRST_DATE,TCONF_LAST_DATE) ';
  660. qry:=qry+format(' VALUES(%d,%d,%d,%d,%d,%d,%d,"%s","%s","%s","%s","%s","%s") ',
  661. [TestRunID, TestRunID, TestRunID, TestCPUID,
  662. TestOSID, TestVersionID, TestCategoryID,
  663. Submitter, Machine, Comment,
  664. TestDate, TestDate, TestDate]);
  665. Result:=InsertQuery(qry);
  666. AddTestHistoryEntry(TestRunID,0);
  667. end;
  668. procedure UpdateTestConfig;
  669. var
  670. qry : string;
  671. res : TQueryResult;
  672. begin
  673. qry:='SHOW TABLES LIKE ''TESTCONFIG''';
  674. if not RunQuery(Qry,Res) then
  675. exit;
  676. { Row_Count is zero if table does not exist }
  677. if Res^.Row_Count=0 then exit;
  678. FreeQueryResult(Res);
  679. if GetTestRunHistoryID(TestRunID) <> -1 then
  680. begin
  681. Verbose(V_DEBUG,format('TestRun %d already in TestHistory table',[TestRunID]));
  682. exit;
  683. end;
  684. if GetTestConfigID >= 0 then
  685. begin
  686. if not UpdateTestConfigID then
  687. Verbose(V_Warning, ' Update of TESTCONFIG table failed');
  688. end
  689. else
  690. begin
  691. if InsertNewTestConfigID = -1 then
  692. Verbose(V_Warning, ' Insert of new entry into TESTCONFIG table failed');
  693. end;
  694. end;
  695. begin
  696. ProcessConfigFile('dbdigest.cfg');
  697. ProcessCommandLine;
  698. If LogFileName<>'' then
  699. begin
  700. ConnectToDatabase(DatabaseName,HostName,UserName,Password,Port);
  701. if LongLogFileName<>'' then
  702. begin
  703. {$I-}
  704. Assign(LongLogFile,LongLogFileName);
  705. Reset(LongLogFile);
  706. If IOResult=0 then
  707. begin
  708. UseLongLog:=true;
  709. inc(LongLogOpenCount);
  710. end;
  711. {$I+}
  712. end;
  713. GetIDs;
  714. ProcessFile(LogFileName);
  715. UpdateTestRun;
  716. UpdateTestConfig;
  717. if UseLongLog then
  718. begin
  719. Close(LongLogFile);
  720. if LongLogOpenCount>1 then
  721. Verbose(V_Warning,format('LongLog file was read %d times.',[LongLogOpenCount]));
  722. end
  723. end
  724. else
  725. Verbose(V_ERROR,'Missing log file name');
  726. end.