dotest.pp 59 KB

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