dotest.pp 59 KB

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