dotest.pp 57 KB

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