dotest.pp 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152
  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. If UniqueSuffix<>'' then
  1221. begin
  1222. FileList:=BuildFileList;
  1223. if assigned(FileList) then
  1224. begin
  1225. LocalPath:=SplitPath(PPFile[current]);
  1226. if Length(LocalPath) > 0 then
  1227. LocalPath:=LocalPath+'/';
  1228. for i:=0 to FileList.count-1 do
  1229. begin
  1230. LocalFile:=FileList[i];
  1231. CopyFile(LocalPath+LocalFile,TestOutputDir+'/'+LocalFile,false);
  1232. end;
  1233. FileList.Free;
  1234. end;
  1235. end;
  1236. exit(true);
  1237. end;
  1238. execres:=true;
  1239. { Check if library should be deleted. Do not copy to remote target in such case. }
  1240. if (deAfter in DelExecutable) and (Config.DelFiles <> '') then
  1241. if SplitFileName(FileToCopy) = DllPrefix + Trim(Config.DelFiles) + DllExt then
  1242. exit;
  1243. { We don't want to create subdirs, remove paths from the test }
  1244. TestRemoteExe:=RemotePath+'/'+SplitFileName(FileToCopy);
  1245. if deBefore in DelExecutable then
  1246. begin
  1247. s:=RemoteRshParas+' rm ';
  1248. if rshprog <> 'adb' then
  1249. s:=s+'-f ';
  1250. ExecuteRemote(rshprog,s+TestRemoteExe,
  1251. StartTicks,EndTicks);
  1252. end;
  1253. execres:=ExecuteRemote(rcpprog,RemotePara+' '+FileToCopy+' '+
  1254. RemotePathPrefix+TestRemoteExe,StartTicks,EndTicks);
  1255. if not execres then
  1256. begin
  1257. Verbose(V_normal, 'Could not copy executable '+FileToCopy);
  1258. exit(execres);
  1259. end;
  1260. FileList:=BuildFileList;
  1261. if assigned(FileList) then
  1262. begin
  1263. LocalPath:=SplitPath(PPFile[current]);
  1264. if Length(LocalPath) > 0 then
  1265. LocalPath:=LocalPath+'/';
  1266. for i:=0 to FileList.count-1 do
  1267. begin
  1268. LocalFile:=FileList[i];
  1269. RemoteFile:=RemotePath+'/'+SplitFileName(LocalFile);
  1270. LocalFile:=LocalPath+LocalFile;
  1271. if DoVerbose and (rcpprog='pscp') then
  1272. pref:='-v '
  1273. else
  1274. pref:='';
  1275. execres:=ExecuteRemote(rcpprog,pref+RemotePara+' '+LocalFile+' '+
  1276. RemotePathPrefix+RemoteFile,StartTicks,EndTicks);
  1277. if not execres then
  1278. begin
  1279. Verbose(V_normal, 'Could not copy required file '+LocalFile);
  1280. FileList.Free;
  1281. exit(false);
  1282. end;
  1283. end;
  1284. end;
  1285. FileList.Free;
  1286. MaybeCopyFiles:=execres;
  1287. end;
  1288. function RunExecutable:boolean;
  1289. const
  1290. {$ifdef unix}
  1291. CurrDir = './';
  1292. {$else}
  1293. CurrDir = '';
  1294. {$endif}
  1295. var
  1296. OldDir, s, ss,
  1297. execcmd,
  1298. FullExeLogFile,
  1299. TestRemoteExe,
  1300. TestExe : string;
  1301. execres : boolean;
  1302. EndTicks,
  1303. StartTicks : int64;
  1304. begin
  1305. RunExecutable:=false;
  1306. execres:=true;
  1307. TestExe:=TestOutputFilename('',PPFile[current],ExeExt);
  1308. execres:=MaybeCopyFiles(TestExe);
  1309. if EmulatorName<>'' then
  1310. begin
  1311. { Get full name out log file, because we change the directory during
  1312. execution }
  1313. FullExeLogFile:=FExpand(EXELogFile);
  1314. {$I-}
  1315. GetDir(0,OldDir);
  1316. ChDir(TestOutputDir);
  1317. {$I+}
  1318. ioresult;
  1319. s:=CurrDir+SplitFileName(TestExe);
  1320. execres:=ExecuteEmulated(EmulatorName,s,FullExeLogFile,StartTicks,EndTicks);
  1321. {$I-}
  1322. ChDir(OldDir);
  1323. {$I+}
  1324. end
  1325. else if RemoteAddr<>'' then
  1326. begin
  1327. TestRemoteExe:=RemotePath+'/'+SplitFileName(TestExe);
  1328. { rsh doesn't pass the exitcode, use a second command to print the exitcode
  1329. on the remoteshell to stdout }
  1330. if DoVerbose and (rshprog='plink') then
  1331. execcmd:='-v '+RemoteRshParas
  1332. else
  1333. execcmd:=RemoteRshParas;
  1334. execcmd:=execcmd+' '+rquote+
  1335. 'chmod 755 '+TestRemoteExe+
  1336. ' && cd '+RemotePath+' && { ';
  1337. { Using -rpath . at compile time does not seem
  1338. to work for programs copied over to remote machine,
  1339. at least not for FreeBSD.
  1340. Does this work for all shells? }
  1341. if Config.NeedLibrary then
  1342. begin
  1343. if RemoteShellNeedsExport then
  1344. if CompilerTarget='darwin' then
  1345. execcmd:=execcmd+' DYLD_LIBRARY_PATH=.; export DYLD_LIBRARY_PATH;'
  1346. else
  1347. execcmd:=execcmd+' LD_LIBRARY_PATH=.; export LD_LIBRARY_PATH;'
  1348. else
  1349. if CompilerTarget='darwin' then
  1350. execcmd:=execcmd+' setenv DYLD_LIBRARY_PATH=.; '
  1351. else
  1352. execcmd:=execcmd+' setenv LD_LIBRARY_PATH=.; '
  1353. end;
  1354. if UseTimeout then
  1355. begin
  1356. if Config.Timeout=0 then
  1357. Config.Timeout:=DefaultTimeout;
  1358. str(Config.Timeout,s);
  1359. if (RemoteShellBase='bash') then
  1360. execcmd:=execcmd+'ulimit -t '+s+'; '
  1361. else
  1362. execcmd:=execcmd+'timeout -9 '+s;
  1363. end;
  1364. { as we moved to RemotePath, if path is not absolute
  1365. we need to use ./execfilename only }
  1366. if not isabsolute(TestRemoteExe) then
  1367. execcmd:=execcmd+' ./'+SplitFileName(TestRemoteExe)
  1368. else
  1369. execcmd:=execcmd+' '+TestRemoteExe;
  1370. execcmd:=execcmd+' ; echo TestExitCode: $?';
  1371. if (deAfter in DelExecutable) and
  1372. not Config.NeededAfter then
  1373. begin
  1374. execcmd:=execcmd+' ; rm ';
  1375. if rshprog <> 'adb' then
  1376. execcmd:=execcmd+'-f ';
  1377. execcmd:=execcmd+SplitFileName(TestRemoteExe);
  1378. end;
  1379. execcmd:=execcmd+'; }'+rquote;
  1380. execres:=ExecuteRemote(rshprog,execcmd,StartTicks,EndTicks);
  1381. { Check for TestExitCode error in output, sets ExecuteResult }
  1382. if not CheckTestExitCode(EXELogFile) then
  1383. Verbose(V_Debug,'Failed to check exit code for '+execcmd);
  1384. if (deAfter in DelExecutable) and ( (Config.DelFiles <> '') or (Config.Files <> '')) then
  1385. begin
  1386. ss:=Trim(Config.DelFiles + ' ' + Config.Files);
  1387. execcmd:=RemoteRshParas+' ' + rquote + 'cd ' + RemotePath + ' && { ';
  1388. while ss <> '' do
  1389. begin
  1390. s:=Trim(GetToken(ss, [' ',',',';']));
  1391. if s = '' then
  1392. break;
  1393. if ExtractFileExt(s) = '' then
  1394. // If file has no extension, treat it as exe or shared lib
  1395. execcmd:=execcmd + 'rm ' + s + ExeExt + '; rm ' + DllPrefix + s + DllExt
  1396. else
  1397. execcmd:=execcmd + 'rm ' + s;
  1398. execcmd:=execcmd + '; ';
  1399. end;
  1400. ExecuteRemote(rshprog,execcmd+'}'+rquote,StartTicks,EndTicks);
  1401. end;
  1402. end
  1403. else
  1404. begin
  1405. { Get full name out log file, because we change the directory during
  1406. execution }
  1407. FullExeLogFile:=FExpand(EXELogFile);
  1408. Verbose(V_Debug,'Executing '+TestExe);
  1409. {$I-}
  1410. GetDir(0,OldDir);
  1411. ChDir(TestOutputDir);
  1412. {$I+}
  1413. ioresult;
  1414. { don't redirect interactive and graph programs }
  1415. StartTicks:=GetMicroSTicks;
  1416. if Config.IsInteractive or Config.UsesGraph then
  1417. execres:=ExecuteRedir(CurrDir+SplitFileName(TestExe),'','','','')
  1418. else
  1419. execres:=ExecuteRedir(CurrDir+SplitFileName(TestExe),'','',FullExeLogFile,'stdout');
  1420. EndTicks:=GetMicroSTicks;
  1421. {$I-}
  1422. ChDir(OldDir);
  1423. {$I+}
  1424. ioresult;
  1425. end;
  1426. { Error during execution? }
  1427. Verbose(V_Debug,'Exitcode '+ToStr(ExecuteResult));
  1428. if BenchmarkInfo then
  1429. begin
  1430. Verbose(V_Normal,'Execution took '+ToStr(EndTicks-StartTicks)+' us');
  1431. end;
  1432. if (not execres) and (ExecuteResult=0) then
  1433. begin
  1434. AddLog(FailLogFile,TestName);
  1435. AddLog(ResLogFile,failed_to_run+PPFileInfo[current]);
  1436. AddLog(LongLogFile,line_separation);
  1437. AddLog(LongLogFile,failed_to_run+PPFileInfo[current]);
  1438. if CopyFile(EXELogFile,LongLogFile,true)=0 then
  1439. AddLog(LongLogFile,'IOStatus: '+ToStr(IOStatus));
  1440. { avoid to try again }
  1441. AddLog(ExeLogFile,failed_to_run+PPFileInfo[current]);
  1442. Verbose(V_Warning,'IOStatus: '+ToStr(IOStatus));
  1443. exit;
  1444. end;
  1445. if ExecuteResult<>Config.ResultCode then
  1446. begin
  1447. if (ExecuteResult<>0) and
  1448. (ExecuteResult=Config.KnownRunError) then
  1449. begin
  1450. AddLog(FailLogFile,TestName+known_problem+Config.KnownRunNote);
  1451. AddLog(ResLogFile,failed_to_run+PPFileInfo[current]+known_problem+Config.KnownRunNote);
  1452. AddLog(LongLogFile,line_separation);
  1453. AddLog(LongLogFile,known_problem+Config.KnownRunNote);
  1454. AddLog(LongLogFile,failed_to_run+PPFileInfo[current]+' ('+ToStr(ExecuteResult)+')');
  1455. if Copyfile(EXELogFile,LongLogFile,true)=0 then
  1456. begin
  1457. AddLog(LongLogFile,known_problem+'exitcode: '+ToStr(ExecuteResult)+' (expected '+ToStr(Config.ResultCode)+')');
  1458. AddLog(ExeLogFile,known_problem+'exitcode: '+ToStr(ExecuteResult)+' (expected '+ToStr(Config.ResultCode)+')');
  1459. end;
  1460. Verbose(V_Warning,known_problem+'exitcode: '+ToStr(ExecuteResult)+' (expected '+ToStr(Config.ResultCode)+')');
  1461. end
  1462. else
  1463. begin
  1464. AddLog(FailLogFile,TestName);
  1465. AddLog(ResLogFile,failed_to_run+PPFileInfo[current]);
  1466. AddLog(LongLogFile,line_separation);
  1467. AddLog(LongLogFile,failed_to_run+PPFileInfo[current]+' ('+ToStr(ExecuteResult)+')');
  1468. if Copyfile(EXELogFile,LongLogFile,true)=0 then
  1469. begin
  1470. AddLog(LongLogFile,'Exitcode: '+ToStr(ExecuteResult)+' (expected '+ToStr(Config.ResultCode)+')');
  1471. AddLog(ExeLogFile,'Exitcode: '+ToStr(ExecuteResult)+' (expected '+ToStr(Config.ResultCode)+')');
  1472. end;
  1473. Verbose(V_Warning,'Exitcode: '+ToStr(ExecuteResult)+' (expected '+ToStr(Config.ResultCode)+')');
  1474. end
  1475. end
  1476. else
  1477. begin
  1478. AddLog(ResLogFile,successfully_run+PPFileInfo[current]);
  1479. RunExecutable:=true;
  1480. end;
  1481. if (deAfter in DelExecutable) and not Config.NeededAfter then
  1482. begin
  1483. Verbose(V_Debug,'Deleting executable '+TestExe);
  1484. RemoveFile(TestExe);
  1485. RemoveFile(ForceExtension(TestExe,ObjExt));
  1486. RemoveFile(ForceExtension(TestExe,PPUExt));
  1487. end;
  1488. end;
  1489. { Try to collect information concerning the remote configuration
  1490. Currently only records RemoteShell name and sets
  1491. RemoteShellNeedsExport boolean variable }
  1492. procedure SetRemoteConfiguration;
  1493. var
  1494. f : text;
  1495. StartTicks,EndTicks : int64;
  1496. begin
  1497. if RemoteAddr='' then
  1498. exit;
  1499. if rshprog = 'adb' then
  1500. begin
  1501. RemoteShellNeedsExport:=true;
  1502. exit;
  1503. end;
  1504. ExeLogFile:='__remote.tmp';
  1505. ExecuteRemote(rshprog,RemoteRshParas+
  1506. ' "echo SHELL=${SHELL}"',StartTicks,EndTicks);
  1507. Assign(f,ExeLogFile);
  1508. Reset(f);
  1509. While not eof(f) do
  1510. begin
  1511. Readln(f,RemoteShellBase);
  1512. if pos('SHELL=',RemoteShellBase)>0 then
  1513. begin
  1514. RemoteShell:=TrimSpace(Copy(RemoteShellBase,pos('SHELL=',RemoteShellBase)+6,
  1515. length(RemoteShellBase)));
  1516. Verbose(V_Debug,'Remote shell is "'+RemoteShell+'"');
  1517. RemoteShellBase:=SplitFileBase(RemoteShell);
  1518. if (RemoteShellBase='bash') or (RemoteShellBase='sh') then
  1519. RemoteShellNeedsExport:=true;
  1520. end;
  1521. end;
  1522. Close(f);
  1523. end;
  1524. procedure getargs;
  1525. procedure helpscreen;
  1526. begin
  1527. writeln('dotest [Options] <File>');
  1528. writeln;
  1529. writeln('Options can be:');
  1530. writeln(' !ENV_NAME parse environment variable ENV_NAME for options');
  1531. writeln(' -A include ALL tests');
  1532. writeln(' -ADB use ADB to run tests');
  1533. writeln(' -B delete executable before remote upload');
  1534. writeln(' -C<compiler> set compiler to use');
  1535. writeln(' -D display execution time');
  1536. writeln(' -E execute test also');
  1537. writeln(' -G include graph tests');
  1538. writeln(' -I include interactive tests');
  1539. writeln(' -K include known bug tests');
  1540. writeln(' -L<ext> set extension of temporary files (prevent conflicts with parallel invocations)');
  1541. writeln(' -M<emulator> run the tests using the given emulator');
  1542. writeln(' -O use timeout wrapper for (remote) execution');
  1543. writeln(' -P<path> path to the tests tree on the remote machine');
  1544. writeln(' -R<remote> run the tests remotely with the given rsh/ssh address');
  1545. writeln(' -S use ssh instead of rsh');
  1546. writeln(' -T[cpu-]<os> run tests for target cpu and os');
  1547. writeln(' -U<remotepara>');
  1548. writeln(' pass additional parameter to remote program. Multiple -U can be used');
  1549. writeln(' -V be verbose');
  1550. writeln(' -W use putty compatible file names when testing (plink and pscp)');
  1551. writeln(' -X don''t use COMSPEC');
  1552. writeln(' -Y<opts> extra options passed to the compiler. Several -Y<opt> can be given.');
  1553. writeln(' -Z remove temporary files (executable,ppu,o)');
  1554. halt(1);
  1555. end;
  1556. procedure interpret_option (para : string);
  1557. var
  1558. ch : char;
  1559. j : longint;
  1560. begin
  1561. Verbose(V_Debug,'Interpreting option"'+para+'"');
  1562. ch:=Upcase(para[2]);
  1563. delete(para,1,2);
  1564. case ch of
  1565. 'A' :
  1566. if UpperCase(para) = 'DB' then
  1567. begin
  1568. rshprog:='adb';
  1569. rcpprog:='adb';
  1570. rquote:='"';
  1571. if RemoteAddr = '' then
  1572. RemoteAddr:='1'; // fake remote addr (default device will be used)
  1573. end
  1574. else
  1575. begin
  1576. DoGraph:=true;
  1577. DoInteractive:=true;
  1578. DoKnown:=true;
  1579. DoAll:=true;
  1580. end;
  1581. 'B' : Include(DelExecutable,deBefore);
  1582. 'C' : CompilerBin:=Para;
  1583. 'D' : BenchMarkInfo:=true;
  1584. 'E' : DoExecute:=true;
  1585. 'G' : begin
  1586. DoGraph:=true;
  1587. if para='-' then
  1588. DoUsual:=false;
  1589. end;
  1590. 'I' : begin
  1591. DoInteractive:=true;
  1592. if para='-' then
  1593. DoUsual:=false;
  1594. end;
  1595. 'K' : begin
  1596. DoKnown:=true;
  1597. if para='-' then
  1598. DoUsual:=false;
  1599. end;
  1600. 'L' : begin
  1601. UniqueSuffix:=Para;
  1602. end;
  1603. 'M' : EmulatorName:=Para;
  1604. 'O' : UseTimeout:=true;
  1605. 'P' : RemotePath:=Para;
  1606. 'R' : RemoteAddr:=Para;
  1607. 'S' :
  1608. begin
  1609. rshprog:='ssh';
  1610. rcpprog:='scp';
  1611. end;
  1612. 'T' :
  1613. begin
  1614. j:=Pos('-',Para);
  1615. if j>0 then
  1616. begin
  1617. CompilerCPU:=Copy(Para,1,j-1);
  1618. CompilerTarget:=Copy(Para,j+1,length(para));
  1619. end
  1620. else
  1621. CompilerTarget:=Para
  1622. end;
  1623. 'U' :
  1624. RemotePara:=RemotePara+' '+Para;
  1625. 'V' : DoVerbose:=true;
  1626. 'W' :
  1627. begin
  1628. rshprog:='plink';
  1629. rcpprog:='pscp';
  1630. rquote:='"';
  1631. end;
  1632. 'X' : UseComSpec:=false;
  1633. 'Y' : ExtraCompilerOpts:= ExtraCompilerOpts +' '+ Para;
  1634. 'Z' : Include(DelExecutable,deAfter);
  1635. end;
  1636. end;
  1637. procedure interpret_env(arg : string);
  1638. var
  1639. para : string;
  1640. pspace : longint;
  1641. begin
  1642. Verbose(V_Debug,'Interpreting environment option"'+arg+'"');
  1643. { Get rid of leading '!' }
  1644. delete(arg,1,1);
  1645. arg:=getenv(arg);
  1646. Verbose(V_Debug,'Environment value is "'+arg+'"');
  1647. while (length(arg)>0) do
  1648. begin
  1649. while (length(arg)>0) and (arg[1]=' ') do
  1650. delete(arg,1,1);
  1651. pspace:=pos(' ',arg);
  1652. if pspace=0 then
  1653. pspace:=length(arg)+1;
  1654. para:=copy(arg,1,pspace-1);
  1655. if (length(para)>0) and (para[1]='-') then
  1656. interpret_option (para)
  1657. else
  1658. begin
  1659. PPFile.Insert(current,ForceExtension(Para,'pp'));
  1660. inc(current);
  1661. end;
  1662. delete(arg,1,pspace);
  1663. end;
  1664. end;
  1665. var
  1666. param : string;
  1667. i : longint;
  1668. begin
  1669. CompilerBin:='ppc386'+srcexeext;
  1670. for i:=1 to paramcount do
  1671. begin
  1672. param:=Paramstr(i);
  1673. if (param[1]='-') then
  1674. interpret_option(param)
  1675. else if (param[1]='!') then
  1676. interpret_env(param)
  1677. else
  1678. begin
  1679. PPFile.Insert(current,ForceExtension(Param,'pp'));
  1680. inc(current);
  1681. end;
  1682. end;
  1683. if current=0 then
  1684. HelpScreen;
  1685. { disable graph,interactive when running remote }
  1686. if RemoteAddr<>'' then
  1687. begin
  1688. DoGraph:=false;
  1689. DoInteractive:=false;
  1690. end;
  1691. { If we use PuTTY plink program with -load option,
  1692. the IP address or name should not be added to
  1693. the command line }
  1694. if (rshprog='plink') and (pos('-load',RemotePara)>0) then
  1695. RemoteRshParas:=RemotePara
  1696. else
  1697. if rshprog='adb' then
  1698. begin
  1699. if RemoteAddr <> '1' then
  1700. RemotePara:=Trim('-s ' + RemoteAddr + ' ' + RemotePara);
  1701. RemoteRshParas:=Trim(RemotePara + ' shell');
  1702. end
  1703. else
  1704. RemoteRshParas:=RemotePara+' '+RemoteAddr;
  1705. if rcpprog = 'adb' then
  1706. begin
  1707. RemotePathPrefix:='';
  1708. RemotePara:=Trim(RemotePara + ' push');
  1709. end
  1710. else
  1711. RemotePathPrefix:=RemoteAddr + ':';
  1712. end;
  1713. procedure RunTest;
  1714. var
  1715. PPDir,LibraryName,LogSuffix : string;
  1716. Res : boolean;
  1717. begin
  1718. Res:=GetConfig(PPFile[current],Config);
  1719. TranslateConfig(Config);
  1720. if Res then
  1721. begin
  1722. Res:=GetCompilerCPU;
  1723. Res:=GetCompilerTarget;
  1724. {$ifndef MACOS}
  1725. RTLUnitsDir:='tstunits/'+CompilerFullTarget;
  1726. {$else MACOS}
  1727. RTLUnitsDir:=':tstunits:'+CompilerFullTarget;
  1728. {$endif MACOS}
  1729. if not PathExists(RTLUnitsDir) then
  1730. Verbose(V_Abort,'Unit path "'+RTLUnitsDir+'" does not exists');
  1731. {$ifndef MACOS}
  1732. OutputDir:='output/'+CompilerFullTarget;
  1733. {$else MACOS}
  1734. OutputDir:=':output:'+CompilerFullTarget;
  1735. {$endif MACOS}
  1736. if not PathExists(OutputDir) then
  1737. Verbose(V_Abort,'Output path "'+OutputDir+'" does not exists');
  1738. { Make subdir in output if needed }
  1739. PPDir:=SplitPath(PPFile[current]);
  1740. if PPDir[length(PPDir)] in ['/','\'{$ifdef MACOS},':'{$endif MACOS}] then
  1741. Delete(PPDir,length(PPDir),1);
  1742. if PPDir<>'' then
  1743. begin
  1744. {$ifndef MACOS}
  1745. TestOutputDir:=OutputDir+'/'+PPDir;
  1746. if UniqueSuffix<>'' then
  1747. TestOutputDir:=TestOutputDir+'/'+UniqueSuffix;
  1748. {$else MACOS}
  1749. TestOutputDir:=OutputDir+PPDir;
  1750. if UniqueSuffix<>'' then
  1751. TestOutputDir:=TestOutputDir+':'+UniqueSuffix;
  1752. {$endif MACOS}
  1753. mkdirtree(TestOutputDir);
  1754. end
  1755. else
  1756. TestOutputDir:=OutputDir;
  1757. if UniqueSuffix<>'' then
  1758. LogSuffix:=UniqueSuffix
  1759. else
  1760. LogSuffix:=SplitBasePath(PPDir)+'log';
  1761. ResLogFile:=OutputFileName('log',LogSuffix);
  1762. LongLogFile:=OutputFileName('longlog',LogSuffix);
  1763. FailLogFile:=OutputFileName('faillist',LogSuffix);
  1764. ForceLog(ResLogFile);
  1765. ForceLog(LongLogFile);
  1766. ForceLog(FailLogFile);
  1767. { Per test logfiles }
  1768. CompilerLogFile:=TestLogFileName('',SplitFileName(PPFile[current]),'log');
  1769. ExeLogFile:=TestLogFileName('',SplitFileName(PPFile[current]),'elg');
  1770. Verbose(V_Debug,'Using Compiler logfile: '+CompilerLogFile);
  1771. Verbose(V_Debug,'Using Execution logfile: '+ExeLogFile);
  1772. end;
  1773. if Res then
  1774. begin
  1775. if Config.UsesGraph and (not DoGraph) then
  1776. begin
  1777. AddLog(ResLogFile,skipping_graph_test+PPFileInfo[current]);
  1778. { avoid a second attempt by writing to elg file }
  1779. AddLog(EXELogFile,skipping_graph_test+PPFileInfo[current]);
  1780. Verbose(V_Warning,skipping_graph_test);
  1781. Res:=false;
  1782. end;
  1783. end;
  1784. if Res then
  1785. begin
  1786. if Config.IsInteractive and (not DoInteractive) then
  1787. begin
  1788. { avoid a second attempt by writing to elg file }
  1789. AddLog(EXELogFile,skipping_interactive_test+PPFileInfo[current]);
  1790. AddLog(ResLogFile,skipping_interactive_test+PPFileInfo[current]);
  1791. Verbose(V_Warning,skipping_interactive_test);
  1792. Res:=false;
  1793. end;
  1794. end;
  1795. if Res then
  1796. begin
  1797. if Config.IsKnownCompileError and (not DoKnown) then
  1798. begin
  1799. { avoid a second attempt by writing to elg file }
  1800. AddLog(EXELogFile,skipping_known_bug+PPFileInfo[current]);
  1801. AddLog(ResLogFile,skipping_known_bug+PPFileInfo[current]);
  1802. Verbose(V_Warning,skipping_known_bug);
  1803. Res:=false;
  1804. end;
  1805. end;
  1806. if Res and not DoUsual then
  1807. res:=(Config.IsInteractive and DoInteractive) or
  1808. (Config.IsKnownRunError and DoKnown) or
  1809. (Config.UsesGraph and DoGraph);
  1810. if Res then
  1811. begin
  1812. if (Config.MinVersion<>'') and not DoAll then
  1813. begin
  1814. Verbose(V_Debug,'Required compiler version: '+Config.MinVersion);
  1815. Res:=GetCompilerVersion;
  1816. if CompilerVersion<Config.MinVersion then
  1817. begin
  1818. { avoid a second attempt by writing to elg file }
  1819. AddLog(EXELogFile,skipping_compiler_version_too_low+PPFileInfo[current]);
  1820. AddLog(ResLogFile,skipping_compiler_version_too_low+PPFileInfo[current]);
  1821. Verbose(V_Warning,'Compiler version too low '+CompilerVersion+' < '+Config.MinVersion);
  1822. Res:=false;
  1823. end;
  1824. end;
  1825. end;
  1826. if Res then
  1827. begin
  1828. if (Config.MaxVersion<>'') and not DoAll then
  1829. begin
  1830. Verbose(V_Debug,'Highest compiler version: '+Config.MaxVersion);
  1831. Res:=GetCompilerVersion;
  1832. if CompilerVersion>Config.MaxVersion then
  1833. begin
  1834. { avoid a second attempt by writing to elg file }
  1835. AddLog(EXELogFile,skipping_compiler_version_too_high+PPFileInfo[current]);
  1836. AddLog(ResLogFile,skipping_compiler_version_too_high+PPFileInfo[current]);
  1837. Verbose(V_Warning,'Compiler version too high '+CompilerVersion+' > '+Config.MaxVersion);
  1838. Res:=false;
  1839. end;
  1840. end;
  1841. end;
  1842. if Res then
  1843. begin
  1844. if Config.NeedCPU<>'' then
  1845. begin
  1846. Verbose(V_Debug,'Required compiler cpu: '+Config.NeedCPU);
  1847. if not IsInList(CompilerCPU,Config.NeedCPU) then
  1848. begin
  1849. { avoid a second attempt by writing to elg file }
  1850. AddLog(EXELogFile,skipping_other_cpu+PPFileInfo[current]);
  1851. AddLog(ResLogFile,skipping_other_cpu+PPFileInfo[current]);
  1852. Verbose(V_Warning,'Compiler cpu "'+CompilerCPU+'" is not in list "'+Config.NeedCPU+'"');
  1853. Res:=false;
  1854. end;
  1855. end;
  1856. end;
  1857. if Res then
  1858. begin
  1859. if Config.SkipCPU<>'' then
  1860. begin
  1861. Verbose(V_Debug,'Skip compiler cpu: '+Config.SkipCPU);
  1862. if IsInList(CompilerCPU,Config.SkipCPU) then
  1863. begin
  1864. { avoid a second attempt by writing to elg file }
  1865. AddLog(EXELogFile,skipping_other_cpu+PPFileInfo[current]);
  1866. AddLog(ResLogFile,skipping_other_cpu+PPFileInfo[current]);
  1867. Verbose(V_Warning,'Compiler cpu "'+CompilerCPU+'" is in list "'+Config.SkipCPU+'"');
  1868. Res:=false;
  1869. end;
  1870. end;
  1871. end;
  1872. if Res then
  1873. begin
  1874. if Config.SkipEmu<>'' then
  1875. begin
  1876. Verbose(V_Debug,'Skip emulator: '+emulatorname);
  1877. if IsInList(emulatorname,Config.SkipEmu) then
  1878. begin
  1879. { avoid a second attempt by writing to elg file }
  1880. AddLog(EXELogFile,skipping_other_cpu+PPFileInfo[current]);
  1881. AddLog(ResLogFile,skipping_other_cpu+PPFileInfo[current]);
  1882. Verbose(V_Warning,'Emulator "'+emulatorname+'" is in list "'+Config.SkipEmu+'"');
  1883. Res:=false;
  1884. end;
  1885. end;
  1886. end;
  1887. if Res then
  1888. begin
  1889. if Config.NeedTarget<>'' then
  1890. begin
  1891. Verbose(V_Debug,'Required compiler target: '+Config.NeedTarget);
  1892. if not IsInList(CompilerTarget,Config.NeedTarget) then
  1893. begin
  1894. { avoid a second attempt by writing to elg file }
  1895. AddLog(EXELogFile,skipping_other_target+PPFileInfo[current]);
  1896. AddLog(ResLogFile,skipping_other_target+PPFileInfo[current]);
  1897. Verbose(V_Warning,'Compiler target "'+CompilerTarget+'" is not in list "'+Config.NeedTarget+'"');
  1898. Res:=false;
  1899. end;
  1900. end;
  1901. end;
  1902. if Res then
  1903. begin
  1904. if Config.SkipTarget<>'' then
  1905. begin
  1906. Verbose(V_Debug,'Skip compiler target: '+Config.SkipTarget);
  1907. if IsInList(CompilerTarget,Config.SkipTarget) then
  1908. begin
  1909. { avoid a second attempt by writing to elg file }
  1910. AddLog(EXELogFile,skipping_other_target+PPFileInfo[current]);
  1911. AddLog(ResLogFile,skipping_other_target+PPFileInfo[current]);
  1912. Verbose(V_Warning,'Compiler target "'+CompilerTarget+'" is in list "'+Config.SkipTarget+'"');
  1913. Res:=false;
  1914. end;
  1915. end;
  1916. end;
  1917. if Res then
  1918. begin
  1919. { Use known bug, to avoid adding a new entry for this PM 2011-06-24 }
  1920. if Config.NeedLibrary and not TargetCanCompileLibraries then
  1921. begin
  1922. AddLog(EXELogFile,skipping_known_bug+PPFileInfo[current]);
  1923. AddLog(ResLogFile,skipping_known_bug+PPFileInfo[current]);
  1924. Verbose(V_Warning,'Compiler target "'+CompilerTarget+'" does not support library compilation');
  1925. Res:=false;
  1926. end;
  1927. end;
  1928. if Res then
  1929. begin
  1930. Res:=RunCompiler('');
  1931. if Res and Config.NeedRecompile then
  1932. Res:=RunCompiler(Config.RecompileOpt);
  1933. end;
  1934. if Res and (not Config.ShouldFail) then
  1935. begin
  1936. if (Config.NoRun) then
  1937. begin
  1938. { avoid a second attempt by writing to elg file }
  1939. AddLog(EXELogFile,skipping_run_test+PPFileInfo[current]);
  1940. AddLog(ResLogFile,skipping_run_test+PPFileInfo[current]);
  1941. Verbose(V_Debug,skipping_run_test);
  1942. if LibraryExists(PPFile[current],LibraryName) then
  1943. MaybeCopyFiles(LibraryName);
  1944. end
  1945. else if Config.IsKnownRunError and (not DoKnown) then
  1946. begin
  1947. { avoid a second attempt by writing to elg file }
  1948. AddLog(EXELogFile,skipping_known_bug+PPFileInfo[current]);
  1949. AddLog(ResLogFile,skipping_known_bug+PPFileInfo[current]);
  1950. Verbose(V_Warning,skipping_known_bug);
  1951. end
  1952. else
  1953. begin
  1954. if DoExecute then
  1955. begin
  1956. if FileExists(TestOutputFilename('',PPFile[current],'ppu')) or
  1957. FileExists(TestOutputFilename('',PPFile[current],'ppo')) or
  1958. FileExists(TestOutputFilename('',PPFile[current],'ppw')) then
  1959. begin
  1960. AddLog(ExeLogFile,skipping_run_unit+PPFileInfo[current]);
  1961. AddLog(ResLogFile,skipping_run_unit+PPFileInfo[current]);
  1962. Verbose(V_Debug,'Unit found, skipping run test')
  1963. end
  1964. else if LibraryExists(PPFile[current],LibraryName) then
  1965. begin
  1966. Verbose(V_Debug,'Library found, skipping run test');
  1967. MaybeCopyFiles(LibraryName);
  1968. end
  1969. else
  1970. Res:=RunExecutable;
  1971. end;
  1972. end;
  1973. end;
  1974. end;
  1975. begin
  1976. Current:=0;
  1977. PPFile:=TStringList.Create;
  1978. PPFile.Capacity:=10;
  1979. PPFileInfo:=TStringList.Create;
  1980. PPFileInfo.Capacity:=10;
  1981. GetArgs;
  1982. SetTargetDirectoriesStyle;
  1983. SetTargetCanCompileLibraries;
  1984. SetRemoteConfiguration;
  1985. {$ifdef LIMIT83fs}
  1986. UseOSOnly:=true;
  1987. {$else not LIMIT83fs}
  1988. SetUseOSOnly;
  1989. {$endif not LIMIT83fs}
  1990. Verbose(V_Debug,'Found '+ToStr(PPFile.Count)+' tests to run');
  1991. if current>0 then
  1992. for current:=0 to PPFile.Count-1 do
  1993. begin
  1994. SetPPFileInfo;
  1995. TestName:=Copy(PPFile[current],1,Pos('.pp',PPFile[current])-1);
  1996. Verbose(V_Normal,'Running test '+TestName+', file '+PPFile[current]);
  1997. RunTest;
  1998. end;
  1999. PPFile.Free;
  2000. PPFileInfo.Free;
  2001. end.