dotest.pp 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132
  1. {
  2. This file is part of the Free Pascal test suite.
  3. Copyright (c) 1999-2002 by the Free Pascal development team.
  4. This program makes the compilation and
  5. execution of individual test sources.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$mode objfpc}
  13. {$goto on}
  14. {$H+}
  15. program dotest;
  16. uses
  17. sysutils,
  18. dos,
  19. {$ifdef macos}
  20. macutils,
  21. {$endif}
  22. teststr,
  23. testu,
  24. redir,
  25. bench,
  26. classes;
  27. {$ifdef go32v2}
  28. {$define LIMIT83FS}
  29. {$endif}
  30. {$ifdef os2}
  31. {$define LIMIT83FS}
  32. {$endif}
  33. {$ifdef msdos}
  34. {$define LIMIT83FS}
  35. {$endif}
  36. type
  37. tcompinfo = (compver,comptarget,compcpu);
  38. tdelexecutable = (deBefore, deAfter);
  39. tdelexecutables = set of tdelexecutable;
  40. const
  41. ObjExt='o';
  42. PPUExt='ppu';
  43. {$ifdef UNIX}
  44. SrcExeExt='';
  45. {$else UNIX}
  46. {$ifdef MACOS}
  47. SrcExeExt='';
  48. {$else MACOS}
  49. SrcExeExt='.exe';
  50. {$endif MACOS}
  51. {$endif UNIX}
  52. ExeExt : string = '';
  53. DllExt : string = '.so';
  54. DllPrefix: string = 'lib';
  55. DefaultTimeout=60;
  56. READ_ONLY = 0;
  57. var
  58. Config : TConfig;
  59. CompilerLogFile,
  60. ExeLogFile,
  61. LongLogfile,
  62. FailLogfile,
  63. RTLUnitsDir,
  64. TestOutputDir,
  65. OutputDir : string;
  66. CompilerBin,
  67. { CompilerCPU and CompilerTarget are lowercased at start
  68. to avoid need to call lowercase again and again ... }
  69. CompilerCPU,
  70. CompilerTarget,
  71. CompilerVersion,
  72. DefaultCompilerCPU,
  73. DefaultCompilerTarget,
  74. DefaultCompilerVersion : string;
  75. PPFile : TStringList;
  76. PPFileInfo : TStringList;
  77. TestName : string;
  78. Current : longint;
  79. const
  80. DoGraph : boolean = false;
  81. UseOSOnly : boolean = false;
  82. DoInteractive : boolean = false;
  83. DoExecute : boolean = false;
  84. DoKnown : boolean = false;
  85. DoAll : boolean = false;
  86. DoUsual : boolean = true;
  87. { TargetDir : string = ''; unused }
  88. BenchmarkInfo : boolean = false;
  89. ExtraCompilerOpts : string = '';
  90. DelExecutable : TDelExecutables = [];
  91. RemoteAddr : string = '';
  92. RemotePathPrefix : string = '';
  93. RemotePath : string = '/tmp';
  94. RemotePara : string = '';
  95. RemoteRshParas : string = '';
  96. RemoteShell : string = '';
  97. RemoteShellBase : string = '';
  98. RemoteShellNeedsExport : boolean = false;
  99. rshprog : string = 'rsh';
  100. rcpprog : string = 'rcp';
  101. rquote : string = '''';
  102. UseTimeout : boolean = false;
  103. emulatorname : string = '';
  104. TargetCanCompileLibraries : boolean = true;
  105. UniqueSuffix: string = '';
  106. { Constants used in IsAbsolute function }
  107. TargetHasDosStyleDirectories : boolean = false;
  108. TargetAmigaLike : boolean = false;
  109. TargetIsMacOS : boolean = false;
  110. TargetIsUnix : boolean = false;
  111. { extracted from rtl/macos/macutils.inc }
  112. function IsMacFullPath (const path: string): Boolean;
  113. begin
  114. if Pos(':', path) = 0 then {its partial}
  115. IsMacFullPath := false
  116. else if path[1] = ':' then
  117. IsMacFullPath := false
  118. else
  119. IsMacFullPath := true
  120. end;
  121. Function IsAbsolute (Const F : String) : boolean;
  122. {
  123. Returns True if the name F is a absolute file name
  124. }
  125. begin
  126. IsAbsolute:=false;
  127. if TargetHasDosStyleDirectories then
  128. begin
  129. if (F[1]='/') or (F[1]='\') then
  130. IsAbsolute:=true;
  131. if (Length(F)>2) and (F[2]=':') and ((F[3]='\') or (F[3]='/')) then
  132. IsAbsolute:=true;
  133. end
  134. else if TargetAmigaLike then
  135. begin
  136. if (length(F)>0) and (Pos(':',F) <> 0) then
  137. IsAbsolute:=true;
  138. end
  139. else if TargetIsMacOS then
  140. begin
  141. IsAbsolute:=IsMacFullPath(F);
  142. end
  143. { generic case }
  144. else if (F[1]='/') then
  145. IsAbsolute:=true;
  146. end;
  147. Function FileExists (Const F : String) : Boolean;
  148. {
  149. Returns True if the file exists, False if not.
  150. }
  151. Var
  152. info : searchrec;
  153. begin
  154. FindFirst (F,anyfile,Info);
  155. FileExists:=DosError=0;
  156. FindClose (Info);
  157. end;
  158. Function PathExists (Const F : String) : Boolean;
  159. {
  160. Returns True if the file exists, False if not.
  161. }
  162. Var
  163. info : searchrec;
  164. begin
  165. FindFirst (F,anyfile,Info);
  166. PathExists:=(DosError=0) and (Info.Attr and Directory=Directory);
  167. FindClose (Info);
  168. end;
  169. function ToStr(l:longint):string;
  170. var
  171. s : string;
  172. begin
  173. Str(l,s);
  174. ToStr:=s;
  175. end;
  176. function ToStrZero(l:longint;nbzero : byte):string;
  177. var
  178. s : string;
  179. begin
  180. Str(l,s);
  181. while length(s)<nbzero do
  182. s:='0'+s;
  183. ToStrZero:=s;
  184. end;
  185. function trimspace(const s:string):string;
  186. var
  187. i,j : longint;
  188. begin
  189. i:=length(s);
  190. while (i>0) and (s[i] in [#9,' ']) do
  191. dec(i);
  192. j:=1;
  193. while (j<i) and (s[j] in [#9,' ']) do
  194. inc(j);
  195. trimspace:=Copy(s,j,i-j+1);
  196. end;
  197. function IsInList(const entry,list:string):boolean;
  198. var
  199. i,istart : longint;
  200. begin
  201. IsInList:=false;
  202. i:=0;
  203. while (i<length(list)) do
  204. begin
  205. { Find list item }
  206. istart:=i+1;
  207. while (i<length(list)) and
  208. (list[i+1]<>',') do
  209. inc(i);
  210. if Upcase(entry)=Upcase(TrimSpace(Copy(list,istart,i-istart+1))) then
  211. begin
  212. IsInList:=true;
  213. exit;
  214. end;
  215. { skip , }
  216. inc(i);
  217. end;
  218. end;
  219. procedure SetPPFileInfo;
  220. Var
  221. info : searchrec;
  222. dt : DateTime;
  223. begin
  224. FindFirst (PPFile[current],anyfile,Info);
  225. If DosError=0 then
  226. begin
  227. UnpackTime(info.time,dt);
  228. PPFileInfo.Insert(current,PPFile[current]+' '+ToStr(dt.year)+'/'+ToStrZero(dt.month,2)+'/'+
  229. ToStrZero(dt.day,2)+' '+ToStrZero(dt.Hour,2)+':'+ToStrZero(dt.min,2)+':'+ToStrZero(dt.sec,2));
  230. end
  231. else
  232. PPFileInfo.Insert(current,PPFile[current]);
  233. FindClose (Info);
  234. end;
  235. function SplitPath(const s:string):string;
  236. var
  237. i : longint;
  238. begin
  239. i:=Length(s);
  240. while (i>0) and not(s[i] in ['/','\'{$IFDEF MACOS},':'{$ENDIF}]) do
  241. dec(i);
  242. SplitPath:=Copy(s,1,i);
  243. end;
  244. function SplitBasePath(const s:string): string;
  245. var
  246. i : longint;
  247. begin
  248. i:=1;
  249. while (i<length(s)) and not(s[i] in ['/','\'{$IFDEF MACOS},':'{$ENDIF}]) do
  250. inc(i);
  251. if s[i] in ['/','\'{$IFDEF MACOS},':'{$ENDIF}] then
  252. dec(i);
  253. SplitBasePath:=Copy(s,1,i);
  254. end;
  255. Function SplitFileName(const s:string):string;
  256. var
  257. p : dirstr;
  258. n : namestr;
  259. e : extstr;
  260. begin
  261. FSplit(s,p,n,e);
  262. SplitFileName:=n+e;
  263. end;
  264. Function SplitFileBase(const s:string):string;
  265. var
  266. p : dirstr;
  267. n : namestr;
  268. e : extstr;
  269. begin
  270. FSplit(s,p,n,e);
  271. SplitFileBase:=n;
  272. end;
  273. Function SplitFileExt(const s:string):string;
  274. var
  275. p : dirstr;
  276. n : namestr;
  277. e : extstr;
  278. begin
  279. FSplit(s,p,n,e);
  280. SplitFileExt:=e;
  281. end;
  282. function ForceExtension(Const HStr,ext:String):String;
  283. {
  284. Return a filename which certainly has the extension ext
  285. }
  286. var
  287. j : longint;
  288. begin
  289. j:=length(Hstr);
  290. while (j>0) and (Hstr[j]<>'.') do
  291. dec(j);
  292. if j=0 then
  293. j:=length(Hstr)+1;
  294. if Ext<>'' then
  295. begin
  296. if Ext[1]='.' then
  297. ForceExtension:=Copy(Hstr,1,j-1)+Ext
  298. else
  299. ForceExtension:=Copy(Hstr,1,j-1)+'.'+Ext
  300. end
  301. else
  302. ForceExtension:=Copy(Hstr,1,j-1);
  303. end;
  304. type
  305. TCharSet = set of char;
  306. function GetToken(var s: string; Delims: TCharSet = [' ']):string;
  307. var
  308. i : longint;
  309. p: PChar;
  310. begin
  311. p:=PChar(s);
  312. i:=0;
  313. while (p^ <> #0) and not (p^ in Delims) do begin
  314. Inc(p);
  315. Inc(i);
  316. end;
  317. GetToken:=Copy(s,1,i);
  318. Delete(s,1,i+1);
  319. end;
  320. procedure mkdirtree(const s:string);
  321. var
  322. SErr, hs : string;
  323. Err: longint;
  324. begin
  325. if s='' then
  326. exit;
  327. if s[length(s)] in ['\','/'{$IFDEF MACOS},':'{$ENDIF}] then
  328. hs:=Copy(s,1,length(s)-1)
  329. else
  330. hs:=s;
  331. if not PathExists(hs) then
  332. begin
  333. { Try parent first }
  334. mkdirtree(SplitPath(hs));
  335. { make this dir }
  336. Verbose(V_Debug,'Making directory '+s);
  337. {$I-}
  338. MkDir (HS);
  339. {$I+}
  340. Err := IOResult;
  341. if Err <> 0 then
  342. begin
  343. { did another parallel instance create it in the mean time? }
  344. if not PathExists(hs) then
  345. begin
  346. { no -> error }
  347. Str (Err, SErr);
  348. Verbose (V_Error, 'Directory creation of "'+HS+'" failed ' + SErr);
  349. end;
  350. end;
  351. end;
  352. end;
  353. Function RemoveFile(const f:string):boolean;
  354. var
  355. g : file;
  356. begin
  357. assign(g,f);
  358. {$I-}
  359. erase(g);
  360. {$I+}
  361. RemoveFile:=(ioresult=0);
  362. end;
  363. function Copyfile(const fn1,fn2:string;append:boolean) : longint;
  364. const
  365. bufsize = 16384;
  366. var
  367. f,g : file;
  368. oldfilemode : byte;
  369. st : string;
  370. addsize,
  371. i : longint;
  372. buf : pointer;
  373. begin
  374. if Append then
  375. Verbose(V_Debug,'Appending '+fn1+' to '+fn2)
  376. else
  377. Verbose(V_Debug,'Copying '+fn1+' to '+fn2);
  378. assign(g,fn2);
  379. if append then
  380. begin
  381. {$I-}
  382. reset(g,1);
  383. {$I+}
  384. if ioresult<>0 then
  385. append:=false
  386. else
  387. seek(g,filesize(g));
  388. end;
  389. if not append then
  390. begin
  391. {$I-}
  392. rewrite(g,1);
  393. {$I+}
  394. if ioresult<>0 then
  395. Verbose(V_Error,'Can''t open '+fn2+' for output');
  396. end;
  397. assign(f,fn1);
  398. {$I-}
  399. { Try using read only file mode }
  400. oldfilemode:=filemode;
  401. filemode:=READ_ONLY;
  402. reset(f,1);
  403. {$I+}
  404. addsize:=0;
  405. getmem(buf,bufsize);
  406. if ioresult<>0 then
  407. begin
  408. sleep(1000);
  409. {$I-}
  410. reset(f,1);
  411. {$I+}
  412. if ioresult<>0 then
  413. begin
  414. Verbose(V_Warning,'Can''t open '+fn1);
  415. st:='Can''t open '+fn1;
  416. i:=length(st);
  417. // blocksize is larger than 255, so no check is needed
  418. move(st[1],buf^,i);
  419. blockwrite(g,buf^,i);
  420. freemem(buf,bufsize);
  421. close(g);
  422. filemode:=oldfilemode;
  423. exit;
  424. end;
  425. end;
  426. filemode:=oldfilemode;
  427. repeat
  428. blockread(f,buf^,bufsize,i);
  429. blockwrite(g,buf^,i);
  430. addsize:=addsize+i;
  431. until i<bufsize;
  432. freemem(buf,bufsize);
  433. close(f);
  434. close(g);
  435. CopyFile:=addsize;
  436. end;
  437. procedure AddLog(const logfile,s:string);
  438. var
  439. t : text;
  440. begin
  441. assign(t,logfile);
  442. {$I-}
  443. append(t);
  444. {$I+}
  445. if ioresult<>0 then
  446. begin
  447. {$I-}
  448. rewrite(t);
  449. {$I+}
  450. if ioresult<>0 then
  451. Verbose(V_Abort,'Can''t append to '+logfile);
  452. end;
  453. writeln(t,s);
  454. close(t);
  455. end;
  456. procedure ForceLog(const logfile:string);
  457. var
  458. t : text;
  459. begin
  460. assign(t,logfile);
  461. {$I-}
  462. append(t);
  463. {$I+}
  464. if ioresult<>0 then
  465. begin
  466. {$I-}
  467. rewrite(t);
  468. {$I+}
  469. if ioresult<>0 then
  470. Verbose(V_Abort,'Can''t Create '+logfile);
  471. end;
  472. close(t);
  473. end;
  474. function GetCompilerInfo(c:tcompinfo):boolean;
  475. var
  476. t : text;
  477. hs : string;
  478. begin
  479. GetCompilerInfo:=false;
  480. { Try to get all information in one call, this is
  481. supported in 1.1. Older compilers 1.0.x will only
  482. return the first info }
  483. case c of
  484. compver :
  485. begin
  486. if DefaultCompilerVersion<>'' then
  487. begin
  488. GetCompilerInfo:=true;
  489. exit;
  490. end;
  491. hs:='-iVTPTO';
  492. end;
  493. compcpu :
  494. begin
  495. if DefaultCompilerCPU<>'' then
  496. begin
  497. GetCompilerInfo:=true;
  498. exit;
  499. end;
  500. hs:='-iTPTOV';
  501. end;
  502. comptarget :
  503. begin
  504. if DefaultCompilerTarget<>'' then
  505. begin
  506. GetCompilerInfo:=true;
  507. exit;
  508. end;
  509. hs:='-iTOTPV';
  510. end;
  511. end;
  512. ExecuteRedir(CompilerBin,hs,'','out.'+UniqueSuffix,'');
  513. assign(t,'out.'+UniqueSuffix);
  514. {$I-}
  515. reset(t);
  516. {$ifdef windows}
  517. { try to cope with Windows problems related to AntiVirus scanner
  518. that generate lag time during which access to a given if is forbidden }
  519. if (inoutres=5) then
  520. begin
  521. Sleep(5000);
  522. ioresult;
  523. Verbose(V_Warning,'Windows file not accessible out.'+UniqueSuffix);
  524. reset(t);
  525. end;
  526. {$endif windows}
  527. readln(t,hs);
  528. close(t);
  529. erase(t);
  530. {$I+}
  531. if ioresult<>0 then
  532. Verbose(V_Error,'Can''t get Compiler Info')
  533. else
  534. begin
  535. Verbose(V_Debug,'Retrieved Compiler Info: "'+hs+'"');
  536. case c of
  537. compver :
  538. begin
  539. DefaultCompilerVersion:=GetToken(hs);
  540. DefaultCompilerCPU:=GetToken(hs);
  541. DefaultCompilerTarget:=GetToken(hs);
  542. end;
  543. compcpu :
  544. begin
  545. DefaultCompilerCPU:=GetToken(hs);
  546. DefaultCompilerTarget:=GetToken(hs);
  547. DefaultCompilerVersion:=GetToken(hs);
  548. end;
  549. comptarget :
  550. begin
  551. DefaultCompilerTarget:=GetToken(hs);
  552. DefaultCompilerCPU:=GetToken(hs);
  553. DefaultCompilerVersion:=GetToken(hs);
  554. end;
  555. end;
  556. GetCompilerInfo:=true;
  557. end;
  558. end;
  559. function GetCompilerVersion:boolean;
  560. const
  561. CompilerVersionDebugWritten : boolean = false;
  562. begin
  563. if CompilerVersion='' then
  564. begin
  565. GetCompilerVersion:=GetCompilerInfo(compver);
  566. CompilerVersion:=DefaultCompilerVersion;
  567. end
  568. else
  569. GetCompilerVersion:=true;
  570. if GetCompilerVersion and not CompilerVersionDebugWritten then
  571. begin
  572. Verbose(V_Debug,'Compiler Version: "'+CompilerVersion+'"');
  573. CompilerVersionDebugWritten:=true;
  574. end;
  575. end;
  576. function GetCompilerCPU:boolean;
  577. const
  578. CompilerCPUDebugWritten : boolean = false;
  579. begin
  580. if CompilerCPU='' then
  581. begin
  582. GetCompilerCPU:=GetCompilerInfo(compcpu);
  583. CompilerCPU:=lowercase(DefaultCompilerCPU);
  584. end
  585. else
  586. GetCompilerCPU:=true;
  587. if GetCompilerCPU and not CompilerCPUDebugWritten then
  588. begin
  589. Verbose(V_Debug,'Compiler CPU: "'+CompilerCPU+'"');
  590. CompilerCPUDebugWritten:=true;
  591. end;
  592. end;
  593. function GetCompilerTarget:boolean;
  594. const
  595. CompilerTargetDebugWritten : boolean = false;
  596. begin
  597. if CompilerTarget='' then
  598. begin
  599. GetCompilerTarget:=GetCompilerInfo(comptarget);
  600. CompilerTarget:=lowercase(DefaultCompilerTarget);
  601. end
  602. else
  603. GetCompilerTarget:=true;
  604. if GetCompilerTarget and not CompilerTargetDebugWritten then
  605. begin
  606. Verbose(V_Debug,'Compiler Target: "'+CompilerTarget+'"');
  607. CompilerTargetDebugWritten:=true;
  608. end;
  609. end;
  610. function CompilerFullTarget:string;
  611. begin
  612. if UseOSOnly then
  613. CompilerFullTarget:=CompilerTarget
  614. else
  615. CompilerFullTarget:=CompilerCPU+'-'+CompilerTarget;
  616. end;
  617. { Set the three constants above according to
  618. the current target }
  619. procedure SetTargetDirectoriesStyle;
  620. var
  621. LTarget : string;
  622. begin
  623. { Call this first to ensure that CompilerTarget is not empty }
  624. GetCompilerTarget;
  625. LTarget := CompilerTarget;
  626. TargetHasDosStyleDirectories :=
  627. (LTarget='emx') or
  628. (LTarget='go32v2') or
  629. (LTarget='nativent') or
  630. (LTarget='os2') or
  631. (LTarget='symbian') or
  632. (LTarget='watcom') or
  633. (LTarget='wdosx') or
  634. (LTarget='win32') or
  635. (LTarget='win64');
  636. TargetAmigaLike:=
  637. (LTarget='amiga') or
  638. (LTarget='morphos');
  639. TargetIsMacOS:=
  640. (LTarget='macos');
  641. { Base on whether UNIX is defined as default macro
  642. in extradefines in systesms/i_XXX.pas units }
  643. TargetIsUnix:=
  644. (LTarget='linux') or
  645. (LTarget='linux6432') or
  646. (LTarget='freebsd') or
  647. (LTarget='openbsd') or
  648. (LTarget='netbsd') or
  649. (LTarget='beos') or
  650. (LTarget='haiku') or
  651. (LTarget='solaris') or
  652. (LTarget='iphonesim') or
  653. (LTarget='darwin') or
  654. (LTarget='aix') or
  655. (LTarget='android');
  656. { Set ExeExt for CompilerTarget.
  657. This list has been set up 2013-01 using the information in
  658. compiler/system/i_XXX.pas units.
  659. We should update this list when adding new targets PM }
  660. if (TargetHasDosStyleDirectories) or (LTarget='wince') then
  661. begin
  662. ExeExt:='.exe';
  663. DllExt:='.dll';
  664. DllPrefix:='';
  665. end
  666. else if LTarget='atari' then
  667. begin
  668. ExeExt:='.tpp';
  669. DllExt:='.dll';
  670. DllPrefix:='';
  671. end
  672. else if LTarget='gba' then
  673. ExeExt:='.gba'
  674. else if LTarget='nds' then
  675. ExeExt:='.bin'
  676. else if (LTarget='netware') or (LTarget='netwlibc') then
  677. begin
  678. ExeExt:='.nlm';
  679. DllExt:='.nlm';
  680. DllPrefix:='';
  681. end
  682. else if LTarget='wii' then
  683. ExeExt:='.dol';
  684. end;
  685. {$ifndef LIMIT83FS}
  686. { Set the UseOSOnly constant above according to
  687. the current target }
  688. procedure SetUseOSOnly;
  689. var
  690. LTarget : string;
  691. begin
  692. { Call this first to ensure that CompilerTarget is not empty }
  693. GetCompilerTarget;
  694. LTarget := CompilerTarget;
  695. UseOSOnly:= (LTarget='emx') or
  696. (LTarget='go32v2') or
  697. (LTarget='msdos') or
  698. (LTarget='os2');
  699. end;
  700. {$endif not LIMIT83FS}
  701. procedure SetTargetCanCompileLibraries;
  702. var
  703. LTarget : string;
  704. begin
  705. { Call this first to ensure that CompilerTarget is not empty }
  706. GetCompilerTarget;
  707. LTarget := CompilerTarget;
  708. { Feel free to add other targets here }
  709. if (LTarget='go32v2') then
  710. TargetCanCompileLibraries:=false;
  711. end;
  712. function OutputFileName(Const s,ext:String):String;
  713. begin
  714. {$ifndef macos}
  715. OutputFileName:=OutputDir+'/'+ForceExtension(s,ext);
  716. {$else macos}
  717. OutputFileName:=ConcatMacPath(OutputDir,ForceExtension(s,ext));
  718. {$endif macos}
  719. end;
  720. function TestOutputFileName(Const pref,base,ext:String):String;
  721. begin
  722. {$ifndef macos}
  723. TestOutputFileName:=TestOutputDir+'/'+ForceExtension(pref+SplitFileName(base),ext);
  724. {$else macos}
  725. TestOutputFileName:=ConcatMacPath(TestOutputDir,ForceExtension(pref+SplitFileName(base),ext));
  726. {$endif macos}
  727. end;
  728. function TestLogFileName(Const pref,base,ext:String):String;
  729. var
  730. LogDir: String;
  731. begin
  732. LogDir:=TestOutputDir;
  733. {$ifndef macos}
  734. if UniqueSuffix<>'' then
  735. LogDir:=LogDir+'/..';
  736. TestLogFileName:=LogDir+'/'+ForceExtension(pref+SplitFileName(base),ext);
  737. {$else macos}
  738. if UniqueSuffix<>'' then
  739. LogDir:=LogDir+'::';
  740. TestLogFileName:=ConcatMacPath(LogDir,ForceExtension(pref+SplitFileName(base),ext));
  741. {$endif macos}
  742. end;
  743. function ExitWithInternalError(const OutName:string):boolean;
  744. var
  745. t : text;
  746. s : string;
  747. begin
  748. ExitWithInternalError:=false;
  749. { open logfile }
  750. assign(t,Outname);
  751. {$I-}
  752. reset(t);
  753. {$I+}
  754. if ioresult<>0 then
  755. exit;
  756. while not eof(t) do
  757. begin
  758. readln(t,s);
  759. if pos('Fatal: Internal error ',s)>0 then
  760. begin
  761. ExitWithInternalError:=true;
  762. break;
  763. end;
  764. end;
  765. close(t);
  766. end;
  767. { Takes each option from AddOptions list
  768. considered as a space separated list
  769. and adds the option to args
  770. unless option contains a percent sign,
  771. in that case, the option after % will be added
  772. to args only if CompilerTarget is listed in
  773. the string part before %.
  774. NOTE: this function does not check for
  775. quoted options...
  776. The list before % must of course contain no spaces. }
  777. procedure AppendOptions(AddOptions : string;var args : string);
  778. var
  779. endopt,percentpos : longint;
  780. opttarget, currentopt : string;
  781. begin
  782. Verbose(V_Debug,'AppendOptions called with AddOptions="'+AddOptions+'"');
  783. AddOptions:=trimspace(AddOptions);
  784. repeat
  785. endopt:=pos(' ',AddOptions);
  786. if endopt=0 then
  787. endopt:=length(AddOptions);
  788. currentopt:=trimspace(copy(AddOptions,1,endopt));
  789. AddOptions:=trimspace(copy(Addoptions,endopt+1,length(AddOptions)));
  790. if currentopt<>'' then
  791. begin
  792. percentpos:=pos('%',currentopt);
  793. if (percentpos=0) then
  794. begin
  795. Verbose(V_Debug,'Adding option="'+currentopt+'"');
  796. args:=args+' '+currentopt;
  797. end
  798. else
  799. begin
  800. opttarget:=lowercase(copy(currentopt,1,percentpos-1));
  801. if IsInList(CompilerTarget, opttarget) then
  802. begin
  803. Verbose(V_Debug,'Adding target specific option="'+currentopt+'" for '+opttarget);
  804. args:=args+' '+copy(currentopt,percentpos+1,length(currentopt))
  805. end
  806. else
  807. Verbose(V_Debug,'No matching target "'+currentopt+'"');
  808. end;
  809. end;
  810. until AddOptions='';
  811. end;
  812. { This function removes some incompatible
  813. options from TEST_OPT before adding them to
  814. the list of options passed to the compiler.
  815. %DELOPT=XYZ will remove XYZ exactly
  816. %DELOPT=XYZ* will remove all options starting with XYZ.
  817. NOTE: This fuinction does not handle quoted options. }
  818. function DelOptions(Pattern, opts : string) : string;
  819. var
  820. currentopt : string;
  821. optpos, endopt, startpos, endpos : longint;
  822. iswild : boolean;
  823. begin
  824. opts:=trimspace(opts);
  825. pattern:=trimspace(pattern);
  826. repeat
  827. endpos:=pos(' ',pattern);
  828. if endpos=0 then
  829. endpos:=length(pattern);
  830. currentopt:=trimspace(copy(pattern,1,endpos));
  831. pattern:=trimspace(copy(pattern,endpos+1,length(pattern)));
  832. if currentopt<>'' then
  833. begin
  834. if currentopt[length(currentopt)]='*' then
  835. begin
  836. iswild:=true;
  837. system.delete(currentopt,length(currentopt),1);
  838. end
  839. else
  840. iswild:=false;
  841. startpos:=1;
  842. repeat
  843. optpos:=pos(currentopt,copy(opts,startpos,length(opts)));
  844. if optpos>0 then
  845. begin
  846. { move to index in full opts string }
  847. optpos:=optpos+startpos-1;
  848. { compute position of end of opt }
  849. endopt:=optpos+length(currentopt);
  850. { use that end as start position for next round }
  851. startpos:=endopt;
  852. if iswild then
  853. begin
  854. while (opts[endopt]<>' ') and
  855. (endopt<length(opts)) do
  856. begin
  857. inc(endopt);
  858. inc(startpos);
  859. end;
  860. Verbose(V_Debug,'Pattern match found "'+currentopt+'*" in "'+opts+'"');
  861. system.delete(opts,optpos,endopt-optpos+1);
  862. Verbose(V_Debug,'After opts="'+opts+'"');
  863. end
  864. else
  865. begin
  866. if (endopt>length(opts)) or (opts[endopt]=' ') then
  867. begin
  868. Verbose(V_Debug,'Exact match found "'+currentopt+'" in "'+opts+'"');
  869. system.delete(opts,optpos,endopt-optpos+1);
  870. Verbose(V_Debug,'After opts="'+opts+'"');
  871. end
  872. else
  873. begin
  874. Verbose(V_Debug,'No exact match "'+currentopt+'" in "'+opts+'"');
  875. end;
  876. end;
  877. end;
  878. until optpos=0;
  879. end;
  880. until pattern='';
  881. DelOptions:=opts;
  882. end;
  883. function RunCompiler(const ExtraPara: string):boolean;
  884. var
  885. args,LocalExtraArgs,
  886. wpoargs : string;
  887. passnr,
  888. passes : longint;
  889. execres : boolean;
  890. EndTicks,
  891. StartTicks : int64;
  892. begin
  893. RunCompiler:=false;
  894. args:='-n -T'+CompilerTarget+' -Fu'+RTLUnitsDir;
  895. if ExtraPara<>'' then
  896. args:=args+' '+ExtraPara;
  897. { the helper object files have been copied to the common directory }
  898. if UniqueSuffix<>'' then
  899. args:=args+' -Fo'+TestOutputDir+'/..';
  900. args:=args+' -FE'+TestOutputDir;
  901. if TargetIsMacOS then
  902. args:=args+' -WT '; {tests should be compiled as MPWTool}
  903. if Config.DelOptions<>'' then
  904. LocalExtraArgs:=DelOptions(Config.DelOptions,ExtraCompilerOpts)
  905. else
  906. LocalExtraArgs:=ExtraCompilerOpts;
  907. if LocalExtraArgs<>'' then
  908. args:=args+' '+LocalExtraArgs;
  909. if TargetIsUnix then
  910. begin
  911. { Add runtime library path to current dir to find .so files }
  912. if Config.NeedLibrary then
  913. begin
  914. if (CompilerTarget='darwin') or
  915. (CompilerTarget='aix') then
  916. args:=args+' -Fl'+TestOutputDir
  917. else
  918. { do not use single quote for -k as they are mishandled on
  919. Windows Shells }
  920. args:=args+' -Fl'+TestOutputDir+' -k-rpath -k.'
  921. end;
  922. end;
  923. if Config.NeedOptions<>'' then
  924. AppendOptions(Config.NeedOptions,args);
  925. wpoargs:='';
  926. if (Config.WpoPasses=0) or
  927. (Config.WpoParas='') then
  928. passes:=1
  929. else
  930. passes:=config.wpopasses+1;
  931. args:=args+' '+PPFile[current];
  932. for passnr:=1 to passes do
  933. begin
  934. if (passes>1) then
  935. begin
  936. wpoargs:=' -OW'+config.wpoparas+' -FW'+TestOutputFileName('',PPFile[current],'wp'+tostr(passnr));
  937. if (passnr>1) then
  938. wpoargs:=wpoargs+' -Ow'+config.wpoparas+' -Fw'+TestOutputFileName('',PPFile[current],'wp'+tostr(passnr-1));
  939. end;
  940. Verbose(V_Debug,'Executing '+compilerbin+' '+args+wpoargs);
  941. { also get the output from as and ld that writes to stderr sometimes }
  942. StartTicks:=GetMicroSTicks;
  943. {$ifndef macos}
  944. execres:=ExecuteRedir(CompilerBin,args+wpoargs,'',CompilerLogFile,'stdout');
  945. {$else macos}
  946. {Due to that Toolserver is not reentrant, we have to asm and link via script.}
  947. execres:=ExecuteRedir(CompilerBin,'-s '+args+wpoargs,'',CompilerLogFile,'stdout');
  948. if execres then
  949. execres:=ExecuteRedir(TestOutputDir + ':ppas','','',CompilerLogFile,'stdout');
  950. {$endif macos}
  951. EndTicks:=GetMicroSTicks;
  952. Verbose(V_Debug,'Exitcode '+ToStr(ExecuteResult));
  953. if BenchmarkInfo then
  954. begin
  955. Verbose(V_Normal,'Compilation took '+ToStr(EndTicks-StartTicks)+' us');
  956. end;
  957. { Error during execution? }
  958. if (not execres) and (ExecuteResult=0) then
  959. begin
  960. AddLog(FailLogFile,TestName);
  961. AddLog(ResLogFile,failed_to_compile+PPFileInfo[current]);
  962. AddLog(LongLogFile,line_separation);
  963. AddLog(LongLogFile,failed_to_compile+PPFileInfo[current]);
  964. if CopyFile(CompilerLogFile,LongLogFile,true)=0 then
  965. AddLog(LongLogFile,'IOStatus'+ToStr(IOStatus));
  966. { avoid to try again }
  967. AddLog(ExeLogFile,failed_to_compile+PPFileInfo[current]);
  968. Verbose(V_Warning,'IOStatus: '+ToStr(IOStatus));
  969. exit;
  970. end;
  971. { Check for internal error }
  972. if ExitWithInternalError(CompilerLogFile) then
  973. begin
  974. AddLog(FailLogFile,TestName);
  975. if Config.Note<>'' then
  976. AddLog(FailLogFile,Config.Note);
  977. AddLog(ResLogFile,failed_to_compile+PPFileInfo[current]+' internalerror generated');
  978. AddLog(LongLogFile,line_separation);
  979. AddLog(LongLogFile,failed_to_compile+PPFileInfo[current]);
  980. if Config.Note<>'' then
  981. AddLog(LongLogFile,Config.Note);
  982. if CopyFile(CompilerLogFile,LongLogFile,true)=0 then
  983. AddLog(LongLogFile,'Internal error in compiler');
  984. { avoid to try again }
  985. AddLog(ExeLogFile,failed_to_compile+PPFileInfo[current]);
  986. Verbose(V_Warning,'Internal error in compiler');
  987. exit;
  988. end;
  989. end;
  990. { Should the compile fail ? }
  991. if Config.ShouldFail then
  992. begin
  993. if ExecuteResult<>0 then
  994. begin
  995. AddLog(ResLogFile,success_compilation_failed+PPFileInfo[current]);
  996. { avoid to try again }
  997. AddLog(ExeLogFile,success_compilation_failed+PPFileInfo[current]);
  998. RunCompiler:=true;
  999. end
  1000. else
  1001. begin
  1002. AddLog(FailLogFile,TestName);
  1003. if Config.Note<>'' then
  1004. AddLog(FailLogFile,Config.Note);
  1005. AddLog(ResLogFile,failed_compilation_successful+PPFileInfo[current]);
  1006. AddLog(LongLogFile,line_separation);
  1007. AddLog(LongLogFile,failed_compilation_successful+PPFileInfo[current]);
  1008. { avoid to try again }
  1009. AddLog(ExeLogFile,failed_compilation_successful+PPFileInfo[current]);
  1010. if Config.Note<>'' then
  1011. AddLog(LongLogFile,Config.Note);
  1012. CopyFile(CompilerLogFile,LongLogFile,true);
  1013. end;
  1014. end
  1015. else
  1016. begin
  1017. if (ExecuteResult<>0) and
  1018. (((Config.KnownCompileNote<>'') and (Config.KnownCompileError=0)) or
  1019. ((Config.KnownCompileError<>0) and (ExecuteResult=Config.KnownCompileError))) then
  1020. begin
  1021. AddLog(FailLogFile,TestName+known_problem+Config.KnownCompileNote);
  1022. AddLog(ResLogFile,failed_to_compile+PPFileInfo[current]+known_problem+Config.KnownCompileNote);
  1023. AddLog(LongLogFile,line_separation);
  1024. AddLog(LongLogFile,known_problem+Config.KnownCompileNote);
  1025. AddLog(LongLogFile,failed_to_compile+PPFileInfo[current]+' ('+ToStr(ExecuteResult)+')');
  1026. if Copyfile(CompilerLogFile,LongLogFile,true)=0 then
  1027. AddLog(LongLogFile,known_problem+'exitcode: '+ToStr(ExecuteResult));
  1028. Verbose(V_Warning,known_problem+'exitcode: '+ToStr(ExecuteResult));
  1029. end
  1030. else if ExecuteResult<>0 then
  1031. begin
  1032. AddLog(FailLogFile,TestName);
  1033. if Config.Note<>'' then
  1034. AddLog(FailLogFile,Config.Note);
  1035. AddLog(ResLogFile,failed_to_compile+PPFileInfo[current]);
  1036. AddLog(LongLogFile,line_separation);
  1037. AddLog(LongLogFile,failed_to_compile+PPFileInfo[current]);
  1038. if Config.Note<>'' then
  1039. AddLog(LongLogFile,Config.Note);
  1040. if CopyFile(CompilerLogFile,LongLogFile,true)=0 then
  1041. AddLog(LongLogFile,'Exitcode: '+ToStr(ExecuteResult)+' (expected 0)');
  1042. { avoid to try again }
  1043. AddLog(ExeLogFile,failed_to_compile+PPFileInfo[current]);
  1044. Verbose(V_Warning,'Exitcode: '+ToStr(ExecuteResult)+' (expected 0)');
  1045. end
  1046. else
  1047. begin
  1048. AddLog(ResLogFile,successfully_compiled+PPFileInfo[current]);
  1049. RunCompiler:=true;
  1050. end;
  1051. end;
  1052. end;
  1053. function CheckTestExitCode(const OutName:string):boolean;
  1054. var
  1055. t : text;
  1056. s : string;
  1057. i,code : integer;
  1058. begin
  1059. CheckTestExitCode:=false;
  1060. { open logfile }
  1061. assign(t,Outname);
  1062. {$I-}
  1063. reset(t);
  1064. {$I+}
  1065. if ioresult<>0 then
  1066. exit;
  1067. while not eof(t) do
  1068. begin
  1069. readln(t,s);
  1070. i:=pos('TestExitCode: ',s);
  1071. if i>0 then
  1072. begin
  1073. delete(s,1,i+14-1);
  1074. val(s,ExecuteResult,code);
  1075. if code=0 then
  1076. CheckTestExitCode:=true;
  1077. break;
  1078. end;
  1079. end;
  1080. close(t);
  1081. end;
  1082. function LibraryExists(const PPFile : string; out FileName : string) : boolean;
  1083. begin
  1084. { Check if a dynamic library XXX was created }
  1085. { Windows XXX.dll style }
  1086. FileName:=TestOutputFilename('',PPFile,'dll');
  1087. if FileExists(FileName) then
  1088. begin
  1089. LibraryExists:=true;
  1090. exit;
  1091. end;
  1092. { Linux libXXX.so style }
  1093. FileName:=TestOutputFilename('lib',PPFile,'so');
  1094. if FileExists(FileName) then
  1095. begin
  1096. LibraryExists:=true;
  1097. exit;
  1098. end;
  1099. { Darwin libXXX.dylib style }
  1100. FileName:=TestOutputFilename('lib',PPFile,'dylib');
  1101. if FileExists(FileName) then
  1102. begin
  1103. LibraryExists:=true;
  1104. exit;
  1105. end;
  1106. { MacOS LibXXX style }
  1107. FileName:=TestOutputFilename('Lib',PPFile,'');
  1108. if FileExists(FileName) then
  1109. begin
  1110. LibraryExists:=true;
  1111. exit;
  1112. end;
  1113. { Netware wlic XXX.nlm style }
  1114. FileName:=TestOutputFilename('',PPFile,'nlm');
  1115. if FileExists(FileName) then
  1116. begin
  1117. LibraryExists:=true;
  1118. exit;
  1119. end;
  1120. { Amiga XXX.library style }
  1121. FileName:=TestOutputFilename('',PPFile,'library');
  1122. if FileExists(FileName) then
  1123. begin
  1124. LibraryExists:=true;
  1125. exit;
  1126. end;
  1127. LibraryExists:=false;
  1128. end;
  1129. function ExecuteRemote(prog,args:string;out StartTicks,EndTicks : int64):boolean;
  1130. const
  1131. MaxTrials = 5;
  1132. var
  1133. Trials : longint;
  1134. Res : boolean;
  1135. begin
  1136. if SplitFileExt(prog)='' then
  1137. prog:=prog+SrcExeExt;
  1138. Verbose(V_Debug,'RemoteExecuting '+Prog+' '+args);
  1139. StartTicks:=GetMicroSTicks;
  1140. Res:=false;
  1141. Trials:=0;
  1142. While (Trials<MaxTrials) and not Res do
  1143. begin
  1144. inc(Trials);
  1145. Res:=ExecuteRedir(prog,args,'',EXELogFile,'stdout');
  1146. if not Res then
  1147. Verbose(V_Debug,'Call to '+prog+' failed: '+
  1148. 'IOStatus='+ToStr(IOStatus)+
  1149. ' RedirErrorOut='+ToStr(RedirErrorOut)+
  1150. ' RedirErrorIn='+ToStr(RedirErrorIn)+
  1151. ' RedirErrorError='+ToStr(RedirErrorError)+
  1152. ' ExecuteResult='+ToStr(ExecuteResult));
  1153. end;
  1154. if Trials>1 then
  1155. Verbose(V_Debug,'Done in '+tostr(trials)+' trials');
  1156. EndTicks:=GetMicroSTicks;
  1157. ExecuteRemote:=res;
  1158. end;
  1159. function ExecuteEmulated(const prog,args,FullExeLogFile:string;out StartTicks,EndTicks : int64):boolean;
  1160. begin
  1161. Verbose(V_Debug,'EmulatorExecuting '+Prog+' '+args);
  1162. StartTicks:=GetMicroSTicks;
  1163. ExecuteEmulated:=ExecuteRedir(prog,args,'',FullExeLogFile,'stdout');
  1164. EndTicks:=GetMicroSTicks;
  1165. end;
  1166. function MaybeCopyFiles(const FileToCopy : string) : boolean;
  1167. var
  1168. TestRemoteExe,
  1169. pref : string;
  1170. LocalFile, RemoteFile, s: string;
  1171. LocalPath: string;
  1172. i : integer;
  1173. execres : boolean;
  1174. EndTicks,
  1175. StartTicks : int64;
  1176. FileList : TStringList;
  1177. function BuildFileList: TStringList;
  1178. var
  1179. s : string;
  1180. index : longint;
  1181. begin
  1182. s:=Config.Files;
  1183. if length(s) = 0 then
  1184. begin
  1185. Result:=nil;
  1186. exit;
  1187. end;
  1188. Result:=TStringList.Create;
  1189. repeat
  1190. index:=pos(' ',s);
  1191. if index=0 then
  1192. LocalFile:=s
  1193. else
  1194. LocalFile:=copy(s,1,index-1);
  1195. Result.Add(LocalFile);
  1196. if index=0 then
  1197. break;
  1198. s:=copy(s,index+1,length(s)-index);
  1199. until false;
  1200. end;
  1201. begin
  1202. if RemoteAddr='' then
  1203. begin
  1204. If UniqueSuffix<>'' then
  1205. begin
  1206. FileList:=BuildFileList;
  1207. if assigned(FileList) then
  1208. begin
  1209. LocalPath:=SplitPath(PPFile[current]);
  1210. if Length(LocalPath) > 0 then
  1211. LocalPath:=LocalPath+'/';
  1212. for i:=0 to FileList.count-1 do
  1213. begin
  1214. LocalFile:=FileList[i];
  1215. CopyFile(LocalPath+LocalFile,TestOutputDir+'/'+LocalFile,false);
  1216. end;
  1217. FileList.Free;
  1218. end;
  1219. end;
  1220. exit(true);
  1221. end;
  1222. execres:=true;
  1223. { Check if library should be deleted. Do not copy to remote target in such case. }
  1224. if (deAfter in DelExecutable) and (Config.DelFiles <> '') then
  1225. if SplitFileName(FileToCopy) = DllPrefix + Trim(Config.DelFiles) + DllExt then
  1226. exit;
  1227. { We don't want to create subdirs, remove paths from the test }
  1228. TestRemoteExe:=RemotePath+'/'+SplitFileName(FileToCopy);
  1229. if deBefore in DelExecutable then
  1230. begin
  1231. s:=RemoteRshParas+' rm ';
  1232. if rshprog <> 'adb' then
  1233. s:=s+'-f ';
  1234. ExecuteRemote(rshprog,s+TestRemoteExe,
  1235. StartTicks,EndTicks);
  1236. end;
  1237. execres:=ExecuteRemote(rcpprog,RemotePara+' '+FileToCopy+' '+
  1238. RemotePathPrefix+TestRemoteExe,StartTicks,EndTicks);
  1239. if not execres then
  1240. begin
  1241. Verbose(V_normal, 'Could not copy executable '+FileToCopy);
  1242. exit(execres);
  1243. end;
  1244. FileList:=BuildFileList;
  1245. if assigned(FileList) then
  1246. begin
  1247. LocalPath:=SplitPath(PPFile[current]);
  1248. if Length(LocalPath) > 0 then
  1249. LocalPath:=LocalPath+'/';
  1250. for i:=0 to FileList.count-1 do
  1251. begin
  1252. LocalFile:=FileList[i];
  1253. RemoteFile:=RemotePath+'/'+SplitFileName(LocalFile);
  1254. LocalFile:=LocalPath+LocalFile;
  1255. if DoVerbose and (rcpprog='pscp') then
  1256. pref:='-v '
  1257. else
  1258. pref:='';
  1259. execres:=ExecuteRemote(rcpprog,pref+RemotePara+' '+LocalFile+' '+
  1260. RemotePathPrefix+RemoteFile,StartTicks,EndTicks);
  1261. if not execres then
  1262. begin
  1263. Verbose(V_normal, 'Could not copy required file '+LocalFile);
  1264. FileList.Free;
  1265. exit(false);
  1266. end;
  1267. end;
  1268. end;
  1269. FileList.Free;
  1270. MaybeCopyFiles:=execres;
  1271. end;
  1272. function RunExecutable:boolean;
  1273. const
  1274. {$ifdef unix}
  1275. CurrDir = './';
  1276. {$else}
  1277. CurrDir = '';
  1278. {$endif}
  1279. var
  1280. OldDir, s, ss,
  1281. execcmd,
  1282. FullExeLogFile,
  1283. TestRemoteExe,
  1284. TestExe : string;
  1285. execres : boolean;
  1286. EndTicks,
  1287. StartTicks : int64;
  1288. begin
  1289. RunExecutable:=false;
  1290. execres:=true;
  1291. TestExe:=TestOutputFilename('',PPFile[current],ExeExt);
  1292. execres:=MaybeCopyFiles(TestExe);
  1293. if EmulatorName<>'' then
  1294. begin
  1295. { Get full name out log file, because we change the directory during
  1296. execution }
  1297. FullExeLogFile:=FExpand(EXELogFile);
  1298. {$I-}
  1299. GetDir(0,OldDir);
  1300. ChDir(TestOutputDir);
  1301. {$I+}
  1302. ioresult;
  1303. s:=CurrDir+SplitFileName(TestExe);
  1304. execres:=ExecuteEmulated(EmulatorName,s,FullExeLogFile,StartTicks,EndTicks);
  1305. {$I-}
  1306. ChDir(OldDir);
  1307. {$I+}
  1308. end
  1309. else if RemoteAddr<>'' then
  1310. begin
  1311. TestRemoteExe:=RemotePath+'/'+SplitFileName(TestExe);
  1312. { rsh doesn't pass the exitcode, use a second command to print the exitcode
  1313. on the remoteshell to stdout }
  1314. if DoVerbose and (rshprog='plink') then
  1315. execcmd:='-v '+RemoteRshParas
  1316. else
  1317. execcmd:=RemoteRshParas;
  1318. execcmd:=execcmd+' '+rquote+
  1319. 'chmod 755 '+TestRemoteExe+
  1320. ' && cd '+RemotePath+' && { ';
  1321. { Using -rpath . at compile time does not seem
  1322. to work for programs copied over to remote machine,
  1323. at least not for FreeBSD.
  1324. Does this work for all shells? }
  1325. if Config.NeedLibrary then
  1326. begin
  1327. if RemoteShellNeedsExport then
  1328. if CompilerTarget='darwin' then
  1329. execcmd:=execcmd+' DYLD_LIBRARY_PATH=.; export DYLD_LIBRARY_PATH;'
  1330. else
  1331. execcmd:=execcmd+' LD_LIBRARY_PATH=.; export LD_LIBRARY_PATH;'
  1332. else
  1333. if CompilerTarget='darwin' then
  1334. execcmd:=execcmd+' setenv DYLD_LIBRARY_PATH=.; '
  1335. else
  1336. execcmd:=execcmd+' setenv LD_LIBRARY_PATH=.; '
  1337. end;
  1338. if UseTimeout then
  1339. begin
  1340. if Config.Timeout=0 then
  1341. Config.Timeout:=DefaultTimeout;
  1342. str(Config.Timeout,s);
  1343. if (RemoteShellBase='bash') then
  1344. execcmd:=execcmd+'ulimit -t '+s+'; '
  1345. else
  1346. execcmd:=execcmd+'timeout -9 '+s;
  1347. end;
  1348. { as we moved to RemotePath, if path is not absolute
  1349. we need to use ./execfilename only }
  1350. if not isabsolute(TestRemoteExe) then
  1351. execcmd:=execcmd+' ./'+SplitFileName(TestRemoteExe)
  1352. else
  1353. execcmd:=execcmd+' '+TestRemoteExe;
  1354. execcmd:=execcmd+' ; echo TestExitCode: $?';
  1355. if (deAfter in DelExecutable) and
  1356. not Config.NeededAfter then
  1357. begin
  1358. execcmd:=execcmd+' ; rm ';
  1359. if rshprog <> 'adb' then
  1360. execcmd:=execcmd+'-f ';
  1361. execcmd:=execcmd+SplitFileName(TestRemoteExe);
  1362. end;
  1363. execcmd:=execcmd+'; }'+rquote;
  1364. execres:=ExecuteRemote(rshprog,execcmd,StartTicks,EndTicks);
  1365. { Check for TestExitCode error in output, sets ExecuteResult }
  1366. if not CheckTestExitCode(EXELogFile) then
  1367. Verbose(V_Debug,'Failed to check exit code for '+execcmd);
  1368. if (deAfter in DelExecutable) and ( (Config.DelFiles <> '') or (Config.Files <> '')) then
  1369. begin
  1370. ss:=Trim(Config.DelFiles + ' ' + Config.Files);
  1371. execcmd:=RemoteRshParas+' ' + rquote + 'cd ' + RemotePath + ' && { ';
  1372. while ss <> '' do
  1373. begin
  1374. s:=Trim(GetToken(ss, [' ',',',';']));
  1375. if s = '' then
  1376. break;
  1377. if ExtractFileExt(s) = '' then
  1378. // If file has no extension, treat it as exe or shared lib
  1379. execcmd:=execcmd + 'rm ' + s + ExeExt + '; rm ' + DllPrefix + s + DllExt
  1380. else
  1381. execcmd:=execcmd + 'rm ' + s;
  1382. execcmd:=execcmd + '; ';
  1383. end;
  1384. ExecuteRemote(rshprog,execcmd+'}'+rquote,StartTicks,EndTicks);
  1385. end;
  1386. end
  1387. else
  1388. begin
  1389. { Get full name out log file, because we change the directory during
  1390. execution }
  1391. FullExeLogFile:=FExpand(EXELogFile);
  1392. Verbose(V_Debug,'Executing '+TestExe);
  1393. {$I-}
  1394. GetDir(0,OldDir);
  1395. ChDir(TestOutputDir);
  1396. {$I+}
  1397. ioresult;
  1398. { don't redirect interactive and graph programs }
  1399. StartTicks:=GetMicroSTicks;
  1400. if Config.IsInteractive or Config.UsesGraph then
  1401. execres:=ExecuteRedir(CurrDir+SplitFileName(TestExe),'','','','')
  1402. else
  1403. execres:=ExecuteRedir(CurrDir+SplitFileName(TestExe),'','',FullExeLogFile,'stdout');
  1404. EndTicks:=GetMicroSTicks;
  1405. {$I-}
  1406. ChDir(OldDir);
  1407. {$I+}
  1408. ioresult;
  1409. end;
  1410. { Error during execution? }
  1411. Verbose(V_Debug,'Exitcode '+ToStr(ExecuteResult));
  1412. if BenchmarkInfo then
  1413. begin
  1414. Verbose(V_Normal,'Execution took '+ToStr(EndTicks-StartTicks)+' us');
  1415. end;
  1416. if (not execres) and (ExecuteResult=0) then
  1417. begin
  1418. AddLog(FailLogFile,TestName);
  1419. AddLog(ResLogFile,failed_to_run+PPFileInfo[current]);
  1420. AddLog(LongLogFile,line_separation);
  1421. AddLog(LongLogFile,failed_to_run+PPFileInfo[current]);
  1422. if CopyFile(EXELogFile,LongLogFile,true)=0 then
  1423. AddLog(LongLogFile,'IOStatus: '+ToStr(IOStatus));
  1424. { avoid to try again }
  1425. AddLog(ExeLogFile,failed_to_run+PPFileInfo[current]);
  1426. Verbose(V_Warning,'IOStatus: '+ToStr(IOStatus));
  1427. exit;
  1428. end;
  1429. if ExecuteResult<>Config.ResultCode then
  1430. begin
  1431. if (ExecuteResult<>0) and
  1432. (ExecuteResult=Config.KnownRunError) then
  1433. begin
  1434. AddLog(FailLogFile,TestName+known_problem+Config.KnownRunNote);
  1435. AddLog(ResLogFile,failed_to_run+PPFileInfo[current]+known_problem+Config.KnownRunNote);
  1436. AddLog(LongLogFile,line_separation);
  1437. AddLog(LongLogFile,known_problem+Config.KnownRunNote);
  1438. AddLog(LongLogFile,failed_to_run+PPFileInfo[current]+' ('+ToStr(ExecuteResult)+')');
  1439. if Copyfile(EXELogFile,LongLogFile,true)=0 then
  1440. begin
  1441. AddLog(LongLogFile,known_problem+'exitcode: '+ToStr(ExecuteResult)+' (expected '+ToStr(Config.ResultCode)+')');
  1442. AddLog(ExeLogFile,known_problem+'exitcode: '+ToStr(ExecuteResult)+' (expected '+ToStr(Config.ResultCode)+')');
  1443. end;
  1444. Verbose(V_Warning,known_problem+'exitcode: '+ToStr(ExecuteResult)+' (expected '+ToStr(Config.ResultCode)+')');
  1445. end
  1446. else
  1447. begin
  1448. AddLog(FailLogFile,TestName);
  1449. AddLog(ResLogFile,failed_to_run+PPFileInfo[current]);
  1450. AddLog(LongLogFile,line_separation);
  1451. AddLog(LongLogFile,failed_to_run+PPFileInfo[current]+' ('+ToStr(ExecuteResult)+')');
  1452. if Copyfile(EXELogFile,LongLogFile,true)=0 then
  1453. begin
  1454. AddLog(LongLogFile,'Exitcode: '+ToStr(ExecuteResult)+' (expected '+ToStr(Config.ResultCode)+')');
  1455. AddLog(ExeLogFile,'Exitcode: '+ToStr(ExecuteResult)+' (expected '+ToStr(Config.ResultCode)+')');
  1456. end;
  1457. Verbose(V_Warning,'Exitcode: '+ToStr(ExecuteResult)+' (expected '+ToStr(Config.ResultCode)+')');
  1458. end
  1459. end
  1460. else
  1461. begin
  1462. AddLog(ResLogFile,successfully_run+PPFileInfo[current]);
  1463. RunExecutable:=true;
  1464. end;
  1465. if (deAfter in DelExecutable) and not Config.NeededAfter then
  1466. begin
  1467. Verbose(V_Debug,'Deleting executable '+TestExe);
  1468. RemoveFile(TestExe);
  1469. RemoveFile(ForceExtension(TestExe,ObjExt));
  1470. RemoveFile(ForceExtension(TestExe,PPUExt));
  1471. end;
  1472. end;
  1473. { Try to collect information concerning the remote configuration
  1474. Currently only records RemoteShell name and sets
  1475. RemoteShellNeedsExport boolean variable }
  1476. procedure SetRemoteConfiguration;
  1477. var
  1478. f : text;
  1479. StartTicks,EndTicks : int64;
  1480. begin
  1481. if RemoteAddr='' then
  1482. exit;
  1483. if rshprog = 'adb' then
  1484. begin
  1485. RemoteShellNeedsExport:=true;
  1486. exit;
  1487. end;
  1488. ExeLogFile:='__remote.tmp';
  1489. ExecuteRemote(rshprog,RemoteRshParas+
  1490. ' "echo SHELL=${SHELL}"',StartTicks,EndTicks);
  1491. Assign(f,ExeLogFile);
  1492. Reset(f);
  1493. While not eof(f) do
  1494. begin
  1495. Readln(f,RemoteShellBase);
  1496. if pos('SHELL=',RemoteShellBase)>0 then
  1497. begin
  1498. RemoteShell:=TrimSpace(Copy(RemoteShellBase,pos('SHELL=',RemoteShellBase)+6,
  1499. length(RemoteShellBase)));
  1500. Verbose(V_Debug,'Remote shell is "'+RemoteShell+'"');
  1501. RemoteShellBase:=SplitFileBase(RemoteShell);
  1502. if (RemoteShellBase='bash') or (RemoteShellBase='sh') then
  1503. RemoteShellNeedsExport:=true;
  1504. end;
  1505. end;
  1506. Close(f);
  1507. end;
  1508. procedure getargs;
  1509. procedure helpscreen;
  1510. begin
  1511. writeln('dotest [Options] <File>');
  1512. writeln;
  1513. writeln('Options can be:');
  1514. writeln(' !ENV_NAME parse environment variable ENV_NAME for options');
  1515. writeln(' -A include ALL tests');
  1516. writeln(' -ADB use ADB to run tests');
  1517. writeln(' -B delete executable before remote upload');
  1518. writeln(' -C<compiler> set compiler to use');
  1519. writeln(' -D display execution time');
  1520. writeln(' -E execute test also');
  1521. writeln(' -G include graph tests');
  1522. writeln(' -I include interactive tests');
  1523. writeln(' -K include known bug tests');
  1524. writeln(' -L<ext> set extension of temporary files (prevent conflicts with parallel invocations)');
  1525. writeln(' -M<emulator> run the tests using the given emulator');
  1526. writeln(' -O use timeout wrapper for (remote) execution');
  1527. writeln(' -P<path> path to the tests tree on the remote machine');
  1528. writeln(' -R<remote> run the tests remotely with the given rsh/ssh address');
  1529. writeln(' -S use ssh instead of rsh');
  1530. writeln(' -T[cpu-]<os> run tests for target cpu and os');
  1531. writeln(' -U<remotepara>');
  1532. writeln(' pass additional parameter to remote program. Multiple -U can be used');
  1533. writeln(' -V be verbose');
  1534. writeln(' -W use putty compatible file names when testing (plink and pscp)');
  1535. writeln(' -X don''t use COMSPEC');
  1536. writeln(' -Y<opts> extra options passed to the compiler. Several -Y<opt> can be given.');
  1537. writeln(' -Z remove temporary files (executable,ppu,o)');
  1538. halt(1);
  1539. end;
  1540. procedure interpret_option (para : string);
  1541. var
  1542. ch : char;
  1543. j : longint;
  1544. begin
  1545. Verbose(V_Debug,'Interpreting option"'+para+'"');
  1546. ch:=Upcase(para[2]);
  1547. delete(para,1,2);
  1548. case ch of
  1549. 'A' :
  1550. if UpperCase(para) = 'DB' then
  1551. begin
  1552. rshprog:='adb';
  1553. rcpprog:='adb';
  1554. rquote:='"';
  1555. if RemoteAddr = '' then
  1556. RemoteAddr:='1'; // fake remote addr (default device will be used)
  1557. end
  1558. else
  1559. begin
  1560. DoGraph:=true;
  1561. DoInteractive:=true;
  1562. DoKnown:=true;
  1563. DoAll:=true;
  1564. end;
  1565. 'B' : Include(DelExecutable,deBefore);
  1566. 'C' : CompilerBin:=Para;
  1567. 'D' : BenchMarkInfo:=true;
  1568. 'E' : DoExecute:=true;
  1569. 'G' : begin
  1570. DoGraph:=true;
  1571. if para='-' then
  1572. DoUsual:=false;
  1573. end;
  1574. 'I' : begin
  1575. DoInteractive:=true;
  1576. if para='-' then
  1577. DoUsual:=false;
  1578. end;
  1579. 'K' : begin
  1580. DoKnown:=true;
  1581. if para='-' then
  1582. DoUsual:=false;
  1583. end;
  1584. 'L' : begin
  1585. UniqueSuffix:=Para;
  1586. end;
  1587. 'M' : EmulatorName:=Para;
  1588. 'O' : UseTimeout:=true;
  1589. 'P' : RemotePath:=Para;
  1590. 'R' : RemoteAddr:=Para;
  1591. 'S' :
  1592. begin
  1593. rshprog:='ssh';
  1594. rcpprog:='scp';
  1595. end;
  1596. 'T' :
  1597. begin
  1598. j:=Pos('-',Para);
  1599. if j>0 then
  1600. begin
  1601. CompilerCPU:=Copy(Para,1,j-1);
  1602. CompilerTarget:=Copy(Para,j+1,length(para));
  1603. end
  1604. else
  1605. CompilerTarget:=Para
  1606. end;
  1607. 'U' :
  1608. RemotePara:=RemotePara+' '+Para;
  1609. 'V' : DoVerbose:=true;
  1610. 'W' :
  1611. begin
  1612. rshprog:='plink';
  1613. rcpprog:='pscp';
  1614. rquote:='"';
  1615. end;
  1616. 'X' : UseComSpec:=false;
  1617. 'Y' : ExtraCompilerOpts:= ExtraCompilerOpts +' '+ Para;
  1618. 'Z' : Include(DelExecutable,deAfter);
  1619. end;
  1620. end;
  1621. procedure interpret_env(arg : string);
  1622. var
  1623. para : string;
  1624. pspace : longint;
  1625. begin
  1626. Verbose(V_Debug,'Interpreting environment option"'+arg+'"');
  1627. { Get rid of leading '!' }
  1628. delete(arg,1,1);
  1629. arg:=getenv(arg);
  1630. Verbose(V_Debug,'Environment value is "'+arg+'"');
  1631. while (length(arg)>0) do
  1632. begin
  1633. while (length(arg)>0) and (arg[1]=' ') do
  1634. delete(arg,1,1);
  1635. pspace:=pos(' ',arg);
  1636. if pspace=0 then
  1637. pspace:=length(arg)+1;
  1638. para:=copy(arg,1,pspace-1);
  1639. if (length(para)>0) and (para[1]='-') then
  1640. interpret_option (para)
  1641. else
  1642. begin
  1643. PPFile.Insert(current,ForceExtension(Para,'pp'));
  1644. inc(current);
  1645. end;
  1646. delete(arg,1,pspace);
  1647. end;
  1648. end;
  1649. var
  1650. param : string;
  1651. i : longint;
  1652. begin
  1653. CompilerBin:='ppc386'+srcexeext;
  1654. for i:=1 to paramcount do
  1655. begin
  1656. param:=Paramstr(i);
  1657. if (param[1]='-') then
  1658. interpret_option(param)
  1659. else if (param[1]='!') then
  1660. interpret_env(param)
  1661. else
  1662. begin
  1663. PPFile.Insert(current,ForceExtension(Param,'pp'));
  1664. inc(current);
  1665. end;
  1666. end;
  1667. if current=0 then
  1668. HelpScreen;
  1669. { disable graph,interactive when running remote }
  1670. if RemoteAddr<>'' then
  1671. begin
  1672. DoGraph:=false;
  1673. DoInteractive:=false;
  1674. end;
  1675. { If we use PuTTY plink program with -load option,
  1676. the IP address or name should not be added to
  1677. the command line }
  1678. if (rshprog='plink') and (pos('-load',RemotePara)>0) then
  1679. RemoteRshParas:=RemotePara
  1680. else
  1681. if rshprog='adb' then
  1682. begin
  1683. if RemoteAddr <> '1' then
  1684. RemotePara:=Trim('-s ' + RemoteAddr + ' ' + RemotePara);
  1685. RemoteRshParas:=Trim(RemotePara + ' shell');
  1686. end
  1687. else
  1688. RemoteRshParas:=RemotePara+' '+RemoteAddr;
  1689. if rcpprog = 'adb' then
  1690. begin
  1691. RemotePathPrefix:='';
  1692. RemotePara:=Trim(RemotePara + ' push');
  1693. end
  1694. else
  1695. RemotePathPrefix:=RemoteAddr + ':';
  1696. end;
  1697. procedure RunTest;
  1698. var
  1699. PPDir,LibraryName,LogSuffix : string;
  1700. Res : boolean;
  1701. begin
  1702. Res:=GetConfig(PPFile[current],Config);
  1703. if Res then
  1704. begin
  1705. Res:=GetCompilerCPU;
  1706. Res:=GetCompilerTarget;
  1707. {$ifndef MACOS}
  1708. RTLUnitsDir:='tstunits/'+CompilerFullTarget;
  1709. {$else MACOS}
  1710. RTLUnitsDir:=':tstunits:'+CompilerFullTarget;
  1711. {$endif MACOS}
  1712. if not PathExists(RTLUnitsDir) then
  1713. Verbose(V_Abort,'Unit path "'+RTLUnitsDir+'" does not exists');
  1714. {$ifndef MACOS}
  1715. OutputDir:='output/'+CompilerFullTarget;
  1716. {$else MACOS}
  1717. OutputDir:=':output:'+CompilerFullTarget;
  1718. {$endif MACOS}
  1719. if not PathExists(OutputDir) then
  1720. Verbose(V_Abort,'Output path "'+OutputDir+'" does not exists');
  1721. { Make subdir in output if needed }
  1722. PPDir:=SplitPath(PPFile[current]);
  1723. if PPDir[length(PPDir)] in ['/','\'{$ifdef MACOS},':'{$endif MACOS}] then
  1724. Delete(PPDir,length(PPDir),1);
  1725. if PPDir<>'' then
  1726. begin
  1727. {$ifndef MACOS}
  1728. TestOutputDir:=OutputDir+'/'+PPDir;
  1729. if UniqueSuffix<>'' then
  1730. TestOutputDir:=TestOutputDir+'/'+UniqueSuffix;
  1731. {$else MACOS}
  1732. TestOutputDir:=OutputDir+PPDir;
  1733. if UniqueSuffix<>'' then
  1734. TestOutputDir:=TestOutputDir+':'+UniqueSuffix;
  1735. {$endif MACOS}
  1736. mkdirtree(TestOutputDir);
  1737. end
  1738. else
  1739. TestOutputDir:=OutputDir;
  1740. if UniqueSuffix<>'' then
  1741. LogSuffix:=UniqueSuffix
  1742. else
  1743. LogSuffix:=SplitBasePath(PPDir)+'log';
  1744. ResLogFile:=OutputFileName('log',LogSuffix);
  1745. LongLogFile:=OutputFileName('longlog',LogSuffix);
  1746. FailLogFile:=OutputFileName('faillist',LogSuffix);
  1747. ForceLog(ResLogFile);
  1748. ForceLog(LongLogFile);
  1749. ForceLog(FailLogFile);
  1750. { Per test logfiles }
  1751. CompilerLogFile:=TestLogFileName('',SplitFileName(PPFile[current]),'log');
  1752. ExeLogFile:=TestLogFileName('',SplitFileName(PPFile[current]),'elg');
  1753. Verbose(V_Debug,'Using Compiler logfile: '+CompilerLogFile);
  1754. Verbose(V_Debug,'Using Execution logfile: '+ExeLogFile);
  1755. end;
  1756. if Res then
  1757. begin
  1758. if Config.UsesGraph and (not DoGraph) then
  1759. begin
  1760. AddLog(ResLogFile,skipping_graph_test+PPFileInfo[current]);
  1761. { avoid a second attempt by writing to elg file }
  1762. AddLog(EXELogFile,skipping_graph_test+PPFileInfo[current]);
  1763. Verbose(V_Warning,skipping_graph_test);
  1764. Res:=false;
  1765. end;
  1766. end;
  1767. if Res then
  1768. begin
  1769. if Config.IsInteractive and (not DoInteractive) then
  1770. begin
  1771. { avoid a second attempt by writing to elg file }
  1772. AddLog(EXELogFile,skipping_interactive_test+PPFileInfo[current]);
  1773. AddLog(ResLogFile,skipping_interactive_test+PPFileInfo[current]);
  1774. Verbose(V_Warning,skipping_interactive_test);
  1775. Res:=false;
  1776. end;
  1777. end;
  1778. if Res then
  1779. begin
  1780. if Config.IsKnownCompileError and (not DoKnown) then
  1781. begin
  1782. { avoid a second attempt by writing to elg file }
  1783. AddLog(EXELogFile,skipping_known_bug+PPFileInfo[current]);
  1784. AddLog(ResLogFile,skipping_known_bug+PPFileInfo[current]);
  1785. Verbose(V_Warning,skipping_known_bug);
  1786. Res:=false;
  1787. end;
  1788. end;
  1789. if Res and not DoUsual then
  1790. res:=(Config.IsInteractive and DoInteractive) or
  1791. (Config.IsKnownRunError and DoKnown) or
  1792. (Config.UsesGraph and DoGraph);
  1793. if Res then
  1794. begin
  1795. if (Config.MinVersion<>'') and not DoAll then
  1796. begin
  1797. Verbose(V_Debug,'Required compiler version: '+Config.MinVersion);
  1798. Res:=GetCompilerVersion;
  1799. if CompilerVersion<Config.MinVersion then
  1800. begin
  1801. { avoid a second attempt by writing to elg file }
  1802. AddLog(EXELogFile,skipping_compiler_version_too_low+PPFileInfo[current]);
  1803. AddLog(ResLogFile,skipping_compiler_version_too_low+PPFileInfo[current]);
  1804. Verbose(V_Warning,'Compiler version too low '+CompilerVersion+' < '+Config.MinVersion);
  1805. Res:=false;
  1806. end;
  1807. end;
  1808. end;
  1809. if Res then
  1810. begin
  1811. if (Config.MaxVersion<>'') and not DoAll then
  1812. begin
  1813. Verbose(V_Debug,'Highest compiler version: '+Config.MaxVersion);
  1814. Res:=GetCompilerVersion;
  1815. if CompilerVersion>Config.MaxVersion then
  1816. begin
  1817. { avoid a second attempt by writing to elg file }
  1818. AddLog(EXELogFile,skipping_compiler_version_too_high+PPFileInfo[current]);
  1819. AddLog(ResLogFile,skipping_compiler_version_too_high+PPFileInfo[current]);
  1820. Verbose(V_Warning,'Compiler version too high '+CompilerVersion+' > '+Config.MaxVersion);
  1821. Res:=false;
  1822. end;
  1823. end;
  1824. end;
  1825. if Res then
  1826. begin
  1827. if Config.NeedCPU<>'' then
  1828. begin
  1829. Verbose(V_Debug,'Required compiler cpu: '+Config.NeedCPU);
  1830. if not IsInList(CompilerCPU,Config.NeedCPU) then
  1831. begin
  1832. { avoid a second attempt by writing to elg file }
  1833. AddLog(EXELogFile,skipping_other_cpu+PPFileInfo[current]);
  1834. AddLog(ResLogFile,skipping_other_cpu+PPFileInfo[current]);
  1835. Verbose(V_Warning,'Compiler cpu "'+CompilerCPU+'" is not in list "'+Config.NeedCPU+'"');
  1836. Res:=false;
  1837. end;
  1838. end;
  1839. end;
  1840. if Res then
  1841. begin
  1842. if Config.SkipCPU<>'' then
  1843. begin
  1844. Verbose(V_Debug,'Skip compiler cpu: '+Config.SkipCPU);
  1845. if IsInList(CompilerCPU,Config.SkipCPU) then
  1846. begin
  1847. { avoid a second attempt by writing to elg file }
  1848. AddLog(EXELogFile,skipping_other_cpu+PPFileInfo[current]);
  1849. AddLog(ResLogFile,skipping_other_cpu+PPFileInfo[current]);
  1850. Verbose(V_Warning,'Compiler cpu "'+CompilerCPU+'" is in list "'+Config.SkipCPU+'"');
  1851. Res:=false;
  1852. end;
  1853. end;
  1854. end;
  1855. if Res then
  1856. begin
  1857. if Config.SkipEmu<>'' then
  1858. begin
  1859. Verbose(V_Debug,'Skip emulator: '+emulatorname);
  1860. if IsInList(emulatorname,Config.SkipEmu) then
  1861. begin
  1862. { avoid a second attempt by writing to elg file }
  1863. AddLog(EXELogFile,skipping_other_cpu+PPFileInfo[current]);
  1864. AddLog(ResLogFile,skipping_other_cpu+PPFileInfo[current]);
  1865. Verbose(V_Warning,'Emulator "'+emulatorname+'" is in list "'+Config.SkipEmu+'"');
  1866. Res:=false;
  1867. end;
  1868. end;
  1869. end;
  1870. if Res then
  1871. begin
  1872. if Config.NeedTarget<>'' then
  1873. begin
  1874. Verbose(V_Debug,'Required compiler target: '+Config.NeedTarget);
  1875. if not IsInList(CompilerTarget,Config.NeedTarget) then
  1876. begin
  1877. { avoid a second attempt by writing to elg file }
  1878. AddLog(EXELogFile,skipping_other_target+PPFileInfo[current]);
  1879. AddLog(ResLogFile,skipping_other_target+PPFileInfo[current]);
  1880. Verbose(V_Warning,'Compiler target "'+CompilerTarget+'" is not in list "'+Config.NeedTarget+'"');
  1881. Res:=false;
  1882. end;
  1883. end;
  1884. end;
  1885. if Res then
  1886. begin
  1887. if Config.SkipTarget<>'' then
  1888. begin
  1889. Verbose(V_Debug,'Skip compiler target: '+Config.SkipTarget);
  1890. if IsInList(CompilerTarget,Config.SkipTarget) then
  1891. begin
  1892. { avoid a second attempt by writing to elg file }
  1893. AddLog(EXELogFile,skipping_other_target+PPFileInfo[current]);
  1894. AddLog(ResLogFile,skipping_other_target+PPFileInfo[current]);
  1895. Verbose(V_Warning,'Compiler target "'+CompilerTarget+'" is in list "'+Config.SkipTarget+'"');
  1896. Res:=false;
  1897. end;
  1898. end;
  1899. end;
  1900. if Res then
  1901. begin
  1902. { Use known bug, to avoid adding a new entry for this PM 2011-06-24 }
  1903. if Config.NeedLibrary and not TargetCanCompileLibraries then
  1904. begin
  1905. AddLog(EXELogFile,skipping_known_bug+PPFileInfo[current]);
  1906. AddLog(ResLogFile,skipping_known_bug+PPFileInfo[current]);
  1907. Verbose(V_Warning,'Compiler target "'+CompilerTarget+'" does not support library compilation');
  1908. Res:=false;
  1909. end;
  1910. end;
  1911. if Res then
  1912. begin
  1913. Res:=RunCompiler('');
  1914. if Res and Config.NeedRecompile then
  1915. Res:=RunCompiler(Config.RecompileOpt);
  1916. end;
  1917. if Res and (not Config.ShouldFail) then
  1918. begin
  1919. if (Config.NoRun) then
  1920. begin
  1921. { avoid a second attempt by writing to elg file }
  1922. AddLog(EXELogFile,skipping_run_test+PPFileInfo[current]);
  1923. AddLog(ResLogFile,skipping_run_test+PPFileInfo[current]);
  1924. Verbose(V_Debug,skipping_run_test);
  1925. if LibraryExists(PPFile[current],LibraryName) then
  1926. MaybeCopyFiles(LibraryName);
  1927. end
  1928. else if Config.IsKnownRunError and (not DoKnown) then
  1929. begin
  1930. { avoid a second attempt by writing to elg file }
  1931. AddLog(EXELogFile,skipping_known_bug+PPFileInfo[current]);
  1932. AddLog(ResLogFile,skipping_known_bug+PPFileInfo[current]);
  1933. Verbose(V_Warning,skipping_known_bug);
  1934. end
  1935. else
  1936. begin
  1937. if DoExecute then
  1938. begin
  1939. if FileExists(TestOutputFilename('',PPFile[current],'ppu')) or
  1940. FileExists(TestOutputFilename('',PPFile[current],'ppo')) or
  1941. FileExists(TestOutputFilename('',PPFile[current],'ppw')) then
  1942. begin
  1943. AddLog(ExeLogFile,skipping_run_unit+PPFileInfo[current]);
  1944. AddLog(ResLogFile,skipping_run_unit+PPFileInfo[current]);
  1945. Verbose(V_Debug,'Unit found, skipping run test')
  1946. end
  1947. else if LibraryExists(PPFile[current],LibraryName) then
  1948. begin
  1949. Verbose(V_Debug,'Library found, skipping run test');
  1950. MaybeCopyFiles(LibraryName);
  1951. end
  1952. else
  1953. Res:=RunExecutable;
  1954. end;
  1955. end;
  1956. end;
  1957. end;
  1958. begin
  1959. Current:=0;
  1960. PPFile:=TStringList.Create;
  1961. PPFile.Capacity:=10;
  1962. PPFileInfo:=TStringList.Create;
  1963. PPFileInfo.Capacity:=10;
  1964. GetArgs;
  1965. SetTargetDirectoriesStyle;
  1966. SetTargetCanCompileLibraries;
  1967. SetRemoteConfiguration;
  1968. {$ifdef LIMIT83fs}
  1969. UseOSOnly:=true;
  1970. {$else not LIMIT83fs}
  1971. SetUseOSOnly;
  1972. {$endif not LIMIT83fs}
  1973. Verbose(V_Debug,'Found '+ToStr(PPFile.Count)+' tests to run');
  1974. if current>0 then
  1975. for current:=0 to PPFile.Count-1 do
  1976. begin
  1977. SetPPFileInfo;
  1978. TestName:=Copy(PPFile[current],1,Pos('.pp',PPFile[current])-1);
  1979. Verbose(V_Normal,'Running test '+TestName+', file '+PPFile[current]);
  1980. RunTest;
  1981. end;
  1982. PPFile.Free;
  1983. PPFileInfo.Free;
  1984. end.