dotest.pp 47 KB

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