dbdigest.pp 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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. TS:=FirstStatus;
  127. Result:=False;
  128. For TS:=FirstStatus to LastStatus do
  129. begin
  130. Result:=Pos(StatusText[TS],Line)=1;
  131. If Result then
  132. begin
  133. Status:=TS;
  134. Delete(Line,1,Length(StatusText[TS]));
  135. ExtractTestFileName(Line);
  136. Break;
  137. end;
  138. TS:=succ(TS);
  139. end;
  140. end;
  141. Type
  142. TConfigOpt = (
  143. coDatabaseName,
  144. soHost,
  145. coUserName,
  146. coPassword,
  147. coLogFile,
  148. coOS,
  149. coCPU,
  150. coVersion,
  151. coDate
  152. );
  153. Const
  154. ConfigStrings : Array [TConfigOpt] of string = (
  155. 'databasename',
  156. 'host',
  157. 'username',
  158. 'password',
  159. 'logfile',
  160. 'os',
  161. 'cpu',
  162. 'version',
  163. 'date'
  164. );
  165. ConfigOpts : Array[TConfigOpt] of char
  166. = ('d','h','u','p','l','o','c','v','t');
  167. Var
  168. TestOS,
  169. TestCPU,
  170. TestVersion,
  171. DatabaseName,
  172. HostName,
  173. UserName,
  174. Password,
  175. LogFileName : String;
  176. TestDate : TDateTime;
  177. Procedure SetOpt (O : TConfigOpt; Value : string);
  178. begin
  179. Case O of
  180. coDatabaseName : DatabaseName:=Value;
  181. soHost : HostName:=Value;
  182. coUserName : UserName:=Value;
  183. coPassword : Password:=Value;
  184. coLogFile : LogFileName:=Value;
  185. coOS : TestOS:=Value;
  186. coCPU : TestCPU:=Value;
  187. coVersion : TestVersion:=Value;
  188. coDate : TestDate:=StrToDate(Value);
  189. end;
  190. end;
  191. Function ProcessOption(S: String) : Boolean;
  192. Var
  193. N : String;
  194. I : Integer;
  195. Found : Boolean;
  196. co,o : TConfigOpt;
  197. begin
  198. Verbose(V_DEBUG,'Processing option: '+S);
  199. I:=Pos('=',S);
  200. Result:=(I<>0);
  201. If Result then
  202. begin
  203. N:=Copy(S,1,I-1);
  204. Delete(S,1,I);
  205. For co:=coDatabaseName to coDate do
  206. begin
  207. Result:=CompareText(ConfigStrings[co],N)=0;
  208. If Result then
  209. begin
  210. o:=co;
  211. Break;
  212. end;
  213. end;
  214. end;
  215. If Result then
  216. SetOpt(co,S)
  217. else
  218. Verbose(V_ERROR,'Unknown option : '+S);
  219. end;
  220. Procedure ProcessConfigfile(FN : String);
  221. Var
  222. F : Text;
  223. S : String;
  224. I : Integer;
  225. begin
  226. If Not FileExists(FN) Then
  227. Exit;
  228. Verbose(V_DEBUG,'Parsing config file: '+FN);
  229. Assign(F,FN);
  230. {$i-}
  231. Reset(F);
  232. If IOResult<>0 then
  233. Exit;
  234. {$I+}
  235. While not(EOF(F)) do
  236. begin
  237. ReadLn(F,S);
  238. S:=trim(S);
  239. I:=Pos('#',S);
  240. If I<>0 then
  241. S:=Copy(S,1,I-1);
  242. If (S<>'') then
  243. ProcessOption(S);
  244. end;
  245. Close(F);
  246. end;
  247. Procedure ProcessCommandLine;
  248. Var
  249. I : Integer;
  250. O,V : String;
  251. c,co : TConfigOpt;
  252. Found : Boolean;
  253. begin
  254. I:=1;
  255. While I<=ParamCount do
  256. begin
  257. O:=Paramstr(I);
  258. Found:=Length(O)=2;
  259. If Found then
  260. For co:=coDatabaseName to coDate do
  261. begin
  262. Found:=(O[2]=ConfigOpts[co]);
  263. If Found then
  264. begin
  265. c:=co;
  266. Break;
  267. end;
  268. end;
  269. If Not Found then
  270. Verbose(V_ERROR,'Illegal command-line option : '+O)
  271. else
  272. begin
  273. Found:=(I<ParamCount);
  274. If Not found then
  275. Verbose(V_ERROR,'Option requires argument : '+O)
  276. else
  277. begin
  278. inc(I);
  279. O:=Paramstr(I);
  280. SetOpt(c,o);
  281. end;
  282. end;
  283. Inc(I);
  284. end;
  285. end;
  286. Var
  287. TestCPUID : Integer;
  288. TestOSID : Integer;
  289. TestVersionID : Integer;
  290. Procedure GetIDs;
  291. begin
  292. TestCPUID := GetCPUId(TestCPU);
  293. If TestCPUID=-1 then
  294. Verbose(V_Error,'NO ID for CPU "'+TestCPU+'" found.');
  295. TestOSID := GetOSID(TestOS);
  296. If TestOSID=-1 then
  297. Verbose(V_Error,'NO ID for OS "'+TestOS+'" found.');
  298. TestVersionID := GetVersionID(TestVersion);
  299. If TestVersionID=-1 then
  300. Verbose(V_Error,'NO ID for version "'+TestVersion+'" found.');
  301. If (Round(TestDate)=0) then
  302. Testdate:=Date;
  303. end;
  304. Function GetLog(FN : String) : String;
  305. begin
  306. FN:=ChangeFileExt(FN,'.elg');
  307. If FileExists(FN) then
  308. Result:=GetFileContents(FN)
  309. else
  310. Result:='';
  311. end;
  312. Procedure Processfile (FN: String);
  313. var
  314. logfile : text;
  315. line : string;
  316. TS : TTestStatus;
  317. ID : integer;
  318. Testlog : string;
  319. begin
  320. Assign(logfile,FN);
  321. {$i-}
  322. reset(logfile);
  323. if ioresult<>0 then
  324. Verbose(V_Error,'Unable to open log file'+logfilename);
  325. {$i+}
  326. while not eof(logfile) do
  327. begin
  328. readln(logfile,line);
  329. If analyse(line,TS) then
  330. begin
  331. Verbose(V_NORMAL,'Analysing result for test'+Line);
  332. Inc(StatusCount[TS]);
  333. If Not ExpectRun[TS] then
  334. begin
  335. ID:=RequireTestID(Line);
  336. If (ID<>-1) then
  337. begin
  338. If Not (TestOK[TS] or TestSkipped[TS]) then
  339. TestLog:=GetLog(Line)
  340. else
  341. TestLog:='';
  342. AddTestResult(ID,TestOSID,TestCPUID,TestVersionID,Ord(TS),
  343. TestOK[TS],TestSkipped[TS],
  344. TestLog,
  345. TestDate);
  346. end;
  347. end
  348. end
  349. else
  350. Inc(UnknownLines);
  351. end;
  352. close(logfile);
  353. end;
  354. begin
  355. ProcessConfigFile('dbdigest.cfg');
  356. ProcessCommandLine;
  357. If LogFileName<>'' then
  358. begin
  359. ConnectToDatabase(DatabaseName,HostName,UserName,Password);
  360. GetIDs;
  361. ProcessFile(LogFileName)
  362. end
  363. else
  364. Verbose(V_ERROR,'Missing log file name');
  365. end.
  366. {
  367. $Log$
  368. Revision 1.4 2002-12-24 21:47:49 peter
  369. * NeedTarget, SkipTarget, SkipCPU added
  370. * Retrieve compiler info in a single call for 1.1 compiler
  371. Revision 1.3 2002/12/21 15:39:11 michael
  372. * Some verbosity changes
  373. Revision 1.2 2002/12/21 15:31:16 michael
  374. + Added support for compiler version
  375. Revision 1.1 2002/12/17 15:04:32 michael
  376. + Added dbdigest to store results in a database
  377. Revision 1.2 2002/11/18 16:42:43 pierre
  378. + KNOWNRUNERROR added
  379. Revision 1.1 2002/11/13 15:26:24 pierre
  380. + digest program added
  381. }