dbdigest.pp 9.7 KB

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