utests.pp 91 KB

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