2
0

dbdigest.pp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. {
  2. $Id$
  3. This file is part of the Free Pascal test suite.
  4. Copyright (c) 2002 by the Free Pascal development team.
  5. This program generates a digest
  6. of the last tests run.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. {$mode objfpc}
  14. {$h+}
  15. program digest;
  16. uses
  17. sysutils,teststr,testu,dbtests;
  18. Type
  19. TTestStatus = (
  20. stFailedToCompile,
  21. stSuccessCompilationFailed,
  22. stFailedCompilationsuccessful,
  23. stSuccessfullyCompiled,
  24. stFailedToRun,
  25. stKnownRunProblem,
  26. stSuccessFullyRun,
  27. stFailedExecuteCompiler,
  28. stFailedExecuteTest,
  29. stSkippingGraphTest,
  30. stSkippingInteractiveTest,
  31. stSkippingKnownBug,
  32. stSkippingCompilerVersionTooLow,
  33. stSkippingCompilerVersionTooHigh,
  34. stSkippingOtherCpu,
  35. stSkippingOtherTarget,
  36. stskippingRunUnit,
  37. stskippingRunTest
  38. );
  39. Const
  40. FirstStatus = stFailedToCompile;
  41. LastStatus = stskippingRunTest;
  42. TestOK : Array[TTestStatus] of Boolean = (
  43. False, // stFailedToCompile,
  44. True, // stSuccessCompilationFailed,
  45. False, // stFailedCompilationsuccessful,
  46. True, // stSuccessfullyCompiled,
  47. False, // stFailedToRun,
  48. True, // stKnownRunProblem,
  49. True, // stSuccessFullyRun,
  50. False, // stFailedExecuteCompiler
  51. False, // stFailedExecuteTest
  52. False, // stSkippingGraphTest,
  53. False, // stSkippingInteractiveTest,
  54. False, // stSkippingKnownBug,
  55. False, // stSkippingCompilerVersionTooLow,
  56. False, // stSkippingCompilerVersionTooHigh,
  57. False, // stSkippingOtherCpu,
  58. False, // stSkippingOtherTarget,
  59. False, // stskippingRunUnit,
  60. False // stskippingRunTest
  61. );
  62. TestSkipped : Array[TTestStatus] of Boolean = (
  63. False, // stFailedToCompile,
  64. False, // stSuccessCompilationFailed,
  65. False, // stFailedCompilationsuccessful,
  66. False, // stSuccessfullyCompiled,
  67. False, // stFailedToRun,
  68. False, // stKnownRunProblem,
  69. False, // stSuccessFullyRun,
  70. False, // stFailedExecuteCompiler
  71. False, // stFailedExecuteTest
  72. True, // stSkippingGraphTest,
  73. True, // stSkippingInteractiveTest,
  74. True, // stSkippingKnownBug,
  75. True, // stSkippingCompilerVersionTooLow,
  76. True, // stSkippingCompilerVersionTooHigh,
  77. True, // stSkippingOtherCpu,
  78. True, // stSkippingOtherTarget,
  79. True, // stskippingRunUnit,
  80. True // stskippingRunTest
  81. );
  82. ExpectRun : Array[TTestStatus] of Boolean = (
  83. False, // stFailedToCompile,
  84. False, // stSuccessCompilationFailed,
  85. False, // stFailedCompilationsuccessful,
  86. True , // stSuccessfullyCompiled,
  87. False, // stFailedToRun,
  88. False, // stKnownRunProblem,
  89. False, // stSuccessFullyRun,
  90. False, // stFailedExecuteCompiler
  91. False, // stFailedExecuteTest
  92. False, // stSkippingGraphTest,
  93. False, // stSkippingInteractiveTest,
  94. False, // stSkippingKnownBug,
  95. False, // stSkippingCompilerVersionTooLow,
  96. False, // stSkippingCompilerVersionTooHigh,
  97. False, // stSkippingOtherCpu,
  98. False, // stSkippingOtherTarget,
  99. False, // stskippingRunUnit,
  100. False // stskippingRunTest
  101. );
  102. StatusText : Array[TTestStatus] of String = (
  103. failed_to_compile,
  104. success_compilation_failed,
  105. failed_compilation_successful ,
  106. successfully_compiled ,
  107. failed_to_run ,
  108. known_problem ,
  109. successfully_run ,
  110. failed_to_execute_compiler,
  111. failed_to_execute_test,
  112. skipping_graph_test ,
  113. skipping_interactive_test ,
  114. skipping_known_bug ,
  115. skipping_compiler_version_too_low,
  116. skipping_compiler_version_too_high,
  117. skipping_other_cpu ,
  118. skipping_other_target ,
  119. skipping_run_unit ,
  120. skipping_run_test
  121. );
  122. SQLField : Array[TTestStatus] of String = (
  123. 'TU_FAILEDTOCOMPILE',
  124. 'TU_SUCCESSFULLYFAILED',
  125. 'TU_FAILEDTOFAIL',
  126. 'TU_SUCCESFULLYCOMPILED',
  127. 'TU_FAILEDTORUN',
  128. 'TU_KNOWNPROBLEM',
  129. 'TU_SUCCESSFULLYRUN',
  130. 'TU_FAILEDTOCOMPILE', // Combined with compiler failures
  131. 'TU_FAILEDTORUN', // Combined with compiler failures
  132. 'TU_SKIPPEDGRAPHTEST',
  133. 'TU_SKIPPEDINTERACTIVETEST',
  134. 'TU_KNOWNBUG',
  135. 'TU_COMPILERVERIONTOOLOW',
  136. 'TU_COMPILERVERIONTOOHIGH',
  137. 'TU_OTHERCPU',
  138. 'TU_OTHERTARGET',
  139. 'TU_UNIT',
  140. 'TU_SKIPPINGRUNTEST'
  141. );
  142. Var
  143. StatusCount : Array[TTestStatus] of Integer;
  144. UnknownLines,
  145. unexpected_run : Integer;
  146. next_should_be_run : boolean;
  147. var
  148. prevline : string;
  149. Procedure ExtractTestFileName(Var Line : string);
  150. Var I : integer;
  151. begin
  152. I:=Pos(' ',Line);
  153. If (I<>0) then
  154. Line:=Copy(Line,1,I-1);
  155. end;
  156. Function Analyse(Var Line : string; Var Status : TTestStatus) : Boolean;
  157. Var
  158. TS : TTestStatus;
  159. Found : Boolean;
  160. begin
  161. Result:=False;
  162. For TS:=FirstStatus to LastStatus do
  163. begin
  164. Result:=Pos(StatusText[TS],Line)=1;
  165. If Result then
  166. begin
  167. Status:=TS;
  168. Delete(Line,1,Length(StatusText[TS]));
  169. ExtractTestFileName(Line);
  170. Break;
  171. end;
  172. end;
  173. end;
  174. Type
  175. TConfigOpt = (
  176. coDatabaseName,
  177. soHost,
  178. coUserName,
  179. coPassword,
  180. coLogFile,
  181. coOS,
  182. coCPU,
  183. coVersion,
  184. coDate,
  185. coSubmitter,
  186. coMachine,
  187. coComment
  188. );
  189. Const
  190. ConfigStrings : Array [TConfigOpt] of string = (
  191. 'databasename',
  192. 'host',
  193. 'username',
  194. 'password',
  195. 'logfile',
  196. 'os',
  197. 'cpu',
  198. 'version',
  199. 'date',
  200. 'submitter',
  201. 'machine',
  202. 'comment'
  203. );
  204. ConfigOpts : Array[TConfigOpt] of char
  205. = ('d','h','u','p','l','o','c','v','t','s','m','C');
  206. Var
  207. TestOS,
  208. TestCPU,
  209. TestVersion,
  210. DatabaseName,
  211. HostName,
  212. UserName,
  213. Password,
  214. LogFileName,
  215. Submitter,
  216. Machine,
  217. Comment : String;
  218. TestDate : TDateTime;
  219. Procedure SetOpt (O : TConfigOpt; Value : string);
  220. begin
  221. Case O of
  222. coDatabaseName : DatabaseName:=Value;
  223. soHost : HostName:=Value;
  224. coUserName : UserName:=Value;
  225. coPassword : Password:=Value;
  226. coLogFile : LogFileName:=Value;
  227. coOS : TestOS:=Value;
  228. coCPU : TestCPU:=Value;
  229. coVersion : TestVersion:=Value;
  230. coDate : TestDate:=StrToDate(Value);
  231. coSubmitter : Submitter:=Value;
  232. coMachine : Machine:=Value;
  233. coComment : Comment:=Value;
  234. end;
  235. end;
  236. Function ProcessOption(S: String) : Boolean;
  237. Var
  238. N : String;
  239. I : Integer;
  240. Found : Boolean;
  241. co,o : TConfigOpt;
  242. begin
  243. Verbose(V_DEBUG,'Processing option: '+S);
  244. I:=Pos('=',S);
  245. Result:=(I<>0);
  246. If Result then
  247. begin
  248. N:=Copy(S,1,I-1);
  249. Delete(S,1,I);
  250. For co:=low(TConfigOpt) to high(TConfigOpt) do
  251. begin
  252. Result:=CompareText(ConfigStrings[co],N)=0;
  253. If Result then
  254. begin
  255. o:=co;
  256. Break;
  257. end;
  258. end;
  259. end;
  260. If Result then
  261. SetOpt(co,S)
  262. else
  263. Verbose(V_ERROR,'Unknown option : '+n+S);
  264. end;
  265. Procedure ProcessConfigfile(FN : String);
  266. Var
  267. F : Text;
  268. S : String;
  269. I : Integer;
  270. begin
  271. If Not FileExists(FN) Then
  272. Exit;
  273. Verbose(V_DEBUG,'Parsing config file: '+FN);
  274. Assign(F,FN);
  275. {$i-}
  276. Reset(F);
  277. If IOResult<>0 then
  278. Exit;
  279. {$I+}
  280. While not(EOF(F)) do
  281. begin
  282. ReadLn(F,S);
  283. S:=trim(S);
  284. I:=Pos('#',S);
  285. If I<>0 then
  286. S:=Copy(S,1,I-1);
  287. If (S<>'') then
  288. ProcessOption(S);
  289. end;
  290. Close(F);
  291. end;
  292. Procedure ProcessCommandLine;
  293. Var
  294. I : Integer;
  295. O,V : String;
  296. c,co : TConfigOpt;
  297. Found : Boolean;
  298. begin
  299. I:=1;
  300. While I<=ParamCount do
  301. begin
  302. O:=Paramstr(I);
  303. Found:=Length(O)=2;
  304. If Found then
  305. For co:=low(TConfigOpt) to high(TConfigOpt) do
  306. begin
  307. Found:=(O[2]=ConfigOpts[co]);
  308. If Found then
  309. begin
  310. c:=co;
  311. Break;
  312. end;
  313. end;
  314. If Not Found then
  315. Verbose(V_ERROR,'Illegal command-line option : '+O)
  316. else
  317. begin
  318. Found:=(I<ParamCount);
  319. If Not found then
  320. Verbose(V_ERROR,'Option requires argument : '+O)
  321. else
  322. begin
  323. inc(I);
  324. O:=Paramstr(I);
  325. SetOpt(c,o);
  326. end;
  327. end;
  328. Inc(I);
  329. end;
  330. end;
  331. Var
  332. TestCPUID : Integer;
  333. TestOSID : Integer;
  334. TestVersionID : Integer;
  335. TestRunID : Integer;
  336. Procedure GetIDs;
  337. begin
  338. TestCPUID := GetCPUId(TestCPU);
  339. If TestCPUID=-1 then
  340. Verbose(V_Error,'NO ID for CPU "'+TestCPU+'" found.');
  341. TestOSID := GetOSID(TestOS);
  342. If TestOSID=-1 then
  343. Verbose(V_Error,'NO ID for OS "'+TestOS+'" found.');
  344. TestVersionID := GetVersionID(TestVersion);
  345. If TestVersionID=-1 then
  346. Verbose(V_Error,'NO ID for version "'+TestVersion+'" found.');
  347. If (Round(TestDate)=0) then
  348. Testdate:=Now;
  349. TestRunID:=GetRunID(TestOSID,TestCPUID,TestVersionID,TestDate);
  350. If (TestRunID=-1) then
  351. begin
  352. TestRunID:=AddRun(TestOSID,TestCPUID,TestVersionID,TestDate);
  353. If TestRUnID=-1 then
  354. Verbose(V_Error,'Could not insert new testrun record!');
  355. end
  356. else
  357. CleanTestRun(TestRunID);
  358. end;
  359. Function GetLog(FN : String) : String;
  360. begin
  361. FN:=ChangeFileExt(FN,'.elg');
  362. If FileExists(FN) then
  363. Result:=GetFileContents(FN)
  364. else
  365. Result:='';
  366. end;
  367. Procedure Processfile (FN: String);
  368. var
  369. logfile : text;
  370. line : string;
  371. TS : TTestStatus;
  372. ID : integer;
  373. Testlog : string;
  374. begin
  375. Assign(logfile,FN);
  376. {$i-}
  377. reset(logfile);
  378. if ioresult<>0 then
  379. Verbose(V_Error,'Unable to open log file'+logfilename);
  380. {$i+}
  381. while not eof(logfile) do
  382. begin
  383. readln(logfile,line);
  384. If analyse(line,TS) then
  385. begin
  386. Verbose(V_NORMAL,'Analysing result for test '+Line);
  387. Inc(StatusCount[TS]);
  388. If Not ExpectRun[TS] then
  389. begin
  390. ID:=RequireTestID(Line);
  391. If (ID<>-1) then
  392. begin
  393. If Not (TestOK[TS] or TestSkipped[TS]) then
  394. TestLog:=GetLog(Line)
  395. else
  396. TestLog:='';
  397. AddTestResult(ID,TestRunID,Ord(TS),TestOK[TS],TestSkipped[TS],TestLog);
  398. end;
  399. end
  400. end
  401. else
  402. Inc(UnknownLines);
  403. end;
  404. close(logfile);
  405. end;
  406. procedure UpdateTestRun;
  407. var
  408. i : TTestStatus;
  409. qry : string;
  410. res : TQueryResult;
  411. begin
  412. qry:='UPDATE TESTRUN SET ';
  413. for i:=low(TTestStatus) to high(TTestStatus) do
  414. qry:=qry+format('%s=%d, ',[SQLField[i],StatusCount[i]]);
  415. qry:=qry+format('TU_SUBMITTER="%s", TU_MACHINE="%s", TU_COMMENT="%s"',[Submitter,Machine,Comment]);
  416. qry:=qry+' WHERE TU_ID='+format('%d',[TestRunID]);
  417. RunQuery(Qry,res)
  418. end;
  419. begin
  420. ProcessConfigFile('dbdigest.cfg');
  421. ProcessCommandLine;
  422. If LogFileName<>'' then
  423. begin
  424. ConnectToDatabase(DatabaseName,HostName,UserName,Password);
  425. GetIDs;
  426. ProcessFile(LogFileName);
  427. UpdateTestRun;
  428. end
  429. else
  430. Verbose(V_ERROR,'Missing log file name');
  431. end.
  432. {
  433. $Log$
  434. Revision 1.12 2004-04-29 22:03:18 peter
  435. * support new execute errors
  436. Revision 1.11 2003/10/17 08:08:07 florian
  437. * cosmetic fix in console output
  438. Revision 1.10 2003/10/15 21:45:50 florian
  439. + added submitter, machine and comment field to sql version
  440. Revision 1.9 2003/10/15 19:39:42 florian
  441. * exact result counts are inserted into the table
  442. Revision 1.8 2003/10/13 14:19:02 peter
  443. * digest updated for max version limit
  444. Revision 1.7 2003/10/06 16:53:04 fpc
  445. * allow digest programs on commandline
  446. Revision 1.6 2003/10/04 21:30:21 florian
  447. + added time to timestamp so multiple runs per day can be done
  448. Revision 1.5 2003/10/03 22:51:02 michael
  449. + Changed database structure after suggestion of florian
  450. Revision 1.4 2002/12/24 21:47:49 peter
  451. * NeedTarget, SkipTarget, SkipCPU added
  452. * Retrieve compiler info in a single call for 1.1 compiler
  453. Revision 1.3 2002/12/21 15:39:11 michael
  454. * Some verbosity changes
  455. Revision 1.2 2002/12/21 15:31:16 michael
  456. + Added support for compiler version
  457. Revision 1.1 2002/12/17 15:04:32 michael
  458. + Added dbdigest to store results in a database
  459. Revision 1.2 2002/11/18 16:42:43 pierre
  460. + KNOWNRUNERROR added
  461. Revision 1.1 2002/11/13 15:26:24 pierre
  462. + digest program added
  463. }