dbdigest.pp 8.5 KB

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