dbdigest.pp 11 KB

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