utests.pp 79 KB

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