dotest.pp 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290
  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. {$ifdef go32v2}
  25. {$define LIMIT83FS}
  26. {$endif}
  27. {$ifdef os2}
  28. {$define LIMIT83FS}
  29. {$endif}
  30. type
  31. tcompinfo = (compver,comptarget,compcpu);
  32. tdelexecutable = (deBefore, deAfter);
  33. tdelexecutables = set of tdelexecutable;
  34. const
  35. ObjExt='o';
  36. PPUExt='ppu';
  37. {$ifdef UNIX}
  38. ExeExt='';
  39. {$else UNIX}
  40. {$ifdef MACOS}
  41. ExeExt='';
  42. {$else MACOS}
  43. ExeExt='exe';
  44. {$endif MACOS}
  45. {$endif UNIX}
  46. DefaultTimeout=60;
  47. var
  48. Config : TConfig;
  49. CompilerLogFile,
  50. ExeLogFile,
  51. LongLogfile,
  52. FailLogfile,
  53. RTLUnitsDir,
  54. TestOutputDir,
  55. OutputDir : string;
  56. CompilerBin,
  57. CompilerCPU,
  58. CompilerTarget,
  59. CompilerVersion,
  60. DefaultCompilerCPU,
  61. DefaultCompilerTarget,
  62. DefaultCompilerVersion : string;
  63. PPFile : string;
  64. PPFileInfo : string;
  65. TestName : string;
  66. const
  67. DoGraph : boolean = false;
  68. DoInteractive : boolean = false;
  69. DoExecute : boolean = false;
  70. DoKnown : boolean = false;
  71. DoAll : boolean = false;
  72. DoUsual : boolean = true;
  73. TargetDir : string = '';
  74. BenchmarkInfo : boolean = false;
  75. ExtraCompilerOpts : string = '';
  76. DelExecutable : TDelExecutables = [];
  77. RemoteAddr : string = '';
  78. RemotePath : string = '/tmp';
  79. RemotePara : string = '';
  80. rshprog : string = 'rsh';
  81. rcpprog : string = 'rcp';
  82. rquote : char = '''';
  83. UseTimeout : boolean = false;
  84. emulatorname : string = '';
  85. Function FileExists (Const F : String) : Boolean;
  86. {
  87. Returns True if the file exists, False if not.
  88. }
  89. Var
  90. info : searchrec;
  91. begin
  92. FindFirst (F,anyfile,Info);
  93. FileExists:=DosError=0;
  94. FindClose (Info);
  95. end;
  96. Function PathExists (Const F : String) : Boolean;
  97. {
  98. Returns True if the file exists, False if not.
  99. }
  100. Var
  101. info : searchrec;
  102. begin
  103. FindFirst (F,anyfile,Info);
  104. PathExists:=(DosError=0) and (Info.Attr and Directory=Directory);
  105. FindClose (Info);
  106. end;
  107. function ToStr(l:longint):string;
  108. var
  109. s : string;
  110. begin
  111. Str(l,s);
  112. ToStr:=s;
  113. end;
  114. function ToStrZero(l:longint;nbzero : byte):string;
  115. var
  116. s : string;
  117. begin
  118. Str(l,s);
  119. while length(s)<nbzero do
  120. s:='0'+s;
  121. ToStrZero:=s;
  122. end;
  123. function trimspace(const s:string):string;
  124. var
  125. i,j : longint;
  126. begin
  127. i:=length(s);
  128. while (i>0) and (s[i] in [#9,' ']) do
  129. dec(i);
  130. j:=1;
  131. while (j<i) and (s[j] in [#9,' ']) do
  132. inc(j);
  133. trimspace:=Copy(s,j,i-j+1);
  134. end;
  135. function IsInList(const entry,list:string):boolean;
  136. var
  137. i,istart : longint;
  138. begin
  139. IsInList:=false;
  140. i:=0;
  141. while (i<length(list)) do
  142. begin
  143. { Find list item }
  144. istart:=i+1;
  145. while (i<length(list)) and
  146. (list[i+1]<>',') do
  147. inc(i);
  148. if Upcase(entry)=Upcase(TrimSpace(Copy(list,istart,i-istart+1))) then
  149. begin
  150. IsInList:=true;
  151. exit;
  152. end;
  153. { skip , }
  154. inc(i);
  155. end;
  156. end;
  157. procedure SetPPFileInfo;
  158. Var
  159. info : searchrec;
  160. dt : DateTime;
  161. begin
  162. FindFirst (PPFile,anyfile,Info);
  163. If DosError=0 then
  164. begin
  165. UnpackTime(info.time,dt);
  166. PPFileInfo:=PPFile+' '+ToStr(dt.year)+'/'+ToStrZero(dt.month,2)+'/'+
  167. ToStrZero(dt.day,2)+' '+ToStrZero(dt.Hour,2)+':'+ToStrZero(dt.min,2)+':'+ToStrZero(dt.sec,2);
  168. end
  169. else
  170. PPFileInfo:=PPfile;
  171. FindClose (Info);
  172. end;
  173. function SplitPath(const s:string):string;
  174. var
  175. i : longint;
  176. begin
  177. i:=Length(s);
  178. while (i>0) and not(s[i] in ['/','\'{$IFDEF MACOS},':'{$ENDIF}]) do
  179. dec(i);
  180. SplitPath:=Copy(s,1,i);
  181. end;
  182. Function SplitFileName(const s:string):string;
  183. var
  184. p : dirstr;
  185. n : namestr;
  186. e : extstr;
  187. begin
  188. FSplit(s,p,n,e);
  189. SplitFileName:=n+e;
  190. end;
  191. function ForceExtension(Const HStr,ext:String):String;
  192. {
  193. Return a filename which certainly has the extension ext
  194. }
  195. var
  196. j : longint;
  197. begin
  198. j:=length(Hstr);
  199. while (j>0) and (Hstr[j]<>'.') do
  200. dec(j);
  201. if j=0 then
  202. j:=255;
  203. if Ext<>'' then
  204. ForceExtension:=Copy(Hstr,1,j-1)+'.'+Ext
  205. else
  206. ForceExtension:=Copy(Hstr,1,j-1);
  207. end;
  208. procedure mkdirtree(const s:string);
  209. var
  210. hs : string;
  211. begin
  212. if s='' then
  213. exit;
  214. if s[length(s)] in ['\','/'{$IFDEF MACOS},':'{$ENDIF}] then
  215. hs:=Copy(s,1,length(s)-1)
  216. else
  217. hs:=s;
  218. if not PathExists(hs) then
  219. begin
  220. { Try parent first }
  221. mkdirtree(SplitPath(hs));
  222. { make this dir }
  223. Verbose(V_Debug,'Making Directory '+s);
  224. {$I-}
  225. mkdir(s);
  226. {$I+}
  227. ioresult;
  228. end;
  229. end;
  230. Function RemoveFile(const f:string):boolean;
  231. var
  232. g : file;
  233. begin
  234. assign(g,f);
  235. {$I-}
  236. erase(g);
  237. {$I+}
  238. RemoveFile:=(ioresult=0);
  239. end;
  240. procedure Copyfile(const fn1,fn2:string;append:boolean);
  241. const
  242. bufsize = 16384;
  243. var
  244. f,g : file;
  245. i : longint;
  246. buf : pointer;
  247. begin
  248. if Append then
  249. Verbose(V_Debug,'Appending '+fn1+' to '+fn2)
  250. else
  251. Verbose(V_Debug,'Copying '+fn1+' to '+fn2);
  252. assign(f,fn1);
  253. assign(g,fn2);
  254. {$I-}
  255. reset(f,1);
  256. {$I+}
  257. if ioresult<>0 then
  258. Verbose(V_Error,'Can''t open '+fn1);
  259. if append then
  260. begin
  261. {$I-}
  262. reset(g,1);
  263. {$I+}
  264. if ioresult<>0 then
  265. append:=false
  266. else
  267. seek(g,filesize(g));
  268. end;
  269. if not append then
  270. begin
  271. {$I-}
  272. rewrite(g,1);
  273. {$I+}
  274. if ioresult<>0 then
  275. Verbose(V_Error,'Can''t open '+fn2+' for output');
  276. end;
  277. getmem(buf,bufsize);
  278. repeat
  279. blockread(f,buf^,bufsize,i);
  280. blockwrite(g,buf^,i);
  281. until i<bufsize;
  282. freemem(buf,bufsize);
  283. close(f);
  284. close(g);
  285. end;
  286. procedure AddLog(const logfile,s:string);
  287. var
  288. t : text;
  289. begin
  290. assign(t,logfile);
  291. {$I-}
  292. append(t);
  293. {$I+}
  294. if ioresult<>0 then
  295. begin
  296. {$I-}
  297. rewrite(t);
  298. {$I+}
  299. if ioresult<>0 then
  300. Verbose(V_Abort,'Can''t append to '+logfile);
  301. end;
  302. writeln(t,s);
  303. close(t);
  304. end;
  305. function GetCompilerInfo(c:tcompinfo):boolean;
  306. function GetToken(var s:string):string;
  307. var
  308. i : longint;
  309. begin
  310. i:=pos(' ',s);
  311. if i=0 then
  312. i:=length(s)+1;
  313. GetToken:=Copy(s,1,i-1);
  314. Delete(s,1,i);
  315. end;
  316. var
  317. t : text;
  318. hs : string;
  319. begin
  320. GetCompilerInfo:=false;
  321. { Try to get all information in one call, this is
  322. supported in 1.1. Older compilers 1.0.x will only
  323. return the first info }
  324. case c of
  325. compver :
  326. begin
  327. if DefaultCompilerVersion<>'' then
  328. begin
  329. GetCompilerInfo:=true;
  330. exit;
  331. end;
  332. hs:='-iVTPTO';
  333. end;
  334. compcpu :
  335. begin
  336. if DefaultCompilerCPU<>'' then
  337. begin
  338. GetCompilerInfo:=true;
  339. exit;
  340. end;
  341. hs:='-iTPTOV';
  342. end;
  343. comptarget :
  344. begin
  345. if DefaultCompilerTarget<>'' then
  346. begin
  347. GetCompilerInfo:=true;
  348. exit;
  349. end;
  350. hs:='-iTOTPV';
  351. end;
  352. end;
  353. ExecuteRedir(CompilerBin,hs,'','out','');
  354. assign(t,'out');
  355. {$I-}
  356. reset(t);
  357. readln(t,hs);
  358. close(t);
  359. erase(t);
  360. {$I+}
  361. if ioresult<>0 then
  362. Verbose(V_Error,'Can''t get Compiler Info')
  363. else
  364. begin
  365. Verbose(V_Debug,'Retrieved Compiler Info: "'+hs+'"');
  366. case c of
  367. compver :
  368. begin
  369. DefaultCompilerVersion:=GetToken(hs);
  370. DefaultCompilerCPU:=GetToken(hs);
  371. DefaultCompilerTarget:=GetToken(hs);
  372. end;
  373. compcpu :
  374. begin
  375. DefaultCompilerCPU:=GetToken(hs);
  376. DefaultCompilerTarget:=GetToken(hs);
  377. DefaultCompilerVersion:=GetToken(hs);
  378. end;
  379. comptarget :
  380. begin
  381. DefaultCompilerTarget:=GetToken(hs);
  382. DefaultCompilerCPU:=GetToken(hs);
  383. DefaultCompilerVersion:=GetToken(hs);
  384. end;
  385. end;
  386. GetCompilerInfo:=true;
  387. end;
  388. end;
  389. function GetCompilerVersion:boolean;
  390. begin
  391. if CompilerVersion='' then
  392. begin
  393. GetCompilerVersion:=GetCompilerInfo(compver);
  394. CompilerVersion:=DefaultCompilerVersion;
  395. end
  396. else
  397. GetCompilerVersion:=true;
  398. if GetCompilerVersion then
  399. Verbose(V_Debug,'Compiler Version: "'+CompilerVersion+'"');
  400. end;
  401. function GetCompilerCPU:boolean;
  402. begin
  403. if CompilerCPU='' then
  404. begin
  405. GetCompilerCPU:=GetCompilerInfo(compcpu);
  406. CompilerCPU:=DefaultCompilerCPU;
  407. end
  408. else
  409. GetCompilerCPU:=true;
  410. if GetCompilerCPU then
  411. Verbose(V_Debug,'Compiler CPU: "'+CompilerCPU+'"');
  412. end;
  413. function GetCompilerTarget:boolean;
  414. begin
  415. if CompilerTarget='' then
  416. begin
  417. GetCompilerTarget:=GetCompilerInfo(comptarget);
  418. CompilerTarget:=DefaultCompilerTarget;
  419. end
  420. else
  421. GetCompilerTarget:=true;
  422. if GetCompilerTarget then
  423. Verbose(V_Debug,'Compiler Target: "'+CompilerTarget+'"');
  424. end;
  425. function CompilerFullTarget:string;
  426. begin
  427. CompilerFullTarget:=CompilerCPU+'-'+CompilerTarget;
  428. end;
  429. function OutputFileName(Const s,ext:String):String;
  430. begin
  431. {$ifndef macos}
  432. OutputFileName:=OutputDir+'/'+ForceExtension(s,ext);
  433. {$else macos}
  434. OutputFileName:=ConcatMacPath(OutputDir,ForceExtension(s,ext));
  435. {$endif macos}
  436. end;
  437. function TestOutputFileName(Const s,ext:String):String;
  438. begin
  439. {$ifndef macos}
  440. TestOutputFileName:=TestOutputDir+'/'+ForceExtension(SplitFileName(s),ext);
  441. {$else macos}
  442. TestOutputFileName:=ConcatMacPath(TestOutputDir,ForceExtension(SplitFileName(s),ext));
  443. {$endif macos}
  444. end;
  445. function ExitWithInternalError(const OutName:string):boolean;
  446. var
  447. t : text;
  448. s : string;
  449. begin
  450. ExitWithInternalError:=false;
  451. { open logfile }
  452. assign(t,Outname);
  453. {$I-}
  454. reset(t);
  455. {$I+}
  456. if ioresult<>0 then
  457. exit;
  458. while not eof(t) do
  459. begin
  460. readln(t,s);
  461. if pos('Fatal: Internal error ',s)>0 then
  462. begin
  463. ExitWithInternalError:=true;
  464. break;
  465. end;
  466. end;
  467. close(t);
  468. end;
  469. function RunCompiler:boolean;
  470. var
  471. args : string;
  472. execres : boolean;
  473. begin
  474. RunCompiler:=false;
  475. args:='-n -T'+CompilerTarget+' -Fu'+RTLUnitsDir;
  476. args:=args+' -FE'+TestOutputDir;
  477. {$ifdef macos}
  478. args:=args+' -WT '; {tests should be compiled as MPWTool}
  479. {$endif macos}
  480. if ExtraCompilerOpts<>'' then
  481. args:=args+ExtraCompilerOpts;
  482. {$ifdef unix}
  483. { Add runtime library path to current dir to find .so files }
  484. if Config.NeedLibrary then
  485. {$ifndef darwin}
  486. args:=args+' -Fl'+TestOutputDir+' ''-k-rpath .''';
  487. {$else darwin}
  488. args:=args+' -Fl'+TestOutputDir;
  489. {$endif darwin}
  490. {$endif unix}
  491. if Config.NeedOptions<>'' then
  492. args:=args+' '+Config.NeedOptions;
  493. args:=args+' '+ppfile;
  494. Verbose(V_Debug,'Executing '+compilerbin+' '+args);
  495. { also get the output from as and ld that writes to stderr sometimes }
  496. {$ifndef macos}
  497. execres:=ExecuteRedir(CompilerBin,args,'',CompilerLogFile,'stdout');
  498. {$else macos}
  499. {Due to that Toolserver is not reentrant, we have to asm and link via script.}
  500. execres:=ExecuteRedir(CompilerBin,'-s '+args,'',CompilerLogFile,'stdout');
  501. if execres then
  502. execres:=ExecuteRedir(TestOutputDir + ':ppas','','',CompilerLogFile,'stdout');
  503. {$endif macos}
  504. Verbose(V_Debug,'Exitcode '+ToStr(ExecuteResult));
  505. { Error during execution? }
  506. if (not execres) and (ExecuteResult=0) then
  507. begin
  508. AddLog(FailLogFile,TestName);
  509. AddLog(ResLogFile,failed_to_compile+PPFileInfo);
  510. AddLog(LongLogFile,line_separation);
  511. AddLog(LongLogFile,failed_to_compile+PPFileInfo);
  512. CopyFile(CompilerLogFile,LongLogFile,true);
  513. { avoid to try again }
  514. AddLog(ExeLogFile,failed_to_compile+PPFileInfo);
  515. Verbose(V_Abort,'IOStatus: '+ToStr(IOStatus));
  516. exit;
  517. end;
  518. { Check for internal error }
  519. if ExitWithInternalError(CompilerLogFile) then
  520. begin
  521. AddLog(FailLogFile,TestName);
  522. if Config.Note<>'' then
  523. AddLog(FailLogFile,Config.Note);
  524. AddLog(ResLogFile,failed_to_compile+PPFileInfo+' internalerror generated');
  525. AddLog(LongLogFile,line_separation);
  526. AddLog(LongLogFile,failed_to_compile+PPFileInfo);
  527. if Config.Note<>'' then
  528. AddLog(LongLogFile,Config.Note);
  529. CopyFile(CompilerLogFile,LongLogFile,true);
  530. { avoid to try again }
  531. AddLog(ExeLogFile,'Failed to compile '+PPFileInfo);
  532. Verbose(V_Abort,'Internal error in compiler');
  533. exit;
  534. end;
  535. { Should the compile fail ? }
  536. if Config.ShouldFail then
  537. begin
  538. if ExecuteResult<>0 then
  539. begin
  540. AddLog(ResLogFile,success_compilation_failed+PPFileInfo);
  541. { avoid to try again }
  542. AddLog(ExeLogFile,success_compilation_failed+PPFileInfo);
  543. RunCompiler:=true;
  544. end
  545. else
  546. begin
  547. AddLog(FailLogFile,TestName);
  548. if Config.Note<>'' then
  549. AddLog(FailLogFile,Config.Note);
  550. AddLog(ResLogFile,failed_compilation_successful+PPFileInfo);
  551. AddLog(LongLogFile,line_separation);
  552. AddLog(LongLogFile,failed_compilation_successful+PPFileInfo);
  553. { avoid to try again }
  554. AddLog(ExeLogFile,failed_compilation_successful+PPFileInfo);
  555. if Config.Note<>'' then
  556. AddLog(LongLogFile,Config.Note);
  557. CopyFile(CompilerLogFile,LongLogFile,true);
  558. end;
  559. end
  560. else
  561. begin
  562. if (ExecuteResult<>0) and
  563. (((Config.KnownCompileNote<>'') and (Config.KnownCompileError=0)) or
  564. ((Config.KnownCompileError<>0) and (ExecuteResult=Config.KnownCompileError))) then
  565. begin
  566. AddLog(FailLogFile,TestName+known_problem+Config.KnownCompileNote);
  567. AddLog(ResLogFile,failed_to_run+PPFileInfo+known_problem+Config.KnownCompileNote);
  568. AddLog(LongLogFile,line_separation);
  569. AddLog(LongLogFile,known_problem+Config.KnownCompileNote);
  570. AddLog(LongLogFile,failed_to_compile+PPFileInfo+' ('+ToStr(ExecuteResult)+')');
  571. Copyfile(CompilerLogFile,LongLogFile,true);
  572. Verbose(V_Abort,known_problem+'exitcode: '+ToStr(ExecuteResult));
  573. end
  574. else if ExecuteResult<>0 then
  575. begin
  576. AddLog(FailLogFile,TestName);
  577. if Config.Note<>'' then
  578. AddLog(FailLogFile,Config.Note);
  579. AddLog(ResLogFile,failed_to_compile+PPFileInfo);
  580. AddLog(LongLogFile,line_separation);
  581. AddLog(LongLogFile,failed_to_compile+PPFileInfo);
  582. if Config.Note<>'' then
  583. AddLog(LongLogFile,Config.Note);
  584. CopyFile(CompilerLogFile,LongLogFile,true);
  585. { avoid to try again }
  586. AddLog(ExeLogFile,failed_to_compile+PPFileInfo);
  587. Verbose(V_Abort,'Exitcode: '+ToStr(ExecuteResult)+' (expected 0)');
  588. end
  589. else
  590. begin
  591. AddLog(ResLogFile,successfully_compiled+PPFileInfo);
  592. RunCompiler:=true;
  593. end;
  594. end;
  595. end;
  596. function CheckTestExitCode(const OutName:string):boolean;
  597. var
  598. t : text;
  599. s : string;
  600. i,code : integer;
  601. begin
  602. CheckTestExitCode:=false;
  603. { open logfile }
  604. assign(t,Outname);
  605. {$I-}
  606. reset(t);
  607. {$I+}
  608. if ioresult<>0 then
  609. exit;
  610. while not eof(t) do
  611. begin
  612. readln(t,s);
  613. i:=pos('TestExitCode: ',s);
  614. if i>0 then
  615. begin
  616. delete(s,1,i+14-1);
  617. val(s,ExecuteResult,code);
  618. if code=0 then;
  619. CheckTestExitCode:=true;
  620. break;
  621. end;
  622. end;
  623. close(t);
  624. end;
  625. function RunExecutable:boolean;
  626. const
  627. {$ifdef unix}
  628. CurrDir = './';
  629. {$else}
  630. CurrDir = '';
  631. {$endif}
  632. var
  633. s,
  634. OldDir,
  635. FullExeLogFile,
  636. TestRemoteExe,
  637. TestExe : string;
  638. LocalFile, RemoteFile: string;
  639. LocalPath: string;
  640. execcmd : string;
  641. execres : boolean;
  642. index : integer;
  643. EndTicks,
  644. StartTicks : int64;
  645. function ExecuteRemote(const prog,args:string):boolean;
  646. begin
  647. Verbose(V_Debug,'RemoteExecuting '+Prog+' '+args);
  648. StartTicks:=GetMicroSTicks;
  649. ExecuteRemote:=ExecuteRedir(prog,args,'',EXELogFile,'stdout');
  650. EndTicks:=GetMicroSTicks;
  651. end;
  652. function ExecuteEmulated(const prog,args:string):boolean;
  653. begin
  654. Verbose(V_Debug,'EmulatorExecuting '+Prog+' '+args);
  655. StartTicks:=GetMicroSTicks;
  656. ExecuteEmulated:=ExecuteRedir(prog,args,'',FullExeLogFile,'stdout');
  657. EndTicks:=GetMicroSTicks;
  658. end;
  659. label
  660. done;
  661. begin
  662. RunExecutable:=false;
  663. execres:=true;
  664. { when remote testing, leave extension away }
  665. if RemoteAddr='' then
  666. TestExe:=OutputFileName(PPFile,ExeExt)
  667. else
  668. TestExe:=OutputFileName(PPFile,'');
  669. if EmulatorName<>'' then
  670. begin
  671. { Get full name out log file, because we change the directory during
  672. execution }
  673. FullExeLogFile:=FExpand(EXELogFile);
  674. {$I-}
  675. GetDir(0,OldDir);
  676. ChDir(TestOutputDir);
  677. {$I+}
  678. ioresult;
  679. s:=CurrDir+SplitFileName(TestExe);
  680. execres:=ExecuteEmulated(EmulatorName,s);
  681. {$I-}
  682. ChDir(OldDir);
  683. {$I+}
  684. end
  685. else if RemoteAddr<>'' then
  686. begin
  687. { We don't want to create subdirs, remove paths from the test }
  688. TestRemoteExe:=RemotePath+'/'+SplitFileName(TestExe);
  689. if deBefore in DelExecutable then
  690. ExecuteRemote(rshprog,RemotePara+' '+RemoteAddr+' rm -f '+TestRemoteExe);
  691. execres:=ExecuteRemote(rcpprog,RemotePara+' '+TestExe+' '+RemoteAddr+':'+TestRemoteExe);
  692. if not execres then
  693. begin
  694. Verbose(V_Abort, 'Could not copy executable '+TestExe);
  695. goto done;
  696. end;
  697. s:=Config.Files;
  698. if length(s) > 0 then
  699. begin
  700. LocalPath:=SplitPath(PPFile);
  701. if Length(LocalPath) > 0 then
  702. LocalPath:=LocalPath+'/';
  703. repeat
  704. index:=pos(' ',s);
  705. if index=0 then
  706. LocalFile:=s
  707. else
  708. LocalFile:=copy(s,1,index-1);
  709. RemoteFile:=RemotePath+'/'+SplitFileName(LocalFile);
  710. LocalFile:=LocalPath+LocalFile;
  711. execres:=ExecuteRemote(rcpprog,RemotePara+' '+LocalFile+' '+RemoteAddr+':'+RemoteFile);
  712. if not execres then
  713. begin
  714. Verbose(V_Abort, 'Could not copy required file '+LocalFile);
  715. goto done;
  716. end;
  717. if index=0 then
  718. break;
  719. s:=copy(s,index+1,length(s)-index);
  720. until false;
  721. end;
  722. { rsh doesn't pass the exitcode, use a second command to print the exitcode
  723. on the remoteshell to stdout }
  724. execcmd:=RemotePara+' '+RemoteAddr+' '+rquote+'chmod 755 '+TestRemoteExe+
  725. ' ; cd '+RemotePath+' ;';
  726. if UseTimeout then
  727. begin
  728. execcmd:=execcmd+'timeout -9 ';
  729. if Config.Timeout=0 then
  730. Config.Timeout:=DefaultTimeout;
  731. str(Config.Timeout,s);
  732. execcmd:=execcmd+s;
  733. end;
  734. execcmd:=execcmd+' '+TestRemoteExe+' ; echo "TestExitCode: $?"';
  735. if deAfter in DelExecutable then
  736. execcmd:=execcmd+' ; rm -f '+TestRemoteExe;
  737. execcmd:=execcmd+rquote;
  738. execres:=ExecuteRemote(rshprog,execcmd);
  739. { Check for TestExitCode error in output, sets ExecuteResult }
  740. CheckTestExitCode(EXELogFile);
  741. end
  742. else
  743. begin
  744. { Get full name out log file, because we change the directory during
  745. execution }
  746. FullExeLogFile:=FExpand(EXELogFile);
  747. Verbose(V_Debug,'Executing '+TestExe);
  748. {$I-}
  749. GetDir(0,OldDir);
  750. ChDir(TestOutputDir);
  751. {$I+}
  752. ioresult;
  753. { don't redirect interactive and graph programs }
  754. StartTicks:=GetMicroSTicks;
  755. if Config.IsInteractive or Config.UsesGraph then
  756. execres:=ExecuteRedir(CurrDir+SplitFileName(TestExe),'','','','')
  757. else
  758. execres:=ExecuteRedir(CurrDir+SplitFileName(TestExe),'','',FullExeLogFile,'stdout');
  759. EndTicks:=GetMicroSTicks;
  760. {$I-}
  761. ChDir(OldDir);
  762. {$I+}
  763. ioresult;
  764. end;
  765. { Error during execution? }
  766. Verbose(V_Debug,'Exitcode '+ToStr(ExecuteResult));
  767. if BenchmarkInfo then
  768. begin
  769. Verbose(V_Normal,'Execution took '+ToStr(EndTicks-StartTicks)+' us');
  770. end;
  771. done:
  772. if (not execres) and (ExecuteResult=0) then
  773. begin
  774. AddLog(FailLogFile,TestName);
  775. AddLog(ResLogFile,failed_to_run+PPFileInfo);
  776. AddLog(LongLogFile,line_separation);
  777. AddLog(LongLogFile,failed_to_run+PPFileInfo);
  778. CopyFile(EXELogFile,LongLogFile,true);
  779. { avoid to try again }
  780. AddLog(ExeLogFile,failed_to_run+PPFileInfo);
  781. Verbose(V_Abort,'IOStatus: '+ToStr(IOStatus));
  782. exit;
  783. end;
  784. if ExecuteResult<>Config.ResultCode then
  785. begin
  786. if (ExecuteResult<>0) and
  787. (ExecuteResult=Config.KnownRunError) then
  788. begin
  789. AddLog(FailLogFile,TestName+known_problem+Config.KnownRunNote);
  790. AddLog(ResLogFile,failed_to_run+PPFileInfo+known_problem+Config.KnownRunNote);
  791. AddLog(LongLogFile,line_separation);
  792. AddLog(LongLogFile,known_problem+Config.KnownRunNote);
  793. AddLog(LongLogFile,failed_to_run+PPFileInfo+' ('+ToStr(ExecuteResult)+')');
  794. Copyfile(EXELogFile,LongLogFile,true);
  795. Verbose(V_Abort,known_problem+'exitcode: '+ToStr(ExecuteResult)+' (expected '+ToStr(Config.ResultCode)+')');
  796. end
  797. else
  798. begin
  799. AddLog(FailLogFile,TestName);
  800. AddLog(ResLogFile,failed_to_run+PPFileInfo);
  801. AddLog(LongLogFile,line_separation);
  802. AddLog(LongLogFile,failed_to_run+PPFileInfo+' ('+ToStr(ExecuteResult)+')');
  803. Copyfile(EXELogFile,LongLogFile,true);
  804. Verbose(V_Abort,'Exitcode: '+ToStr(ExecuteResult)+' (expected '+ToStr(Config.ResultCode)+')');
  805. end
  806. end
  807. else
  808. begin
  809. AddLog(ResLogFile,successfully_run+PPFileInfo);
  810. RunExecutable:=true;
  811. end;
  812. if deAfter in DelExecutable then
  813. begin
  814. Verbose(V_Debug,'Deleting executable '+TestExe);
  815. RemoveFile(TestExe);
  816. RemoveFile(ForceExtension(TestExe,ObjExt));
  817. RemoveFile(ForceExtension(TestExe,PPUExt));
  818. end;
  819. end;
  820. procedure getargs;
  821. var
  822. ch : char;
  823. para : string;
  824. i,j : longint;
  825. procedure helpscreen;
  826. begin
  827. writeln('dotest [Options] <File>');
  828. writeln;
  829. writeln('Options can be:');
  830. writeln(' -B delete executable before remote upload');
  831. writeln(' -C<compiler> set compiler to use');
  832. writeln(' -V verbose');
  833. writeln(' -E execute test also');
  834. writeln(' -X don''t use COMSPEC');
  835. writeln(' -A include ALL tests');
  836. writeln(' -G include graph tests');
  837. writeln(' -K include known bug tests');
  838. writeln(' -I include interactive tests');
  839. writeln(' -O use timeout wrapper for (remote) execution');
  840. writeln(' -M<emulator> run the tests using the given emulator');
  841. writeln(' -R<remote> run the tests remotely with the given rsh/ssh address');
  842. writeln(' -S use ssh instead of rsh');
  843. writeln(' -T[cpu-]<os> run tests for target cpu and os');
  844. writeln(' -P<path> path to the tests tree on the remote machine');
  845. writeln(' -U<remotepara>');
  846. writeln(' pass additional parameter to remote program. Multiple -U can be used');
  847. writeln(' -V be verbose');
  848. writeln(' -W use putty compatible file names when testing (plink and pscp)');
  849. writeln(' -Y<opts> extra options passed to the compiler. Several -Y<opt> can be given.');
  850. writeln(' -Z remove temporary files (executable,ppu,o)');
  851. halt(1);
  852. end;
  853. begin
  854. PPFile:='';
  855. if exeext<>'' then
  856. CompilerBin:='ppc386.'+exeext
  857. else
  858. CompilerBin:='ppc386';
  859. for i:=1 to paramcount do
  860. begin
  861. para:=Paramstr(i);
  862. if (para[1]='-') then
  863. begin
  864. ch:=Upcase(para[2]);
  865. delete(para,1,2);
  866. case ch of
  867. 'A' :
  868. begin
  869. DoGraph:=true;
  870. DoInteractive:=true;
  871. DoKnown:=true;
  872. DoAll:=true;
  873. end;
  874. 'B' : Include(DelExecutable,deBefore);
  875. 'C' : CompilerBin:=Para;
  876. 'E' : DoExecute:=true;
  877. 'G' : begin
  878. DoGraph:=true;
  879. if para='-' then
  880. DoUsual:=false;
  881. end;
  882. 'I' : begin
  883. DoInteractive:=true;
  884. if para='-' then
  885. DoUsual:=false;
  886. end;
  887. 'K' : begin
  888. DoKnown:=true;
  889. if para='-' then
  890. DoUsual:=false;
  891. end;
  892. 'M' : EmulatorName:=Para;
  893. 'O' : UseTimeout:=true;
  894. 'P' : RemotePath:=Para;
  895. 'R' : RemoteAddr:=Para;
  896. 'S' :
  897. begin
  898. rshprog:='ssh';
  899. rcpprog:='scp';
  900. end;
  901. 'T' :
  902. begin
  903. j:=Pos('-',Para);
  904. if j>0 then
  905. begin
  906. CompilerCPU:=Copy(Para,1,j-1);
  907. CompilerTarget:=Copy(Para,j+1,255);
  908. end
  909. else
  910. CompilerTarget:=Para
  911. end;
  912. 'U' :
  913. RemotePara:=RemotePara+' '+Para;
  914. 'V' : DoVerbose:=true;
  915. 'W' :
  916. begin
  917. rshprog:='plink';
  918. rcpprog:='pscp';
  919. rquote:=' ';
  920. end;
  921. 'X' : UseComSpec:=false;
  922. 'Y' : ExtraCompilerOpts:= ExtraCompilerOpts +' '+ Para;
  923. 'Z' : Include(DelExecutable,deAfter);
  924. end;
  925. end
  926. else
  927. begin
  928. If PPFile<>'' then
  929. HelpScreen;
  930. PPFile:=ForceExtension(Para,'pp');
  931. end;
  932. end;
  933. if (PPFile='') then
  934. HelpScreen;
  935. { disable graph,interactive when running remote }
  936. if RemoteAddr<>'' then
  937. begin
  938. DoGraph:=false;
  939. DoInteractive:=false;
  940. end;
  941. SetPPFileInfo;
  942. TestName:=Copy(PPFile,1,Pos('.pp',PPFile)-1);
  943. Verbose(V_Debug,'Running test '+TestName+', file '+PPFile);
  944. end;
  945. procedure RunTest;
  946. var
  947. PPDir : string;
  948. Res : boolean;
  949. begin
  950. Res:=GetConfig(ppfile,Config);
  951. if Res then
  952. begin
  953. Res:=GetCompilerCPU;
  954. Res:=GetCompilerTarget;
  955. {$ifndef MACOS}
  956. RTLUnitsDir:='units/'+{$ifdef LIMIT83FS}CompilerTarget{$else}CompilerFullTarget{$endif};
  957. {$else MACOS}
  958. RTLUnitsDir:=':units:'+CompilerFullTarget;
  959. {$endif MACOS}
  960. if not PathExists(RTLUnitsDir) then
  961. Verbose(V_Abort,'Unit path "'+RTLUnitsDir+'" does not exists');
  962. {$ifndef MACOS}
  963. OutputDir:='output/'+{$ifdef LIMIT83FS}CompilerTarget{$else}CompilerFullTarget{$endif};
  964. {$else MACOS}
  965. OutputDir:=':output:'+CompilerFullTarget;
  966. {$endif MACOS}
  967. if not PathExists(OutputDir) then
  968. Verbose(V_Abort,'Output path "'+OutputDir+'" does not exists');
  969. { Global log files }
  970. ResLogFile:=OutputFileName('log','');
  971. LongLogFile:=OutputFileName('longlog','');
  972. FailLogFile:=OutputFileName('faillist','');
  973. { Make subdir in output if needed }
  974. PPDir:=SplitPath(PPFile);
  975. if PPDir[length(PPDir)] in ['/','\'{$ifdef MACOS},':'{$endif MACOS}] then
  976. Delete(PPDir,length(PPDir),1);
  977. if PPDir<>'' then
  978. begin
  979. {$ifndef MACOS}
  980. TestOutputDir:=OutputDir+'/'+PPDir;
  981. {$else MACOS}
  982. TestOutputDir:=OutputDir+PPDir;
  983. {$endif MACOS}
  984. mkdirtree(TestOutputDir);
  985. end
  986. else
  987. TestOutputDir:=OutputDir;
  988. { Per test logfiles }
  989. CompilerLogFile:=TestOutputFileName(SplitFileName(PPFile),'log');
  990. ExeLogFile:=TestOutputFileName(SplitFileName(PPFile),'elg');
  991. Verbose(V_Debug,'Using Compiler logfile: '+CompilerLogFile);
  992. Verbose(V_Debug,'Using Execution logfile: '+ExeLogFile);
  993. end;
  994. if Res then
  995. begin
  996. if Config.UsesGraph and (not DoGraph) then
  997. begin
  998. AddLog(ResLogFile,skipping_graph_test+PPFileInfo);
  999. { avoid a second attempt by writing to elg file }
  1000. AddLog(EXELogFile,skipping_graph_test+PPFileInfo);
  1001. Verbose(V_Abort,skipping_graph_test);
  1002. Res:=false;
  1003. end;
  1004. end;
  1005. if Res then
  1006. begin
  1007. if Config.IsInteractive and (not DoInteractive) then
  1008. begin
  1009. { avoid a second attempt by writing to elg file }
  1010. AddLog(EXELogFile,skipping_interactive_test+PPFileInfo);
  1011. AddLog(ResLogFile,skipping_interactive_test+PPFileInfo);
  1012. Verbose(V_Abort,skipping_interactive_test);
  1013. Res:=false;
  1014. end;
  1015. end;
  1016. if Res then
  1017. begin
  1018. if Config.IsKnownCompileError and (not DoKnown) then
  1019. begin
  1020. { avoid a second attempt by writing to elg file }
  1021. AddLog(EXELogFile,skipping_known_bug+PPFileInfo);
  1022. AddLog(ResLogFile,skipping_known_bug+PPFileInfo);
  1023. Verbose(V_Abort,skipping_known_bug);
  1024. Res:=false;
  1025. end;
  1026. end;
  1027. if Res and not DoUsual then
  1028. res:=(Config.IsInteractive and DoInteractive) or
  1029. (Config.IsKnownRunError and DoKnown) or
  1030. (Config.UsesGraph and DoGraph);
  1031. if Res then
  1032. begin
  1033. if (Config.MinVersion<>'') and not DoAll then
  1034. begin
  1035. Verbose(V_Debug,'Required compiler version: '+Config.MinVersion);
  1036. Res:=GetCompilerVersion;
  1037. if CompilerVersion<Config.MinVersion then
  1038. begin
  1039. { avoid a second attempt by writing to elg file }
  1040. AddLog(EXELogFile,skipping_compiler_version_too_low+PPFileInfo);
  1041. AddLog(ResLogFile,skipping_compiler_version_too_low+PPFileInfo);
  1042. Verbose(V_Abort,'Compiler version too low '+CompilerVersion+' < '+Config.MinVersion);
  1043. Res:=false;
  1044. end;
  1045. end;
  1046. end;
  1047. if Res then
  1048. begin
  1049. if (Config.MaxVersion<>'') and not DoAll then
  1050. begin
  1051. Verbose(V_Debug,'Highest compiler version: '+Config.MaxVersion);
  1052. Res:=GetCompilerVersion;
  1053. if CompilerVersion>Config.MaxVersion then
  1054. begin
  1055. { avoid a second attempt by writing to elg file }
  1056. AddLog(EXELogFile,skipping_compiler_version_too_high+PPFileInfo);
  1057. AddLog(ResLogFile,skipping_compiler_version_too_high+PPFileInfo);
  1058. Verbose(V_Abort,'Compiler version too high '+CompilerVersion+' > '+Config.MaxVersion);
  1059. Res:=false;
  1060. end;
  1061. end;
  1062. end;
  1063. if Res then
  1064. begin
  1065. if Config.NeedCPU<>'' then
  1066. begin
  1067. Verbose(V_Debug,'Required compiler cpu: '+Config.NeedCPU);
  1068. if not IsInList(CompilerCPU,Config.NeedCPU) then
  1069. begin
  1070. { avoid a second attempt by writing to elg file }
  1071. AddLog(EXELogFile,skipping_other_cpu+PPFileInfo);
  1072. AddLog(ResLogFile,skipping_other_cpu+PPFileInfo);
  1073. Verbose(V_Abort,'Compiler cpu "'+CompilerCPU+'" is not in list "'+Config.NeedCPU+'"');
  1074. Res:=false;
  1075. end;
  1076. end;
  1077. end;
  1078. if Res then
  1079. begin
  1080. if Config.SkipCPU<>'' then
  1081. begin
  1082. Verbose(V_Debug,'Skip compiler cpu: '+Config.SkipCPU);
  1083. if IsInList(CompilerCPU,Config.SkipCPU) then
  1084. begin
  1085. { avoid a second attempt by writing to elg file }
  1086. AddLog(EXELogFile,skipping_other_cpu+PPFileInfo);
  1087. AddLog(ResLogFile,skipping_other_cpu+PPFileInfo);
  1088. Verbose(V_Abort,'Compiler cpu "'+CompilerCPU+'" is in list "'+Config.SkipCPU+'"');
  1089. Res:=false;
  1090. end;
  1091. end;
  1092. end;
  1093. if Res then
  1094. begin
  1095. if Config.SkipEmu<>'' then
  1096. begin
  1097. Verbose(V_Debug,'Skip emulator: '+emulatorname);
  1098. if IsInList(emulatorname,Config.SkipEmu) then
  1099. begin
  1100. { avoid a second attempt by writing to elg file }
  1101. AddLog(EXELogFile,skipping_other_cpu+PPFileInfo);
  1102. AddLog(ResLogFile,skipping_other_cpu+PPFileInfo);
  1103. Verbose(V_Abort,'Emulator "'+emulatorname+'" is in list "'+Config.SkipEmu+'"');
  1104. Res:=false;
  1105. end;
  1106. end;
  1107. end;
  1108. if Res then
  1109. begin
  1110. if Config.NeedTarget<>'' then
  1111. begin
  1112. Verbose(V_Debug,'Required compiler target: '+Config.NeedTarget);
  1113. if not IsInList(CompilerTarget,Config.NeedTarget) then
  1114. begin
  1115. { avoid a second attempt by writing to elg file }
  1116. AddLog(EXELogFile,skipping_other_target+PPFileInfo);
  1117. AddLog(ResLogFile,skipping_other_target+PPFileInfo);
  1118. Verbose(V_Abort,'Compiler target "'+CompilerTarget+'" is not in list "'+Config.NeedTarget+'"');
  1119. Res:=false;
  1120. end;
  1121. end;
  1122. end;
  1123. if Res then
  1124. begin
  1125. if Config.SkipTarget<>'' then
  1126. begin
  1127. Verbose(V_Debug,'Skip compiler target: '+Config.NeedTarget);
  1128. if IsInList(CompilerTarget,Config.SkipTarget) then
  1129. begin
  1130. { avoid a second attempt by writing to elg file }
  1131. AddLog(EXELogFile,skipping_other_target+PPFileInfo);
  1132. AddLog(ResLogFile,skipping_other_target+PPFileInfo);
  1133. Verbose(V_Abort,'Compiler target "'+CompilerTarget+'" is in list "'+Config.SkipTarget+'"');
  1134. Res:=false;
  1135. end;
  1136. end;
  1137. end;
  1138. if Res then
  1139. begin
  1140. Res:=RunCompiler;
  1141. if Res and Config.NeedRecompile then
  1142. Res:=RunCompiler;
  1143. end;
  1144. if Res and (not Config.ShouldFail) then
  1145. begin
  1146. if (Config.NoRun) then
  1147. begin
  1148. { avoid a second attempt by writing to elg file }
  1149. AddLog(EXELogFile,skipping_run_test+PPFileInfo);
  1150. AddLog(ResLogFile,skipping_run_test+PPFileInfo);
  1151. Verbose(V_Debug,skipping_run_test);
  1152. end
  1153. else if Config.IsKnownRunError and (not DoKnown) then
  1154. begin
  1155. { avoid a second attempt by writing to elg file }
  1156. AddLog(EXELogFile,skipping_known_bug+PPFileInfo);
  1157. AddLog(ResLogFile,skipping_known_bug+PPFileInfo);
  1158. Verbose(V_Abort,skipping_known_bug);
  1159. end
  1160. else
  1161. begin
  1162. if DoExecute then
  1163. begin
  1164. if FileExists(TestOutputFilename(PPFile,'ppu')) or
  1165. FileExists(TestOutputFilename(PPFile,'ppo')) or
  1166. FileExists(TestOutputFilename(PPFile,'ppw')) then
  1167. begin
  1168. AddLog(ExeLogFile,skipping_run_unit+PPFileInfo);
  1169. AddLog(ResLogFile,skipping_run_unit+PPFileInfo);
  1170. Verbose(V_Debug,'Unit found, skipping run test')
  1171. end
  1172. else
  1173. Res:=RunExecutable;
  1174. end;
  1175. end;
  1176. end;
  1177. end;
  1178. begin
  1179. GetArgs;
  1180. RunTest;
  1181. end.