rlrun.cpp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. // rlrun.c
  6. //
  7. // executable regression worker for rl.c
  8. #include "rl.h"
  9. #define TMP_PREFIX "ex" // 2 characters
  10. #define POGO_PGD "rlpogo.pgd"
  11. // In the RL environment running Pogo tests, some warnings in the optimization
  12. // compile should be errors, since we do the instrumentation and optimization
  13. // compiles back-to-back.
  14. // 4951 "'%s' has been edited since profile data was collected, function profile data not used"
  15. // 4952 "'%s' : no profile data found in program database '%s'"
  16. // 4953 "Inlinee '%s' has been edited since profile data was collected, profile data not used"
  17. // 4961 "No profile data was merged into '%s', profile-guided optimizations disabled"
  18. // 4962 "Profile-guided optimizations disabled because profile data became inconsistent"
  19. // 4963 "'%s' : no profile data found; different compiler options were used in instrumented build"
  20. static char *PogoForceErrors = "-we4951 -we4952 -we4953 -we4961 -we4962 -we4963";
  21. //
  22. // Global variables set before worker threads start, and only accessed
  23. // (not set) by the worker threads.
  24. //
  25. // sets of options to iterate over
  26. char *OptFlags[MAXOPTIONS + 1], *PogoOptFlags[MAXOPTIONS + 1];
  27. // use a big global array as scratch pad for passing the child process env vars
  28. #define MAX_ENV_LEN 10000
  29. __declspec(thread) char EnvFlags[MAX_ENV_LEN];
  30. //
  31. // Global variables read and written by the worker threads: these need to
  32. // either be protected by synchronization or use thread-local storage.
  33. //
  34. // currently, none
  35. LOCAL void __cdecl
  36. RunCleanUp()
  37. {
  38. }
  39. void
  40. RunInit()
  41. {
  42. char *opts; // value of EXEC_TESTS_FLAGS environment variable
  43. int numOptions;
  44. int numPogoOptions;
  45. int i;
  46. atexit(RunCleanUp);
  47. // Break EXEC_TESTS up into different sets of flags. The sets should
  48. // be separated by semi-colons. Options don't apply to Pogo testing
  49. // unless prefixed with POGO_TEST_PREFIX. Those options _only_ apply
  50. // to Pogo tests.
  51. opts = EXEC_TESTS_FLAGS;
  52. ASSERTNR(opts);
  53. numOptions = numPogoOptions = 0;
  54. while (opts) {
  55. while (isspace(*opts))
  56. opts++;
  57. if (*opts == '\0')
  58. break;
  59. if (!_strnicmp(opts, POGO_TEST_PREFIX, strlen(POGO_TEST_PREFIX))) {
  60. opts += strlen(POGO_TEST_PREFIX);
  61. PogoOptFlags[numPogoOptions] = opts;
  62. ++numPogoOptions;
  63. if (numPogoOptions == MAXOPTIONS)
  64. Fatal("Too many options in EXEC_TESTS_FLAGS");
  65. }
  66. else {
  67. OptFlags[numOptions] = opts;
  68. ++numOptions;
  69. if (numOptions == MAXOPTIONS)
  70. Fatal("Too many options in EXEC_TESTS_FLAGS");
  71. }
  72. opts = strchr(opts, ';');
  73. if (opts)
  74. *opts++ = '\0';
  75. }
  76. for (i = 0; i < numPogoOptions; i++) {
  77. if (strstr(PogoOptFlags[i], "GL") == NULL) {
  78. Fatal("Pogo without LTCG is not supported");
  79. }
  80. }
  81. OptFlags[numOptions] = NULL;
  82. PogoOptFlags[numPogoOptions] = NULL;
  83. if (FVerbose) {
  84. printf("(Normal) Exec flags:");
  85. for (i = 0; i < numOptions; i++) {
  86. printf(" '%s'", OptFlags[i]);
  87. }
  88. printf("\nPogo Exec flags:");
  89. for (i = 0; i < numPogoOptions; i++) {
  90. printf(" '%s'", PogoOptFlags[i]);
  91. }
  92. printf("\n");
  93. }
  94. }
  95. BOOL
  96. RunStartDir(
  97. char * /*dir -- unused*/
  98. )
  99. {
  100. return TRUE;
  101. }
  102. void
  103. DumpFileToLog(
  104. char* path
  105. )
  106. {
  107. FILE* fp;
  108. char buf[BUFFER_SIZE];
  109. char* p;
  110. fp = fopen_unsafe(path, "r");
  111. if (fp == NULL) {
  112. LogError("ERROR: DumpFileToLog couldn't open file '%s' with error '%s'", path, strerror_unsafe(errno));
  113. }
  114. else {
  115. int fd = _fileno(fp);
  116. struct _stat64 fileStats;
  117. if(fd != -1 && _fstat64(fd, &fileStats) != -1)
  118. {
  119. char creationTime[256];
  120. char accessTime[256];
  121. char currTime[256];
  122. __time64_t now = _time64(NULL);
  123. _ctime64_s(currTime, &now);
  124. _ctime64_s(creationTime, &fileStats.st_ctime);
  125. _ctime64_s(accessTime, &fileStats.st_atime);
  126. auto stripNewline = [](char *buf) {
  127. if(char *ptr = strchr(buf, '\n'))
  128. *ptr = '\0';
  129. };
  130. stripNewline(creationTime);
  131. stripNewline(accessTime);
  132. stripNewline(currTime);
  133. LogOut("ERROR: name of output file: %s; size: %I64d; creation: %s, last access: %s, now: %s", path, fileStats.st_size, creationTime, accessTime, currTime);
  134. }
  135. LogOut("ERROR: bad output file follows ============");
  136. while (fgets(buf, BUFFER_SIZE, fp) != NULL) {
  137. // Strip the newline, since LogOut adds one
  138. p = strchr(buf, '\n');
  139. if (p != NULL) {
  140. *p = '\0';
  141. }
  142. LogOut("%s", buf);
  143. }
  144. fclose(fp);
  145. LogOut("ERROR: end of bad output file ============");
  146. }
  147. }
  148. // Use a state machine to recognize the word "pass"
  149. BOOL
  150. LookForPass(
  151. char *p
  152. )
  153. {
  154. int state = 0;
  155. for(; *p != '\0'; p++) {
  156. switch(tolower(*p)) {
  157. case 'p':
  158. state = 1;
  159. break;
  160. case 'a':
  161. if (state == 1)
  162. state = 2;
  163. else
  164. state = 0;
  165. break;
  166. case 's':
  167. if (state == 2)
  168. state = 3;
  169. else if (state == 3)
  170. return TRUE;
  171. else
  172. state = 0;
  173. break;
  174. default:
  175. state = 0;
  176. }
  177. }
  178. return FALSE;
  179. }
  180. // Return TRUE if the specified test is Pogo-specific.
  181. BOOL
  182. IsPogoTest(
  183. Test * pTest
  184. )
  185. {
  186. return HasInfo(pTest->defaultTestInfo.data[TIK_TAGS], XML_DELIM, "Pogo");
  187. }
  188. // Return TRUE if the specified test should NOT use nogpfnt.obj.
  189. BOOL
  190. SuppressNoGPF(
  191. Test * pTest
  192. )
  193. {
  194. return HasInfo(pTest->defaultTestInfo.data[TIK_RL_DIRECTIVES], XML_DELIM,
  195. "NoGPF");
  196. }
  197. template <size_t bufSize>
  198. void
  199. FillNoGPFFlags(
  200. char (&nogpfFlags)[bufSize],
  201. BOOL fSuppressNoGPF
  202. )
  203. {
  204. nogpfFlags[0] = '\0';
  205. if (FNogpfnt && TargetInfo[TargetMachine].fUseNoGPF) {
  206. if (!fSuppressNoGPF) {
  207. sprintf_s(nogpfFlags,
  208. " %s\\bin\\%s\\nogpfnt.obj /entry:nogpfntStartup",
  209. REGRESS, TargetInfo[TargetMachine].name);
  210. }
  211. }
  212. }
  213. BOOL
  214. CheckForPass(char * filename, char * optReportBuf, char * cmdbuf, BOOL fDumpOutputFile = TRUE)
  215. {
  216. FILE * fp;
  217. char buf[BUFFER_SIZE];
  218. // Check to see if the exe ran at all.
  219. fp = fopen_unsafe(filename, "r");
  220. if (fp == NULL) {
  221. LogOut("ERROR: Test failed to run. Unable to open file '%s', error '%s' (%s):", filename, strerror_unsafe(errno), optReportBuf);
  222. LogOut(" %s", cmdbuf);
  223. return FALSE;
  224. }
  225. // Parse the output file and verify that all lines must be pass/passed, or empty lines
  226. BOOL pass = FALSE;
  227. while(fgets(buf, BUFFER_SIZE, fp) != NULL)
  228. {
  229. if(!_strcmpi(buf, "pass\n") || !_strcmpi(buf, "passed\n"))
  230. {
  231. // Passing strings were found - pass
  232. pass = TRUE;
  233. }
  234. else if(_strcmpi(buf, "\n") != 0)
  235. {
  236. // Something else other than a newline was found - this is a failure.
  237. pass = FALSE;
  238. break;
  239. }
  240. }
  241. fclose(fp);
  242. if (!pass)
  243. {
  244. LogOut("ERROR: Test failed to run correctly: pass not found in output file (%s):", optReportBuf);
  245. LogOut(" %s", cmdbuf);
  246. if (fDumpOutputFile)
  247. {
  248. DumpFileToLog(filename);
  249. }
  250. }
  251. return pass;
  252. }
  253. void CopyRebaseFile(PCSTR testout, PCSTR baseline)
  254. {
  255. if (FRebase)
  256. {
  257. char rebase[_MAX_PATH];
  258. sprintf_s(rebase, "%s.rebase", baseline);
  259. CopyFile(testout, rebase, FALSE);
  260. }
  261. }
  262. // Handle external test scripts. We support three kinds, makefiles (rl.mak),
  263. // command shell (dotest.cmd), and JScript (*.js).
  264. //
  265. // Standardized makefiles have the following targets:
  266. // clean: delete all generated files
  267. // build: build the test (OPT=compile options)
  268. // run: run the test
  269. // copy: copy the generated files to a subdirectory (COPYDIR=subdir)
  270. //
  271. int
  272. DoOneExternalTest(
  273. CDirectory* pDir,
  274. TestVariant *pTestVariant,
  275. char *optFlags,
  276. char *inCCFlags,
  277. char *inLinkFlags,
  278. char *testCmd,
  279. ExternalTestKind kind,
  280. BOOL fSyncVariationWhenFinished,
  281. BOOL fCleanBefore,
  282. BOOL fCleanAfter,
  283. BOOL fSuppressNoGPF,
  284. void *envFlags,
  285. DWORD millisecTimeout
  286. )
  287. {
  288. #define NMAKE "nmake -nologo -R -f "
  289. char full[MAX_PATH];
  290. char cmdbuf[BUFFER_SIZE];
  291. char buf[BUFFER_SIZE];
  292. char ccFlags[BUFFER_SIZE];
  293. char linkFlags[BUFFER_SIZE];
  294. char nogpfFlags[BUFFER_SIZE];
  295. char optReportBuf[BUFFER_SIZE];
  296. char nonZeroReturnBuf[BUFFER_SIZE];
  297. char *reason = NULL;
  298. time_t start_variation;
  299. UINT elapsed_variation;
  300. time_t start_build_variation;
  301. UINT elapsed_build_variation;
  302. LARGE_INTEGER start_run, end_run, frequency;
  303. UINT elapsed_run;
  304. BOOL fFailed = FALSE;
  305. BOOL fDumpOutputFile = FVerbose;
  306. BOOL fFileToDelete = FALSE;
  307. int cmdResult;
  308. static unsigned int testCount = 0;
  309. unsigned int localTestCount = InterlockedIncrement(&testCount);
  310. // Avoid conditionals by copying/creating ccFlags appropriately.
  311. if (inCCFlags)
  312. sprintf_s(ccFlags, " %s", inCCFlags);
  313. else
  314. ccFlags[0] = '\0';
  315. switch (TargetMachine) {
  316. case TM_WVM:
  317. case TM_WVMX86:
  318. case TM_WVM64:
  319. strcat_s(ccFlags, " /BC ");
  320. break;
  321. }
  322. if (inLinkFlags)
  323. strcpy_s(linkFlags, inLinkFlags);
  324. else
  325. linkFlags[0] = '\0';
  326. sprintf_s(optReportBuf, "%s%s%s", optFlags, *linkFlags ? ";" : "", linkFlags);
  327. // Update the status.
  328. sprintf_s(buf, " (%s)", optReportBuf);
  329. ThreadInfo[ThreadId].SetCurrentTest(pDir->GetDirectoryName(),
  330. buf, pDir->IsBaseline());
  331. UpdateTitleStatus();
  332. // Make sure the file that will say pass or fail is not present.
  333. sprintf_s(full, "%s\\testout%d", pDir->GetDirectoryPath(), localTestCount);
  334. DeleteFileIfFound(full);
  335. start_variation = time(NULL);
  336. if (kind == TK_MAKEFILE) {
  337. Message(""); // newline
  338. Message("Processing %s with '%s' flags",
  339. testCmd, optReportBuf);
  340. Message(""); // newline
  341. if (FTest)
  342. {
  343. return 0;
  344. }
  345. if (fCleanBefore) {
  346. // Clean the directory.
  347. sprintf_s(cmdbuf, NMAKE"%s clean", testCmd);
  348. Message(cmdbuf);
  349. ExecuteCommand(pDir->GetDirectoryPath(), cmdbuf);
  350. }
  351. FillNoGPFFlags(nogpfFlags, fSuppressNoGPF);
  352. // Build the test.
  353. start_build_variation = time(NULL);
  354. sprintf_s(cmdbuf, NMAKE"%s build OPT=\"%s %s%s\" LINKFLAGS=\"%s %s %s\"",
  355. testCmd,
  356. optFlags, EXTRA_CC_FLAGS, ccFlags,
  357. LINKFLAGS, linkFlags, nogpfFlags);
  358. if (strlen(cmdbuf) > BUFFER_SIZE - 1)
  359. Fatal("Buffer overrun");
  360. Message(cmdbuf);
  361. fFailed = ExecuteCommand(pDir->GetDirectoryPath(), cmdbuf);
  362. elapsed_build_variation = (int)(time(NULL) - start_build_variation);
  363. if (Timing & TIME_VARIATION) {
  364. Message("RL: Variation elapsed time (build) (%s, %s, %s): %02d:%02d",
  365. pDir->GetDirectoryName(),
  366. "rl.mak",
  367. optReportBuf,
  368. elapsed_build_variation / 60, elapsed_build_variation % 60);
  369. }
  370. if (fFailed) {
  371. reason = "build failure";
  372. goto logFailure;
  373. }
  374. // Run the test.
  375. QueryPerformanceCounter(&start_run);
  376. sprintf_s(cmdbuf, NMAKE"%s run", testCmd);
  377. Message(cmdbuf);
  378. cmdResult = ExecuteCommand(pDir->GetDirectoryPath(), cmdbuf, millisecTimeout);
  379. QueryPerformanceCounter(&end_run);
  380. QueryPerformanceFrequency(&frequency);
  381. elapsed_run = (int) (((end_run.QuadPart - start_run.QuadPart) * 1000UI64) / frequency.QuadPart);
  382. if (Timing & TIME_VARIATION) {
  383. Message("RL: Variation elapsed time (run) (%s, %s, %s): %02d:%02d.%03d",
  384. pDir->GetDirectoryName(),
  385. "rl.mak",
  386. optReportBuf,
  387. elapsed_run / 60000, (elapsed_run % 60000)/1000, elapsed_run % 1000);
  388. }
  389. }
  390. else if (kind == TK_CMDSCRIPT)
  391. {
  392. // Build up the test command string
  393. sprintf_s(cmdbuf, "%s %s %s%s >testout%d", testCmd, optFlags, EXTRA_CC_FLAGS, ccFlags, localTestCount);
  394. Message("Running '%s'", cmdbuf);
  395. if (FTest)
  396. {
  397. return 0;
  398. }
  399. cmdResult = ExecuteCommand(pDir->GetDirectoryPath(), cmdbuf, millisecTimeout, envFlags);
  400. }
  401. else if (kind == TK_JSCRIPT || kind==TK_HTML || kind == TK_COMMAND)
  402. {
  403. char tempExtraCCFlags[MAX_PATH] = {0};
  404. // Only append when EXTRA_CC_FLAGS isn't empty.
  405. if (EXTRA_CC_FLAGS[0])
  406. {
  407. // Append test case unique identifier to the end of EXTRA_CC_FLAGS.
  408. if (FAppendTestNameToExtraCCFlags)
  409. {
  410. sprintf_s(tempExtraCCFlags, "%s.%s", EXTRA_CC_FLAGS, pTestVariant->testInfo.data[TIK_FILES]);
  411. }
  412. else
  413. {
  414. strcpy_s(tempExtraCCFlags, EXTRA_CC_FLAGS);
  415. }
  416. }
  417. char* cmd = JCBinary;
  418. if (kind != TK_JSCRIPT && kind != TK_HTML)
  419. {
  420. cmd = pTestVariant->testInfo.data[TIK_COMMAND];
  421. }
  422. sprintf_s(cmdbuf, "%s %s %s %s %s >testout%d 2>&1", cmd, optFlags, tempExtraCCFlags, ccFlags, testCmd, localTestCount);
  423. Message("Running '%s'", cmdbuf);
  424. if(FTest)
  425. {
  426. DeleteFileIfFound(full);
  427. return 0;
  428. }
  429. cmdResult = ExecuteCommand(pDir->GetDirectoryPath(), cmdbuf, millisecTimeout, envFlags);
  430. if (cmdResult && cmdResult != WAIT_TIMEOUT && !pTestVariant->testInfo.data[TIK_BASELINE]) // failure code, not baseline diffing
  431. {
  432. fFailed = TRUE;
  433. sprintf_s(nonZeroReturnBuf, "non-zero (%08X) return value from test command", cmdResult);
  434. reason = nonZeroReturnBuf;
  435. goto logFailure;
  436. }
  437. }
  438. else
  439. {
  440. ASSERTNR(UNREACHED);
  441. cmdResult = NOERROR; // calm compiler warning about uninitialized variable usage
  442. }
  443. // Check for timeout.
  444. if (cmdResult == WAIT_TIMEOUT) {
  445. ASSERT(millisecTimeout != INFINITE);
  446. sprintf_s(nonZeroReturnBuf, "timed out after %u second%s", millisecTimeout / 1000, millisecTimeout == 1000 ? "" : "s");
  447. reason = nonZeroReturnBuf;
  448. fFailed = TRUE;
  449. goto logFailure;
  450. }
  451. // If we have a baseline test, we need to check the baseline file.
  452. if (pTestVariant->testInfo.data[TIK_BASELINE]) {
  453. char baseline_file[_MAX_PATH];
  454. sprintf_s(baseline_file, "%s\\%s", pDir->GetDirectoryPath(),
  455. pTestVariant->testInfo.data[TIK_BASELINE]);
  456. if (DoCompare(baseline_file, full)) {
  457. reason = "diffs from baseline";
  458. sprintf_s(optReportBuf, "%s", baseline_file);
  459. fFailed = TRUE;
  460. CopyRebaseFile(full, baseline_file);
  461. }
  462. }
  463. else if ((kind == TK_JSCRIPT || kind == TK_HTML || kind == TK_COMMAND) && !pTestVariant->testInfo.hasData[TIK_BASELINE]) {
  464. if (!CheckForPass(full, optReportBuf, cmdbuf, fDumpOutputFile)) {
  465. fFailed = TRUE;
  466. goto SkipLogFailure;
  467. }
  468. }
  469. logFailure:
  470. if (fFailed) {
  471. LogOut("ERROR: Test failed to run correctly: %s (%s):",
  472. reason, optReportBuf);
  473. LogOut(" %s", cmdbuf);
  474. if (fDumpOutputFile) {
  475. DumpFileToLog(full);
  476. }
  477. }
  478. SkipLogFailure:
  479. if (fFileToDelete && !FNoDelete) {
  480. DeleteFileRetryMsg(full);
  481. }
  482. elapsed_variation = (int)(time(NULL) - start_variation);
  483. if (Timing & TIME_VARIATION) {
  484. Message("RL: Variation elapsed time (%s, %s, %s): %02d:%02d",
  485. pDir->GetDirectoryName(),
  486. kind == TK_MAKEFILE ? "rl.mak" : "dotest.cmd",
  487. optReportBuf,
  488. elapsed_variation / 60, elapsed_variation % 60);
  489. }
  490. if (kind == TK_MAKEFILE) {
  491. // If the test failed and we are asked to copy the failures, do so.
  492. if (fFailed && FCopyOnFail) {
  493. sprintf_s(cmdbuf, NMAKE"%s copy COPYDIR=\"fail.%s.%s\"",
  494. testCmd, optFlags, linkFlags);
  495. Message(cmdbuf);
  496. ExecuteCommand(pDir->GetDirectoryPath(), cmdbuf);
  497. }
  498. // Clean up after ourselves.
  499. if (!FNoDelete && (fFailed || fCleanAfter)) {
  500. sprintf_s(cmdbuf, NMAKE"%s clean", testCmd);
  501. Message(cmdbuf);
  502. ExecuteCommand(pDir->GetDirectoryPath(), cmdbuf);
  503. }
  504. }
  505. if (FSyncVariation) {
  506. if (FRLFE && fFailed) {
  507. RLFEAddLog(pDir, RLFES_FAILED, testCmd,
  508. optReportBuf, ThreadOut->GetText());
  509. }
  510. if (fSyncVariationWhenFinished)
  511. FlushOutput();
  512. }
  513. DeleteFileIfFound(full);
  514. return fFailed ? -1 : 0;
  515. }
  516. // null terminated string of null terminated strings
  517. // name=data from testinfo and all of parent process env, arg for CreateProcess()
  518. void * GetEnvFlags
  519. (
  520. TestVariant * pTestVariant
  521. )
  522. {
  523. char temp[BUFFER_SIZE];
  524. size_t len = 0, totalEnvLen = 0;
  525. char * envFlags = NULL;
  526. Xml::Node *env = (Xml::Node *)pTestVariant->testInfo.data[TIK_ENV];
  527. if (env != NULL) {
  528. // use a fixed global array for memory
  529. memset(EnvFlags, '\0', MAX_ENV_LEN);
  530. *temp = '\0';
  531. for ( Xml::Node * child = env->ChildList; child != NULL; child = child->Next) {
  532. sprintf_s(temp, "%s=%s", child->Name, child->Data);
  533. if (envFlags == NULL) {
  534. sprintf_s(EnvFlags, "%s", temp);
  535. envFlags = EnvFlags;
  536. } else {
  537. strcat_s(envFlags, REMAININGARRAYLEN(EnvFlags, envFlags), temp);
  538. }
  539. len = strlen(envFlags);
  540. envFlags += len+1;
  541. }
  542. LPTSTR lpszParentEnv = GetEnvironmentStrings();
  543. totalEnvLen = len;
  544. ASSERT(totalEnvLen < BUFFER_SIZE);
  545. len = 0;
  546. while(!((lpszParentEnv[len] == '\0') && (lpszParentEnv[len+1] == '\0'))) {
  547. len++;
  548. }
  549. ASSERT(totalEnvLen+len+2 < MAX_ENV_LEN);
  550. memcpy(envFlags, lpszParentEnv, len+2);
  551. FreeEnvironmentStrings(lpszParentEnv);
  552. envFlags = EnvFlags;
  553. }
  554. return (void*)envFlags;
  555. }
  556. int
  557. DoExternalTest(
  558. CDirectory* pDir,
  559. TestVariant * pTestVariant,
  560. char *testCmd,
  561. ExternalTestKind kind,
  562. BOOL fSuppressNoGPF,
  563. DWORD millisecTimeout
  564. )
  565. {
  566. char *ccFlags = pTestVariant->testInfo.data[TIK_COMPILE_FLAGS];
  567. void *envFlags = GetEnvFlags(pTestVariant);
  568. return DoOneExternalTest(pDir, pTestVariant, pTestVariant->optFlags, ccFlags, NULL,
  569. testCmd, kind, TRUE, TRUE, TRUE, fSuppressNoGPF, envFlags, millisecTimeout);
  570. }
  571. int
  572. DoPogoExternalTest(
  573. CDirectory* pDir,
  574. TestVariant * pTestVariant,
  575. char *testCmd,
  576. ExternalTestKind kind,
  577. BOOL fSuppressNoGPF,
  578. DWORD millisecTimeout
  579. )
  580. {
  581. static char *pgc = "*.pgc";
  582. static char *pgd = POGO_PGD;
  583. char pgdFull[MAX_PATH];
  584. char ccFlags[BUFFER_SIZE];
  585. char linkFlags[BUFFER_SIZE];
  586. char cmdbuf[BUFFER_SIZE];
  587. BOOL fFailed;
  588. void *envFlags = GetEnvFlags(pTestVariant);
  589. sprintf_s(pgdFull, "%s\\%s", pDir->GetDirectoryPath(), pgd);
  590. char * inCCFlags = pTestVariant->testInfo.data[TIK_COMPILE_FLAGS];
  591. char * optFlags = pTestVariant->optFlags;
  592. DeleteFileIfFound(pgdFull);
  593. DeleteMultipleFiles(pDir, pgc);
  594. fFailed = FALSE;
  595. // Pogo requires LTCG
  596. ASSERT(strstr(optFlags, "GL") != NULL);
  597. if (!kind == TK_MAKEFILE) {
  598. Warning("'%s\\%s' is not a makefile test; Pogo almost certainly won't work", pDir->GetDirectoryPath(), testCmd);
  599. }
  600. sprintf_s(ccFlags, "%s %s", PogoForceErrors, optFlags);
  601. sprintf_s(linkFlags, "-ltcg:pgi -pgd:%s", pgd);
  602. if (DoOneExternalTest(pDir, pTestVariant, ccFlags, inCCFlags, linkFlags,
  603. testCmd, kind, FALSE, TRUE, FALSE, fSuppressNoGPF, envFlags, millisecTimeout)) {
  604. fFailed = TRUE;
  605. goto logFailure;
  606. }
  607. sprintf_s(ccFlags, "%s %s", PogoForceErrors, optFlags);
  608. sprintf_s(linkFlags, "-ltcg:pgo -pgd:%s", pgd);
  609. // Manually erase EXE and DLL files to get makefile to relink.
  610. // Also erase ASM files because some makefiles try to rebuild from
  611. // them.
  612. DeleteMultipleFiles(pDir, "*.exe");
  613. DeleteMultipleFiles(pDir, "*.dll");
  614. DeleteMultipleFiles(pDir, "*.asm");
  615. if (DoOneExternalTest(pDir, pTestVariant, ccFlags, inCCFlags, linkFlags,
  616. testCmd, kind, FALSE, FALSE, TRUE, fSuppressNoGPF, envFlags, millisecTimeout)) {
  617. fFailed = TRUE;
  618. }
  619. logFailure:
  620. if (FSyncVariation) {
  621. if (FRLFE && fFailed) {
  622. sprintf_s(cmdbuf, "%s%s%s", ccFlags,
  623. *linkFlags ? ";" : "", linkFlags);
  624. RLFEAddLog(pDir, RLFES_FAILED, testCmd,
  625. cmdbuf, ThreadOut->GetText());
  626. }
  627. FlushOutput();
  628. }
  629. if (FRLFE)
  630. RLFETestStatus(pDir);
  631. if (!FNoDelete) {
  632. DeleteFileRetryMsg(pgdFull);
  633. DeleteMultipleFiles(pDir, pgc);
  634. }
  635. return fFailed ? -1 : 0;
  636. }
  637. BOOL
  638. DoOneSimpleTest(
  639. CDirectory *pDir,
  640. Test * pTest,
  641. TestVariant * pTestVariant,
  642. char *optFlags,
  643. char *inCCFlags,
  644. char *inLinkFlags,
  645. BOOL fSyncVariationWhenFinished,
  646. BOOL fCleanAfter,
  647. BOOL fLinkOnly, // relink only
  648. BOOL fSuppressNoGPF,
  649. DWORD millisecTimeout
  650. )
  651. {
  652. int rc;
  653. char *p = NULL;
  654. char cmdbuf[BUFFER_SIZE*2];
  655. char ccFlags[BUFFER_SIZE];
  656. char linkFlags[BUFFER_SIZE];
  657. char nogpfFlags[BUFFER_SIZE];
  658. char optReportBuf[BUFFER_SIZE];
  659. char full[MAX_PATH];
  660. char exebuf[BUFFER_SIZE];
  661. char fullexebuf[BUFFER_SIZE];
  662. char buf[BUFFER_SIZE];
  663. char failDir[BUFFER_SIZE];
  664. char copyName[BUFFER_SIZE];
  665. char tmp_file1[MAX_PATH];
  666. char tmp_file2[MAX_PATH];
  667. time_t start_variation;
  668. UINT elapsed_variation;
  669. BOOL fFailed;
  670. void *envFlags = GetEnvFlags(pTestVariant);
  671. // Avoid conditionals by copying/creating ccFlags appropriately.
  672. if (inCCFlags)
  673. sprintf_s(ccFlags, " %s", inCCFlags);
  674. else
  675. ccFlags[0] = '\0';
  676. switch (TargetMachine) {
  677. case TM_WVM:
  678. case TM_WVMX86:
  679. case TM_WVM64:
  680. strcat_s(ccFlags, " /BC ");
  681. break;
  682. }
  683. if (inLinkFlags)
  684. strcpy_s(linkFlags, inLinkFlags);
  685. else
  686. linkFlags[0] = '\0';
  687. sprintf_s(optReportBuf, "%s%s%s", optFlags, *linkFlags ? ";" : "", linkFlags);
  688. // Figure out the exe name and path
  689. strcpy_s(exebuf, pTest->name);
  690. p = strrchr(exebuf, '.');
  691. if (p != NULL)
  692. {
  693. strcpy_s(p + 1, REMAININGARRAYLEN(exebuf, p + 1), "exe");
  694. }
  695. else
  696. {
  697. strcat_s(exebuf, ".exe");
  698. }
  699. sprintf_s(fullexebuf, "%s\\%s", pDir->GetDirectoryPath(), exebuf);
  700. start_variation = time(NULL);
  701. // Build up the compile command string.
  702. sprintf_s(cmdbuf, "%s %s%s %s", REGR_CL,
  703. optFlags, ccFlags, EXTRA_CC_FLAGS);
  704. for (StringList * pFile = pTest->files; pFile != NULL; pFile = pFile->next)
  705. {
  706. strcat_s(cmdbuf, " ");
  707. strcat_s(cmdbuf, pFile->string);
  708. // If we're only relinking, hammer the extension to .obj
  709. if (fLinkOnly)
  710. {
  711. p = strrchr(cmdbuf, '.');
  712. sprintf_s(p, REMAININGARRAYLEN(cmdbuf, p), ".obj");
  713. }
  714. }
  715. // Build the link option string.
  716. if (LINKFLAGS && LINKFLAGS[0] != '\0') {
  717. strcat_s(linkFlags, " ");
  718. strcat_s(linkFlags, LINKFLAGS);
  719. }
  720. FillNoGPFFlags(nogpfFlags, fSuppressNoGPF);
  721. strcat_s(linkFlags, nogpfFlags);
  722. switch (TargetMachine) {
  723. case TM_X86:
  724. case TM_IA64:
  725. case TM_AMD64:
  726. case TM_AMD64SYS:
  727. case TM_AM33:
  728. case TM_ARM:
  729. case TM_ARM64:
  730. case TM_THUMB:
  731. case TM_M32R:
  732. case TM_MIPS:
  733. case TM_SH3:
  734. case TM_SH4:
  735. case TM_SH5M:
  736. case TM_SH5C:
  737. case TM_WVMX86:
  738. if (*linkFlags) {
  739. strcat_s(cmdbuf, " /link ");
  740. strcat_s(cmdbuf, linkFlags);
  741. }
  742. break;
  743. case TM_WVM:
  744. strcat_s(cmdbuf, " /c ");
  745. break;
  746. case TM_PPCWCE:
  747. if (*linkFlags) {
  748. strcat_s(cmdbuf, " ");
  749. strcat_s(cmdbuf, linkFlags);
  750. }
  751. break;
  752. }
  753. sprintf_s(buf, "%s (%s)", pTest->name, optReportBuf);
  754. ThreadInfo[ThreadId].SetCurrentTest(pDir->GetDirectoryName(), buf, pDir->IsBaseline());
  755. UpdateTitleStatus();
  756. // Remove exe if it's already there. We have to keep trying to delete it
  757. // until it's gone, or else the link will fail (if it is somehow still in
  758. // use).
  759. DeleteFileRetryMsg(fullexebuf);
  760. if (FTest)
  761. {
  762. Message("%s", cmdbuf);
  763. if (pTestVariant->testInfo.data[TIK_BASELINE]) {
  764. Message(" (baseline %s)", pTestVariant->testInfo.data[TIK_BASELINE]);
  765. }
  766. return 0;
  767. }
  768. // Do the compile.
  769. Message("Compiling:");
  770. Message(" %s", cmdbuf);
  771. rc = ExecuteCommand(pDir->GetDirectoryPath(), cmdbuf);
  772. // Some machines require separate linking of the
  773. // compiler and/or assembler output.
  774. if (rc == 0)
  775. {
  776. switch (TargetMachine)
  777. {
  778. case TM_WVM:
  779. // Build up the linker command string.
  780. strcpy_s(cmdbuf, LINKER);
  781. for (StringList * pFile = pTest->files;
  782. pFile != NULL;
  783. pFile = pFile->next)
  784. {
  785. strcat_s(cmdbuf, " ");
  786. strcat_s(cmdbuf, pFile->string);
  787. p = strrchr(cmdbuf, '.');
  788. strcpy_s(p + 1, REMAININGARRAYLEN(cmdbuf, p + 1), "obj");
  789. }
  790. if (linkFlags) {
  791. strcat_s(cmdbuf, " ");
  792. strcat_s(cmdbuf, linkFlags);
  793. }
  794. // Do the link.
  795. Message("Linking:");
  796. Message(" %s", cmdbuf);
  797. ExecuteCommand(pDir->GetDirectoryPath(), cmdbuf);
  798. break;
  799. default:
  800. break;
  801. }
  802. }
  803. // See if the compile succeeded by checking for the existence
  804. // of the executable.
  805. if ((rc != 0) || GetFileAttributes(fullexebuf) == INVALID_FILE_ATTRIBUTES) {
  806. LogOut("ERROR: Test failed to compile or link (%s):", optReportBuf);
  807. LogOut(" %s", cmdbuf);
  808. fFailed = TRUE;
  809. goto logFailure;
  810. }
  811. // Run the resulting exe.
  812. if (TargetVM) {
  813. strcpy_s(buf, TargetVM);
  814. strcat_s(buf, " ");
  815. strcat_s(buf, exebuf);
  816. // Copy the VM command to cmdbuf, so we get a useful error message
  817. // in the log file if test fails.
  818. strcpy_s(cmdbuf, buf);
  819. }
  820. else {
  821. strcpy_s(buf, exebuf);
  822. }
  823. // We need some temporary files.
  824. // Note: these are full pathnames, not relative pathnames. Also, note that
  825. // mytmpnam creates the file to be used. To avoid losing that file, and
  826. // risking another program using it, don't delete the file before use.
  827. // We currently delete the file before running the test, so we can see if
  828. // the test ever creates it. We should probably create the temp files in
  829. // the same directory as the test, since we guarantee that no other copies
  830. // of RL are running in the same directory.
  831. if (mytmpnam(pDir->GetDirectoryPath(), TMP_PREFIX, tmp_file1) == NULL ||
  832. mytmpnam(pDir->GetDirectoryPath(), TMP_PREFIX, tmp_file2) == NULL) {
  833. Fatal("Unable to create temporary files");
  834. }
  835. ThreadInfo[ThreadId].AddToTmpFileList(tmp_file1);
  836. ThreadInfo[ThreadId].AddToTmpFileList(tmp_file2);
  837. if (FVerbose)
  838. Message("INFO: tmp file 1 = %s, tmp file 2 = %s", tmp_file1, tmp_file2);
  839. Message("Running the test (%s)", buf);
  840. strcat_s(buf, " > ");
  841. strcat_s(buf, tmp_file1);
  842. // Make sure the output file isn't there.
  843. DeleteFileIfFound(tmp_file1);
  844. int retval = ExecuteCommand(pDir->GetDirectoryPath(), buf, millisecTimeout, envFlags);
  845. fFailed = FALSE;
  846. // Check for timeout.
  847. if (retval == WAIT_TIMEOUT) {
  848. ASSERT(millisecTimeout != INFINITE);
  849. LogOut("ERROR: Test timed out after %ul seconds", millisecTimeout / 1000);
  850. fFailed = TRUE;
  851. goto logFailure;
  852. }
  853. // Check the output.
  854. if (pTestVariant->testInfo.data[TIK_BASELINE]) {
  855. int spiff_ret;
  856. // Check to see if the exe ran at all.
  857. if (GetFileAttributes(tmp_file1) == INVALID_FILE_ATTRIBUTES) {
  858. LogOut("ERROR: Test failed to run. Couldn't find file '%s' (%s):", tmp_file1, optReportBuf);
  859. LogOut(" %s", cmdbuf);
  860. fFailed = TRUE;
  861. }
  862. else {
  863. sprintf_s(full, "%s\\%s", pDir->GetDirectoryPath(),
  864. pTestVariant->testInfo.data[TIK_BASELINE]);
  865. if (DoCompare(tmp_file1, full)) {
  866. // Output differs, run spiff to see if it's just minor
  867. // floating point anomalies.
  868. DeleteFileIfFound(tmp_file2);
  869. sprintf_s(buf, "spiff -m -n -s \"command spiff\" %s %s > %s",
  870. tmp_file1, full, tmp_file2);
  871. spiff_ret = ExecuteCommand(pDir->GetDirectoryPath(), buf);
  872. if (GetFileAttributes(tmp_file2) == INVALID_FILE_ATTRIBUTES) {
  873. LogError("ERROR: spiff failed to run");
  874. fFailed = TRUE;
  875. }
  876. else if (spiff_ret) {
  877. LogOut("ERROR: Test failed to run correctly. spiff returned %d (%s):", spiff_ret, optReportBuf);
  878. LogOut(" %s", cmdbuf);
  879. fFailed = TRUE;
  880. }
  881. }
  882. }
  883. }
  884. else {
  885. if (!CheckForPass(tmp_file1, optReportBuf, cmdbuf)) {
  886. fFailed = TRUE;
  887. }
  888. }
  889. logFailure:
  890. if (fFailed) {
  891. if (FCopyOnFail) {
  892. if (FVerbose)
  893. Message("INFO: Copying '%s' failure", optReportBuf);
  894. sprintf_s(failDir, "%s\\fail.%s",
  895. pDir->GetDirectoryPath(), optReportBuf);
  896. if ((GetFileAttributes(failDir) == INVALID_FILE_ATTRIBUTES) &&
  897. !CreateDirectory(failDir, NULL)) {
  898. Message("ERROR: Couldn't create directory '%s'", failDir);
  899. }
  900. else
  901. {
  902. for (StringList * pFile = pTest->files;
  903. pFile != NULL;
  904. pFile = pFile->next)
  905. {
  906. sprintf_s(copyName, "%s\\%s", failDir, pFile->string);
  907. p = strrchr(copyName, '.') + 1;
  908. strcpy_s(p, REMAININGARRAYLEN(copyName, p + 1), "obj");
  909. sprintf_s(buf, "%s\\%s", pDir->GetDirectoryPath(),
  910. pFile->string);
  911. p = strrchr(buf, '.') + 1;
  912. strcpy_s(p, REMAININGARRAYLEN(buf, p + 1), "obj");
  913. if (!CopyFile(buf, copyName, FALSE)) {
  914. Message("ERROR: Couldn't copy '%s' to '%s'",
  915. buf, copyName);
  916. }
  917. }
  918. sprintf_s(copyName, "%s\\%s", failDir, exebuf);
  919. if (!CopyFile(fullexebuf, copyName, FALSE)) {
  920. Message("ERROR: Couldn't copy '%s' to '%s'",
  921. fullexebuf, copyName);
  922. }
  923. }
  924. }
  925. }
  926. if (FRLFE) {
  927. RLFETestStatus(pDir);
  928. }
  929. if (FVerbose)
  930. Message("INFO: cleaning up test run");
  931. // Remove the exe.
  932. if (!FNoDelete) {
  933. DeleteFileRetryMsg(fullexebuf);
  934. }
  935. // Don't trash fullexebuf!
  936. strcpy_s(buf, fullexebuf);
  937. p = strrchr(buf, '.') + 1;
  938. // Remove the pdb(s) (if it exists).
  939. strcpy_s(p, REMAININGARRAYLEN(buf, p), "pdb");
  940. DeleteFileIfFound(buf);
  941. DeleteMultipleFiles(pDir, "*.pdb");
  942. // Remove the ilk (if it exists).
  943. strcpy_s(p, REMAININGARRAYLEN(buf, p), "ilk");
  944. DeleteFileIfFound(buf);
  945. // Remove the objs.
  946. if (!FNoDelete)
  947. {
  948. for (StringList * pFile = pTest->files;
  949. pFile != NULL;
  950. pFile = pFile->next)
  951. {
  952. sprintf_s(buf, "%s\\%s", pDir->GetDirectoryPath(), pFile->string);
  953. p = strrchr(buf, '.') + 1;
  954. if (fCleanAfter)
  955. {
  956. strcpy_s(p, REMAININGARRAYLEN(buf, p), "obj");
  957. DeleteFileRetryMsg(buf);
  958. }
  959. if (REGR_ASM) {
  960. strcpy_s(p, REMAININGARRAYLEN(buf, p), "asm");
  961. DeleteFileRetryMsg(buf);
  962. }
  963. }
  964. }
  965. elapsed_variation = (int)(time(NULL) - start_variation);
  966. if (Timing & TIME_VARIATION) {
  967. Message("RL: Variation elapsed time (%s, %s, %s): %02d:%02d",
  968. pDir->GetDirectoryName(), pTest->name, optReportBuf,
  969. elapsed_variation / 60, elapsed_variation % 60);
  970. }
  971. if (FSyncVariation) {
  972. if (FRLFE && fFailed)
  973. RLFEAddLog(pDir, RLFES_FAILED, pTest->name, optReportBuf, ThreadOut->GetText());
  974. if (fSyncVariationWhenFinished)
  975. FlushOutput();
  976. }
  977. ThreadInfo[ThreadId].DeleteTmpFileList();
  978. return fFailed ? -1 : 0;
  979. }
  980. int
  981. DoSimpleTest(
  982. CDirectory *pDir,
  983. Test * pTest,
  984. TestVariant * pTestVariant,
  985. BOOL fSuppressNoGPF,
  986. DWORD millisecTimeout
  987. )
  988. {
  989. return DoOneSimpleTest(pDir, pTest, pTestVariant, pTestVariant->optFlags,
  990. pTestVariant->testInfo.data[TIK_COMPILE_FLAGS],
  991. pTestVariant->testInfo.data[TIK_LINK_FLAGS],
  992. TRUE, TRUE, FALSE, fSuppressNoGPF, millisecTimeout);
  993. }
  994. int
  995. DoPogoSimpleTest(
  996. CDirectory *pDir,
  997. Test * pTest,
  998. TestVariant * pTestVariant,
  999. BOOL fSuppressNoGPF,
  1000. DWORD millisecTimeout
  1001. )
  1002. {
  1003. static char *pgc = "*.pgc";
  1004. static char *pgd = POGO_PGD;
  1005. char pgdFull[MAX_PATH];
  1006. char ccFlags[BUFFER_SIZE];
  1007. char linkFlags[BUFFER_SIZE];
  1008. BOOL fFailed;
  1009. sprintf_s(pgdFull, "%s\\%s", pDir->GetDirectoryPath(), pgd);
  1010. char * inCCFlags = pTestVariant->testInfo.data[TIK_COMPILE_FLAGS];
  1011. char * optFlags = pTestVariant->optFlags;
  1012. DeleteFileIfFound(pgdFull);
  1013. DeleteMultipleFiles(pDir, pgc);
  1014. fFailed = FALSE;
  1015. // Pogo requires LTCG
  1016. ASSERT(strstr(optFlags, "GL") != NULL);
  1017. sprintf_s(ccFlags, "%s %s", PogoForceErrors, optFlags);
  1018. sprintf_s(linkFlags, "-ltcg:pgi -pgd:%s", pgd);
  1019. if (DoOneSimpleTest(pDir, pTest, pTestVariant, ccFlags, inCCFlags,
  1020. linkFlags, FALSE, FALSE, FALSE, fSuppressNoGPF, millisecTimeout)) {
  1021. fFailed = TRUE;
  1022. goto logFailure;
  1023. }
  1024. if (FTest)
  1025. {
  1026. return 0;
  1027. }
  1028. sprintf_s(ccFlags, "%s %s", PogoForceErrors, optFlags);
  1029. sprintf_s(linkFlags, "-ltcg:pgo -pgd:%s", pgd);
  1030. if (DoOneSimpleTest(pDir, pTest, pTestVariant, ccFlags, inCCFlags,
  1031. linkFlags, FALSE, TRUE, TRUE, fSuppressNoGPF, millisecTimeout)) {
  1032. fFailed = TRUE;
  1033. }
  1034. logFailure:
  1035. if (FSyncVariation) {
  1036. #if 0
  1037. if (FRLFE && fFailed) {
  1038. sprintf_s(cmdbuf, "%s%s%s", ccFlags,
  1039. *linkFlags ? ";" : "", linkFlags);
  1040. RLFEAddLog(pDir, RLFES_FAILED, testCmd,
  1041. cmdbuf, ThreadOut->GetText());
  1042. }
  1043. #endif
  1044. FlushOutput();
  1045. }
  1046. if (!FNoDelete) {
  1047. DeleteFileRetryMsg(pgdFull);
  1048. DeleteMultipleFiles(pDir, pgc);
  1049. }
  1050. return fFailed ? -1 : 0;
  1051. }
  1052. int
  1053. ExecTest
  1054. (
  1055. CDirectory* pDir,
  1056. Test * pTest,
  1057. TestVariant * pTestVariant
  1058. )
  1059. {
  1060. char *p = NULL;
  1061. char full[MAX_PATH];
  1062. DWORD millisecTimeout = DEFAULT_TEST_TIMEOUT;
  1063. char *strTimeout = pTestVariant->testInfo.data[TIK_TIMEOUT];
  1064. if (strTimeout) {
  1065. char *end;
  1066. _set_errno(0);
  1067. unsigned long secTimeout = strtoul(strTimeout, &end, 10);
  1068. millisecTimeout = 1000 * secTimeout;
  1069. // Validation has already occurred so this string should
  1070. // parse fine and the value shouldn't overflow the DWORD.
  1071. ASSERT(errno == 0 && *end == 0);
  1072. ASSERT(millisecTimeout > secTimeout);
  1073. }
  1074. // Check to see if all of the files exist.
  1075. for (StringList * pFile = pTest->files; pFile != NULL; pFile = pFile->next)
  1076. {
  1077. // Get a pointer to the filename sans path, if present.
  1078. p = GetFilenamePtr(pFile->string);
  1079. // If we have no pathname, use the current directory.
  1080. if (p == pFile->string) {
  1081. sprintf_s(full, "%s\\", pDir->GetDirectoryPath());
  1082. }
  1083. else {
  1084. // Look for %REGRESS% specifier.
  1085. if (!_strnicmp(pFile->string, "%REGRESS%",
  1086. strlen("%REGRESS%"))) {
  1087. // Temporarily truncate the filename.
  1088. ASSERT(p[-1] == '\\');
  1089. p[-1] = '\0';
  1090. sprintf_s(full, "%s%s\\",
  1091. REGRESS, pFile->string + strlen("%REGRESS%"));
  1092. p[-1] = '\\';
  1093. }
  1094. else {
  1095. *p = '\0';
  1096. }
  1097. }
  1098. strcat_s(full, p);
  1099. if (GetFileAttributes(full) == INVALID_FILE_ATTRIBUTES) {
  1100. LogError("ERROR: '%s' does not exist", pFile->string);
  1101. return -1;
  1102. }
  1103. }
  1104. const char* ext = GetFilenameExt(p);
  1105. // Special case dotest.cmd
  1106. if (!_stricmp(p, "dotest.cmd")) {
  1107. // We don't handle these yet.
  1108. ASSERTNR(pTestVariant->testInfo.data[TIK_LINK_FLAGS] == NULL);
  1109. if (IsPogoTest(pTest))
  1110. return DoPogoExternalTest(pDir, pTestVariant, full, TK_CMDSCRIPT, TRUE, millisecTimeout);
  1111. else
  1112. return DoExternalTest(pDir, pTestVariant, full, TK_CMDSCRIPT, TRUE, millisecTimeout);
  1113. }
  1114. // Special case for standardized RL makefiles.
  1115. else if (!_stricmp(p, "rl.mak")) {
  1116. // We don't handle these yet.
  1117. ASSERTNR(pTestVariant->testInfo.data[TIK_LINK_FLAGS] == NULL);
  1118. if (IsPogoTest(pTest))
  1119. return DoPogoExternalTest(pDir, pTestVariant, full, TK_MAKEFILE, FALSE, millisecTimeout);
  1120. else
  1121. return DoExternalTest(pDir, pTestVariant, full, TK_MAKEFILE, SuppressNoGPF(pTest), millisecTimeout);
  1122. }
  1123. // Special case for files ending with ".js", ".html", ".htm" (<command> dealt with separately)
  1124. else if (pTestVariant->testInfo.data[TIK_COMMAND] == NULL
  1125. && !_stricmp(ext, ".js"))
  1126. {
  1127. return DoExternalTest(pDir, pTestVariant, full, TK_JSCRIPT, FALSE, millisecTimeout);
  1128. }
  1129. else if (pTestVariant->testInfo.data[TIK_COMMAND] == NULL
  1130. && (!_stricmp(ext, ".html") || !_stricmp(ext, ".htm")))
  1131. {
  1132. return DoExternalTest(pDir, pTestVariant, full, TK_HTML, FALSE, millisecTimeout);
  1133. }
  1134. // Special case for tests with a <command> argument
  1135. else if (pTestVariant->testInfo.data[TIK_COMMAND] != NULL)
  1136. {
  1137. return DoExternalTest(pDir, pTestVariant, full, TK_COMMAND, FALSE, millisecTimeout);
  1138. }
  1139. // Non-scripted test.
  1140. else {
  1141. if (IsPogoTest(pTest)) {
  1142. // We don't handle these yet.
  1143. ASSERTNR(pTestVariant->testInfo.data[TIK_LINK_FLAGS] == NULL);
  1144. return DoPogoSimpleTest(pDir, pTest, pTestVariant, FALSE, millisecTimeout);
  1145. }
  1146. else
  1147. {
  1148. return DoSimpleTest(pDir, pTest, pTestVariant, SuppressNoGPF(pTest), millisecTimeout);
  1149. }
  1150. }
  1151. }