rlrun.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407
  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. // 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. const char *optFlags,
  276. const char *inCCFlags,
  277. const char *inLinkFlags,
  278. const 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. const 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. {
  313. if (pDir->HasTestInfoData(TIK_SOURCE_PATH))
  314. {
  315. sprintf_s(ccFlags, " %s -baselinePath:%s", inCCFlags, pDir->GetDirectoryPath());
  316. }
  317. else
  318. {
  319. sprintf_s(ccFlags, " %s", inCCFlags);
  320. }
  321. }
  322. else
  323. {
  324. ccFlags[0] = '\0';
  325. }
  326. switch (TargetMachine) {
  327. case TM_WVM:
  328. case TM_WVMX86:
  329. case TM_WVM64:
  330. strcat_s(ccFlags, " /BC ");
  331. break;
  332. }
  333. if (inLinkFlags)
  334. strcpy_s(linkFlags, inLinkFlags);
  335. else
  336. linkFlags[0] = '\0';
  337. sprintf_s(optReportBuf, "%s%s%s", optFlags, *linkFlags ? ";" : "", linkFlags);
  338. // Update the status.
  339. sprintf_s(buf, " (%s)", optReportBuf);
  340. ThreadInfo[ThreadId].SetCurrentTest(pDir->GetDirectoryName(),
  341. buf, pDir->IsBaseline());
  342. UpdateTitleStatus();
  343. // Make sure the file that will say pass or fail is not present.
  344. sprintf_s(full, "%s\\testout%d", pDir->GetDirectoryPath(), localTestCount);
  345. DeleteFileIfFound(full);
  346. start_variation = time(NULL);
  347. if (kind == TK_MAKEFILE) {
  348. Message(""); // newline
  349. Message("Processing %s with '%s' flags",
  350. testCmd, optReportBuf);
  351. Message(""); // newline
  352. if (FTest)
  353. {
  354. return 0;
  355. }
  356. if (fCleanBefore) {
  357. // Clean the directory.
  358. sprintf_s(cmdbuf, NMAKE"%s clean", testCmd);
  359. Message(cmdbuf);
  360. ExecuteCommand(pDir->GetDirectoryPath(), cmdbuf);
  361. }
  362. FillNoGPFFlags(nogpfFlags, fSuppressNoGPF);
  363. // Build the test.
  364. start_build_variation = time(NULL);
  365. sprintf_s(cmdbuf, NMAKE"%s build OPT=\"%s %s%s\" LINKFLAGS=\"%s %s %s\"",
  366. testCmd,
  367. optFlags, EXTRA_CC_FLAGS, ccFlags,
  368. LINKFLAGS, linkFlags, nogpfFlags);
  369. if (strlen(cmdbuf) > BUFFER_SIZE - 1)
  370. Fatal("Buffer overrun");
  371. Message(cmdbuf);
  372. fFailed = ExecuteCommand(pDir->GetDirectoryPath(), cmdbuf);
  373. elapsed_build_variation = (int)(time(NULL) - start_build_variation);
  374. if (Timing & TIME_VARIATION) {
  375. Message("RL: Variation elapsed time (build) (%s, %s, %s): %02d:%02d",
  376. pDir->GetDirectoryName(),
  377. "rl.mak",
  378. optReportBuf,
  379. elapsed_build_variation / 60, elapsed_build_variation % 60);
  380. }
  381. if (fFailed) {
  382. reason = "build failure";
  383. goto logFailure;
  384. }
  385. // Run the test.
  386. QueryPerformanceCounter(&start_run);
  387. sprintf_s(cmdbuf, NMAKE"%s run", testCmd);
  388. Message(cmdbuf);
  389. cmdResult = ExecuteCommand(pDir->GetDirectoryPath(), cmdbuf, millisecTimeout);
  390. QueryPerformanceCounter(&end_run);
  391. QueryPerformanceFrequency(&frequency);
  392. elapsed_run = (int) (((end_run.QuadPart - start_run.QuadPart) * 1000UI64) / frequency.QuadPart);
  393. if (Timing & TIME_VARIATION) {
  394. Message("RL: Variation elapsed time (run) (%s, %s, %s): %02d:%02d.%03d",
  395. pDir->GetDirectoryName(),
  396. "rl.mak",
  397. optReportBuf,
  398. elapsed_run / 60000, (elapsed_run % 60000)/1000, elapsed_run % 1000);
  399. }
  400. }
  401. else if (kind == TK_CMDSCRIPT)
  402. {
  403. // Build up the test command string
  404. sprintf_s(cmdbuf, "%s %s %s%s >testout%d", testCmd, optFlags, EXTRA_CC_FLAGS, ccFlags, localTestCount);
  405. Message("Running '%s'", cmdbuf);
  406. if (FTest)
  407. {
  408. return 0;
  409. }
  410. cmdResult = ExecuteCommand(pDir->GetDirectoryPath(), cmdbuf, millisecTimeout, envFlags);
  411. }
  412. else if (kind == TK_JSCRIPT || kind==TK_HTML || kind == TK_COMMAND)
  413. {
  414. char tempExtraCCFlags[MAX_PATH*2] = {0};
  415. // Only append when EXTRA_CC_FLAGS isn't empty.
  416. if (EXTRA_CC_FLAGS[0])
  417. {
  418. // Append test case unique identifier to the end of EXTRA_CC_FLAGS.
  419. if (FAppendTestNameToExtraCCFlags)
  420. {
  421. sprintf_s(tempExtraCCFlags, "%s.%s", EXTRA_CC_FLAGS, pTestVariant->testInfo.data[TIK_FILES]);
  422. }
  423. else
  424. {
  425. strcpy_s(tempExtraCCFlags, EXTRA_CC_FLAGS);
  426. }
  427. }
  428. const char* cmd = JCBinary;
  429. if (kind != TK_JSCRIPT && kind != TK_HTML)
  430. {
  431. cmd = pTestVariant->testInfo.data[TIK_COMMAND];
  432. }
  433. sprintf_s(cmdbuf, "%s %s %s %s %s >%s 2>&1", cmd, optFlags, tempExtraCCFlags, ccFlags, testCmd, full);
  434. Message("Running '%s'", cmdbuf);
  435. if(FTest)
  436. {
  437. DeleteFileIfFound(full);
  438. return 0;
  439. }
  440. cmdResult = ExecuteCommand(pDir->GetFullPathFromSourceOrDirectory(), cmdbuf, millisecTimeout, envFlags);
  441. if (cmdResult && cmdResult != WAIT_TIMEOUT && !pTestVariant->testInfo.data[TIK_BASELINE]) // failure code, not baseline diffing
  442. {
  443. fFailed = TRUE;
  444. sprintf_s(nonZeroReturnBuf, "non-zero (%08X) return value from test command", cmdResult);
  445. reason = nonZeroReturnBuf;
  446. goto logFailure;
  447. }
  448. }
  449. else
  450. {
  451. ASSERTNR(UNREACHED);
  452. cmdResult = NOERROR; // calm compiler warning about uninitialized variable usage
  453. }
  454. // Check for timeout.
  455. if (cmdResult == WAIT_TIMEOUT) {
  456. ASSERT(millisecTimeout != INFINITE);
  457. sprintf_s(nonZeroReturnBuf, "timed out after %u second%s", millisecTimeout / 1000, millisecTimeout == 1000 ? "" : "s");
  458. reason = nonZeroReturnBuf;
  459. fFailed = TRUE;
  460. goto logFailure;
  461. }
  462. // If we have a baseline test, we need to check the baseline file.
  463. if (pTestVariant->testInfo.data[TIK_BASELINE]) {
  464. char baseline_file[_MAX_PATH];
  465. sprintf_s(baseline_file, "%s\\%s", pDir->GetFullPathFromSourceOrDirectory(),
  466. pTestVariant->testInfo.data[TIK_BASELINE]);
  467. if (DoCompare(baseline_file, full)) {
  468. reason = "diffs from baseline";
  469. sprintf_s(optReportBuf, "%s", baseline_file);
  470. fFailed = TRUE;
  471. CopyRebaseFile(full, baseline_file);
  472. }
  473. }
  474. else if ((kind == TK_JSCRIPT || kind == TK_HTML || kind == TK_COMMAND) && !pTestVariant->testInfo.hasData[TIK_BASELINE]) {
  475. if (!CheckForPass(full, optReportBuf, cmdbuf, fDumpOutputFile)) {
  476. fFailed = TRUE;
  477. goto SkipLogFailure;
  478. }
  479. }
  480. logFailure:
  481. if (fFailed) {
  482. LogOut("ERROR: Test failed to run correctly: %s (%s):",
  483. reason, optReportBuf);
  484. LogOut(" %s", cmdbuf);
  485. if (fDumpOutputFile) {
  486. DumpFileToLog(full);
  487. }
  488. }
  489. SkipLogFailure:
  490. if (fFileToDelete && !FNoDelete) {
  491. DeleteFileRetryMsg(full);
  492. }
  493. elapsed_variation = (int)(time(NULL) - start_variation);
  494. if (Timing & TIME_VARIATION) {
  495. Message("RL: Variation elapsed time (%s, %s, %s): %02d:%02d",
  496. pDir->GetDirectoryName(),
  497. kind == TK_MAKEFILE ? "rl.mak" : "dotest.cmd",
  498. optReportBuf,
  499. elapsed_variation / 60, elapsed_variation % 60);
  500. }
  501. if (kind == TK_MAKEFILE) {
  502. // If the test failed and we are asked to copy the failures, do so.
  503. if (fFailed && FCopyOnFail) {
  504. sprintf_s(cmdbuf, NMAKE"%s copy COPYDIR=\"fail.%s.%s\"",
  505. testCmd, optFlags, linkFlags);
  506. Message(cmdbuf);
  507. ExecuteCommand(pDir->GetDirectoryPath(), cmdbuf);
  508. }
  509. // Clean up after ourselves.
  510. if (!FNoDelete && (fFailed || fCleanAfter)) {
  511. sprintf_s(cmdbuf, NMAKE"%s clean", testCmd);
  512. Message(cmdbuf);
  513. ExecuteCommand(pDir->GetDirectoryPath(), cmdbuf);
  514. }
  515. }
  516. if (FSyncVariation) {
  517. if (FRLFE && fFailed) {
  518. RLFEAddLog(pDir, RLFES_FAILED, testCmd,
  519. optReportBuf, ThreadOut->GetText());
  520. }
  521. if (fSyncVariationWhenFinished)
  522. FlushOutput();
  523. }
  524. DeleteFileIfFound(full);
  525. return fFailed ? -1 : 0;
  526. }
  527. // null terminated string of null terminated strings
  528. // name=data from testinfo and all of parent process env, arg for CreateProcess()
  529. void * GetEnvFlags
  530. (
  531. TestVariant * pTestVariant
  532. )
  533. {
  534. char temp[BUFFER_SIZE];
  535. size_t len = 0, totalEnvLen = 0;
  536. char * envFlags = NULL;
  537. Xml::Node *env = (Xml::Node *)pTestVariant->testInfo.data[TIK_ENV];
  538. if (env != NULL) {
  539. // use a fixed global array for memory
  540. memset(EnvFlags, '\0', MAX_ENV_LEN);
  541. *temp = '\0';
  542. for ( Xml::Node * child = env->ChildList; child != NULL; child = child->Next) {
  543. sprintf_s(temp, "%s=%s", child->Name, child->Data);
  544. if (envFlags == NULL) {
  545. sprintf_s(EnvFlags, "%s", temp);
  546. envFlags = EnvFlags;
  547. } else {
  548. strcat_s(envFlags, REMAININGARRAYLEN(EnvFlags, envFlags), temp);
  549. }
  550. len = strlen(envFlags);
  551. envFlags += len+1;
  552. }
  553. LPTSTR lpszParentEnv = GetEnvironmentStrings();
  554. totalEnvLen = len;
  555. ASSERT(totalEnvLen < BUFFER_SIZE);
  556. len = 0;
  557. while(!((lpszParentEnv[len] == '\0') && (lpszParentEnv[len+1] == '\0'))) {
  558. len++;
  559. }
  560. ASSERT(totalEnvLen+len+2 < MAX_ENV_LEN);
  561. memcpy(envFlags, lpszParentEnv, len+2);
  562. FreeEnvironmentStrings(lpszParentEnv);
  563. envFlags = EnvFlags;
  564. }
  565. return (void*)envFlags;
  566. }
  567. int
  568. DoExternalTest(
  569. CDirectory* pDir,
  570. TestVariant * pTestVariant,
  571. char *testCmd,
  572. ExternalTestKind kind,
  573. BOOL fSuppressNoGPF,
  574. DWORD millisecTimeout
  575. )
  576. {
  577. const char *ccFlags = pTestVariant->testInfo.data[TIK_COMPILE_FLAGS];
  578. void *envFlags = GetEnvFlags(pTestVariant);
  579. return DoOneExternalTest(pDir, pTestVariant, pTestVariant->optFlags, ccFlags, NULL,
  580. testCmd, kind, TRUE, TRUE, TRUE, fSuppressNoGPF, envFlags, millisecTimeout);
  581. }
  582. int
  583. DoPogoExternalTest(
  584. CDirectory* pDir,
  585. TestVariant * pTestVariant,
  586. char *testCmd,
  587. ExternalTestKind kind,
  588. BOOL fSuppressNoGPF,
  589. DWORD millisecTimeout
  590. )
  591. {
  592. static const char *pgc = "*.pgc";
  593. static const char *pgd = POGO_PGD;
  594. char pgdFull[MAX_PATH];
  595. char ccFlags[BUFFER_SIZE];
  596. char linkFlags[BUFFER_SIZE];
  597. char cmdbuf[BUFFER_SIZE];
  598. BOOL fFailed;
  599. void *envFlags = GetEnvFlags(pTestVariant);
  600. sprintf_s(pgdFull, "%s\\%s", pDir->GetDirectoryPath(), pgd);
  601. const char * inCCFlags = pTestVariant->testInfo.data[TIK_COMPILE_FLAGS];
  602. const char * optFlags = pTestVariant->optFlags;
  603. DeleteFileIfFound(pgdFull);
  604. DeleteMultipleFiles(pDir, pgc);
  605. fFailed = FALSE;
  606. // Pogo requires LTCG
  607. ASSERT(strstr(optFlags, "GL") != NULL);
  608. if (!kind == TK_MAKEFILE) {
  609. Warning("'%s\\%s' is not a makefile test; Pogo almost certainly won't work", pDir->GetDirectoryPath(), testCmd);
  610. }
  611. sprintf_s(ccFlags, "%s %s", PogoForceErrors, optFlags);
  612. sprintf_s(linkFlags, "-ltcg:pgi -pgd:%s", pgd);
  613. if (DoOneExternalTest(pDir, pTestVariant, ccFlags, inCCFlags, linkFlags,
  614. testCmd, kind, FALSE, TRUE, FALSE, fSuppressNoGPF, envFlags, millisecTimeout)) {
  615. fFailed = TRUE;
  616. goto logFailure;
  617. }
  618. sprintf_s(ccFlags, "%s %s", PogoForceErrors, optFlags);
  619. sprintf_s(linkFlags, "-ltcg:pgo -pgd:%s", pgd);
  620. // Manually erase EXE and DLL files to get makefile to relink.
  621. // Also erase ASM files because some makefiles try to rebuild from
  622. // them.
  623. DeleteMultipleFiles(pDir, "*.exe");
  624. DeleteMultipleFiles(pDir, "*.dll");
  625. DeleteMultipleFiles(pDir, "*.asm");
  626. if (DoOneExternalTest(pDir, pTestVariant, ccFlags, inCCFlags, linkFlags,
  627. testCmd, kind, FALSE, FALSE, TRUE, fSuppressNoGPF, envFlags, millisecTimeout)) {
  628. fFailed = TRUE;
  629. }
  630. logFailure:
  631. if (FSyncVariation) {
  632. if (FRLFE && fFailed) {
  633. sprintf_s(cmdbuf, "%s%s%s", ccFlags,
  634. *linkFlags ? ";" : "", linkFlags);
  635. RLFEAddLog(pDir, RLFES_FAILED, testCmd,
  636. cmdbuf, ThreadOut->GetText());
  637. }
  638. FlushOutput();
  639. }
  640. if (FRLFE)
  641. RLFETestStatus(pDir);
  642. if (!FNoDelete) {
  643. DeleteFileRetryMsg(pgdFull);
  644. DeleteMultipleFiles(pDir, pgc);
  645. }
  646. return fFailed ? -1 : 0;
  647. }
  648. BOOL
  649. DoOneSimpleTest(
  650. CDirectory *pDir,
  651. Test * pTest,
  652. TestVariant * pTestVariant,
  653. const char *optFlags,
  654. const char *inCCFlags,
  655. const char *inLinkFlags,
  656. BOOL fSyncVariationWhenFinished,
  657. BOOL fCleanAfter,
  658. BOOL fLinkOnly, // relink only
  659. BOOL fSuppressNoGPF,
  660. DWORD millisecTimeout
  661. )
  662. {
  663. int rc;
  664. char *p = NULL;
  665. char cmdbuf[BUFFER_SIZE*2];
  666. char ccFlags[BUFFER_SIZE];
  667. char linkFlags[BUFFER_SIZE];
  668. char nogpfFlags[BUFFER_SIZE];
  669. char optReportBuf[BUFFER_SIZE];
  670. char full[MAX_PATH];
  671. char exebuf[BUFFER_SIZE];
  672. char fullexebuf[BUFFER_SIZE];
  673. char buf[BUFFER_SIZE];
  674. char failDir[BUFFER_SIZE];
  675. char copyName[BUFFER_SIZE];
  676. char tmp_file1[MAX_PATH];
  677. char tmp_file2[MAX_PATH];
  678. time_t start_variation;
  679. UINT elapsed_variation;
  680. BOOL fFailed;
  681. void *envFlags = GetEnvFlags(pTestVariant);
  682. // Avoid conditionals by copying/creating ccFlags appropriately.
  683. if (inCCFlags)
  684. sprintf_s(ccFlags, " %s", inCCFlags);
  685. else
  686. ccFlags[0] = '\0';
  687. switch (TargetMachine) {
  688. case TM_WVM:
  689. case TM_WVMX86:
  690. case TM_WVM64:
  691. strcat_s(ccFlags, " /BC ");
  692. break;
  693. }
  694. if (inLinkFlags)
  695. strcpy_s(linkFlags, inLinkFlags);
  696. else
  697. linkFlags[0] = '\0';
  698. sprintf_s(optReportBuf, "%s%s%s", optFlags, *linkFlags ? ";" : "", linkFlags);
  699. // Figure out the exe name and path
  700. strcpy_s(exebuf, pTest->name);
  701. p = strrchr(exebuf, '.');
  702. if (p != NULL)
  703. {
  704. strcpy_s(p + 1, REMAININGARRAYLEN(exebuf, p + 1), "exe");
  705. }
  706. else
  707. {
  708. strcat_s(exebuf, ".exe");
  709. }
  710. sprintf_s(fullexebuf, "%s\\%s", pDir->GetDirectoryPath(), exebuf);
  711. start_variation = time(NULL);
  712. // Build up the compile command string.
  713. sprintf_s(cmdbuf, "%s %s%s %s", REGR_CL,
  714. optFlags, ccFlags, EXTRA_CC_FLAGS);
  715. for (StringList * pFile = pTest->files; pFile != NULL; pFile = pFile->next)
  716. {
  717. strcat_s(cmdbuf, " ");
  718. strcat_s(cmdbuf, pFile->string);
  719. // If we're only relinking, hammer the extension to .obj
  720. if (fLinkOnly)
  721. {
  722. p = strrchr(cmdbuf, '.');
  723. sprintf_s(p, REMAININGARRAYLEN(cmdbuf, p), ".obj");
  724. }
  725. }
  726. // Build the link option string.
  727. if (LINKFLAGS && LINKFLAGS[0] != '\0') {
  728. strcat_s(linkFlags, " ");
  729. strcat_s(linkFlags, LINKFLAGS);
  730. }
  731. FillNoGPFFlags(nogpfFlags, fSuppressNoGPF);
  732. strcat_s(linkFlags, nogpfFlags);
  733. switch (TargetMachine) {
  734. case TM_X86:
  735. case TM_IA64:
  736. case TM_AMD64:
  737. case TM_AMD64SYS:
  738. case TM_AM33:
  739. case TM_ARM:
  740. case TM_ARM64:
  741. case TM_THUMB:
  742. case TM_M32R:
  743. case TM_MIPS:
  744. case TM_SH3:
  745. case TM_SH4:
  746. case TM_SH5M:
  747. case TM_SH5C:
  748. case TM_WVMX86:
  749. if (*linkFlags) {
  750. strcat_s(cmdbuf, " /link ");
  751. strcat_s(cmdbuf, linkFlags);
  752. }
  753. break;
  754. case TM_WVM:
  755. strcat_s(cmdbuf, " /c ");
  756. break;
  757. case TM_PPCWCE:
  758. if (*linkFlags) {
  759. strcat_s(cmdbuf, " ");
  760. strcat_s(cmdbuf, linkFlags);
  761. }
  762. break;
  763. }
  764. sprintf_s(buf, "%s (%s)", pTest->name, optReportBuf);
  765. ThreadInfo[ThreadId].SetCurrentTest(pDir->GetDirectoryName(), buf, pDir->IsBaseline());
  766. UpdateTitleStatus();
  767. // Remove exe if it's already there. We have to keep trying to delete it
  768. // until it's gone, or else the link will fail (if it is somehow still in
  769. // use).
  770. DeleteFileRetryMsg(fullexebuf);
  771. if (FTest)
  772. {
  773. Message("%s", cmdbuf);
  774. if (pTestVariant->testInfo.data[TIK_BASELINE]) {
  775. Message(" (baseline %s)", pTestVariant->testInfo.data[TIK_BASELINE]);
  776. }
  777. return 0;
  778. }
  779. // Do the compile.
  780. Message("Compiling:");
  781. Message(" %s", cmdbuf);
  782. rc = ExecuteCommand(pDir->GetDirectoryPath(), cmdbuf);
  783. // Some machines require separate linking of the
  784. // compiler and/or assembler output.
  785. if (rc == 0)
  786. {
  787. switch (TargetMachine)
  788. {
  789. case TM_WVM:
  790. // Build up the linker command string.
  791. strcpy_s(cmdbuf, LINKER);
  792. for (StringList * pFile = pTest->files;
  793. pFile != NULL;
  794. pFile = pFile->next)
  795. {
  796. strcat_s(cmdbuf, " ");
  797. strcat_s(cmdbuf, pFile->string);
  798. p = strrchr(cmdbuf, '.');
  799. strcpy_s(p + 1, REMAININGARRAYLEN(cmdbuf, p + 1), "obj");
  800. }
  801. if (linkFlags) {
  802. strcat_s(cmdbuf, " ");
  803. strcat_s(cmdbuf, linkFlags);
  804. }
  805. // Do the link.
  806. Message("Linking:");
  807. Message(" %s", cmdbuf);
  808. ExecuteCommand(pDir->GetDirectoryPath(), cmdbuf);
  809. break;
  810. default:
  811. break;
  812. }
  813. }
  814. // See if the compile succeeded by checking for the existence
  815. // of the executable.
  816. if ((rc != 0) || GetFileAttributes(fullexebuf) == INVALID_FILE_ATTRIBUTES) {
  817. LogOut("ERROR: Test failed to compile or link (%s):", optReportBuf);
  818. LogOut(" %s", cmdbuf);
  819. fFailed = TRUE;
  820. goto logFailure;
  821. }
  822. // Run the resulting exe.
  823. if (TargetVM) {
  824. strcpy_s(buf, TargetVM);
  825. strcat_s(buf, " ");
  826. strcat_s(buf, exebuf);
  827. // Copy the VM command to cmdbuf, so we get a useful error message
  828. // in the log file if test fails.
  829. strcpy_s(cmdbuf, buf);
  830. }
  831. else {
  832. strcpy_s(buf, exebuf);
  833. }
  834. // We need some temporary files.
  835. // Note: these are full pathnames, not relative pathnames. Also, note that
  836. // mytmpnam creates the file to be used. To avoid losing that file, and
  837. // risking another program using it, don't delete the file before use.
  838. // We currently delete the file before running the test, so we can see if
  839. // the test ever creates it. We should probably create the temp files in
  840. // the same directory as the test, since we guarantee that no other copies
  841. // of RL are running in the same directory.
  842. if (mytmpnam(pDir->GetDirectoryPath(), TMP_PREFIX, tmp_file1) == NULL ||
  843. mytmpnam(pDir->GetDirectoryPath(), TMP_PREFIX, tmp_file2) == NULL) {
  844. Fatal("Unable to create temporary files");
  845. }
  846. ThreadInfo[ThreadId].AddToTmpFileList(tmp_file1);
  847. ThreadInfo[ThreadId].AddToTmpFileList(tmp_file2);
  848. if (FVerbose)
  849. Message("INFO: tmp file 1 = %s, tmp file 2 = %s", tmp_file1, tmp_file2);
  850. Message("Running the test (%s)", buf);
  851. strcat_s(buf, " > ");
  852. strcat_s(buf, tmp_file1);
  853. // Make sure the output file isn't there.
  854. DeleteFileIfFound(tmp_file1);
  855. fFailed = FALSE;
  856. // Check for timeout.
  857. {
  858. int retval = ExecuteCommand(pDir->GetDirectoryPath(), buf, millisecTimeout, envFlags);
  859. if (retval == WAIT_TIMEOUT) {
  860. ASSERT(millisecTimeout != INFINITE);
  861. LogOut("ERROR: Test timed out after %ul seconds", millisecTimeout / 1000);
  862. fFailed = TRUE;
  863. goto logFailure;
  864. }
  865. }
  866. // Check the output.
  867. if (pTestVariant->testInfo.data[TIK_BASELINE]) {
  868. int spiff_ret;
  869. // Check to see if the exe ran at all.
  870. if (GetFileAttributes(tmp_file1) == INVALID_FILE_ATTRIBUTES) {
  871. LogOut("ERROR: Test failed to run. Couldn't find file '%s' (%s):", tmp_file1, optReportBuf);
  872. LogOut(" %s", cmdbuf);
  873. fFailed = TRUE;
  874. }
  875. else {
  876. sprintf_s(full, "%s\\%s", pDir->GetFullPathFromSourceOrDirectory(),
  877. pTestVariant->testInfo.data[TIK_BASELINE]);
  878. if (DoCompare(tmp_file1, full)) {
  879. // Output differs, run spiff to see if it's just minor
  880. // floating point anomalies.
  881. DeleteFileIfFound(tmp_file2);
  882. sprintf_s(buf, "spiff -m -n -s \"command spiff\" %s %s > %s",
  883. tmp_file1, full, tmp_file2);
  884. spiff_ret = ExecuteCommand(pDir->GetDirectoryPath(), buf);
  885. if (GetFileAttributes(tmp_file2) == INVALID_FILE_ATTRIBUTES) {
  886. LogError("ERROR: spiff failed to run");
  887. fFailed = TRUE;
  888. }
  889. else if (spiff_ret) {
  890. LogOut("ERROR: Test failed to run correctly. spiff returned %d (%s):", spiff_ret, optReportBuf);
  891. LogOut(" %s", cmdbuf);
  892. fFailed = TRUE;
  893. }
  894. }
  895. }
  896. }
  897. else {
  898. if (!CheckForPass(tmp_file1, optReportBuf, cmdbuf)) {
  899. fFailed = TRUE;
  900. }
  901. }
  902. logFailure:
  903. if (fFailed) {
  904. if (FCopyOnFail) {
  905. if (FVerbose)
  906. Message("INFO: Copying '%s' failure", optReportBuf);
  907. sprintf_s(failDir, "%s\\fail.%s",
  908. pDir->GetDirectoryPath(), optReportBuf);
  909. if ((GetFileAttributes(failDir) == INVALID_FILE_ATTRIBUTES) &&
  910. !CreateDirectory(failDir, NULL)) {
  911. Message("ERROR: Couldn't create directory '%s'", failDir);
  912. }
  913. else
  914. {
  915. for (StringList * pFile = pTest->files;
  916. pFile != NULL;
  917. pFile = pFile->next)
  918. {
  919. sprintf_s(copyName, "%s\\%s", failDir, pFile->string);
  920. p = strrchr(copyName, '.') + 1;
  921. strcpy_s(p, REMAININGARRAYLEN(copyName, p + 1), "obj");
  922. sprintf_s(buf, "%s\\%s", pDir->GetDirectoryPath(),
  923. pFile->string);
  924. p = strrchr(buf, '.') + 1;
  925. strcpy_s(p, REMAININGARRAYLEN(buf, p + 1), "obj");
  926. if (!CopyFile(buf, copyName, FALSE)) {
  927. Message("ERROR: Couldn't copy '%s' to '%s'",
  928. buf, copyName);
  929. }
  930. }
  931. sprintf_s(copyName, "%s\\%s", failDir, exebuf);
  932. if (!CopyFile(fullexebuf, copyName, FALSE)) {
  933. Message("ERROR: Couldn't copy '%s' to '%s'",
  934. fullexebuf, copyName);
  935. }
  936. }
  937. }
  938. }
  939. if (FRLFE) {
  940. RLFETestStatus(pDir);
  941. }
  942. if (FVerbose)
  943. Message("INFO: cleaning up test run");
  944. // Remove the exe.
  945. if (!FNoDelete) {
  946. DeleteFileRetryMsg(fullexebuf);
  947. }
  948. // Don't trash fullexebuf!
  949. strcpy_s(buf, fullexebuf);
  950. p = strrchr(buf, '.') + 1;
  951. // Remove the pdb(s) (if it exists).
  952. strcpy_s(p, REMAININGARRAYLEN(buf, p), "pdb");
  953. DeleteFileIfFound(buf);
  954. DeleteMultipleFiles(pDir, "*.pdb");
  955. // Remove the ilk (if it exists).
  956. strcpy_s(p, REMAININGARRAYLEN(buf, p), "ilk");
  957. DeleteFileIfFound(buf);
  958. // Remove the objs.
  959. if (!FNoDelete)
  960. {
  961. for (StringList * pFile = pTest->files;
  962. pFile != NULL;
  963. pFile = pFile->next)
  964. {
  965. sprintf_s(buf, "%s\\%s", pDir->GetDirectoryPath(), pFile->string);
  966. p = strrchr(buf, '.') + 1;
  967. if (fCleanAfter)
  968. {
  969. strcpy_s(p, REMAININGARRAYLEN(buf, p), "obj");
  970. DeleteFileRetryMsg(buf);
  971. }
  972. if (REGR_ASM) {
  973. strcpy_s(p, REMAININGARRAYLEN(buf, p), "asm");
  974. DeleteFileRetryMsg(buf);
  975. }
  976. }
  977. }
  978. elapsed_variation = (int)(time(NULL) - start_variation);
  979. if (Timing & TIME_VARIATION) {
  980. Message("RL: Variation elapsed time (%s, %s, %s): %02d:%02d",
  981. pDir->GetDirectoryName(), pTest->name, optReportBuf,
  982. elapsed_variation / 60, elapsed_variation % 60);
  983. }
  984. if (FSyncVariation) {
  985. if (FRLFE && fFailed)
  986. RLFEAddLog(pDir, RLFES_FAILED, pTest->name, optReportBuf, ThreadOut->GetText());
  987. if (fSyncVariationWhenFinished)
  988. FlushOutput();
  989. }
  990. ThreadInfo[ThreadId].DeleteTmpFileList();
  991. return fFailed ? -1 : 0;
  992. }
  993. int
  994. DoSimpleTest(
  995. CDirectory *pDir,
  996. Test * pTest,
  997. TestVariant * pTestVariant,
  998. BOOL fSuppressNoGPF,
  999. DWORD millisecTimeout
  1000. )
  1001. {
  1002. return DoOneSimpleTest(pDir, pTest, pTestVariant, pTestVariant->optFlags,
  1003. pTestVariant->testInfo.data[TIK_COMPILE_FLAGS],
  1004. pTestVariant->testInfo.data[TIK_LINK_FLAGS],
  1005. TRUE, TRUE, FALSE, fSuppressNoGPF, millisecTimeout);
  1006. }
  1007. int
  1008. DoPogoSimpleTest(
  1009. CDirectory *pDir,
  1010. Test * pTest,
  1011. TestVariant * pTestVariant,
  1012. BOOL fSuppressNoGPF,
  1013. DWORD millisecTimeout
  1014. )
  1015. {
  1016. static const char *pgc = "*.pgc";
  1017. static const char *pgd = POGO_PGD;
  1018. char pgdFull[MAX_PATH];
  1019. char ccFlags[BUFFER_SIZE];
  1020. char linkFlags[BUFFER_SIZE];
  1021. BOOL fFailed;
  1022. sprintf_s(pgdFull, "%s\\%s", pDir->GetDirectoryPath(), pgd);
  1023. const char * inCCFlags = pTestVariant->testInfo.data[TIK_COMPILE_FLAGS];
  1024. const char * optFlags = pTestVariant->optFlags;
  1025. DeleteFileIfFound(pgdFull);
  1026. DeleteMultipleFiles(pDir, pgc);
  1027. fFailed = FALSE;
  1028. // Pogo requires LTCG
  1029. ASSERT(strstr(optFlags, "GL") != NULL);
  1030. sprintf_s(ccFlags, "%s %s", PogoForceErrors, optFlags);
  1031. sprintf_s(linkFlags, "-ltcg:pgi -pgd:%s", pgd);
  1032. if (DoOneSimpleTest(pDir, pTest, pTestVariant, ccFlags, inCCFlags,
  1033. linkFlags, FALSE, FALSE, FALSE, fSuppressNoGPF, millisecTimeout)) {
  1034. fFailed = TRUE;
  1035. goto logFailure;
  1036. }
  1037. if (FTest)
  1038. {
  1039. return 0;
  1040. }
  1041. sprintf_s(ccFlags, "%s %s", PogoForceErrors, optFlags);
  1042. sprintf_s(linkFlags, "-ltcg:pgo -pgd:%s", pgd);
  1043. if (DoOneSimpleTest(pDir, pTest, pTestVariant, ccFlags, inCCFlags,
  1044. linkFlags, FALSE, TRUE, TRUE, fSuppressNoGPF, millisecTimeout)) {
  1045. fFailed = TRUE;
  1046. }
  1047. logFailure:
  1048. if (FSyncVariation) {
  1049. #if 0
  1050. if (FRLFE && fFailed) {
  1051. sprintf_s(cmdbuf, "%s%s%s", ccFlags,
  1052. *linkFlags ? ";" : "", linkFlags);
  1053. RLFEAddLog(pDir, RLFES_FAILED, testCmd,
  1054. cmdbuf, ThreadOut->GetText());
  1055. }
  1056. #endif
  1057. FlushOutput();
  1058. }
  1059. if (!FNoDelete) {
  1060. DeleteFileRetryMsg(pgdFull);
  1061. DeleteMultipleFiles(pDir, pgc);
  1062. }
  1063. return fFailed ? -1 : 0;
  1064. }
  1065. int
  1066. ExecTest
  1067. (
  1068. CDirectory* pDir,
  1069. Test * pTest,
  1070. TestVariant * pTestVariant
  1071. )
  1072. {
  1073. char *p = NULL;
  1074. char full[MAX_PATH];
  1075. DWORD millisecTimeout = DEFAULT_TEST_TIMEOUT;
  1076. const char *strTimeout = pTestVariant->testInfo.data[TIK_TIMEOUT];
  1077. if (strTimeout) {
  1078. char *end;
  1079. _set_errno(0);
  1080. uint32 secTimeout = strtoul(strTimeout, &end, 10);
  1081. millisecTimeout = 1000 * secTimeout;
  1082. // Validation has already occurred so this string should
  1083. // parse fine and the value shouldn't overflow the DWORD.
  1084. ASSERT(errno == 0 && *end == 0);
  1085. ASSERT(millisecTimeout > secTimeout);
  1086. }
  1087. // Check to see if all of the files exist.
  1088. for (StringList * pFile = pTest->files; pFile != NULL; pFile = pFile->next)
  1089. {
  1090. // Get a pointer to the filename sans path, if present.
  1091. p = GetFilenamePtr(pFile->string);
  1092. // If we have no pathname, use the current directory.
  1093. if (p == pFile->string) {
  1094. sprintf_s(full, "%s\\", pDir->GetFullPathFromSourceOrDirectory());
  1095. }
  1096. else {
  1097. // Look for %REGRESS% specifier.
  1098. if (!_strnicmp(pFile->string, "%REGRESS%",
  1099. strlen("%REGRESS%"))) {
  1100. // Temporarily truncate the filename.
  1101. ASSERT(p[-1] == '\\');
  1102. p[-1] = '\0';
  1103. sprintf_s(full, "%s%s\\",
  1104. REGRESS, pFile->string + strlen("%REGRESS%"));
  1105. p[-1] = '\\';
  1106. }
  1107. else {
  1108. *p = '\0';
  1109. }
  1110. }
  1111. strcat_s(full, p);
  1112. if (GetFileAttributes(full) == INVALID_FILE_ATTRIBUTES) {
  1113. LogError("ERROR: '%s' does not exist", full);
  1114. return -1;
  1115. }
  1116. }
  1117. const char* ext = GetFilenameExt(p);
  1118. // Special case dotest.cmd
  1119. if (!_stricmp(p, "dotest.cmd")) {
  1120. // We don't handle these yet.
  1121. ASSERTNR(pTestVariant->testInfo.data[TIK_LINK_FLAGS] == NULL);
  1122. if (IsPogoTest(pTest))
  1123. return DoPogoExternalTest(pDir, pTestVariant, full, TK_CMDSCRIPT, TRUE, millisecTimeout);
  1124. else
  1125. return DoExternalTest(pDir, pTestVariant, full, TK_CMDSCRIPT, TRUE, millisecTimeout);
  1126. }
  1127. // Special case for standardized RL makefiles.
  1128. else if (!_stricmp(p, "rl.mak")) {
  1129. // We don't handle these yet.
  1130. ASSERTNR(pTestVariant->testInfo.data[TIK_LINK_FLAGS] == NULL);
  1131. if (IsPogoTest(pTest))
  1132. return DoPogoExternalTest(pDir, pTestVariant, full, TK_MAKEFILE, FALSE, millisecTimeout);
  1133. else
  1134. return DoExternalTest(pDir, pTestVariant, full, TK_MAKEFILE, SuppressNoGPF(pTest), millisecTimeout);
  1135. }
  1136. // Special case for files ending with ".js", ".html", ".htm" (<command> dealt with separately)
  1137. else if (pTestVariant->testInfo.data[TIK_COMMAND] == NULL
  1138. && !_stricmp(ext, ".js"))
  1139. {
  1140. return DoExternalTest(pDir, pTestVariant, full, TK_JSCRIPT, FALSE, millisecTimeout);
  1141. }
  1142. else if (pTestVariant->testInfo.data[TIK_COMMAND] == NULL
  1143. && (!_stricmp(ext, ".html") || !_stricmp(ext, ".htm")))
  1144. {
  1145. return DoExternalTest(pDir, pTestVariant, full, TK_HTML, FALSE, millisecTimeout);
  1146. }
  1147. // Special case for tests with a <command> argument
  1148. else if (pTestVariant->testInfo.data[TIK_COMMAND] != NULL)
  1149. {
  1150. return DoExternalTest(pDir, pTestVariant, full, TK_COMMAND, FALSE, millisecTimeout);
  1151. }
  1152. // Non-scripted test.
  1153. else {
  1154. if (IsPogoTest(pTest)) {
  1155. // We don't handle these yet.
  1156. ASSERTNR(pTestVariant->testInfo.data[TIK_LINK_FLAGS] == NULL);
  1157. return DoPogoSimpleTest(pDir, pTest, pTestVariant, FALSE, millisecTimeout);
  1158. }
  1159. else
  1160. {
  1161. return DoSimpleTest(pDir, pTest, pTestVariant, SuppressNoGPF(pTest), millisecTimeout);
  1162. }
  1163. }
  1164. }