utests.pp 90 KB

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