2
0

dbdigest.pp 10 KB

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