dotest.pp 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740
  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. { do not use single quote for -k as they are mishandled on
  665. Windows Shells }
  666. args:=args+' -Fl'+TestOutputDir+' -k-rpath -k.'
  667. else
  668. args:=args+' -Fl'+TestOutputDir;
  669. end;
  670. end;
  671. if Config.NeedOptions<>'' then
  672. args:=args+' '+Config.NeedOptions;
  673. wpoargs:='';
  674. if (Config.WpoPasses=0) or
  675. (Config.WpoParas='') then
  676. passes:=1
  677. else
  678. passes:=config.wpopasses+1;
  679. args:=args+' '+PPFile[current];
  680. for passnr:=1 to passes do
  681. begin
  682. if (passes>1) then
  683. begin
  684. wpoargs:=' -OW'+config.wpoparas+' -FW'+TestOutputFileName('',PPFile[current],'wp'+tostr(passnr));
  685. if (passnr>1) then
  686. wpoargs:=wpoargs+' -Ow'+config.wpoparas+' -Fw'+TestOutputFileName('',PPFile[current],'wp'+tostr(passnr-1));
  687. end;
  688. Verbose(V_Debug,'Executing '+compilerbin+' '+args+wpoargs);
  689. { also get the output from as and ld that writes to stderr sometimes }
  690. StartTicks:=GetMicroSTicks;
  691. {$ifndef macos}
  692. execres:=ExecuteRedir(CompilerBin,args+wpoargs,'',CompilerLogFile,'stdout');
  693. {$else macos}
  694. {Due to that Toolserver is not reentrant, we have to asm and link via script.}
  695. execres:=ExecuteRedir(CompilerBin,'-s '+args+wpoargs,'',CompilerLogFile,'stdout');
  696. if execres then
  697. execres:=ExecuteRedir(TestOutputDir + ':ppas','','',CompilerLogFile,'stdout');
  698. {$endif macos}
  699. EndTicks:=GetMicroSTicks;
  700. Verbose(V_Debug,'Exitcode '+ToStr(ExecuteResult));
  701. if BenchmarkInfo then
  702. begin
  703. Verbose(V_Normal,'Compilation took '+ToStr(EndTicks-StartTicks)+' us');
  704. end;
  705. { Error during execution? }
  706. if (not execres) and (ExecuteResult=0) then
  707. begin
  708. AddLog(FailLogFile,TestName);
  709. AddLog(ResLogFile,failed_to_compile+PPFileInfo[current]);
  710. AddLog(LongLogFile,line_separation);
  711. AddLog(LongLogFile,failed_to_compile+PPFileInfo[current]);
  712. if CopyFile(CompilerLogFile,LongLogFile,true)=0 then
  713. AddLog(LongLogFile,'IOStatus'+ToStr(IOStatus));
  714. { avoid to try again }
  715. AddLog(ExeLogFile,failed_to_compile+PPFileInfo[current]);
  716. Verbose(V_Warning,'IOStatus: '+ToStr(IOStatus));
  717. exit;
  718. end;
  719. { Check for internal error }
  720. if ExitWithInternalError(CompilerLogFile) then
  721. begin
  722. AddLog(FailLogFile,TestName);
  723. if Config.Note<>'' then
  724. AddLog(FailLogFile,Config.Note);
  725. AddLog(ResLogFile,failed_to_compile+PPFileInfo[current]+' internalerror generated');
  726. AddLog(LongLogFile,line_separation);
  727. AddLog(LongLogFile,failed_to_compile+PPFileInfo[current]);
  728. if Config.Note<>'' then
  729. AddLog(LongLogFile,Config.Note);
  730. if CopyFile(CompilerLogFile,LongLogFile,true)=0 then
  731. AddLog(LongLogFile,'Internal error in compiler');
  732. { avoid to try again }
  733. AddLog(ExeLogFile,failed_to_compile+PPFileInfo[current]);
  734. Verbose(V_Warning,'Internal error in compiler');
  735. exit;
  736. end;
  737. end;
  738. { Should the compile fail ? }
  739. if Config.ShouldFail then
  740. begin
  741. if ExecuteResult<>0 then
  742. begin
  743. AddLog(ResLogFile,success_compilation_failed+PPFileInfo[current]);
  744. { avoid to try again }
  745. AddLog(ExeLogFile,success_compilation_failed+PPFileInfo[current]);
  746. RunCompiler:=true;
  747. end
  748. else
  749. begin
  750. AddLog(FailLogFile,TestName);
  751. if Config.Note<>'' then
  752. AddLog(FailLogFile,Config.Note);
  753. AddLog(ResLogFile,failed_compilation_successful+PPFileInfo[current]);
  754. AddLog(LongLogFile,line_separation);
  755. AddLog(LongLogFile,failed_compilation_successful+PPFileInfo[current]);
  756. { avoid to try again }
  757. AddLog(ExeLogFile,failed_compilation_successful+PPFileInfo[current]);
  758. if Config.Note<>'' then
  759. AddLog(LongLogFile,Config.Note);
  760. CopyFile(CompilerLogFile,LongLogFile,true);
  761. end;
  762. end
  763. else
  764. begin
  765. if (ExecuteResult<>0) and
  766. (((Config.KnownCompileNote<>'') and (Config.KnownCompileError=0)) or
  767. ((Config.KnownCompileError<>0) and (ExecuteResult=Config.KnownCompileError))) then
  768. begin
  769. AddLog(FailLogFile,TestName+known_problem+Config.KnownCompileNote);
  770. AddLog(ResLogFile,failed_to_compile+PPFileInfo[current]+known_problem+Config.KnownCompileNote);
  771. AddLog(LongLogFile,line_separation);
  772. AddLog(LongLogFile,known_problem+Config.KnownCompileNote);
  773. AddLog(LongLogFile,failed_to_compile+PPFileInfo[current]+' ('+ToStr(ExecuteResult)+')');
  774. if Copyfile(CompilerLogFile,LongLogFile,true)=0 then
  775. AddLog(LongLogFile,known_problem+'exitcode: '+ToStr(ExecuteResult));
  776. Verbose(V_Warning,known_problem+'exitcode: '+ToStr(ExecuteResult));
  777. end
  778. else if ExecuteResult<>0 then
  779. begin
  780. AddLog(FailLogFile,TestName);
  781. if Config.Note<>'' then
  782. AddLog(FailLogFile,Config.Note);
  783. AddLog(ResLogFile,failed_to_compile+PPFileInfo[current]);
  784. AddLog(LongLogFile,line_separation);
  785. AddLog(LongLogFile,failed_to_compile+PPFileInfo[current]);
  786. if Config.Note<>'' then
  787. AddLog(LongLogFile,Config.Note);
  788. if CopyFile(CompilerLogFile,LongLogFile,true)=0 then
  789. AddLog(LongLogFile,'Exitcode: '+ToStr(ExecuteResult)+' (expected 0)');
  790. { avoid to try again }
  791. AddLog(ExeLogFile,failed_to_compile+PPFileInfo[current]);
  792. Verbose(V_Warning,'Exitcode: '+ToStr(ExecuteResult)+' (expected 0)');
  793. end
  794. else
  795. begin
  796. AddLog(ResLogFile,successfully_compiled+PPFileInfo[current]);
  797. RunCompiler:=true;
  798. end;
  799. end;
  800. end;
  801. function CheckTestExitCode(const OutName:string):boolean;
  802. var
  803. t : text;
  804. s : string;
  805. i,code : integer;
  806. begin
  807. CheckTestExitCode:=false;
  808. { open logfile }
  809. assign(t,Outname);
  810. {$I-}
  811. reset(t);
  812. {$I+}
  813. if ioresult<>0 then
  814. exit;
  815. while not eof(t) do
  816. begin
  817. readln(t,s);
  818. i:=pos('TestExitCode: ',s);
  819. if i>0 then
  820. begin
  821. delete(s,1,i+14-1);
  822. val(s,ExecuteResult,code);
  823. if code=0 then
  824. CheckTestExitCode:=true;
  825. break;
  826. end;
  827. end;
  828. close(t);
  829. end;
  830. function LibraryExists(const PPFile : string; var FileName : string) : boolean;
  831. begin
  832. { Check if a dynamic library XXX was created }
  833. { Windows XXX.dll style }
  834. FileName:=TestOutputFilename('',PPFile,'dll');
  835. if FileExists(FileName) then
  836. begin
  837. LibraryExists:=true;
  838. exit;
  839. end;
  840. { Linux libXXX.so style }
  841. FileName:=TestOutputFilename('lib',PPFile,'so');
  842. if FileExists(FileName) then
  843. begin
  844. LibraryExists:=true;
  845. exit;
  846. end;
  847. { Darwin libXXX.dylib style }
  848. FileName:=TestOutputFilename('lib',PPFile,'dylib');
  849. if FileExists(FileName) then
  850. begin
  851. LibraryExists:=true;
  852. exit;
  853. end;
  854. { MacOS LibXXX style }
  855. FileName:=TestOutputFilename('Lib',PPFile,'');
  856. if FileExists(FileName) then
  857. begin
  858. LibraryExists:=true;
  859. exit;
  860. end;
  861. { Netware wlic XXX.nlm style }
  862. FileName:=TestOutputFilename('',PPFile,'nlm');
  863. if FileExists(FileName) then
  864. begin
  865. LibraryExists:=true;
  866. exit;
  867. end;
  868. { Amiga XXX.library style }
  869. FileName:=TestOutputFilename('',PPFile,'library');
  870. if FileExists(FileName) then
  871. begin
  872. LibraryExists:=true;
  873. exit;
  874. end;
  875. LibraryExists:=false;
  876. end;
  877. function ExecuteRemote(const prog,args:string;var StartTicks,EndTicks : int64):boolean;
  878. const
  879. MaxTrials = 5;
  880. var
  881. Trials : longint;
  882. Res : boolean;
  883. begin
  884. Verbose(V_Debug,'RemoteExecuting '+Prog+' '+args);
  885. StartTicks:=GetMicroSTicks;
  886. Res:=false;
  887. Trials:=0;
  888. While (Trials<MaxTrials) and not Res do
  889. begin
  890. inc(Trials);
  891. Res:=ExecuteRedir(prog,args,'',EXELogFile,'stdout');
  892. if not Res then
  893. Verbose(V_Debug,'Call to '+prog+' failed: '+
  894. 'IOStatus='+ToStr(IOStatus)+
  895. ' RedirErrorOut='+ToStr(RedirErrorOut)+
  896. ' RedirErrorIn='+ToStr(RedirErrorIn)+
  897. ' RedirErrorError='+ToStr(RedirErrorError)+
  898. ' ExecuteResult='+ToStr(ExecuteResult));
  899. end;
  900. if Trials>1 then
  901. Verbose(V_Debug,'Done in '+tostr(trials)+' trials');
  902. EndTicks:=GetMicroSTicks;
  903. ExecuteRemote:=res;
  904. end;
  905. function ExecuteEmulated(const prog,args,FullExeLogFile:string;var StartTicks,EndTicks : int64):boolean;
  906. begin
  907. Verbose(V_Debug,'EmulatorExecuting '+Prog+' '+args);
  908. StartTicks:=GetMicroSTicks;
  909. ExecuteEmulated:=ExecuteRedir(prog,args,'',FullExeLogFile,'stdout');
  910. EndTicks:=GetMicroSTicks;
  911. end;
  912. function MaybeCopyFiles(const FileToCopy : string) : boolean;
  913. var
  914. TestRemoteExe,
  915. s : string;
  916. pref : string;
  917. LocalFile, RemoteFile: string;
  918. LocalPath: string;
  919. index : integer;
  920. execres : boolean;
  921. EndTicks,
  922. StartTicks : int64;
  923. begin
  924. if RemoteAddr='' then
  925. begin
  926. exit(false);
  927. end;
  928. execres:=true;
  929. { We don't want to create subdirs, remove paths from the test }
  930. TestRemoteExe:=RemotePath+'/'+SplitFileName(FileToCopy);
  931. if deBefore in DelExecutable then
  932. ExecuteRemote(rshprog,RemotePara+' '+RemoteAddr+' rm -f '+TestRemoteExe,
  933. StartTicks,EndTicks);
  934. execres:=ExecuteRemote(rcpprog,RemotePara+' '+FileToCopy+' '+
  935. RemoteAddr+':'+TestRemoteExe,StartTicks,EndTicks);
  936. if not execres then
  937. begin
  938. Verbose(V_normal, 'Could not copy executable '+FileToCopy);
  939. exit(execres);
  940. end;
  941. s:=Config.Files;
  942. if length(s) > 0 then
  943. begin
  944. LocalPath:=SplitPath(PPFile[current]);
  945. if Length(LocalPath) > 0 then
  946. LocalPath:=LocalPath+'/';
  947. repeat
  948. index:=pos(' ',s);
  949. if index=0 then
  950. LocalFile:=s
  951. else
  952. LocalFile:=copy(s,1,index-1);
  953. RemoteFile:=RemotePath+'/'+SplitFileName(LocalFile);
  954. LocalFile:=LocalPath+LocalFile;
  955. if DoVerbose and (rcpprog='pscp') then
  956. pref:='-v '
  957. else
  958. pref:='';
  959. execres:=ExecuteRemote(rcpprog,pref+RemotePara+' '+LocalFile+' '+
  960. RemoteAddr+':'+RemoteFile,StartTicks,EndTicks);
  961. if not execres then
  962. begin
  963. Verbose(V_normal, 'Could not copy required file '+LocalFile);
  964. exit(false);
  965. end;
  966. if index=0 then
  967. break;
  968. s:=copy(s,index+1,length(s)-index);
  969. until false;
  970. end;
  971. MaybeCopyFiles:=execres;
  972. end;
  973. function RunExecutable:boolean;
  974. const
  975. {$ifdef unix}
  976. CurrDir = './';
  977. {$else}
  978. CurrDir = '';
  979. {$endif}
  980. var
  981. OldDir, s,
  982. execcmd,
  983. FullExeLogFile,
  984. TestRemoteExe,
  985. TestExe : string;
  986. execres : boolean;
  987. EndTicks,
  988. StartTicks : int64;
  989. begin
  990. RunExecutable:=false;
  991. execres:=true;
  992. TestExe:=OutputFileName(PPFile[current],ExeExt);
  993. if EmulatorName<>'' then
  994. begin
  995. { Get full name out log file, because we change the directory during
  996. execution }
  997. FullExeLogFile:=FExpand(EXELogFile);
  998. {$I-}
  999. GetDir(0,OldDir);
  1000. ChDir(TestOutputDir);
  1001. {$I+}
  1002. ioresult;
  1003. s:=CurrDir+SplitFileName(TestExe);
  1004. execres:=ExecuteEmulated(EmulatorName,s,FullExeLogFile,StartTicks,EndTicks);
  1005. {$I-}
  1006. ChDir(OldDir);
  1007. {$I+}
  1008. end
  1009. else if RemoteAddr<>'' then
  1010. begin
  1011. execres:=MaybeCopyFiles(TestExe);
  1012. TestRemoteExe:=RemotePath+'/'+SplitFileName(TestExe);
  1013. { rsh doesn't pass the exitcode, use a second command to print the exitcode
  1014. on the remoteshell to stdout }
  1015. if DoVerbose and (rshprog='plink') then
  1016. execcmd:='-v '
  1017. else
  1018. execcmd:='';
  1019. execcmd:=execcmd+RemotePara+' '+RemoteAddr+' '+rquote+
  1020. 'chmod 755 '+TestRemoteExe+
  1021. ' ; cd '+RemotePath+' ; ';
  1022. { Using -rpath . at compile time does not seem
  1023. to work for programs copied over to remote machine,
  1024. at least not for FreeBSD.
  1025. Does this work for all shells? }
  1026. if Config.NeedLibrary then
  1027. begin
  1028. if RemoteShellNeedsExport then
  1029. execcmd:=execcmd+' LD_LIBRARY_PATH=.; export LD_LIBRARY_PATH;'
  1030. else
  1031. execcmd:=execcmd+' setenv LD_LIBRARY_PATH=.; ';
  1032. end;
  1033. if UseTimeout then
  1034. begin
  1035. if Config.Timeout=0 then
  1036. Config.Timeout:=DefaultTimeout;
  1037. str(Config.Timeout,s);
  1038. if (RemoteShellBase='bash') then
  1039. execcmd:=execcmd+'ulimit -t '+s+'; '
  1040. else
  1041. execcmd:=execcmd+'timeout -9 '+s;
  1042. end;
  1043. { as we moved to RemotePath, if path is not absolute
  1044. we need to use ./execfilename only }
  1045. if not isabsolute(TestRemoteExe) then
  1046. execcmd:=execcmd+' ./'+SplitFileName(TestRemoteExe)
  1047. else
  1048. execcmd:=execcmd+' '+TestRemoteExe;
  1049. execcmd:=execcmd+' ; echo "TestExitCode: $?"';
  1050. if (deAfter in DelExecutable) and
  1051. not Config.NeededAfter then
  1052. execcmd:=execcmd+' ; rm -f '+TestRemoteExe;
  1053. execcmd:=execcmd+rquote;
  1054. execres:=ExecuteRemote(rshprog,execcmd,StartTicks,EndTicks);
  1055. { Check for TestExitCode error in output, sets ExecuteResult }
  1056. if not CheckTestExitCode(EXELogFile) then
  1057. Verbose(V_Debug,'Failed to check exit code for '+execcmd);
  1058. end
  1059. else
  1060. begin
  1061. { Get full name out log file, because we change the directory during
  1062. execution }
  1063. FullExeLogFile:=FExpand(EXELogFile);
  1064. Verbose(V_Debug,'Executing '+TestExe);
  1065. {$I-}
  1066. GetDir(0,OldDir);
  1067. ChDir(TestOutputDir);
  1068. {$I+}
  1069. ioresult;
  1070. { don't redirect interactive and graph programs }
  1071. StartTicks:=GetMicroSTicks;
  1072. if Config.IsInteractive or Config.UsesGraph then
  1073. execres:=ExecuteRedir(CurrDir+SplitFileName(TestExe),'','','','')
  1074. else
  1075. execres:=ExecuteRedir(CurrDir+SplitFileName(TestExe),'','',FullExeLogFile,'stdout');
  1076. EndTicks:=GetMicroSTicks;
  1077. {$I-}
  1078. ChDir(OldDir);
  1079. {$I+}
  1080. ioresult;
  1081. end;
  1082. { Error during execution? }
  1083. Verbose(V_Debug,'Exitcode '+ToStr(ExecuteResult));
  1084. if BenchmarkInfo then
  1085. begin
  1086. Verbose(V_Normal,'Execution took '+ToStr(EndTicks-StartTicks)+' us');
  1087. end;
  1088. if (not execres) and (ExecuteResult=0) then
  1089. begin
  1090. AddLog(FailLogFile,TestName);
  1091. AddLog(ResLogFile,failed_to_run+PPFileInfo[current]);
  1092. AddLog(LongLogFile,line_separation);
  1093. AddLog(LongLogFile,failed_to_run+PPFileInfo[current]);
  1094. if CopyFile(EXELogFile,LongLogFile,true)=0 then
  1095. AddLog(LongLogFile,'IOStatus: '+ToStr(IOStatus));
  1096. { avoid to try again }
  1097. AddLog(ExeLogFile,failed_to_run+PPFileInfo[current]);
  1098. Verbose(V_Warning,'IOStatus: '+ToStr(IOStatus));
  1099. exit;
  1100. end;
  1101. if ExecuteResult<>Config.ResultCode then
  1102. begin
  1103. if (ExecuteResult<>0) and
  1104. (ExecuteResult=Config.KnownRunError) then
  1105. begin
  1106. AddLog(FailLogFile,TestName+known_problem+Config.KnownRunNote);
  1107. AddLog(ResLogFile,failed_to_run+PPFileInfo[current]+known_problem+Config.KnownRunNote);
  1108. AddLog(LongLogFile,line_separation);
  1109. AddLog(LongLogFile,known_problem+Config.KnownRunNote);
  1110. AddLog(LongLogFile,failed_to_run+PPFileInfo[current]+' ('+ToStr(ExecuteResult)+')');
  1111. if Copyfile(EXELogFile,LongLogFile,true)=0 then
  1112. begin
  1113. AddLog(LongLogFile,known_problem+'exitcode: '+ToStr(ExecuteResult)+' (expected '+ToStr(Config.ResultCode)+')');
  1114. AddLog(ExeLogFile,known_problem+'exitcode: '+ToStr(ExecuteResult)+' (expected '+ToStr(Config.ResultCode)+')');
  1115. end;
  1116. Verbose(V_Warning,known_problem+'exitcode: '+ToStr(ExecuteResult)+' (expected '+ToStr(Config.ResultCode)+')');
  1117. end
  1118. else
  1119. begin
  1120. AddLog(FailLogFile,TestName);
  1121. AddLog(ResLogFile,failed_to_run+PPFileInfo[current]);
  1122. AddLog(LongLogFile,line_separation);
  1123. AddLog(LongLogFile,failed_to_run+PPFileInfo[current]+' ('+ToStr(ExecuteResult)+')');
  1124. if Copyfile(EXELogFile,LongLogFile,true)=0 then
  1125. begin
  1126. AddLog(LongLogFile,'Exitcode: '+ToStr(ExecuteResult)+' (expected '+ToStr(Config.ResultCode)+')');
  1127. AddLog(ExeLogFile,'Exitcode: '+ToStr(ExecuteResult)+' (expected '+ToStr(Config.ResultCode)+')');
  1128. end;
  1129. Verbose(V_Warning,'Exitcode: '+ToStr(ExecuteResult)+' (expected '+ToStr(Config.ResultCode)+')');
  1130. end
  1131. end
  1132. else
  1133. begin
  1134. AddLog(ResLogFile,successfully_run+PPFileInfo[current]);
  1135. RunExecutable:=true;
  1136. end;
  1137. if (deAfter in DelExecutable) and not Config.NeededAfter then
  1138. begin
  1139. Verbose(V_Debug,'Deleting executable '+TestExe);
  1140. RemoveFile(TestExe);
  1141. RemoveFile(ForceExtension(TestExe,ObjExt));
  1142. RemoveFile(ForceExtension(TestExe,PPUExt));
  1143. end;
  1144. end;
  1145. { Try to collect information concerning the remote configuration
  1146. Currently only records RemoteShell name and sets
  1147. RemoteShellNeedsExport boolean variable }
  1148. procedure SetRemoteConfiguration;
  1149. var
  1150. f : text;
  1151. StartTicks,EndTicks : int64;
  1152. begin
  1153. if RemoteAddr='' then
  1154. exit;
  1155. ExeLogFile:='__remote.tmp';
  1156. ExecuteRemote(rshprog,RemotePara+' '+RemoteAddr+
  1157. ' "echo SHELL=${SHELL}"',StartTicks,EndTicks);
  1158. Assign(f,ExeLogFile);
  1159. Reset(f);
  1160. While not eof(f) do
  1161. begin
  1162. Readln(f,RemoteShellBase);
  1163. if pos('SHELL=',RemoteShellBase)>0 then
  1164. begin
  1165. RemoteShell:=TrimSpace(Copy(RemoteShellBase,pos('SHELL=',RemoteShellBase)+6,
  1166. length(RemoteShellBase)));
  1167. Verbose(V_Debug,'Remote shell is "'+RemoteShell+'"');
  1168. RemoteShellBase:=SplitFileBase(RemoteShell);
  1169. if (RemoteShellBase='bash') or (RemoteShellBase='sh') then
  1170. RemoteShellNeedsExport:=true;
  1171. end;
  1172. end;
  1173. Close(f);
  1174. end;
  1175. procedure getargs;
  1176. procedure helpscreen;
  1177. begin
  1178. writeln('dotest [Options] <File>');
  1179. writeln;
  1180. writeln('Options can be:');
  1181. writeln(' !ENV_NAME parse environment variable ENV_NAME for options');
  1182. writeln(' -A include ALL tests');
  1183. writeln(' -B delete executable before remote upload');
  1184. writeln(' -C<compiler> set compiler to use');
  1185. writeln(' -D display execution time');
  1186. writeln(' -E execute test also');
  1187. writeln(' -G include graph tests');
  1188. writeln(' -I include interactive tests');
  1189. writeln(' -K include known bug tests');
  1190. writeln(' -M<emulator> run the tests using the given emulator');
  1191. writeln(' -O use timeout wrapper for (remote) execution');
  1192. writeln(' -P<path> path to the tests tree on the remote machine');
  1193. writeln(' -R<remote> run the tests remotely with the given rsh/ssh address');
  1194. writeln(' -S use ssh instead of rsh');
  1195. writeln(' -T[cpu-]<os> run tests for target cpu and os');
  1196. writeln(' -U<remotepara>');
  1197. writeln(' pass additional parameter to remote program. Multiple -U can be used');
  1198. writeln(' -V be verbose');
  1199. writeln(' -W use putty compatible file names when testing (plink and pscp)');
  1200. writeln(' -X don''t use COMSPEC');
  1201. writeln(' -Y<opts> extra options passed to the compiler. Several -Y<opt> can be given.');
  1202. writeln(' -Z remove temporary files (executable,ppu,o)');
  1203. halt(1);
  1204. end;
  1205. procedure interpret_option (para : string);
  1206. var
  1207. ch : char;
  1208. j : longint;
  1209. begin
  1210. Verbose(V_Debug,'Interpreting option"'+para+'"');
  1211. ch:=Upcase(para[2]);
  1212. delete(para,1,2);
  1213. case ch of
  1214. 'A' :
  1215. begin
  1216. DoGraph:=true;
  1217. DoInteractive:=true;
  1218. DoKnown:=true;
  1219. DoAll:=true;
  1220. end;
  1221. 'B' : Include(DelExecutable,deBefore);
  1222. 'C' : CompilerBin:=Para;
  1223. 'D' : BenchMarkInfo:=true;
  1224. 'E' : DoExecute:=true;
  1225. 'G' : begin
  1226. DoGraph:=true;
  1227. if para='-' then
  1228. DoUsual:=false;
  1229. end;
  1230. 'I' : begin
  1231. DoInteractive:=true;
  1232. if para='-' then
  1233. DoUsual:=false;
  1234. end;
  1235. 'K' : begin
  1236. DoKnown:=true;
  1237. if para='-' then
  1238. DoUsual:=false;
  1239. end;
  1240. 'M' : EmulatorName:=Para;
  1241. 'O' : UseTimeout:=true;
  1242. 'P' : RemotePath:=Para;
  1243. 'R' : RemoteAddr:=Para;
  1244. 'S' :
  1245. begin
  1246. rshprog:='ssh';
  1247. rcpprog:='scp';
  1248. end;
  1249. 'T' :
  1250. begin
  1251. j:=Pos('-',Para);
  1252. if j>0 then
  1253. begin
  1254. CompilerCPU:=Copy(Para,1,j-1);
  1255. CompilerTarget:=Copy(Para,j+1,length(para));
  1256. end
  1257. else
  1258. CompilerTarget:=Para
  1259. end;
  1260. 'U' :
  1261. RemotePara:=RemotePara+' '+Para;
  1262. 'V' : DoVerbose:=true;
  1263. 'W' :
  1264. begin
  1265. rshprog:='plink';
  1266. rcpprog:='pscp';
  1267. rquote:='"';
  1268. end;
  1269. 'X' : UseComSpec:=false;
  1270. 'Y' : ExtraCompilerOpts:= ExtraCompilerOpts +' '+ Para;
  1271. 'Z' : Include(DelExecutable,deAfter);
  1272. end;
  1273. end;
  1274. procedure interpret_env(arg : string);
  1275. var
  1276. para : string;
  1277. pspace : longint;
  1278. begin
  1279. Verbose(V_Debug,'Interpreting environment option"'+arg+'"');
  1280. { Get rid of leading '!' }
  1281. delete(arg,1,1);
  1282. arg:=getenv(arg);
  1283. Verbose(V_Debug,'Environment value is "'+arg+'"');
  1284. while (length(arg)>0) do
  1285. begin
  1286. while (length(arg)>0) and (arg[1]=' ') do
  1287. delete(arg,1,1);
  1288. pspace:=pos(' ',arg);
  1289. if pspace=0 then
  1290. pspace:=length(arg)+1;
  1291. para:=copy(arg,1,pspace-1);
  1292. if (length(para)>0) and (para[1]='-') then
  1293. interpret_option (para)
  1294. else
  1295. begin
  1296. PPFile.Insert(current,ForceExtension(Para,'pp'));
  1297. inc(current);
  1298. end;
  1299. delete(arg,1,pspace);
  1300. end;
  1301. end;
  1302. var
  1303. param : string;
  1304. i : longint;
  1305. begin
  1306. CompilerBin:='ppc386'+srcexeext;
  1307. for i:=1 to paramcount do
  1308. begin
  1309. param:=Paramstr(i);
  1310. if (param[1]='-') then
  1311. interpret_option(param)
  1312. else if (param[1]='!') then
  1313. interpret_env(param)
  1314. else
  1315. begin
  1316. PPFile.Insert(current,ForceExtension(Param,'pp'));
  1317. inc(current);
  1318. end;
  1319. end;
  1320. if current=0 then
  1321. HelpScreen;
  1322. { disable graph,interactive when running remote }
  1323. if RemoteAddr<>'' then
  1324. begin
  1325. DoGraph:=false;
  1326. DoInteractive:=false;
  1327. end;
  1328. end;
  1329. procedure RunTest;
  1330. var
  1331. PPDir,LibraryName : string;
  1332. Res : boolean;
  1333. begin
  1334. Res:=GetConfig(PPFile[current],Config);
  1335. if Res then
  1336. begin
  1337. Res:=GetCompilerCPU;
  1338. Res:=GetCompilerTarget;
  1339. {$ifndef MACOS}
  1340. RTLUnitsDir:='units/'+CompilerFullTarget;
  1341. {$else MACOS}
  1342. RTLUnitsDir:=':units:'+CompilerFullTarget;
  1343. {$endif MACOS}
  1344. if not PathExists(RTLUnitsDir) then
  1345. Verbose(V_Abort,'Unit path "'+RTLUnitsDir+'" does not exists');
  1346. {$ifndef MACOS}
  1347. OutputDir:='output/'+CompilerFullTarget;
  1348. {$else MACOS}
  1349. OutputDir:=':output:'+CompilerFullTarget;
  1350. {$endif MACOS}
  1351. if not PathExists(OutputDir) then
  1352. Verbose(V_Abort,'Output path "'+OutputDir+'" does not exists');
  1353. { Global log files }
  1354. ResLogFile:=OutputFileName('log','');
  1355. LongLogFile:=OutputFileName('longlog','');
  1356. FailLogFile:=OutputFileName('faillist','');
  1357. { Make subdir in output if needed }
  1358. PPDir:=SplitPath(PPFile[current]);
  1359. if PPDir[length(PPDir)] in ['/','\'{$ifdef MACOS},':'{$endif MACOS}] then
  1360. Delete(PPDir,length(PPDir),1);
  1361. if PPDir<>'' then
  1362. begin
  1363. {$ifndef MACOS}
  1364. TestOutputDir:=OutputDir+'/'+PPDir;
  1365. {$else MACOS}
  1366. TestOutputDir:=OutputDir+PPDir;
  1367. {$endif MACOS}
  1368. mkdirtree(TestOutputDir);
  1369. end
  1370. else
  1371. TestOutputDir:=OutputDir;
  1372. { Per test logfiles }
  1373. CompilerLogFile:=TestOutputFileName('',SplitFileName(PPFile[current]),'log');
  1374. ExeLogFile:=TestOutputFileName('',SplitFileName(PPFile[current]),'elg');
  1375. Verbose(V_Debug,'Using Compiler logfile: '+CompilerLogFile);
  1376. Verbose(V_Debug,'Using Execution logfile: '+ExeLogFile);
  1377. end;
  1378. if Res then
  1379. begin
  1380. if Config.UsesGraph and (not DoGraph) then
  1381. begin
  1382. AddLog(ResLogFile,skipping_graph_test+PPFileInfo[current]);
  1383. { avoid a second attempt by writing to elg file }
  1384. AddLog(EXELogFile,skipping_graph_test+PPFileInfo[current]);
  1385. Verbose(V_Warning,skipping_graph_test);
  1386. Res:=false;
  1387. end;
  1388. end;
  1389. if Res then
  1390. begin
  1391. if Config.IsInteractive and (not DoInteractive) then
  1392. begin
  1393. { avoid a second attempt by writing to elg file }
  1394. AddLog(EXELogFile,skipping_interactive_test+PPFileInfo[current]);
  1395. AddLog(ResLogFile,skipping_interactive_test+PPFileInfo[current]);
  1396. Verbose(V_Warning,skipping_interactive_test);
  1397. Res:=false;
  1398. end;
  1399. end;
  1400. if Res then
  1401. begin
  1402. if Config.IsKnownCompileError and (not DoKnown) then
  1403. begin
  1404. { avoid a second attempt by writing to elg file }
  1405. AddLog(EXELogFile,skipping_known_bug+PPFileInfo[current]);
  1406. AddLog(ResLogFile,skipping_known_bug+PPFileInfo[current]);
  1407. Verbose(V_Warning,skipping_known_bug);
  1408. Res:=false;
  1409. end;
  1410. end;
  1411. if Res and not DoUsual then
  1412. res:=(Config.IsInteractive and DoInteractive) or
  1413. (Config.IsKnownRunError and DoKnown) or
  1414. (Config.UsesGraph and DoGraph);
  1415. if Res then
  1416. begin
  1417. if (Config.MinVersion<>'') and not DoAll then
  1418. begin
  1419. Verbose(V_Debug,'Required compiler version: '+Config.MinVersion);
  1420. Res:=GetCompilerVersion;
  1421. if CompilerVersion<Config.MinVersion then
  1422. begin
  1423. { avoid a second attempt by writing to elg file }
  1424. AddLog(EXELogFile,skipping_compiler_version_too_low+PPFileInfo[current]);
  1425. AddLog(ResLogFile,skipping_compiler_version_too_low+PPFileInfo[current]);
  1426. Verbose(V_Warning,'Compiler version too low '+CompilerVersion+' < '+Config.MinVersion);
  1427. Res:=false;
  1428. end;
  1429. end;
  1430. end;
  1431. if Res then
  1432. begin
  1433. if (Config.MaxVersion<>'') and not DoAll then
  1434. begin
  1435. Verbose(V_Debug,'Highest compiler version: '+Config.MaxVersion);
  1436. Res:=GetCompilerVersion;
  1437. if CompilerVersion>Config.MaxVersion then
  1438. begin
  1439. { avoid a second attempt by writing to elg file }
  1440. AddLog(EXELogFile,skipping_compiler_version_too_high+PPFileInfo[current]);
  1441. AddLog(ResLogFile,skipping_compiler_version_too_high+PPFileInfo[current]);
  1442. Verbose(V_Warning,'Compiler version too high '+CompilerVersion+' > '+Config.MaxVersion);
  1443. Res:=false;
  1444. end;
  1445. end;
  1446. end;
  1447. if Res then
  1448. begin
  1449. if Config.NeedCPU<>'' then
  1450. begin
  1451. Verbose(V_Debug,'Required compiler cpu: '+Config.NeedCPU);
  1452. if not IsInList(CompilerCPU,Config.NeedCPU) then
  1453. begin
  1454. { avoid a second attempt by writing to elg file }
  1455. AddLog(EXELogFile,skipping_other_cpu+PPFileInfo[current]);
  1456. AddLog(ResLogFile,skipping_other_cpu+PPFileInfo[current]);
  1457. Verbose(V_Warning,'Compiler cpu "'+CompilerCPU+'" is not in list "'+Config.NeedCPU+'"');
  1458. Res:=false;
  1459. end;
  1460. end;
  1461. end;
  1462. if Res then
  1463. begin
  1464. if Config.SkipCPU<>'' then
  1465. begin
  1466. Verbose(V_Debug,'Skip compiler cpu: '+Config.SkipCPU);
  1467. if IsInList(CompilerCPU,Config.SkipCPU) then
  1468. begin
  1469. { avoid a second attempt by writing to elg file }
  1470. AddLog(EXELogFile,skipping_other_cpu+PPFileInfo[current]);
  1471. AddLog(ResLogFile,skipping_other_cpu+PPFileInfo[current]);
  1472. Verbose(V_Warning,'Compiler cpu "'+CompilerCPU+'" is in list "'+Config.SkipCPU+'"');
  1473. Res:=false;
  1474. end;
  1475. end;
  1476. end;
  1477. if Res then
  1478. begin
  1479. if Config.SkipEmu<>'' then
  1480. begin
  1481. Verbose(V_Debug,'Skip emulator: '+emulatorname);
  1482. if IsInList(emulatorname,Config.SkipEmu) then
  1483. begin
  1484. { avoid a second attempt by writing to elg file }
  1485. AddLog(EXELogFile,skipping_other_cpu+PPFileInfo[current]);
  1486. AddLog(ResLogFile,skipping_other_cpu+PPFileInfo[current]);
  1487. Verbose(V_Warning,'Emulator "'+emulatorname+'" is in list "'+Config.SkipEmu+'"');
  1488. Res:=false;
  1489. end;
  1490. end;
  1491. end;
  1492. if Res then
  1493. begin
  1494. if Config.NeedTarget<>'' then
  1495. begin
  1496. Verbose(V_Debug,'Required compiler target: '+Config.NeedTarget);
  1497. if not IsInList(CompilerTarget,Config.NeedTarget) then
  1498. begin
  1499. { avoid a second attempt by writing to elg file }
  1500. AddLog(EXELogFile,skipping_other_target+PPFileInfo[current]);
  1501. AddLog(ResLogFile,skipping_other_target+PPFileInfo[current]);
  1502. Verbose(V_Warning,'Compiler target "'+CompilerTarget+'" is not in list "'+Config.NeedTarget+'"');
  1503. Res:=false;
  1504. end;
  1505. end;
  1506. end;
  1507. if Res then
  1508. begin
  1509. if Config.SkipTarget<>'' then
  1510. begin
  1511. Verbose(V_Debug,'Skip compiler target: '+Config.SkipTarget);
  1512. if IsInList(CompilerTarget,Config.SkipTarget) then
  1513. begin
  1514. { avoid a second attempt by writing to elg file }
  1515. AddLog(EXELogFile,skipping_other_target+PPFileInfo[current]);
  1516. AddLog(ResLogFile,skipping_other_target+PPFileInfo[current]);
  1517. Verbose(V_Warning,'Compiler target "'+CompilerTarget+'" is in list "'+Config.SkipTarget+'"');
  1518. Res:=false;
  1519. end;
  1520. end;
  1521. end;
  1522. if Res then
  1523. begin
  1524. { Use known bug, to avoid adding a new entry for this PM 2011-06-24 }
  1525. if Config.NeedLibrary and not TargetCanCompileLibraries then
  1526. begin
  1527. AddLog(EXELogFile,skipping_known_bug+PPFileInfo[current]);
  1528. AddLog(ResLogFile,skipping_known_bug+PPFileInfo[current]);
  1529. Verbose(V_Warning,'Compiler target "'+CompilerTarget+'" does not support library compilation');
  1530. Res:=false;
  1531. end;
  1532. end;
  1533. if Res then
  1534. begin
  1535. Res:=RunCompiler;
  1536. if Res and Config.NeedRecompile then
  1537. Res:=RunCompiler;
  1538. end;
  1539. if Res and (not Config.ShouldFail) then
  1540. begin
  1541. if (Config.NoRun) then
  1542. begin
  1543. { avoid a second attempt by writing to elg file }
  1544. AddLog(EXELogFile,skipping_run_test+PPFileInfo[current]);
  1545. AddLog(ResLogFile,skipping_run_test+PPFileInfo[current]);
  1546. Verbose(V_Debug,skipping_run_test);
  1547. if LibraryExists(PPFile[current],LibraryName) then
  1548. MaybeCopyFiles(LibraryName);
  1549. end
  1550. else if Config.IsKnownRunError and (not DoKnown) then
  1551. begin
  1552. { avoid a second attempt by writing to elg file }
  1553. AddLog(EXELogFile,skipping_known_bug+PPFileInfo[current]);
  1554. AddLog(ResLogFile,skipping_known_bug+PPFileInfo[current]);
  1555. Verbose(V_Warning,skipping_known_bug);
  1556. end
  1557. else
  1558. begin
  1559. if DoExecute then
  1560. begin
  1561. if FileExists(TestOutputFilename('',PPFile[current],'ppu')) or
  1562. FileExists(TestOutputFilename('',PPFile[current],'ppo')) or
  1563. FileExists(TestOutputFilename('',PPFile[current],'ppw')) then
  1564. begin
  1565. AddLog(ExeLogFile,skipping_run_unit+PPFileInfo[current]);
  1566. AddLog(ResLogFile,skipping_run_unit+PPFileInfo[current]);
  1567. Verbose(V_Debug,'Unit found, skipping run test')
  1568. end
  1569. else if LibraryExists(PPFile[current],LibraryName) then
  1570. begin
  1571. Verbose(V_Debug,'Library found, skipping run test');
  1572. MaybeCopyFiles(LibraryName);
  1573. end
  1574. else
  1575. Res:=RunExecutable;
  1576. end;
  1577. end;
  1578. end;
  1579. end;
  1580. begin
  1581. Current:=0;
  1582. PPFile:=TStringList.Create;
  1583. PPFile.Capacity:=10;
  1584. PPFileInfo:=TStringList.Create;
  1585. PPFileInfo.Capacity:=10;
  1586. GetArgs;
  1587. SetTargetDirectoriesStyle;
  1588. SetTargetCanCompileLibraries;
  1589. SetRemoteConfiguration;
  1590. {$ifdef LIMIT83fs}
  1591. UseOSOnly:=true;
  1592. {$else not LIMIT83fs}
  1593. SetUseOSOnly;
  1594. {$endif not LIMIT83fs}
  1595. Verbose(V_Debug,'Found '+ToStr(PPFile.Count)+' tests to run');
  1596. if current>0 then
  1597. for current:=0 to PPFile.Count-1 do
  1598. begin
  1599. SetPPFileInfo;
  1600. TestName:=Copy(PPFile[current],1,Pos('.pp',PPFile[current])-1);
  1601. Verbose(V_Normal,'Running test '+TestName+', file '+PPFile[current]);
  1602. RunTest;
  1603. end;
  1604. PPFile.Free;
  1605. PPFileInfo.Free;
  1606. end.