utests.pp 92 KB

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