rlrun.cpp 42 KB

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