utests.pp 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598
  1. {$mode objfpc}
  2. {$h+}
  3. unit utests;
  4. interface
  5. {$ifdef FPC}
  6. {$ifdef VER2_4}
  7. {$define USE_FPCGI}
  8. {$endif VER2_4}
  9. {$ifdef VER2_5}
  10. {$define USE_FPCGI}
  11. {$endif VER2_5}
  12. {$endif FPC}
  13. {$undef USE_FPCGI}
  14. uses
  15. {$ifdef USE_FPCGI}
  16. fpcgi,
  17. {$else not USE_FPCGI}
  18. cgiapp,
  19. {$endif not USE_FPCGI}
  20. sysutils,mysql50conn,sqldb,whtml,dbwhtml,db,
  21. tresults,
  22. Classes,ftFont,fpimage,fpimgcanv,fpWritePng,fpcanvas;
  23. const
  24. TestsuiteURLPrefix='http://www.freepascal.org/testsuite/';
  25. TestsuiteBin='testsuite.cgi';
  26. ViewURL='http://svn.freepascal.org/cgi-bin/viewvc.cgi/';
  27. TestsSubDir='/tests/';
  28. DataBaseSubDir='/packages/fcl-db/tests/';
  29. var
  30. TestsuiteCGIURL : string;
  31. Type
  32. TTestSuite = Class(TCgiApplication)
  33. Private
  34. FHTMLWriter : THtmlWriter;
  35. FComboBoxProducer : TComboBoxProducer;
  36. FDB : TSQLConnection;
  37. FTrans : TSQLTransaction;
  38. FRunID,
  39. FCompareRunID,
  40. FTestFileID,
  41. FTestFileName,
  42. FVersion,
  43. FVersionBranch,
  44. FCond,
  45. FSubmitter,
  46. FMachine,
  47. FComment,
  48. FCPU,
  49. FOS : String;
  50. FViewVCURL : String;
  51. FDate : TDateTime;
  52. FDebug,
  53. FListAll,
  54. FNoSkipped,
  55. FOnlyFailed : Boolean;
  56. FRunSkipCount,
  57. FRunFailedCount,
  58. FRunCount : Integer;
  59. FAction,
  60. FLimit : Integer;
  61. FTestLastDays : Integer;
  62. FNeedEnd : boolean;
  63. Procedure GetOverviewRowAttr(Sender : TObject; Var BGColor : String;
  64. Var Align : THTMLAlign; Var VAlign : THTMLValign;
  65. Var CustomAttr : String) ;
  66. Procedure GetRunRowAttr(Sender : TObject; Var BGColor : String;
  67. Var Align : THTMLAlign; Var VAlign : THTMLValign;
  68. Var CustomAttr : String) ;
  69. Procedure FormatFailedOverview(Sender : TObject; Var CellData : String);
  70. Procedure FormatTestRunOverview(Sender : TObject; Var CellData : String);
  71. Procedure FormatFileDetails(Sender: TObject; var CellData: String);
  72. Procedure FormatFileIDDetails(Sender: TObject; var CellData: String);
  73. Procedure FormatTestResult(Sender: TObject; var CellData: String);
  74. Function FormatDetailURL(const RunIdStr, CellData : String) : string;
  75. Procedure DoDrawPie(Img : TFPCustomImage; Skipped,Failed,Total : Integer);
  76. Public
  77. Function CreateDataset(Qry : String) : TSQLQuery;
  78. Function CreateTableProducer(DS : TDataset) :TTableProducer;
  79. Procedure DefaultTableFromQuery(Qry,ALink : String; IncludeRecordCount : Boolean);
  80. Procedure ComboBoxFromQuery(Const ComboName,Qry : String);
  81. Procedure ComboBoxFromQuery(Const ComboName,Qry,Value : String);
  82. Function GetSingleTon(Const Qry : String) : String;
  83. Function GetOSName(ID : String) : String;
  84. Function GetCPUName(ID : String) : String;
  85. Function GetVersionName(ID : String) : String;
  86. Function GetTestFileName(ID : String) : String;
  87. Function GetFailCount(RunID : longint) : string;
  88. Function InitCGIVars : Integer;
  89. Procedure DoRun; override;
  90. Procedure EmitOverviewForm;
  91. Procedure EmitHistoryForm;
  92. Procedure ShowRunResults;
  93. Procedure ShowRunComparison;
  94. Procedure ShowOneTest;
  95. Procedure ShowHistory;
  96. Function ConnectToDB : Boolean;
  97. procedure DisconnectFromDB;
  98. Procedure EmitTitle(ATitle : String);
  99. Procedure EmitEnd;
  100. Procedure ShowRunOverview;
  101. Procedure CreateRunPie;
  102. Function ShowRunData : Boolean;
  103. end;
  104. implementation
  105. Const
  106. {$i utests.cfg}
  107. { if utests.cfg is missed, create one with the following contents:
  108. DefDatabase = 'TESTSUITE';
  109. DefHost = '';
  110. DefDBUser = ''; // fill this in when compiling.
  111. DefPassword = ''; // fill this in, too.
  112. }
  113. Const
  114. OldTestResultsTableName = 'OLDTESTRESULTS';
  115. NewTestResultsTableName = 'TESTRESULTS';
  116. LastOldTestRun = 91178;
  117. Function TestResultsTableName(const RunId : String) : string;
  118. var
  119. RunIDVal : qword;
  120. Error : word;
  121. begin
  122. system.val (RunId,RunIdVal,error);
  123. if (error<>0) then
  124. result:='ErrorTable'
  125. else if (RunIdVal <= LastOldTestRun) then
  126. result:=OldTestResultsTableName
  127. else
  128. result:=NewTestResultsTableName;
  129. end;
  130. Var
  131. SDetailsURL : string;
  132. type
  133. known_versions = (
  134. ver_unknown,
  135. ver_1_0_10,
  136. ver_2_0_0,
  137. ver_2_0_1,
  138. ver_2_0_2,
  139. ver_2_0_3,
  140. ver_2_0_4,
  141. ver_2_0_5,
  142. ver_2_1_2,
  143. ver_2_1_4,
  144. ver_2_2_0,
  145. ver_2_2_1,
  146. ver_2_2_2,
  147. ver_2_2_3,
  148. ver_2_2_4,
  149. ver_2_2_5,
  150. ver_2_3_1,
  151. ver_2_4_0,
  152. ver_2_4_1,
  153. ver_2_4_2,
  154. ver_2_4_3,
  155. ver_2_4_4,
  156. ver_2_4_5,
  157. ver_2_5_1,
  158. ver_2_7_1);
  159. const
  160. ver_trunk = high (known_versions);
  161. const
  162. ver_string : array[known_versions] of string =
  163. (
  164. 'unknown',
  165. '1.0.10',
  166. '2.0.0',
  167. '2.0.1',
  168. '2.0.2',
  169. '2.0.3',
  170. '2.0.4',
  171. '2.0.5',
  172. '2.1.2',
  173. '2.1.4',
  174. '2.2.0',
  175. '2.2.1',
  176. '2.2.2',
  177. '2.2.3',
  178. '2.2.4',
  179. '2.2.5',
  180. '2.3.1',
  181. '2.4.0',
  182. '2.4.1',
  183. '2.4.2',
  184. '2.4.3',
  185. '2.4.4',
  186. '2.4.5',
  187. '2.5.1',
  188. '2.7.1'
  189. );
  190. ver_branch : array [known_versions] of string =
  191. (
  192. '',
  193. '',
  194. 'tags/release_2_0_0',
  195. 'branches/fixes_2_0',
  196. 'tags/release_2_0_2',
  197. 'branches/fixes_2_0',
  198. 'tags/release_2_0_4',
  199. 'branches/fixes_2_0',
  200. 'tags/release_2_1_2',
  201. 'tags/release_2_1_4',
  202. 'tags/release_2_2_0',
  203. 'branches/fixes_2_2',
  204. 'tags/release_2_2_2',
  205. 'branches/fixes_2_2',
  206. 'tags/release_2_2_4',
  207. 'branches/fixes_2_2',
  208. 'tags/release_2_4_0',
  209. 'tags/release_2_4_0',
  210. 'tags/release_2_4_2',
  211. 'tags/release_2_4_2',
  212. 'tags/release_2_4_4',
  213. 'tags/release_2_4_4',
  214. 'branches/fixes_2_4',
  215. 'branches/fixes_2_6',
  216. 'trunk'
  217. );
  218. Procedure TTestSuite.DoRun;
  219. begin
  220. Try
  221. Try
  222. Case InitCGIVars of
  223. 0 : EmitOverviewForm;
  224. 1 :
  225. if Length(FCompareRunID) = 0 then
  226. ShowRunResults
  227. else
  228. ShowRunComparison;
  229. 2 : CreateRunPie;
  230. 3 : ShowOneTest;
  231. 4 : ShowHistory;
  232. {$ifdef TEST}
  233. 98 :
  234. begin
  235. ///EmitOverviewForm;
  236. system.Writeln(stdout,'<PRE>');
  237. system.Writeln(stdout,'paramstr(0) is ',paramstr(0));
  238. system.FreeMem(pointer($ffffffff));
  239. system.Writeln(stdout,'</PRE>');
  240. system.Flush(stdout);
  241. end;
  242. 99 :
  243. begin
  244. EmitOverviewForm;
  245. system.Writeln(stdout,'<PRE>');
  246. system.Dump_stack(stdout,get_frame);
  247. system.Writeln(stdout,'</PRE>');
  248. system.Flush(stdout);
  249. end;
  250. {$endif TEST}
  251. end;
  252. finally
  253. EmitEnd;
  254. DisConnectFromDB;
  255. end;
  256. Finally
  257. Terminate;
  258. end;
  259. end;
  260. Function TTestSuite.InitCGIVars : Integer;
  261. Var
  262. S : String;
  263. begin
  264. FHtmlWriter:=THTMLWriter.Create(Response);
  265. FComboBoxProducer:=TComboBoxProducer.Create(Self);
  266. DateSeparator:='/';
  267. Result:=0;
  268. S:=RequestVariables['action'];
  269. if Length(S) = 0 then
  270. S:=RequestVariables['TESTACTION'];
  271. if S='View history' then
  272. FAction:=4
  273. else
  274. FAction:=StrToIntDef(S,0);
  275. S:=RequestVariables['limit'];
  276. if Length(S) = 0 then
  277. S:=RequestVariables['TESTLIMIT'];
  278. FLimit:=StrToIntDef(S,50);
  279. FVersion:=RequestVariables['version'];
  280. if Length(FVersion) = 0 then
  281. FVersion:=RequestVariables['TESTVERSION'];
  282. FOS:=RequestVariables['os'];
  283. if Length(FOS) = 0 then
  284. FOS:=RequestVariables['TESTOS'];
  285. FCPU:=RequestVariables['cpu'];
  286. if Length(FCPU) = 0 then
  287. FCPU:=RequestVariables['TESTCPU'];
  288. FCond:=RequestVariables['cond'];
  289. if Length(FCond) = 0 then
  290. FCond:=RequestVariables['TESTCOND'];
  291. FComment:=RequestVariables['comment'];
  292. if Length(FComment) = 0 then
  293. FComment:=RequestVariables['TESTCOMMENT'];
  294. FSubmitter:=RequestVariables['submitter'];
  295. if Length(FSubmitter) = 0 then
  296. FSubmitter:=RequestVariables['TESTSUBMITTER'];
  297. FMachine:=RequestVariables['machine'];
  298. if Length(FMachine) = 0 then
  299. FMachine:=RequestVariables['TESTMACHINE'];
  300. FRunID:=RequestVariables['run1id'];
  301. if Length(FRunID) = 0 then
  302. FRunID:=RequestVariables['TESTRUN'];
  303. S:=RequestVariables['lastdays'];
  304. if Length(S) = 0 then
  305. S:=RequestVariables['TESTLASTDAYS'];
  306. FTestLastDays:=StrToIntDef(S,31);
  307. S:=RequestVariables['date'];
  308. if Length(S) = 0 then
  309. S:=RequestVariables['TESTDATE'];
  310. if Length(S) > 0 then
  311. try
  312. FDate:=StrToDate(S);
  313. except
  314. FDate:=0;
  315. end;
  316. S:=RequestVariables['failedonly'];
  317. if Length(S) = 0 then
  318. S:=RequestVariables['TESTFAILEDONLY'];
  319. FOnlyFailed:=(S='1');
  320. S:=RequestVariables['noskipped'];
  321. if Length(S) = 0 then
  322. S:=RequestVariables['TESTNOSKIPPED'];
  323. FNoSkipped:=(S='1');
  324. FCompareRunID:=RequestVariables['run2id'];
  325. FTestFileID:=RequestVariables['testfileid'];
  326. FTestFileName:=RequestVariables['testfilename'];
  327. FRunCount:=StrToIntDef(RequestVariables['PIETOTAL'],0);
  328. FRunSkipCount:=StrToIntDef(RequestVariables['PIESKIPPED'],0);
  329. FRunFailedCount:=StrToIntDef(RequestVariables['PIEFAILED'],0);
  330. S:=RequestVariables['DEBUGCGI'];
  331. FDebug:=(S='1');
  332. S:=RequestVariables['listall'];
  333. FListAll:=(S='1');
  334. Result:=FAction;
  335. end;
  336. Function TTestSuite.ConnectToDB : Boolean;
  337. begin
  338. Result:=False;
  339. FDB:=TMySQl50Connection.Create(Self);
  340. FDB.HostName:=DefHost;
  341. FDB.DatabaseName:=DefDatabase;
  342. FDB.UserName:=DefDBUser;
  343. FDB.Password:=DefPassword;
  344. FTrans := TSQLTransaction.Create(nil);
  345. FTrans.DataBase := FDB;
  346. FDB.Transaction := FTrans;
  347. FDB.Connected:=True;
  348. Result:=True;
  349. end;
  350. procedure TTestSuite.DisconnectFromDB;
  351. begin
  352. If Assigned(FDB) then
  353. begin
  354. if (FDB.Connected) then
  355. FDB.Connected:=False;
  356. FreeAndNil(FDB);
  357. FreeAndNil(FTrans);
  358. end;
  359. end;
  360. Procedure TTestSuite.ComboBoxFromQuery(Const ComboName,Qry: String);
  361. begin
  362. ComboBoxFromQuery(ComboName,Qry,'')
  363. end;
  364. Procedure TTestSuite.ComboBoxFromQuery(Const ComboName,Qry,Value : String);
  365. Var
  366. Q : TSQLQuery;
  367. begin
  368. Q:=TSQLQuery.Create(Self);
  369. try
  370. Q.Database:=FDB;
  371. Q.Transaction:=FTrans;
  372. Q.SQL.Text:=Qry;
  373. Q.Open;
  374. FComboboxProducer.Dataset:=Q;
  375. FComboBoxProducer.ValueField:=Q.Fields[0].FieldName;
  376. FComboBoxProducer.DataField:=Q.Fields[1].FieldName;
  377. FComboBoxProducer.Value:=Value;
  378. FComboBoxProducer.InputName:=ComboName;
  379. FComboBoxProducer.CreateComboBox(Response);
  380. Finally
  381. Q.Free;
  382. end;
  383. end;
  384. Function TTestSuite.GetSingleton(Const Qry : String) : String;
  385. Var
  386. Q : TSQLQuery;
  387. begin
  388. Result:='';
  389. if FDEbug then
  390. begin
  391. system.Writeln('Query=',Qry);
  392. system.flush(output);
  393. end;
  394. Q:=TSQLQuery.Create(Self);
  395. try
  396. Q.Database:=FDB;
  397. Q.Transaction:=FTrans;
  398. Q.SQL.Text:=Qry;
  399. Q.Open;
  400. Try
  401. if FDebug and (Q.FieldCount<>1) then
  402. begin
  403. system.Writeln('GetSingleton number of fields is not 1, but ',
  404. Q.FieldCount);
  405. system.flush(output);
  406. end;
  407. If Not (Q.EOF and Q.BOF) then
  408. Result:=Q.Fields[0].AsString;
  409. Finally
  410. Q.Close;
  411. end;
  412. finally
  413. Q.Free;
  414. end;
  415. end;
  416. Procedure TTestSuite.EmitTitle(ATitle : String);
  417. begin
  418. AddResponseLn('<HTML>');
  419. AddResponseLn('<TITLE>'+ATitle+'</TITLE>');
  420. AddResponseLn('<BODY>');
  421. FNeedEnd:=true;
  422. end;
  423. Procedure TTestSuite.EmitOverviewForm;
  424. begin
  425. ConnectToDB;
  426. ContentType:='text/html';
  427. EmitContentType;
  428. EmitTitle(Title);
  429. With FHTMLWriter do
  430. begin
  431. HeaderStart(1);
  432. Write('View Test suite results');
  433. HeaderEnd(1);
  434. Write('Please specify search criteria:');
  435. ParagraphStart;
  436. FormStart(TestsuiteCGIURL,'');
  437. if FDebug then
  438. EmitHiddenVar('DEBUGCGI', '1');
  439. TableStart(2,true);
  440. RowStart;
  441. CellStart;
  442. Write('Operating system:');
  443. CellNext;
  444. ComboBoxFromQuery('os','SELECT TO_ID,TO_NAME FROM TESTOS ORDER BY TO_NAME',FOS);
  445. CellEnd;
  446. RowNext;
  447. CellStart;
  448. Write('Processor:');
  449. CellNext;
  450. ComboBoxFromQuery('cpu','SELECT TC_ID,TC_NAME FROM TESTCPU ORDER BY TC_NAME',FCPU);
  451. CellEnd;
  452. RowNext;
  453. CellStart;
  454. Write('Version');
  455. CellNext;
  456. ComboBoxFromQuery('version','SELECT TV_ID,TV_VERSION FROM TESTVERSION ORDER BY TV_VERSION DESC',FVERSION);
  457. CellEnd;
  458. RowNext;
  459. CellStart;
  460. Write('Date');
  461. CellNext;
  462. If (FDate=0) then
  463. EmitInput('date','')
  464. else
  465. EmitInput('date',DateToStr(FDate));
  466. CellEnd;
  467. //if FDebug then
  468. begin
  469. RowNext;
  470. CellStart;
  471. Write('Submitter');
  472. CellNext;
  473. If (FSubmitter='') then
  474. EmitInput('submitter','')
  475. else
  476. EmitInput('submitter',FSubmitter);
  477. CellEnd;
  478. RowNext;
  479. CellStart;
  480. Write('Machine');
  481. CellNext;
  482. If (FMachine='') then
  483. EmitInput('machine','')
  484. else
  485. EmitInput('machine',FMachine);
  486. CellEnd;
  487. RowNext;
  488. CellStart;
  489. Write('Comment');
  490. CellNext;
  491. If (FComment='') then
  492. EmitInput('comment','')
  493. else
  494. EmitInput('comment',FComment);
  495. CellEnd;
  496. RowNext;
  497. CellStart;
  498. Write('Cond');
  499. CellNext;
  500. If (FCond='') then
  501. EmitInput('cond','')
  502. else
  503. EmitInput('cond',FCond);
  504. CellEnd;
  505. end;
  506. RowNext;
  507. CellStart;
  508. Write('Only failed tests');
  509. CellNext;
  510. EmitCheckBox('failedonly','1',FonlyFailed);
  511. CellEnd;
  512. RowNext;
  513. CellStart;
  514. Write('Hide skipped tests');
  515. CellNext;
  516. EmitCheckBox('noskipped','1',FNoSkipped);
  517. CellEnd;
  518. RowEnd;
  519. TableEnd;
  520. ParaGraphStart;
  521. EmitSubmitButton('','Search');
  522. EmitSubmitButton('action','View history');
  523. EmitResetButton('','Reset form');
  524. FormEnd;
  525. end;
  526. ShowRunOverview;
  527. end;
  528. Procedure TTestSuite.EmitHistoryForm;
  529. begin
  530. ConnectToDB;
  531. ContentType:='text/html';
  532. EmitContentType;
  533. EmitTitle(Title);
  534. With FHTMLWriter do
  535. begin
  536. HeaderStart(1);
  537. Write('View Test suite results');
  538. HeaderEnd(1);
  539. Write('Please specify search criteria:');
  540. ParagraphStart;
  541. FormStart(TestsuiteCGIURL,'');
  542. if FDebug then
  543. EmitHiddenVar('DEBUGCGI', '1');
  544. EmitHiddenVar('action','4');
  545. TableStart(2,true);
  546. RowStart;
  547. CellStart;
  548. Write('File:');
  549. CellNext;
  550. EmitInput('testfilename',FTestfilename);
  551. CellEnd;
  552. RowNext;
  553. (* CellStart;
  554. Write('FileID:');
  555. CellNext;
  556. EmitInput('testfileid',FTestfileid);
  557. CellEnd;
  558. RowNext; *)
  559. CellStart;
  560. Write('Operating system:');
  561. CellNext;
  562. ComboBoxFromQuery('os','SELECT TO_ID,TO_NAME FROM TESTOS ORDER BY TO_NAME',FOS);
  563. CellEnd;
  564. RowNext;
  565. CellStart;
  566. Write('Processor:');
  567. CellNext;
  568. ComboBoxFromQuery('cpu','SELECT TC_ID,TC_NAME FROM TESTCPU ORDER BY TC_NAME',FCPU);
  569. CellEnd;
  570. RowNext;
  571. CellStart;
  572. Write('Version');
  573. CellNext;
  574. ComboBoxFromQuery('version','SELECT TV_ID,TV_VERSION FROM TESTVERSION ORDER BY TV_VERSION DESC',FVERSION);
  575. CellEnd;
  576. RowNext;
  577. CellStart;
  578. Write('Date');
  579. CellNext;
  580. If (FDate=0) then
  581. EmitInput('date','')
  582. else
  583. EmitInput('date',DateToStr(FDate));
  584. CellEnd;
  585. RowNext;
  586. CellStart;
  587. Write('Submitter');
  588. CellNext;
  589. If (FSubmitter='') then
  590. EmitInput('submitter','')
  591. else
  592. EmitInput('submitter',FSubmitter);
  593. CellEnd;
  594. RowNext;
  595. CellStart;
  596. Write('Machine');
  597. CellNext;
  598. If (FMachine='') then
  599. EmitInput('machine','')
  600. else
  601. EmitInput('machine',FMachine);
  602. CellEnd;
  603. RowNext;
  604. CellStart;
  605. Write('Comment');
  606. CellNext;
  607. If (FComment='') then
  608. EmitInput('comment','')
  609. else
  610. EmitInput('comment',FComment);
  611. CellEnd;
  612. RowNext;
  613. CellStart;
  614. Write('Limit');
  615. CellNext;
  616. EmitInput('limit',IntToStr(FLimit));
  617. CellEnd;
  618. RowNext;
  619. CellStart;
  620. Write('Cond');
  621. CellNext;
  622. If (FCond='') then
  623. EmitInput('cond','')
  624. else
  625. EmitInput('cond',FCond);
  626. CellEnd;
  627. RowNext;
  628. CellStart;
  629. Write('Only failed tests');
  630. CellNext;
  631. EmitCheckBox('failedonly','1',FonlyFailed);
  632. CellEnd;
  633. RowNext;
  634. CellStart;
  635. Write('Hide skipped tests');
  636. CellNext;
  637. EmitCheckBox('noskipped','1',FNoSkipped);
  638. CellEnd;
  639. RowNext;
  640. CellStart;
  641. Write('List all tests');
  642. CellNext;
  643. EmitCheckBox('listall','1',FListAll);
  644. CellEnd;
  645. RowEnd;
  646. TableEnd;
  647. ParaGraphStart;
  648. EmitSubmitButton('','Search');
  649. EmitResetButton('','Reset form');
  650. FormEnd;
  651. end;
  652. end;
  653. procedure TTestSuite.EmitEnd;
  654. begin
  655. if not FNeedEnd then
  656. exit;
  657. AddResponseLn('</BODY>');
  658. AddResponseLn('</HTML>');
  659. end;
  660. procedure TTestSuite.GetOverviewRowAttr(Sender: TObject; var BGColor: String;
  661. var Align: THTMLAlign; var VAlign: THTMLValign; var CustomAttr: String);
  662. begin
  663. If ((Sender as TTAbleProducer).CurrentRow mod 2=0) then
  664. BGColor:='#EEEEEE'
  665. end;
  666. Function TTestSuite.CreateDataset(Qry : String) : TSQLQuery;
  667. begin
  668. Result:=TSQLQuery.Create(Self);
  669. With Result do
  670. begin
  671. Database:=FDB;
  672. Transaction := FTrans;
  673. SQL.Text:=Qry;
  674. end;
  675. end;
  676. Function TTestSuite.CreateTableProducer(DS : TDataset) :TTableProducer;
  677. begin
  678. Result:=TTableProducer.Create(Self);
  679. Result.Dataset:=DS;
  680. end;
  681. Procedure TTestSuite.DefaultTableFromQuery(Qry,Alink : String; IncludeRecordCount : Boolean);
  682. Var
  683. Q : TSQLQuery;
  684. begin
  685. If FDebug then
  686. Writeln('Query : '+Qry);
  687. Q:=CreateDataset(Qry);
  688. With Q do
  689. try
  690. Open;
  691. Try
  692. With CreateTableProducer(Q) do
  693. Try
  694. Border:=True;
  695. If (Alink<>'') then
  696. begin
  697. CreateColumns(Nil);
  698. If TableColumns.Count>0 then
  699. (TableColumns.Items[0] as TTableColumn).ActionURL:=ALink;
  700. end;
  701. CreateTable(Response);
  702. Finally
  703. Free;
  704. end;
  705. If IncludeRecordCount then
  706. FHTMLWriter.DumpLn(Format('<p>Record count: %d </p>',[Q.RecordCount]));
  707. Finally
  708. Close;
  709. end;
  710. finally
  711. Free;
  712. end;
  713. end;
  714. Procedure TTestSuite.ShowRunOverview;
  715. Const
  716. SOverview = 'SELECT TU_ID as ID,TU_DATE as Date,TC_NAME as CPU,TO_NAME as OS,'+
  717. 'TV_VERSION as Version,COUNT(TR_ID) as Count,'+
  718. '(TU_SUCCESSFULLYFAILED+TU_SUCCESFULLYCOMPILED+TU_SUCCESSFULLYRUN) AS OK,'+
  719. '(TU_FAILEDTOCOMPILE+TU_FAILEDTORUN+TU_FAILEDTOFAIL) as Failed,'+
  720. '(TU_SUCCESSFULLYFAILED+TU_SUCCESFULLYCOMPILED+TU_SUCCESSFULLYRUN+'+
  721. 'TU_FAILEDTOCOMPILE+TU_FAILEDTORUN+TU_FAILEDTOFAIL) as Total,'+
  722. 'TU_SUBMITTER as Submitter, TU_MACHINE as Machine, TU_COMMENT as Comment '+
  723. 'FROM TESTRESULTS,TESTRUN,TESTCPU,TESTOS,TESTVERSION '+
  724. 'WHERE '+
  725. '(TC_ID=TU_CPU_FK) AND '+
  726. '(TO_ID=TU_OS_FK) AND '+
  727. '(TV_ID=TU_VERSION_FK) AND '+
  728. '(TR_TESTRUN_FK=TU_ID) '+
  729. '%s '+
  730. 'GROUP BY TU_ID '+
  731. 'ORDER BY TU_ID DESC LIMIT %d';
  732. Var
  733. S,A,Qry : String;
  734. Q : TSQLQuery;
  735. begin
  736. S:='';
  737. If (FCPU<>'') and (GetCPUName(FCPU)<>'All') then
  738. S:=S+' AND (TU_CPU_FK='+FCPU+')';
  739. If (FVersion<>'') and (GetVersionName(FVersion)<>'All') then
  740. S:=S+' AND (TU_VERSION_FK='+FVERSION+')';
  741. if (FOS<>'') and (GetOSName(FOS)<>'All') then
  742. S:=S+' AND (TU_OS_FK='+FOS+')';
  743. If (Round(FDate)<>0) then
  744. S:=S+' AND (TU_DATE LIKE '''+FormatDateTime('YYYY-MM-DD',FDate)+'%'')';
  745. If FSubmitter<>'' then
  746. S:=S+' AND (TU_SUBMITTER='''+FSubmitter+''')';
  747. If FMachine<>'' then
  748. S:=S+' AND (TU_MACHINE='''+FMachine+''')';
  749. If FComment<>'' then
  750. S:=S+' AND (TU_COMMENT LIKE '''+Fcomment+''')';
  751. If FCond<>'' then
  752. S:=S+' AND ('+FCond+')';
  753. If FOnlyFailed then
  754. S:=S+' AND (TR_OK="-")';
  755. A:=SDetailsURL;
  756. If FOnlyFailed then
  757. A:=A+'&failedonly=1';
  758. If FNoSkipped then
  759. A:=A+'&noskipped=1';
  760. Qry:=Format(SOverview,[S,FLimit]);
  761. If FDebug then
  762. Writeln('Query : '+Qry);
  763. Q:=CreateDataset(Qry);
  764. With Q do
  765. try
  766. Open;
  767. Try
  768. With CreateTableProducer(Q) do
  769. Try
  770. Border:=True;
  771. OnGetRowAttributes:=@GetOverViewRowAttr;
  772. CreateColumns(Nil);
  773. TableColumns.ColumnByName('ID').ActionURL:=A;
  774. TableColumns.ColumnByNAme('Failed').OnGetCellContents:=@FormatFailedOverview;
  775. CreateTable(Response);
  776. Finally
  777. Free;
  778. end;
  779. FHTMLWriter.DumpLn(Format('<p>Record count: %d</p>',[Q.RecordCount]));
  780. Finally
  781. Close;
  782. end;
  783. finally
  784. Free;
  785. end;
  786. end;
  787. Function TTestSuite.GetOSName(ID : String) : String;
  788. begin
  789. if (ID<>'') then
  790. Result:=GetSingleTon('SELECT TO_NAME FROM TESTOS WHERE TO_ID='+ID);
  791. end;
  792. Function TTestSuite.GetTestFileName(ID : String) : String;
  793. begin
  794. if (ID<>'') then
  795. Result:=GetSingleTon('SELECT T_NAME FROM TESTS WHERE T_ID='+ID);
  796. end;
  797. Function TTestsuite.GetFailCount(RunID : longint) : string;
  798. begin
  799. if RunID<>0 then
  800. Result:=GetSingleTon('SELECT (TU_FAILEDTOCOMPILE + TU_FAILEDTOFAIL + TU_FAILEDTORUN) FROM TESTRUN WHERE TU_ID='+IntToStr(RunID));
  801. end;
  802. Function TTestSuite.GetCPUName(ID : String) : String;
  803. begin
  804. if (ID<>'') then
  805. Result:=GetSingleTon('SELECT TC_NAME FROM TESTCPU WHERE TC_ID='+ID);
  806. end;
  807. Function TTestSuite.GetVersionName(ID : String) : String;
  808. begin
  809. if (ID<>'') then
  810. Result:=GetSingleton('SELECT TV_VERSION FROM TESTVERSION WHERE TV_ID='+ID);
  811. end;
  812. Function TTestSuite.ShowRunData : Boolean;
  813. Const
  814. SGetRunData = 'SELECT TU_ID,TU_DATE,TC_NAME,TO_NAME,' +
  815. 'TU_SUBMITTER,TU_MACHINE,TU_COMMENT,TV_VERSION,'+
  816. '(TU_SUCCESSFULLYFAILED+TU_SUCCESFULLYCOMPILED+TU_SUCCESSFULLYRUN) AS OK,'+
  817. '(TU_FAILEDTOCOMPILE+TU_FAILEDTORUN+TU_FAILEDTOFAIL) as Failed,'+
  818. '(TU_SUCCESSFULLYFAILED+TU_SUCCESFULLYCOMPILED+TU_SUCCESSFULLYRUN+'+
  819. 'TU_FAILEDTOCOMPILE+TU_FAILEDTORUN+TU_FAILEDTOFAIL) as Total'+
  820. ' FROM TESTRUN,TESTCPU,TESTOS,TESTVERSION '+
  821. 'WHERE '+
  822. ' (TC_ID=TU_CPU_FK) AND '+
  823. ' (TO_ID=TU_OS_FK) AND '+
  824. ' (TV_ID=TU_VERSION_FK) AND '+
  825. ' (TU_ID=%s)';
  826. Var
  827. Q1,Q2 : TSQLQuery;
  828. F : TField;
  829. Date1, Date2: TDateTime;
  830. begin
  831. Result:=(FRunID<>'');
  832. If Result then
  833. begin
  834. Q1:=CreateDataset(Format(SGetRunData,[FRunID]));
  835. if Length(FCompareRunID) > 0 then
  836. Q2:=CreateDataset(Format(SGetRunData,[FCompareRunID]))
  837. else
  838. Q2:=nil;
  839. Try
  840. Q1.Open;
  841. if Q2 <> nil then
  842. Q2.Open;
  843. Result:=Not (Q1.EOF and Q1.BOF);
  844. If Result then
  845. With FHTMLWriter do
  846. begin
  847. FormStart(TestsuiteCGIURL,'get');
  848. EmitHiddenVar('action', '1');
  849. TableStart(3,true);
  850. RowStart;
  851. CellStart;
  852. Write('Run ID:');
  853. CellNext;
  854. EmitInput('run1id',FRunID);
  855. CellNext;
  856. EmitInput('run2id',FCompareRunID);
  857. CellEnd;
  858. RowNext;
  859. CellStart;
  860. Write('Operating system:');
  861. CellNext;
  862. Write(Q1.FieldByName('TO_NAME').AsString);
  863. CellNext;
  864. if Q2 <> nil then
  865. Write(Q2.FieldByName('TO_NAME').AsString);
  866. CellEnd;
  867. RowNext;
  868. CellStart;
  869. Write('Processor:');
  870. CellNext;
  871. Write(Q1.FieldByName('TC_NAME').AsString);
  872. CellNext;
  873. if Q2 <> nil then
  874. Write(Q2.FieldByName('TC_NAME').AsString);
  875. CellEnd;
  876. RowNext;
  877. CellStart;
  878. Write('Version:');
  879. CellNext;
  880. Write(Q1.FieldByNAme('TV_VERSION').AsString);
  881. CellNext;
  882. if Q2 <> nil then
  883. Write(Q2.FieldByNAme('TV_VERSION').AsString);
  884. CellEnd;
  885. RowNext;
  886. CellStart;
  887. Write('Fails/OK/Total:');
  888. CellNext;
  889. Write(Q1.FieldByName('Failed').AsString);
  890. Write('/'+Q1.FieldByName('OK').AsString);
  891. Write('/'+Q1.FieldByName('Total').AsString);
  892. CellNext;
  893. if Q2 <> nil then
  894. begin
  895. Write(Q2.FieldByName('Failed').AsString);
  896. Write('/'+Q2.FieldByName('Ok').AsString);
  897. Write('/'+Q2.FieldByName('Total').AsString);
  898. end;
  899. CellEnd;
  900. RowNext;
  901. CellStart;
  902. Write('Comment:');
  903. CellNext;
  904. Write(Q1.FieldByName('TU_COMMENT').AsString);
  905. CellNext;
  906. if Q2 <> nil then
  907. Write(Q2.FieldByName('TU_COMMENT').AsString);
  908. CellEnd;
  909. RowNext;
  910. CellStart;
  911. Write('Machine:');
  912. CellNext;
  913. Write(Q1.FieldByName('TU_MACHINE').AsString);
  914. CellNext;
  915. if Q2 <> nil then
  916. Write(Q2.FieldByName('TU_MACHINE').AsString);
  917. CellEnd;
  918. RowNext;
  919. CellStart;
  920. Write('Submitter:');
  921. CellNext;
  922. Write(Q1.FieldByName('TU_SUBMITTER').AsString);
  923. CellNext;
  924. if Q2 <> nil then
  925. Write(Q2.FieldByName('TU_SUBMITTER').AsString);
  926. CellEnd;
  927. RowNext;
  928. CellStart;
  929. Write('Date:');
  930. CellNext;
  931. F := Q1.FieldByName('TU_DATE');
  932. Date1 := F.AsDateTime;
  933. Write(F.AsString);
  934. CellNext;
  935. if Q2 <> nil then
  936. begin
  937. F := Q2.FieldByName('TU_DATE');
  938. Date2 := F.AsDateTime;
  939. Write(F.AsString);
  940. end;
  941. CellEnd;
  942. RowEnd;
  943. TableEnd;
  944. ParagraphStart;
  945. EmitCheckBox('noskipped','1',FNoSkipped);
  946. Write(' Hide skipped tests');
  947. ParagraphEnd;
  948. ParagraphStart;
  949. EmitCheckBox('failedonly','1',FonlyFailed);
  950. Write(' Hide successful tests');
  951. ParagraphEnd;
  952. ParaGraphStart;
  953. EmitSubmitButton('','Show/Compare');
  954. EmitResetButton('','Reset form');
  955. ParagraphEnd;
  956. FormEnd;
  957. { give warning if dates reversed }
  958. if (Q2 <> nil) and (Date1 > Date2) then
  959. begin
  960. ParagraphStart;
  961. Write('Warning: testruns are not compared in chronological order.');
  962. ParagraphEnd;
  963. end;
  964. end;
  965. Finally
  966. Q1.Close;
  967. Q1.Free;
  968. if Q2 <> nil then
  969. begin
  970. Q2.Close;
  971. Q2.Free;
  972. end;
  973. end;
  974. end;
  975. end;
  976. Procedure TTestSuite.ShowRunResults;
  977. Var
  978. S : String;
  979. Qry : String;
  980. Q : TSQLQuery;
  981. FL : String;
  982. begin
  983. ConnectToDB;
  984. ContentType:='text/html';
  985. EmitContentType;
  986. EmitTitle(Title+' : Search Results');
  987. With FHTMLWriter do
  988. begin
  989. HeaderStart(1);
  990. Write('Test suite results for run '+FRunID);
  991. HeaderEnd(1);
  992. HeaderStart(2);
  993. Write('Test run data : ');
  994. HeaderEnd(2);
  995. If ShowRunData then
  996. begin
  997. HeaderStart(2);
  998. Write('Detailed test run results:');
  999. FL:='';
  1000. If FOnlyFailed or FNoSkipped then
  1001. begin
  1002. FL:='';
  1003. If FOnlyFailed then
  1004. FL:='successful';
  1005. if FNoSkipped then
  1006. begin
  1007. If (FL<>'') then
  1008. FL:=FL+' and ';
  1009. FL:=FL+'skipped';
  1010. end;
  1011. Write(' ('+FL+' tests are hidden)');
  1012. end;
  1013. HeaderEnd(2);
  1014. ParaGraphStart;
  1015. S:='SELECT T_ID as Id,T_NAME as Filename,TR_SKIP as Skipped'
  1016. +',TR_OK as OK,TR_RESULT as Result'
  1017. +' FROM '+TESTRESULTSTableName(FRunID)+',TESTS'
  1018. +' WHERE (TR_TEST_FK=T_ID) AND (TR_TESTRUN_FK='+FRunID+') ';
  1019. If FOnlyFailed then
  1020. S:=S+' AND (TR_OK="-")';
  1021. If FNoSkipped then
  1022. S:=S+' AND (TR_SKIP="-")';
  1023. S:=S+' ORDER BY TR_ID ';
  1024. Qry:=S;
  1025. If FDebug then
  1026. begin
  1027. Writeln('Query : '+Qry);
  1028. Flush(stdout);
  1029. end;
  1030. FRunCount:=0;
  1031. FRunSkipCount:=0;
  1032. FRunFailedCount:=0;
  1033. Q:=CreateDataset(Qry);
  1034. With Q do
  1035. try
  1036. Open;
  1037. while not EOF do
  1038. Next;
  1039. RecNo:=0;
  1040. DumpLn(Format('<p>Record count: %d </p>',[Q.RecordCount]));
  1041. Try
  1042. With CreateTableProducer(Q) do
  1043. Try
  1044. Border:=True;
  1045. FL:='Id,Filename';
  1046. If Not FNoSkipped then
  1047. FL:=FL+',Skipped';
  1048. If Not FOnlyFailed then
  1049. FL:=FL+',OK';
  1050. FL:=FL+',Result';
  1051. CreateColumns(FL);
  1052. OnGetRowAttributes:=@GetRunRowAttr;
  1053. TableColumns.ColumnByNAme('Id').OnGetCellContents:=
  1054. @FormatFileIDDetails;
  1055. TableColumns.ColumnByNAme('Filename').OnGetCellContents:=
  1056. @FormatFileDetails;
  1057. TableColumns.ColumnByNAme('Result').OnGetCellContents:=
  1058. @FormatTestResult;
  1059. //(TableColumns.Items[0] as TTableColumn).ActionURL:=ALink;
  1060. CreateTable(Response);
  1061. Finally
  1062. Free;
  1063. end;
  1064. Finally
  1065. Close;
  1066. end;
  1067. finally
  1068. Free;
  1069. end;
  1070. If Not (FRunCount=0) and not (FNoSkipped or FOnlyFailed) then
  1071. begin
  1072. ParaGraphStart;
  1073. TagStart('IMG',Format('Src="'+TestsuiteCGIURL+'?action=2&pietotal=%d&piefailed=%d&pieskipped=%d"',[FRunCount,FRunFailedCount,FRunSkipCount]));
  1074. end;
  1075. end
  1076. else
  1077. Write('No data for test run with ID: '+FRunID);
  1078. end;
  1079. end;
  1080. Procedure TTestSuite.ShowOneTest;
  1081. Var
  1082. S,S2 : String;
  1083. Qry : String;
  1084. Base, Category : string;
  1085. Q : TSQLQuery;
  1086. i : longint;
  1087. FieldName,FieldValue,
  1088. Log,Source : String;
  1089. Res : Boolean;
  1090. ver : known_versions;
  1091. begin
  1092. ConnectToDB;
  1093. ContentType:='text/html';
  1094. EmitContentType;
  1095. if FTestFileID='' then
  1096. FTestFileID:=GetSingleton('SELECT T_ID FROM TESTS WHERE T_NAME LIKE ''%'+
  1097. FTestFileName+'%''');
  1098. if FTestFileID<>'' then
  1099. FTestFileName:=GetTestFileName(FTestFileID);
  1100. EmitTitle(Title+' : File '+FTestFileName+' Results');
  1101. With FHTMLWriter do
  1102. begin
  1103. HeaderStart(1);
  1104. Write('Test suite results for test file '+FTestFileName);
  1105. HeaderEnd(1);
  1106. HeaderStart(2);
  1107. Write('Test run data : ');
  1108. HeaderEnd(2);
  1109. if FRunID<>'' then
  1110. begin
  1111. Res:=ShowRunData;
  1112. Res:=true;
  1113. end
  1114. else
  1115. begin
  1116. // This is useless as it is now
  1117. // It should be integrated into a form probably PM
  1118. Write('Only failed tests');
  1119. EmitCheckBox('failedonly','1',FonlyFailed);
  1120. Write('Hide skipped tests');
  1121. EmitCheckBox('noskipped','1',FNoSkipped);
  1122. Res:=true;
  1123. end;
  1124. If Res then
  1125. begin
  1126. HeaderStart(2);
  1127. Write('Test file "'+FTestFileName+'" information:');
  1128. HeaderEnd(2);
  1129. ParaGraphStart;
  1130. if FTestFileID<>'' then
  1131. S:='SELECT * FROM TESTS WHERE T_ID='+FTestFileID
  1132. else
  1133. S:='SELECT * FROM TESTS WHERE T_NAME='+FTestFileName;
  1134. Q:=CreateDataSet(S);
  1135. With Q do
  1136. Try
  1137. Open;
  1138. Try
  1139. For i:=0 to FieldCount-1 do
  1140. begin
  1141. FieldValue:=Fields[i].AsString;
  1142. FieldName:=Fields[i].DisplayName;
  1143. if (FieldValue<>'') and (FieldValue<>'-') and
  1144. (FieldName<>'T_NAME') and (FieldName<>'T_SOURCE') then
  1145. begin
  1146. if (FieldValue='+') then
  1147. Write('Flag ');
  1148. Write(FieldName);
  1149. Write(' ');
  1150. if FieldValue='+' then
  1151. Write(' set')
  1152. else
  1153. Write(FieldValue);
  1154. DumpLn('<BR>');
  1155. end;
  1156. end;
  1157. Finally
  1158. Close;
  1159. end;
  1160. Finally
  1161. Free;
  1162. end;
  1163. ParaGraphEnd;
  1164. HeaderStart(2);
  1165. Write('Detailed test run results:');
  1166. HeaderEnd(2);
  1167. ParaGraphStart;
  1168. S:='SELECT TR_ID,TR_TESTRUN_FK AS RUN,TR_TEST_FK,TR_OK, TR_SKIP,TR_RESULT '
  1169. //S:='SELECT * '
  1170. +' FROM '+TESTRESULTSTableName(FRunID)
  1171. +' WHERE (TR_TEST_FK='+FTestFileID+')';
  1172. If FOnlyFailed then
  1173. S:=S+' AND (TR_OK="-")';
  1174. if Fcomparerunid<>'' then
  1175. begin
  1176. if TESTRESULTSTableName(FRunID)<>TESTRESULTSTableName(FCompareRunID) then
  1177. begin
  1178. S2:='SELECT TR_ID,TR_TESTRUN_FK AS RUN,TR_TEST_FK,TR_OK, TR_SKIP,TR_RESULT '
  1179. +' FROM '+TESTRESULTSTableName(FCompareRunID)
  1180. +' WHERE (TR_TEST_FK='+FTestFileID+')';
  1181. If FOnlyFailed then
  1182. S2:=S2+' AND (TR_OK="-")';
  1183. S:=S+' AND (TR_TESTRUN_FK='+Frunid+') UNION '+
  1184. S2+' AND (TR_TESTRUN_FK='+Fcomparerunid+')'
  1185. end
  1186. else
  1187. S:=S+' AND ((TR_TESTRUN_FK='+Frunid+') OR '+
  1188. '(TR_TESTRUN_FK='+Fcomparerunid+'))'
  1189. end
  1190. else if Frunid<>'' then
  1191. S:=S+' AND (TR_TESTRUN_FK='+Frunid+')'
  1192. else
  1193. S:=S+' ORDER BY TR_TESTRUN_FK DESC LIMIT '+IntToStr(FLimit);
  1194. Qry:=S;
  1195. If FDebug then
  1196. begin
  1197. Writeln('Query : '+Qry);
  1198. Flush(stdout);
  1199. end;
  1200. FRunCount:=0;
  1201. FRunSkipCount:=0;
  1202. FRunFailedCount:=0;
  1203. Q:=CreateDataset(Qry);
  1204. With Q do
  1205. try
  1206. Open;
  1207. Try
  1208. With CreateTableProducer(Q) do
  1209. Try
  1210. Border:=True;
  1211. //FL:='TR_ID,TR_TESTRUN_FK,T_NAME,T_CPU,T_VERSION';
  1212. CreateColumns(Nil);
  1213. TableColumns.Delete(TableColumns.ColumnByName('TR_TEST_FK').Index);
  1214. TableColumns.ColumnByNAme('RUN').OnGetCellContents:=
  1215. @FormatTestRunOverview;
  1216. //OnGetRowAttributes:=@GetRunRowAttr;
  1217. TableColumns.ColumnByNAme('TR_RESULT').OnGetCellContents:=
  1218. @FormatTestResult;
  1219. //(TableColumns.Items[0] as TTableColumn).ActionURL:=ALink;
  1220. CreateTable(Response);
  1221. Finally
  1222. Free;
  1223. end;
  1224. DumpLn(Format('<p>Record count: %d </p>',[Q.RecordCount]));
  1225. Finally
  1226. Close;
  1227. end;
  1228. finally
  1229. Free;
  1230. end;
  1231. //If FDebug then
  1232. Category:='1';
  1233. if FRunId<>'' then
  1234. begin
  1235. Category:=getsingleton('select TU_CATEGORY_FK from TESTRUN where TU_ID='+FRunId);
  1236. FVersionBranch:=GetVersionName(getsingleton('select TU_VERSION_FK from TESTRUN where TU_ID='+fRunId));
  1237. log:='';
  1238. Try
  1239. log:=getsingleton('select TR_LOG from TESTRESULTS where (TR_TEST_FK='+ftestfileid
  1240. +') and (TR_TESTRUN_FK='+frunid+')');
  1241. if Log<>'' then
  1242. begin
  1243. HeaderStart(2);
  1244. Write('Log of '+FRunId+':');
  1245. HeaderEnd(2);
  1246. PreformatStart;
  1247. system.Write(Log);
  1248. system.flush(output);
  1249. PreformatEnd;
  1250. end;
  1251. Finally
  1252. if Log='' then
  1253. begin
  1254. HeaderStart(2);
  1255. Write('No log of '+FRunId+'.');
  1256. HeaderEnd(2);
  1257. end;
  1258. end;
  1259. end;
  1260. if FCompareRunId<>'' then
  1261. begin
  1262. log:='';
  1263. Try
  1264. log:=getsingleton('select TR_LOG from TESTRESULTS where (TR_TEST_FK='+ftestfileid
  1265. +') and (TR_TESTRUN_FK='+fcomparerunid+')');
  1266. if Log<>'' then
  1267. begin
  1268. HeaderStart(2);
  1269. Write('Log of '+FCompareRunId+':');
  1270. HeaderEnd(2);
  1271. PreformatStart;
  1272. system.Write(Log);
  1273. system.flush(output);
  1274. PreformatEnd;
  1275. end;
  1276. Finally
  1277. if Log='' then
  1278. begin
  1279. HeaderStart(2);
  1280. Write('No log of '+FCompareRunId+'.');
  1281. HeaderEnd(2);
  1282. end;
  1283. end;
  1284. end;
  1285. if FDebug then
  1286. Write('After Log.');
  1287. Source:='';
  1288. Try
  1289. Source:=getsingleton('select T_SOURCE from TESTS where T_ID='+ftestfileid);
  1290. if Source<>'' then
  1291. begin
  1292. HeaderStart(2);
  1293. Write('Source:');
  1294. HeaderEnd(2);
  1295. PreformatStart;
  1296. system.Write(Source);
  1297. system.flush(output);
  1298. PreformatEnd;
  1299. end;
  1300. Finally
  1301. Base:='trunk';
  1302. if FVersionBranch<>'' then
  1303. begin
  1304. // Test all but last version, which is assumed to be trunk
  1305. for ver:=low(known_versions) to pred(high(known_versions)) do
  1306. if VER_String[ver]=FVersionBranch then
  1307. begin
  1308. base:=ver_branch[ver];
  1309. break;
  1310. end;
  1311. end;
  1312. FViewVCURL:=ViewURL+Base;
  1313. if Category='1' then
  1314. FViewVCUrl:=FViewVCURL+TestsSubDir
  1315. else
  1316. begin
  1317. FViewVCUrl:=FViewVCURL+DataBaseSubDir;
  1318. // This assumes that type TAnyType is
  1319. // defined in anytype.pas source PM
  1320. if pos('/',FTestFileName)>0 then
  1321. FTestfilename:=lowercase(copy(FTestFilename,2,pos('/',FTestFilename)-2)+'.pas');
  1322. end;
  1323. if Source='' then
  1324. begin
  1325. HeaderStart(3);
  1326. DumpLn('<P>No Source in TestSuite DataBase.</P>');
  1327. DumpLn('Link to SVN view of '+
  1328. '<A HREF="'+FViewVCURL+FTestFileName+'?view=markup'+
  1329. '" TARGET="fpc_source"> '+FTestFileName+'</A> source. ');
  1330. HeaderEnd(3);
  1331. end
  1332. else
  1333. begin
  1334. HeaderStart(3);
  1335. DumpLn('Link to SVN view of '+
  1336. '<A HREF="'+FViewVCURL+FTestFileName+'?view=markup'+
  1337. '" TARGET="fpc_source"> '+FTestFileName+'</A> source. ');
  1338. HeaderEnd(3);
  1339. end;
  1340. end;
  1341. if FDebug then
  1342. Write('After Source.');
  1343. end
  1344. else
  1345. Write(Format('No data for test file with ID: %s',[FTestFileID]));
  1346. end;
  1347. end;
  1348. Procedure TTestSuite.ShowHistory;
  1349. Const
  1350. MaxCombo = 50;
  1351. Type
  1352. StatusLongintArray = Array [TTestStatus] of longint;
  1353. StatusDateTimeArray = Array [TTestStatus] of TDateTime;
  1354. AStatusLA = Array[1..MaxCombo] of StatusLongintArray;
  1355. AStatusDTA = Array[1..MaxCombo] of StatusDateTimeArray;
  1356. PStatusLA = ^AStatusLA;
  1357. PStatusDTA = ^AStatusDTA;
  1358. Var
  1359. S,FL,cpu,version,os : String;
  1360. date : TDateTime;
  1361. Qry : String;
  1362. Base, Category : string;
  1363. Q : TSQLQuery;
  1364. i,run_id,os_id,version_id,cpu_id : longint;
  1365. run_ind,os_ind,version_ind,cpu_ind,
  1366. ok_ind,skip_ind,result_ind,date_ind : longint;
  1367. os_size, cpu_size, version_size : longint;
  1368. os_last, cpu_last, version_last : longint;
  1369. error : word;
  1370. OK_count, not_OK_count,resi,
  1371. total_count, skip_count, not_skip_count : longint;
  1372. TS : TTestStatus;
  1373. result_count : StatusLongintArray;
  1374. os_count,cpu_count,version_count: PStatusLA;
  1375. first_date, last_date : array[TTestStatus] of TDateTime;
  1376. first_date_id, last_date_id : array[TTestStatus] of longint;
  1377. os_first_date, os_last_date,
  1378. cpu_first_date, cpu_last_date,
  1379. version_first_date, version_last_date : PStatusDTA;
  1380. os_first_date_id, os_last_date_id,
  1381. cpu_first_date_id, cpu_last_date_id,
  1382. version_first_date_id, version_last_date_id : PStatusLA;
  1383. FieldName,FieldValue,
  1384. Log,Source : String;
  1385. Res : Boolean;
  1386. ver : known_versions;
  1387. begin
  1388. os_count:=nil;
  1389. cpu_count:=nil;
  1390. version_count:=nil;
  1391. ConnectToDB;
  1392. ContentType:='text/html';
  1393. EmitContentType;
  1394. if (FTestFileID='') and (FTestFileName<>'') then
  1395. FTestFileID:=GetSingleton('SELECT T_ID FROM TESTS WHERE T_NAME LIKE ''%'+
  1396. FTestFileName+'%''');
  1397. if FTestFileID<>'' then
  1398. FTestFileName:=GetTestFileName(FTestFileID);
  1399. if FTestFileName<>'' then
  1400. EmitTitle(Title+' : File '+FTestFileName+' Results')
  1401. else
  1402. EmitTitle(Title+' : History overview');
  1403. With FHTMLWriter do
  1404. begin
  1405. if FTestFileName<>'' then
  1406. begin
  1407. HeaderStart(1);
  1408. Write('Test suite results for test file '+FTestFileName);
  1409. HeaderEnd(1);
  1410. HeaderStart(2);
  1411. Write('Test run data : ');
  1412. HeaderEnd(2);
  1413. end;
  1414. if FRunID<>'' then
  1415. begin
  1416. Res:=ShowRunData;
  1417. Res:=true;
  1418. end
  1419. else
  1420. begin
  1421. // This is useless as it is now
  1422. // It should be integrated into a form probably PM
  1423. //Write('Only failed tests');
  1424. //EmitCheckBox('failedonly','1',FonlyFailed);
  1425. //Write('Hide skipped tests');
  1426. //EmitCheckBox('noskipped','1',FNoSkipped);
  1427. Res:=true;
  1428. EmitHistoryForm;
  1429. end;
  1430. If Res then
  1431. begin
  1432. if (FTestFileName<>'') then
  1433. begin
  1434. HeaderStart(2);
  1435. Write('Test file "'+FTestFileName+'" information:');
  1436. HeaderEnd(2);
  1437. ParaGraphStart;
  1438. S:='SELECT * FROM TESTS WHERE T_ID='+FTestFileID;
  1439. Q:=CreateDataSet(S);
  1440. With Q do
  1441. Try
  1442. Open;
  1443. Try
  1444. For i:=0 to FieldCount-1 do
  1445. begin
  1446. FieldValue:=Fields[i].AsString;
  1447. FieldName:=Fields[i].DisplayName;
  1448. if (FieldValue<>'') and (FieldValue<>'-') and
  1449. (FieldName<>'T_NAME') and (FieldName<>'T_SOURCE') then
  1450. begin
  1451. if (FieldValue='+') then
  1452. Write('Flag ');
  1453. Write(FieldName);
  1454. Write(' ');
  1455. if FieldValue='+' then
  1456. Write(' set')
  1457. else
  1458. Write(FieldValue);
  1459. DumpLn('<BR>');
  1460. end;
  1461. end;
  1462. Finally
  1463. Close;
  1464. end;
  1465. Finally
  1466. Free;
  1467. end;
  1468. ParaGraphEnd;
  1469. HeaderStart(2);
  1470. Write('Detailed test run results:');
  1471. end;
  1472. HeaderEnd(2);
  1473. ParaGraphStart;
  1474. S:='SELECT TR_ID,TR_TESTRUN_FK AS Run,TR_TEST_FK,TR_OK AS OK'
  1475. +', TR_SKIP As Skip,TR_RESULT As Result'
  1476. //S:='SELECT * '
  1477. +',TC_NAME AS CPU, TV_VERSION AS Version, TO_NAME AS OS'
  1478. +',TU_ID,TU_DATE AS Date,TU_SUBMITTER AS Submitter'
  1479. +',(TU_FAILEDTOCOMPILE + TU_FAILEDTOFAIL + TU_FAILEDTORUN) AS Fails'
  1480. +',TU_MACHINE AS Machine,TU_COMMENT AS Comment'
  1481. +',TU_COMPILERDATE As CompDate'
  1482. +',TU_SVNTESTSREVISION AS Tests_rev'
  1483. +',TU_SVNRTLREVISION AS RTL_rev'
  1484. +',TU_SVNCOMPILERREVISION AS Compiler_rev'
  1485. +',TU_SVNPACKAGESREVISION AS Packages_rev'
  1486. +',TO_ID,TC_ID,TV_ID'
  1487. +' FROM TESTRUN '
  1488. +' LEFT JOIN TESTRESULTS ON (TR_TESTRUN_FK=TU_ID)'
  1489. +' LEFT JOIN TESTOS ON (TU_OS_FK=TO_ID)'
  1490. +' LEFT JOIN TESTCPU ON (TU_CPU_FK=TC_ID)'
  1491. +' LEFT JOIN TESTVERSION ON (TU_VERSION_FK=TV_ID)'
  1492. +' WHERE (TR_TEST_FK='+FTestFileID+')';
  1493. If FOnlyFailed then
  1494. S:=S+' AND (TR_OK="-")';
  1495. If FNoSkipped then
  1496. S:=S+' AND (TR_SKIP="-")';
  1497. If FCond<>'' then
  1498. S:=S+' AND ('+FCond+')';
  1499. If (FCPU<>'') and (GetCPUName(FCPU)<>'All') then
  1500. begin
  1501. S:=S+' AND (TU_CPU_FK='+FCPU+')';
  1502. cpu_size:=0;
  1503. end
  1504. else
  1505. begin
  1506. cpu_last:=StrToInt(GetSingleton('SELECT COUNT(*) FROM TESTCPU'));
  1507. cpu_size:=Sizeof(StatusLongintArray)*(1+cpu_last);
  1508. cpu_count:=GetMem(cpu_size);
  1509. FillChar(cpu_count^,cpu_size,#0);
  1510. cpu_first_date_id:=GetMem(cpu_size);
  1511. FillChar(cpu_first_date_id^,cpu_size,#0);
  1512. cpu_last_date_id:=GetMem(cpu_size);
  1513. FillChar(cpu_last_date_id^,cpu_size,#0);
  1514. cpu_first_date:=GetMem(cpu_last*SizeOf(StatusDateTimeArray));
  1515. FillChar(cpu_first_date^,cpu_last*Sizeof(StatusDateTimeArray),#0);
  1516. cpu_last_date:=GetMem(cpu_last*SizeOf(StatusDateTimeArray));
  1517. FillChar(cpu_last_date^,cpu_last*Sizeof(StatusDateTimeArray),#0);
  1518. end;
  1519. If (FVersion<>'') and (GetVersionName(FVersion)<>'All') then
  1520. begin
  1521. S:=S+' AND (TU_VERSION_FK='+FVERSION+')';
  1522. version_size:=0;
  1523. end
  1524. else
  1525. begin
  1526. version_last:=StrToInt(GetSingleton('SELECT COUNT(*) FROM TESTVERSION'));
  1527. version_size:=Sizeof(StatusLongintArray)*(1+version_last);
  1528. version_count:=GetMem(version_size);
  1529. FillChar(version_count^,version_size,#0);
  1530. version_first_date_id:=GetMem(version_size);
  1531. FillChar(version_first_date_id^,version_size,#0);
  1532. version_last_date_id:=GetMem(version_size);
  1533. FillChar(version_last_date_id^,version_size,#0);
  1534. version_first_date:=GetMem(version_last*SizeOf(StatusDateTimeArray));
  1535. FillChar(version_first_date^,version_last*Sizeof(StatusDateTimeArray),#0);
  1536. version_last_date:=GetMem(version_last*SizeOf(StatusDateTimeArray));
  1537. FillChar(version_last_date^,version_last*Sizeof(StatusDateTimeArray),#0);
  1538. end;
  1539. if (FOS<>'') and (GetOSName(FOS)<>'All') then
  1540. begin
  1541. S:=S+' AND (TU_OS_FK='+FOS+')';
  1542. os_size:=0;
  1543. end
  1544. else
  1545. begin
  1546. os_last:=StrToInt(GetSingleton('SELECT COUNT(*) FROM TESTOS'));
  1547. os_size:=Sizeof(StatusLongintArray)*(1+os_last);
  1548. os_count:=GetMem(os_size);
  1549. FillChar(os_count^,os_size,#0);
  1550. os_first_date_id:=GetMem(os_size);
  1551. FillChar(os_first_date_id^,os_size,#0);
  1552. os_last_date_id:=GetMem(os_size);
  1553. FillChar(os_last_date_id^,os_size,#0);
  1554. os_first_date:=GetMem(os_last*SizeOf(StatusDateTimeArray));
  1555. FillChar(os_first_date^,os_last*Sizeof(StatusDateTimeArray),#0);
  1556. os_last_date:=GetMem(os_last*SizeOf(StatusDateTimeArray));
  1557. FillChar(os_last_date^,os_last*Sizeof(StatusDateTimeArray),#0);
  1558. end;
  1559. If FSubmitter<>'' then
  1560. S:=S+' AND (TU_SUBMITTER='''+FSubmitter+''')';
  1561. If FMachine<>'' then
  1562. S:=S+' AND (TU_MACHINE='''+FMachine+''')';
  1563. If FComment<>'' then
  1564. S:=S+' AND (TU_COMMENT LIKE '''+FComment+''')';
  1565. if FDATE<>0 then
  1566. S:=S+' AND (TU_DATE >= '''+FormatDateTime('YYYY-MM-DD',FDate)+''')';
  1567. S:=S+' ORDER BY TU_ID DESC';
  1568. if FDATE=0 then
  1569. S:=S+' LIMIT '+IntToStr(FLimit);
  1570. Qry:=S;
  1571. If FDebug then
  1572. begin
  1573. Writeln(system.stdout,'Query : '+Qry);
  1574. system.Flush(system.stdout);
  1575. end;
  1576. FRunCount:=0;
  1577. FRunSkipCount:=0;
  1578. FRunFailedCount:=0;
  1579. Q:=CreateDataset(Qry);
  1580. With Q do
  1581. try
  1582. Open;
  1583. while not EOF do
  1584. Next;
  1585. DumpLn(Format('<p>Record count: %d </p>',[Q.RecordCount]));
  1586. if RecordCount>0 then
  1587. RecNo:=0;
  1588. Try
  1589. { if FDebug then
  1590. begin
  1591. Writeln(stdout,'FieldKind=',Fields[0].FieldKind);
  1592. Writeln(stdout,'DataType=',Fields[0].DataType);
  1593. system.flush(stdout);
  1594. end; }
  1595. total_count:=0;
  1596. OK_count:=0;
  1597. not_OK_count:=0;
  1598. skip_count:=0;
  1599. not_skip_count:=0;
  1600. fillchar(Result_Count,Sizeof(Result_count),#0);
  1601. ok_ind:=FieldByName('OK').Index;
  1602. skip_ind:=FieldBYName('SKIP').Index;
  1603. result_ind:=FieldByName('Result').Index;
  1604. cpu_ind:=FieldByName('TC_ID').Index;
  1605. os_ind:=FieldByName('TO_ID').Index;
  1606. version_ind:=FieldByName('TV_ID').Index;
  1607. date_ind:=FieldByName('Date').Index;
  1608. run_ind:=FieldByName('TU_ID').Index;
  1609. For i:=0 to Q.RecordCount-1 do
  1610. begin
  1611. Q.RecNo:=i;
  1612. inc(total_count);
  1613. S:=Fields[ok_ind].AsString;
  1614. if S='+' then
  1615. inc(OK_count)
  1616. else
  1617. inc(not_OK_count);
  1618. S:=Fields[skip_ind].AsString;
  1619. if S='+' then
  1620. inc(skip_count)
  1621. else
  1622. inc(not_skip_count);
  1623. S:=Fields[result_ind].AsString;
  1624. cpu:=Fields[cpu_ind].ASString;
  1625. version:=Fields[version_ind].AsString;
  1626. os:=Fields[os_ind].AsString;
  1627. date:=Fields[date_ind].ASDateTime;
  1628. os_id:=Fields[os_ind].AsLongint;
  1629. cpu_id:=Fields[cpu_ind].AsLongint;
  1630. version_id:=Fields[version_ind].AsLongint;
  1631. system.val(S,resi,error);
  1632. run_id:=Fields[run_ind].ASLongint;
  1633. if (error=0) and (Resi>=longint(FirstStatus)) and
  1634. (Resi<=longint(LastStatus)) then
  1635. begin
  1636. TS:=TTestStatus(Resi);
  1637. if Result_count[TS]=0 then
  1638. begin
  1639. first_date[TS]:=date;
  1640. last_date[TS]:=date;
  1641. first_date_id[TS]:=run_id;
  1642. last_date_id[TS]:=run_id;
  1643. end
  1644. else
  1645. begin
  1646. if (date>last_date[TS]) then
  1647. begin
  1648. last_date[TS]:=date;
  1649. last_date_id[TS]:=run_id;
  1650. end;
  1651. if date<first_date[TS] then
  1652. begin
  1653. first_date[TS]:=date;
  1654. first_date_id[TS]:=run_id;
  1655. end;
  1656. end;
  1657. inc(Result_count[TS]);
  1658. if assigned(cpu_count) and (cpu_id<=cpu_last) then
  1659. begin
  1660. if cpu_count^[cpu_id,TS]=0 then
  1661. begin
  1662. cpu_first_date^[cpu_id,TS]:=date;
  1663. cpu_last_date^[cpu_id,TS]:=date;
  1664. cpu_first_date_id^[cpu_id,TS]:=run_id;
  1665. cpu_last_date_id^[cpu_id,TS]:=run_id;
  1666. end
  1667. else
  1668. begin
  1669. if (date>cpu_last_date^[cpu_id,TS]) then
  1670. begin
  1671. cpu_last_date^[cpu_id,TS]:=date;
  1672. cpu_last_date_id^[cpu_id,TS]:=run_id;
  1673. end;
  1674. if date<cpu_first_date^[cpu_id,TS] then
  1675. begin
  1676. cpu_first_date^[cpu_id,TS]:=date;
  1677. cpu_first_date_id^[cpu_id,TS]:=run_id;
  1678. end;
  1679. end;
  1680. inc(cpu_count^[cpu_id,TS]);
  1681. end;
  1682. if assigned(os_count) and (os_id<=os_last) then
  1683. begin
  1684. if os_count^[os_id,TS]=0 then
  1685. begin
  1686. os_first_date^[os_id,TS]:=date;
  1687. os_last_date^[os_id,TS]:=date;
  1688. os_first_date_id^[os_id,TS]:=run_id;
  1689. os_last_date_id^[os_id,TS]:=run_id;
  1690. end
  1691. else
  1692. begin
  1693. if (date>os_last_date^[os_id,TS]) then
  1694. begin
  1695. os_last_date^[os_id,TS]:=date;
  1696. os_last_date_id^[os_id,TS]:=run_id;
  1697. end;
  1698. if date<os_first_date^[os_id,TS] then
  1699. begin
  1700. os_first_date^[os_id,TS]:=date;
  1701. os_first_date_id^[os_id,TS]:=run_id;
  1702. end;
  1703. end;
  1704. inc(os_count^[os_id,TS]);
  1705. end;
  1706. if assigned(version_count) and (version_id<=version_last) then
  1707. begin
  1708. if version_count^[version_id,TS]=0 then
  1709. begin
  1710. version_first_date^[version_id,TS]:=date;
  1711. version_last_date^[version_id,TS]:=date;
  1712. version_first_date_id^[version_id,TS]:=run_id;
  1713. version_last_date_id^[version_id,TS]:=run_id;
  1714. end
  1715. else
  1716. begin
  1717. if (date>version_last_date^[version_id,TS]) then
  1718. begin
  1719. version_last_date^[version_id,TS]:=date;
  1720. version_last_date_id^[version_id,TS]:=run_id;
  1721. end;
  1722. if date<version_first_date^[version_id,TS] then
  1723. begin
  1724. version_first_date^[version_id,TS]:=date;
  1725. version_first_date_id^[version_id,TS]:=run_id;
  1726. end;
  1727. end;
  1728. inc(version_count^[version_id,TS]);
  1729. end;
  1730. end
  1731. else if Fdebug then
  1732. writeln(stdout,'Error for Result, S=',S);
  1733. end;
  1734. DumpLn(Format('<p>Total = %d </p>',[total_count]));
  1735. if Total_count > 0 then
  1736. DumpLn(Format('<p>OK=%d Percentage= %3.2f </p>',[OK_count,OK_count*100/total_count]));
  1737. if Skip_count > 0 then
  1738. DumpLn(Format('<p>Skipped=%d Percentage= %3.2f </p>',[Skip_count,Skip_count*100/total_count]));
  1739. if total_count>0 then
  1740. begin
  1741. TableStart(5,True);
  1742. RowStart;
  1743. CellStart;
  1744. Write('Result type');
  1745. CellNext;
  1746. Write('Cat.');
  1747. CellNext;
  1748. Write('Count');
  1749. CellNext;
  1750. Write('Percentage');
  1751. CellNext;
  1752. Write('First date');
  1753. CellNext;
  1754. Write('Last Date');
  1755. CellEnd;
  1756. end;
  1757. For TS:=FirstStatus to LastStatus do
  1758. if Result_count[TS]>0 then
  1759. begin
  1760. RowNext;
  1761. CellStart;
  1762. Write(StatusText[TS]);
  1763. CellNext;
  1764. CellNext;
  1765. Write(Format('%d',[Result_count[TS]]));
  1766. CellNext;
  1767. Write(Format('%3.1f',[Result_count[TS]*100/total_count]));
  1768. CellNext;
  1769. DumpLn(FormatDetailURL(IntToStr(first_date_id[TS]),
  1770. DateTimeToStr(first_date[TS])));
  1771. Write(' '+GetFailCount(first_date_id[TS]));
  1772. CellNext;
  1773. DumpLn(FormatDetailURL(IntToStr(last_date_id[TS]),
  1774. DateTimeToStr(last_date[TS])));
  1775. Write(' '+GetFailCount(last_date_id[TS]));
  1776. CellEnd;
  1777. if assigned(cpu_count) then
  1778. begin
  1779. for i:=1 to cpu_last do
  1780. if cpu_count^[i,TS]>0 then
  1781. begin
  1782. RowNext;
  1783. CellStart;
  1784. CellNext;
  1785. Write(GetSingleton('SELECT TC_NAME FROM TESTCPU WHERE TC_ID='+IntToStr(i)));
  1786. CellNext;
  1787. Write(Format('%d',[cpu_count^[i,TS]]));
  1788. CellNext;
  1789. Write(Format('%3.1f',[cpu_count^[i,TS]*100/result_count[TS]]));
  1790. CellNext;
  1791. DumpLn(FormatDetailURL(IntToStr(cpu_first_date_id^[i,TS]),
  1792. DateTimeToStr(cpu_first_date^[i,TS])));
  1793. Write(' '+GetFailCount(cpu_first_date_id^[i,TS]));
  1794. CellNext;
  1795. DumpLn(FormatDetailURL(IntToStr(cpu_last_date_id^[i,TS]),
  1796. DateTimeToStr(cpu_last_date^[i,TS])));
  1797. Write(' '+GetFailCount(cpu_last_date_id^[i,TS]));
  1798. CellEnd;
  1799. end;
  1800. end;
  1801. if assigned(os_count) then
  1802. begin
  1803. for i:=1 to os_last do
  1804. if os_count^[i,TS]>0 then
  1805. begin
  1806. RowNext;
  1807. CellStart;
  1808. CellNext;
  1809. Write(GetSingleton('SELECT TO_NAME FROM TESTOS WHERE TO_ID='+IntToStr(i)));
  1810. CellNext;
  1811. Write(Format('%d',[os_count^[i,TS]]));
  1812. CellNext;
  1813. Write(Format('%3.1f',[os_count^[i,TS]*100/result_count[TS]]));
  1814. CellNext;
  1815. DumpLn(FormatDetailURL(IntToStr(os_first_date_id^[i,TS]),
  1816. DateTimeToStr(os_first_date^[i,TS])));
  1817. Write(' '+GetFailCount(os_first_date_id^[i,TS]));
  1818. CellNext;
  1819. DumpLn(FormatDetailURL(IntToStr(os_last_date_id^[i,TS]),
  1820. DateTimeToStr(os_last_date^[i,TS])));
  1821. Write(' '+GetFailCount(os_last_date_id^[i,TS]));
  1822. CellEnd;
  1823. end;
  1824. end;
  1825. if assigned(version_count) then
  1826. begin
  1827. for i:=1 to version_last do
  1828. if version_count^[i,TS]>0 then
  1829. begin
  1830. RowNext;
  1831. CellStart;
  1832. CellNext;
  1833. Write(GetSingleton('SELECT TV_VERSION FROM TESTVERSION WHERE TV_ID='+IntToStr(i)));
  1834. CellNext;
  1835. Write(Format('%d',[version_count^[i,TS]]));
  1836. CellNext;
  1837. Write(Format('%3.1f',[version_count^[i,TS]*100/result_count[TS]]));
  1838. CellNext;
  1839. DumpLn(FormatDetailURL(IntToStr(version_first_date_id^[i,TS]),
  1840. DateTimeToStr(version_first_date^[i,TS])));
  1841. Write(' '+GetFailCount(version_first_date_id^[i,TS]));
  1842. CellNext;
  1843. DumpLn(FormatDetailURL(IntToStr(version_last_date_id^[i,TS]),
  1844. DateTimeToStr(version_last_date^[i,TS])));
  1845. Write(' '+GetFailCount(version_last_date_id^[i,TS]));
  1846. CellEnd;
  1847. end;
  1848. end;
  1849. end;
  1850. if total_count>0 then
  1851. begin
  1852. TableEnd;
  1853. RecNo:=0;
  1854. end;
  1855. If FDebug or FListAll then
  1856. begin
  1857. With CreateTableProducer(Q) do
  1858. Try
  1859. Border:=True;
  1860. FL:='RUN,Date,OK,SKIP,Result';
  1861. if FSubmitter='' then
  1862. FL:=FL+',Submitter';
  1863. if FMachine='' then
  1864. FL:=FL+',Machine';
  1865. if Fcomment='' then
  1866. FL:=FL+',Comment';
  1867. if (FOS='') or (GetOSName(FOS)='All') then
  1868. FL:=FL+',OS';
  1869. if (FCPU='') or (GetCPUName(FCPU)='All') then
  1870. FL:=FL+',CPU';
  1871. if (FVersion='') or (GetVersionName(FVersion)='All') then
  1872. FL:=FL+',Version';
  1873. FL:=FL+',Fails,CompDate';
  1874. FL:=FL+',Tests_rev,RTL_rev,Compiler_rev,Packages_rev';
  1875. CreateColumns(FL);
  1876. //TableColumns.Delete(TableColumns.ColumnByName('TR_TEST_FK').Index);
  1877. TableColumns.ColumnByNAme('RUN').OnGetCellContents:=
  1878. @FormatTestRunOverview;
  1879. //OnGetRowAttributes:=@GetRunRowAttr;
  1880. TableColumns.ColumnByNAme('Result').OnGetCellContents:=
  1881. @FormatTestResult;
  1882. //(TableColumns.Items[0] as TTableColumn).ActionURL:=ALink;
  1883. CreateTable(Response);
  1884. Finally
  1885. Free;
  1886. end;
  1887. end;
  1888. Finally
  1889. Close;
  1890. end;
  1891. finally
  1892. Free;
  1893. end;
  1894. //If FDebug then
  1895. Category:='1';
  1896. if FRunId<>'' then
  1897. begin
  1898. Category:=getsingleton('select TU_CATEGORY_FK from TESTRUN where TU_ID='+FRunId);
  1899. FVersionBranch:=GetVersionName(getsingleton('select TU_VERSION_FK from TESTRUN where TU_ID='+fRunId));
  1900. log:='';
  1901. Try
  1902. log:=getsingleton('select TR_LOG from TESTRESULTS where (TR_TEST_FK='+ftestfileid
  1903. +') and (TR_TESTRUN_FK='+frunid+')');
  1904. if Log<>'' then
  1905. begin
  1906. HeaderStart(2);
  1907. Write('Log of '+FRunId+':');
  1908. HeaderEnd(2);
  1909. PreformatStart;
  1910. system.Write(Log);
  1911. system.flush(output);
  1912. PreformatEnd;
  1913. end;
  1914. Finally
  1915. if Log='' then
  1916. begin
  1917. HeaderStart(2);
  1918. Write('No log of '+FRunId+'.');
  1919. HeaderEnd(2);
  1920. end;
  1921. end;
  1922. end;
  1923. if FCompareRunId<>'' then
  1924. begin
  1925. log:='';
  1926. Try
  1927. log:=getsingleton('select TR_LOG from TESTRESULTS where (TR_TEST_FK='+ftestfileid
  1928. +') and (TR_TESTRUN_FK='+fcomparerunid+')');
  1929. if Log<>'' then
  1930. begin
  1931. HeaderStart(2);
  1932. Write('Log of '+FCompareRunId+':');
  1933. HeaderEnd(2);
  1934. PreformatStart;
  1935. system.Write(Log);
  1936. system.flush(output);
  1937. PreformatEnd;
  1938. end;
  1939. Finally
  1940. if Log='' then
  1941. begin
  1942. HeaderStart(2);
  1943. Write('No log of '+FCompareRunId+'.');
  1944. HeaderEnd(2);
  1945. end;
  1946. end;
  1947. end;
  1948. if FDebug then
  1949. Write('After Log.');
  1950. Source:='';
  1951. Try
  1952. Source:=getsingleton('select T_SOURCE from TESTS where T_ID='+ftestfileid);
  1953. if Source<>'' then
  1954. begin
  1955. HeaderStart(2);
  1956. Write('Source:');
  1957. HeaderEnd(2);
  1958. PreformatStart;
  1959. system.Write(Source);
  1960. system.flush(output);
  1961. PreformatEnd;
  1962. end;
  1963. Finally
  1964. Base:='trunk';
  1965. if FVersionBranch<>'' then
  1966. begin
  1967. // Test all but last version, which is assumed to be trunk
  1968. for ver:=low(known_versions) to pred(high(known_versions)) do
  1969. if ver_string[ver]=FVersionBranch then
  1970. begin
  1971. base:=ver_branch[ver];
  1972. break;
  1973. end;
  1974. end;
  1975. FViewVCURL:=ViewURL+Base;
  1976. if Category='1' then
  1977. FViewVCUrl:=FViewVCURL+TestsSubDir
  1978. else
  1979. begin
  1980. FViewVCUrl:=FViewVCURL+DataBaseSubDir;
  1981. // This assumes that type TAnyType is
  1982. // defined in anytype.pas source PM
  1983. if pos('/',FTestFileName)>0 then
  1984. FTestfilename:=lowercase(copy(FTestFilename,2,pos('/',FTestFilename)-2)+'.pas');
  1985. end;
  1986. if Source='' then
  1987. begin
  1988. HeaderStart(3);
  1989. DumpLn('<P>No Source in TestSuite DataBase.</P>');
  1990. DumpLn('Link to SVN view of '+
  1991. '<A HREF="'+FViewVCURL+FTestFileName+'?view=markup'+
  1992. '" TARGET="fpc_source"> '+FTestFileName+'</A> source. ');
  1993. HeaderEnd(3);
  1994. end
  1995. else
  1996. begin
  1997. HeaderStart(3);
  1998. DumpLn('Link to SVN view of '+
  1999. '<A HREF="'+FViewVCURL+FTestFileName+'?view=markup'+
  2000. '" TARGET="fpc_source"> '+FTestFileName+'</A> source. ');
  2001. HeaderEnd(3);
  2002. end;
  2003. end;
  2004. if FDebug then
  2005. Write('After Source.');
  2006. end
  2007. else
  2008. Write(Format('No data for test file with ID: %s',[FTestFileID]));
  2009. end;
  2010. if assigned(os_count) then
  2011. begin
  2012. FreeMem(os_count);
  2013. FreeMem(os_first_date);
  2014. FreeMem(os_first_date_id);
  2015. FreeMem(os_last_date);
  2016. FreeMem(os_last_date_id);
  2017. end;
  2018. if assigned(cpu_count) then
  2019. begin
  2020. FreeMem(cpu_count);
  2021. FreeMem(cpu_first_date);
  2022. FreeMem(cpu_first_date_id);
  2023. FreeMem(cpu_last_date);
  2024. FreeMem(cpu_last_date_id);
  2025. end;
  2026. if assigned(version_count) then
  2027. begin
  2028. FreeMem(version_count);
  2029. FreeMem(version_first_date);
  2030. FreeMem(version_first_date_id);
  2031. FreeMem(version_last_date);
  2032. FreeMem(version_last_date_id);
  2033. end;
  2034. end;
  2035. Procedure TTestSuite.ShowRunComparison;
  2036. Var
  2037. S : String;
  2038. Qry : String;
  2039. Q : TSQLQuery;
  2040. FL : String;
  2041. begin
  2042. ConnectToDB;
  2043. ContentType:='text/html';
  2044. EmitContentType;
  2045. EmitTitle(Title+' : Compare 2 runs');
  2046. With FHTMLWriter do
  2047. begin
  2048. HeaderStart(1);
  2049. Write('Test suite results for run '+FRunID+' vs. '+FCompareRunID);
  2050. HeaderEnd(1);
  2051. HeaderStart(2);
  2052. Write('Test run data: ');
  2053. HeaderEnd(2);
  2054. If ShowRunData then
  2055. begin
  2056. HeaderStart(2);
  2057. Write('Detailed test run results:');
  2058. FL:='';
  2059. If FOnlyFailed or FNoSkipped then
  2060. begin
  2061. FL:='';
  2062. If FOnlyFailed then
  2063. FL:='successful';
  2064. if FNoSkipped then
  2065. begin
  2066. If (FL<>'') then
  2067. FL:=FL+' and ';
  2068. FL:=FL+'skipped';
  2069. end;
  2070. Write(' ('+FL+' tests are hidden)');
  2071. end;
  2072. HeaderEnd(2);
  2073. ParaGraphStart;
  2074. Q:=CreateDataset('');
  2075. Q.SQL.Text:='CREATE TEMPORARY TABLE tr1 like TESTRESULTS;';
  2076. Q.ExecSQL;
  2077. Q.SQL.Text:='CREATE TEMPORARY TABLE tr2 like TESTRESULTS;';
  2078. Q.ExecSQL;
  2079. Q.SQL.Text:='INSERT INTO tr1 SELECT * FROM '+TESTRESULTSTableName(FRunId)+
  2080. ' WHERE TR_TESTRUN_FK='+FRunID+';';
  2081. Q.ExecSQL;
  2082. Q.SQL.Text:='INSERT INTO tr2 SELECT * FROM '+TESTRESULTSTableName(FCompareRunId)+
  2083. ' WHERE TR_TESTRUN_FK='+FCompareRunID+';';
  2084. Q.ExecSQL;
  2085. S:='SELECT T_ID as Id,T_NAME as Filename,tr1.TR_SKIP as Run1_Skipped,'
  2086. +'tr2.TR_SKIP as Run2_Skipped,tr1.TR_OK as Run1_OK,'
  2087. +'tr2.TR_OK as Run2_OK, tr1.TR_Result as Run1_Result,'
  2088. +'tr2.TR_RESULT as Run2_Result '
  2089. +'FROM TESTS, tr2 LEFT JOIN tr1 USING (TR_TEST_FK) '
  2090. +'WHERE ((tr1.TR_SKIP IS NULL) or'
  2091. +' (tr2.TR_SKIP IS NULL) or '
  2092. +' (%s (tr1.TR_Result<>tr2.TR_Result)))'
  2093. +'and (T_ID=tr2.TR_TEST_FK)';
  2094. If FNoSkipped then
  2095. begin
  2096. Qry:='(((tr1.TR_SKIP="+") and (tr2.TR_OK="-") and (tr2.TR_SKIP="-")) or '
  2097. +'((tr1.TR_OK="-") and (tr1.TR_SKIP="-") and (tr2.TR_SKIP="+")) or '
  2098. +'((tr1.TR_SKIP="-") and (tr2.TR_SKIP="-"))) and ';
  2099. end
  2100. else
  2101. Qry:='';
  2102. Qry:=Format(S,[Qry]);
  2103. If FDebug then
  2104. begin
  2105. Writeln('Query: '+Qry);
  2106. Flush(stdout);
  2107. end;
  2108. FRunCount:=0;
  2109. FRunSkipCount:=0;
  2110. FRunFailedCount:=0;
  2111. Q.SQL.Text:=Qry;
  2112. With Q do
  2113. try
  2114. Open;
  2115. Try
  2116. With CreateTableProducer(Q) do
  2117. Try
  2118. Border:=True;
  2119. FL:='Filename,Run1_OK,Run2_OK';
  2120. If Not FNoSkipped then
  2121. FL:=FL+',Run1_Skipped,Run2_Skipped';
  2122. FL:=FL+',Run1_Result,Run2_Result';
  2123. CreateColumns(FL);
  2124. OnGetRowAttributes:=@GetRunRowAttr;
  2125. TableColumns.ColumnByNAme('Run1_Result').OnGetCellContents:=
  2126. @FormatTestResult;
  2127. TableColumns.ColumnByNAme('Run2_Result').OnGetCellContents:=
  2128. @FormatTestResult;
  2129. TableColumns.ColumnByNAme('Filename').OnGetCellContents:=
  2130. @FormatFileDetails;
  2131. //(TableColumns.Items[0] as TTableColumn).ActionURL:=ALink;
  2132. CreateTable(Response);
  2133. Finally
  2134. Free;
  2135. end;
  2136. Writeln('<p>Record count: ',Q.RecordCount,'</p>');
  2137. Finally
  2138. Close;
  2139. end;
  2140. finally
  2141. Free;
  2142. end;
  2143. If Not (FRunCount=0) and not (FNoSkipped or FOnlyFailed) then
  2144. begin
  2145. ParaGraphStart;
  2146. TagStart('IMG',Format('Src="'+TestsuiteCGIURL+'?action=2&pietotal=%d&piefailed=%d&pieskipped=%d"',[FRunCount,FRunFailedCount,FRunSkipCount]));
  2147. end;
  2148. end
  2149. else
  2150. Write('No data for test run with ID: '+FRunID);
  2151. end;
  2152. end;
  2153. procedure TTestSuite.GetRunRowAttr(Sender: TObject; var BGColor: String;
  2154. var Align: THTMLAlign; var VAlign: THTMLValign; var CustomAttr: String);
  2155. Var
  2156. P : TTableProducer;
  2157. Skip1Field, Skip2Field, Run1Field, Run2Field : TField;
  2158. begin
  2159. P:=(Sender as TTAbleProducer);
  2160. Inc(FRunCount);
  2161. If (FOnlyFailed and FNoSkipped) then
  2162. begin
  2163. If (P.CurrentRow Mod 2)=0 then
  2164. BGColor:='#EEEEEE'
  2165. end
  2166. else
  2167. begin
  2168. Skip1Field := P.Dataset.FindField('Skipped');
  2169. if Skip1Field = nil then
  2170. begin
  2171. Skip1Field := P.Dataset.FindField('Run1_Skipped');
  2172. Skip2Field := P.Dataset.FindField('Run2_Skipped');
  2173. end
  2174. else
  2175. Skip2Field := nil;
  2176. Run1Field := P.Dataset.FindField('OK');
  2177. if Run1Field = nil then
  2178. Run1Field := P.Dataset.FindField('Run1_OK');
  2179. Run2Field := P.Dataset.FindField('OK');
  2180. if Run2Field = nil then
  2181. Run2Field := P.Dataset.FindField('Run2_OK');
  2182. If (not FNoSkipped) and ((Skip1Field.AsString='+')
  2183. or ((Skip2Field <> nil) and (Skip2Field.AsString = '+'))) then
  2184. begin
  2185. Inc(FRunSkipCount);
  2186. BGColor:='yellow'; // Yellow
  2187. end
  2188. else If Run2Field.AsString='+' then
  2189. begin
  2190. if Run1Field.AsString='' then
  2191. BGColor:='#68DFB8'
  2192. else if Run1Field.ASString<>'+' then
  2193. BGColor:='#98FB98'; // pale Green
  2194. end
  2195. else if Run2Field.AsString='-' then
  2196. begin
  2197. Inc(FRunFailedCount);
  2198. if Run1Field.AsString='' then
  2199. BGColor:='#FF82AB' // Light red
  2200. else if Run1Field.AsString<>'-' then
  2201. BGColor:='#FF225B';
  2202. end;
  2203. end;
  2204. end;
  2205. procedure TTestSuite.FormatFailedOverview(Sender: TObject; var CellData: String);
  2206. Var
  2207. S: String;
  2208. P : TTableProducer;
  2209. begin
  2210. P:=(Sender as TTableProducer);
  2211. S:=Format(SDetailsURL,[P.DataSet.FieldByName('ID').AsString]);
  2212. S:=S+'&failedonly=1&noskipped=1';
  2213. CellData:=Format('<A HREF="%s">%s</A>',[S,CellData]);
  2214. end;
  2215. function TTestSuite.FormatDetailURL(const RunIdStr, CellData : String) : string;
  2216. Var
  2217. S : String;
  2218. begin
  2219. S:=Format(SDetailsURL,[RunIdStr]);
  2220. if FOnlyFailed then
  2221. S:=S+'&failedonly=1';
  2222. if FNoSkipped then
  2223. S:=S+'&noskipped=1';
  2224. FormatDetailURL:=Format('<A HREF="%s">%s</A>',[S,CellData]);
  2225. end;
  2226. procedure TTestSuite.FormatTestRunOverview(Sender: TObject; var CellData: String);
  2227. Var
  2228. S: String;
  2229. P : TTableProducer;
  2230. begin
  2231. P:=(Sender as TTableProducer);
  2232. S:=Format(SDetailsURL,[P.DataSet.FieldByName('RUN').AsString]);
  2233. if FOnlyFailed then
  2234. S:=S+'&failedonly=1';
  2235. if FNoSkipped then
  2236. S:=S+'&noskipped=1';
  2237. CellData:=Format('<A HREF="%s">%s</A>',[S,CellData]);
  2238. end;
  2239. procedure TTestSuite.FormatFileIDDetails(Sender: TObject; var CellData: String);
  2240. Var
  2241. S: String;
  2242. P : TTableProducer;
  2243. begin
  2244. P:=(Sender as TTableProducer);
  2245. if FVersion<>'' then
  2246. S:=Format(TestSuiteCGIURL + '?action=4&version=%s&testfileid=%s',
  2247. [FVersion,P.DataSet.FieldByName('Id').AsString])
  2248. else
  2249. S:=Format(TestSuiteCGIURL + '?action=4&testfileid=%s',
  2250. [P.DataSet.FieldByName('Id').AsString]);
  2251. CellData:=Format('<A HREF="%s">%s</A>',[S,CellData]);
  2252. end;
  2253. procedure TTestSuite.FormatFileDetails(Sender: TObject; var CellData: String);
  2254. Var
  2255. S: String;
  2256. P : TTableProducer;
  2257. begin
  2258. P:=(Sender as TTableProducer);
  2259. if FCompareRunID<>'' then
  2260. S:=Format(TestSuiteCGIURL + '?action=3&run1id=%s&run2id=%s&testfileid=%s',
  2261. [FRunID,FCompareRunID,P.DataSet.FieldByName('Id').AsString])
  2262. else
  2263. S:=Format(TestSuiteCGIURL + '?action=3&run1id=%s&testfileid=%s',
  2264. [FRunID,P.DataSet.FieldByName('Id').AsString]);
  2265. CellData:=Format('<A HREF="%s">%s</A>',[S,CellData]);
  2266. end;
  2267. procedure TTestSuite.FormatTestResult(Sender: TObject; var CellData: String);
  2268. Var
  2269. Res : longint;
  2270. Error:word;
  2271. TS : TTestStatus;
  2272. begin
  2273. Val(CellData,Res,Error);
  2274. if (Error=0) and (Res>=longint(FirstStatus)) and
  2275. (Res<=longint(LastStatus)) then
  2276. begin
  2277. TS:=TTestStatus(Res);
  2278. CellData:=StatusText[TS];
  2279. end;
  2280. end;
  2281. Procedure TTestSuite.CreateRunPie;
  2282. Var
  2283. I : TFPMemoryImage;
  2284. M : TMemoryStream;
  2285. begin
  2286. ftFont.InitEngine;
  2287. FontMgr.SearchPath:='/usr/lib/X11/fonts/truetype';
  2288. I:=TFPMemoryImage.Create(320,320);
  2289. try
  2290. If FRunCount=0 Then
  2291. Raise Exception.Create('Invalid parameters passed to script: No total count');
  2292. DoDrawPie(I,FRunSkipCount,FRunFailedCount,FRunCount);
  2293. M:=TMemoryStream.Create;
  2294. Try
  2295. With TFPWriterPNG.Create do
  2296. try
  2297. UseAlpha:=True;
  2298. ImageWrite(M,I);
  2299. Finally
  2300. Free;
  2301. end;
  2302. ContentType:='image/png';
  2303. EmitContentType;
  2304. M.Position:=0;
  2305. Response.CopyFrom(M,M.Size);
  2306. Finally
  2307. M.Free;
  2308. end;
  2309. Finally
  2310. I.Free;
  2311. end;
  2312. end;
  2313. Procedure TTestSuite.DoDrawPie(Img : TFPCustomImage; Skipped,Failed,Total : Integer);
  2314. Var
  2315. Cnv : TFPImageCanvas;
  2316. W,H,FH,CR,ra : Integer;
  2317. A1,A2,FR,SR,PR : Double;
  2318. R : TRect;
  2319. F : TFreeTypeFont;
  2320. Procedure AddPie(X,Y,R : Integer; AStart,AStop : Double; Col : TFPColor);
  2321. Var
  2322. DX,Dy : Integer;
  2323. begin
  2324. DX:=Round(R*Cos(A1));
  2325. DY:=Round(R*Sin(A1));
  2326. Cnv.Line(X,Y,X+DX,Y-DY);
  2327. DX:=Round(Ra*Cos(A2));
  2328. DY:=Round(Ra*Sin(A2));
  2329. Cnv.Line(X,Y,X+DX,Y-Dy);
  2330. DX:=Round(R/2*Cos((A1+A2)/2));
  2331. DY:=Round(R/2*Sin((A1+A2)/2));
  2332. Cnv.Brush.FpColor:=Col;
  2333. Cnv.FloodFill(X+DX,Y-DY);
  2334. end;
  2335. Function FractionAngle(F,T : Integer): Double;
  2336. begin
  2337. Result:=(2*Pi*(F/T))
  2338. end;
  2339. begin
  2340. F:=TFreeTypeFont.Create;
  2341. With F do
  2342. begin
  2343. Name:='arial';
  2344. FontIndex:=0;
  2345. Size:=12;
  2346. FPColor:=colred;
  2347. AntiAliased:=False;
  2348. Resolution:=96;
  2349. end;
  2350. if FDebug then
  2351. Writeln(stdout,'Creating image');
  2352. Cnv:=TFPImageCanvas.Create(Img);
  2353. if FDebug then
  2354. Writeln(stdout,'CNV=0x',hexstr(ptruint(cnv),16));
  2355. if FDebug then
  2356. Writeln(stdout,'Getting width and height');
  2357. W:=Img.Width;
  2358. H:=Img.Height;
  2359. if FDebug then
  2360. begin
  2361. Writeln(stdout,'width=',W,' height=',H);
  2362. //system.flush(stdout);
  2363. end;
  2364. // Writeln('Transparant');
  2365. cnv.Brush.Style:=bsSolid;
  2366. cnv.Brush.FPColor:=colTransparent;
  2367. cnv.Pen.FPColor:=colWhite;
  2368. Cnv.Rectangle(0,0,W,H);
  2369. if FDEbug then
  2370. Writeln(stdout,'Setting font');
  2371. Cnv.Font:=F;
  2372. if FDebug then
  2373. Writeln(stdout,'Getting textwidth ');
  2374. FH:=CNV.GetTextHeight('A');
  2375. If FH=0 then
  2376. FH:=14; // 3 * 14;
  2377. if FDebug then
  2378. writeln(stdout,'FH=',FH);
  2379. Inc(FH,3);
  2380. R.Top:=FH*4;
  2381. R.Left:=0;
  2382. R.Bottom:=H;
  2383. CR:=H-(FH*4);
  2384. If W>CR then
  2385. R.Right:=CR
  2386. else
  2387. R.Right:=W;
  2388. Ra:=CR div 2;
  2389. if FDEbug then
  2390. begin
  2391. Writeln(stdout,'Setting pen color');
  2392. system.flush(stdout);
  2393. end;
  2394. Cnv.Pen.FPColor:=colBlack;
  2395. if FDebug then
  2396. begin
  2397. Writeln(stdout,'Palette size : ',Img.Palette.Count);
  2398. Writeln(stdout,'Setting brush style');
  2399. system.flush(stdout);
  2400. end;
  2401. cnv.brush.FPColor:=colRed;
  2402. // cnv.pen.width:=1;
  2403. // Writeln('Drawing ellipse');
  2404. Cnv.Ellipse(R);
  2405. if FDebug then
  2406. begin
  2407. Writeln(stdout,'Setting text');
  2408. Writeln(stdout,'Palette size : ',Img.Palette.Count);
  2409. end;
  2410. cnv.font.FPColor:=colred;
  2411. Inc(FH,4);
  2412. FR:=Failed/Total;
  2413. SR:=Skipped/Total;
  2414. PR:=1-(FR+SR);
  2415. Cnv.Textout(1,FH,Format('%d Failed (%3.1f%%)',[Failed,Fr*100]));
  2416. // Writeln('Palette size : ',Img.Palette.Count);
  2417. cnv.font.FPColor:=colYellow;
  2418. Cnv.Textout(1,FH*2,Format('%d Skipped (%3.1f%%)',[Skipped,SR*100]));
  2419. A1:=(Pi*2*(failed/total));
  2420. A2:=A1+(Pi*2*(Skipped/Total));
  2421. AddPie(Ra,R.Top+Ra,Ra,A1,A2,ColYellow);
  2422. cnv.font.FPColor:=colGreen;
  2423. // Writeln('Palette size : ',Img.Palette.Count);
  2424. A1:=A2;
  2425. A2:=A1+(Pi*2*((Total-(Skipped+Failed))/Total));
  2426. Cnv.Textout(1,FH*3,Format('%d Passed (%3.1f%%',[Total-Skipped-Failed,PR*100]));
  2427. AddPie(Ra,R.Top+Ra,Ra,A1,A2,ColGreen);
  2428. // Writeln('Palette size : ',Img.Palette.Count);
  2429. // Writeln('All done');
  2430. end;
  2431. begin
  2432. if paramstr(0)<>'' then
  2433. TestsuiteCGIURL:=TestsuiteURLPrefix+'cgi-bin/'+extractfilename(paramstr(0))
  2434. else
  2435. TestsuiteCGIURL:=TestsuiteURLPrefix+'cgi-bin/'+TestsuiteBin;
  2436. SDetailsURL := TestsuiteCGIURL + '?action=1&run1id=%s';
  2437. end.