rl.h 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004
  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. // rl.h
  6. // Header file for rl
  7. #undef UNICODE
  8. #undef _UNICODE
  9. #include <windows.h>
  10. #include <process.h>
  11. #include <io.h>
  12. #include <fcntl.h>
  13. #include <direct.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <time.h>
  18. #include <sys/stat.h>
  19. #include "xmlreader.h"
  20. #include "rlfeint.h"
  21. #pragma warning(disable:4127) // expression is constant, e.g., while(TRUE)
  22. #define LOCAL static
  23. #define BUFFER_SIZE 1024
  24. #define MAXQUEUE 10000
  25. extern void assert(char *file, int line);
  26. #define ASSERT(ex) ((ex) ? (void)0 : assert(__FILE__, __LINE__))
  27. #define ASSERTNR ASSERT
  28. #define UNREACHED FALSE
  29. #define ARRAYLEN(x) (sizeof(x) / sizeof((x)[0]))
  30. #define REMAININGARRAYLEN(a, p) (ASSERT(a <= p && p <= a + ARRAYLEN(a)), ((sizeof(a) - (p - a)) / sizeof((a)[0])))
  31. // Target machines
  32. typedef struct tagTARGETINFO {
  33. char * name;
  34. BOOL fRL_MACHINEonly;
  35. BOOL fAutoCrossCompilation;
  36. BOOL fUseNoGPF;
  37. char * TARGET_VM;
  38. char * LINKFLAGS;
  39. char * NotTags;
  40. } TARGETINFO;
  41. extern TARGETINFO TargetInfo[];
  42. // Any changes made here should have corresponding name added
  43. // to TargetInfo in rl.cpp. NOTE: The TARGET_MACHINES enum is in exactly
  44. // the same order as the TargetInfo array is initialized
  45. typedef enum {
  46. TM_UNKNOWN,
  47. TM_X86,
  48. TM_PPCWCE,
  49. TM_WVM,
  50. TM_WVMCEE,
  51. TM_WVMX86,
  52. TM_MIPS,
  53. TM_ARM,
  54. TM_THUMB,
  55. TM_ARM64,
  56. TM_SH3,
  57. TM_SH4,
  58. TM_SH5C,
  59. TM_SH5M,
  60. TM_IA64,
  61. TM_AMD64,
  62. TM_AMD64SYS,
  63. TM_WVM64,
  64. TM_AM33,
  65. TM_M32R,
  66. TM_MSIL,
  67. TM_ALL
  68. } TARGET_MACHINES;
  69. extern TARGET_MACHINES TargetMachine;
  70. extern TARGET_MACHINES RLMachine;
  71. // Any changes made here should have corresponding name added
  72. // to TargetOSNames in rl.cpp. NOTE: The TARGET_OS enum is in exactly
  73. // the same order as the TargetOSNames array is initialized
  74. typedef enum {
  75. TO_UNKNOWN,
  76. TO_WIN7,
  77. TO_WIN8,
  78. TO_WINBLUE,
  79. TO_WIN10,
  80. TO_WP8,
  81. TO_ALL
  82. } TARGET_OS;
  83. extern TARGET_OS TargetOS;
  84. #define DEFAULT_OS TO_WIN7
  85. #define CFG_ERROR_EX(file,line,fmt,args) fprintf(stderr, "Error: %s(%d) - " ##fmt "\n", file, line, args)
  86. #define CFG_WARNING_EX(file,line,fmt,args) do { if (!FQuiet) printf("Warning: %s(%d) - " ##fmt "\n", file, line, (args)); } while (0)
  87. // Parsing delimiters
  88. #define OPT_DELIM " \t"
  89. #define XML_DELIM ","
  90. #define POGO_TEST_PREFIX "Pogo:"
  91. // Set default target machine based on the host machine
  92. // NOTE: this should be done dynamically, using getenv("PROCESSOR_ARCHITECTURE")
  93. #if defined(_M_IX86)
  94. #define DEFAULT_TM TM_X86
  95. #elif defined(_M_PPC)
  96. #define DEFAULT_TM TM_PPCWCE
  97. #elif defined(_M_MIPS)
  98. #define DEFAULT_TM TM_MIPS
  99. #elif defined(_M_ARM)
  100. #define DEFAULT_TM TM_ARM
  101. #elif defined(_M_ARM64)
  102. #define DEFAULT_TM TM_ARM64
  103. #elif defined(_M_THUMB)
  104. #define DEFAULT_TM TM_THUMB
  105. #elif defined(_M_SH)
  106. #define DEFAULT_TM TM_SH
  107. #elif defined(_M_IA64)
  108. #define DEFAULT_TM TM_IA64
  109. #else
  110. #define DEFAULT_TM TM_X86
  111. #endif
  112. #define RL_PRE_ENV_VAR "RL"
  113. #define RL_POST_ENV_VAR "_RL_"
  114. enum RLMODE
  115. {
  116. RM_ASM, RM_EXE, RM_DIR
  117. };
  118. extern RLMODE Mode;
  119. #define DEFAULT_RLMODE RM_EXE
  120. #define DEFAULT_ASM_DCFG "rlexedirs.xml"
  121. #define DEFAULT_ASM_CFG "rlexe.xml"
  122. #define DEFAULT_ASM_CMD "rl"
  123. #define DEFAULT_EXE_DCFG "rlexedirs.xml"
  124. #define DEFAULT_EXE_CFG "rlexe.xml"
  125. #define DEFAULT_EXE_CMD "rl"
  126. #define DEFAULT_TESTLST_DCFG "test.lst"
  127. #define DEFAULT_ENVLST_CFG "env.lst"
  128. #define DEFAULT_REGR_CL "cl"
  129. #define DEFAULT_REGR_DIFF "diff"
  130. #define DEFAULT_LOG_FILE "rl.log"
  131. #define DEFAULT_FULL_LOG_FILE "rl.full.log"
  132. #define DEFAULT_RESULTS_LOG_FILE "rl.results.log"
  133. #define DEFAULT_CROSS_TARGET_VM "issuerun -id:%d"
  134. #define DEFAULT_LINKER "link"
  135. #define DEFAULT_EXEC_TESTS_FLAGS ";"
  136. #define DEFAULT_TEST_TIMEOUT 60000
  137. #define DIR_LOCKFILE "regrlock.txt"
  138. // Statistics index.
  139. #ifndef _RL_STATS_DEFINED
  140. #define _RL_STATS_DEFINED
  141. typedef enum RL_STATS {
  142. RLS_TOTAL = 0, // overall stats
  143. RLS_EXE, // should == RLS_TOTAL at this time
  144. RLS_BASELINES, // baseline stats (== total if FBaseline && !FDiff)
  145. RLS_DIFFS, // diff stats (== total if FDiff && !FBaseline)
  146. RLS_COUNT
  147. };
  148. #endif
  149. enum ExternalTestKind
  150. {
  151. TK_MAKEFILE,
  152. TK_CMDSCRIPT,
  153. TK_JSCRIPT,
  154. TK_HTML,
  155. TK_COMMAND,
  156. };
  157. enum TestInfoKind
  158. {
  159. TIK_FILES = 0,
  160. TIK_BASELINE,
  161. TIK_COMPILE_FLAGS,
  162. TIK_LINK_FLAGS,
  163. TIK_TAGS,
  164. TIK_RL_DIRECTIVES,
  165. TIK_ENV,
  166. TIK_COMMAND,
  167. TIK_TIMEOUT,
  168. _TIK_COUNT
  169. };
  170. extern const char * const TestInfoKindName[];
  171. struct TestInfo
  172. {
  173. BOOL hasData[_TIK_COUNT];
  174. char * data[_TIK_COUNT];
  175. };
  176. struct Tags
  177. {
  178. Tags * next;
  179. const char * str;
  180. BOOL fInclude;
  181. };
  182. struct ConditionNodeList
  183. {
  184. ConditionNodeList * next;
  185. Xml::Node * node;
  186. };
  187. enum FILE_STATUS
  188. {
  189. FS_NONE, FS_EXCLUDED, FS_INCLUDED
  190. };
  191. enum PROCESS_CONFIG_STATUS
  192. {
  193. PCS_OK, PCS_ERROR, PCS_FILE_NOT_FOUND
  194. };
  195. enum FILE_CONFIG_STATUS
  196. {
  197. FCS_USER_SPECIFIED, FCS_US_FLAGS, FCS_READ
  198. };
  199. struct StringList
  200. {
  201. StringList * next;
  202. char * string;
  203. };
  204. struct TestVariant
  205. {
  206. TestVariant() : next(NULL), optFlags(NULL) {}
  207. TestVariant * next;
  208. // Exe optimization flags.
  209. char * optFlags;
  210. // Test-specific info.
  211. TestInfo testInfo;
  212. };
  213. struct Test
  214. {
  215. Test * next;
  216. // For tests
  217. StringList * files;
  218. // For directories
  219. char * name;
  220. char * fullPath;
  221. int num;
  222. // Common.
  223. ConditionNodeList * conditionNodeList;
  224. TestInfo defaultTestInfo;
  225. TestVariant * variants;
  226. };
  227. struct TestList
  228. {
  229. Test * first;
  230. Test * last;
  231. };
  232. // Time options. Can do multiple types of timings, so do it bitwise
  233. #define TIME_NOTHING 0x0
  234. #define TIME_DIR 0x1
  235. #define TIME_TEST 0x2
  236. #define TIME_VARIATION 0x4
  237. #define TIME_ALL 0x7 // bitmask of all timing options
  238. typedef int TIME_OPTION; // could be enum, but C++ doesn't like |= on enum
  239. extern TIME_OPTION Timing;
  240. /////////////////////////////////////////////////////////////////////////
  241. //
  242. // Class declarations. Non-inline member functions are defined in rlmp.cpp.
  243. //
  244. /////////////////////////////////////////////////////////////////////////
  245. class CProtectedLong;
  246. class CHandle;
  247. class CDirectory;
  248. class CDirectoryQueue;
  249. class CThreadInfo;
  250. class COutputBuffer;
  251. /////////////////////////////////////////////////////////////////////////
  252. // CProtectedLong: a single value protected by a critical section. This is
  253. // used for things like test counts which are accessed by both worker threads
  254. // and the display thread.
  255. class CProtectedLong {
  256. CRITICAL_SECTION _cs;
  257. long _value;
  258. public:
  259. CProtectedLong() : _value(0)
  260. {
  261. InitializeCriticalSection(&_cs);
  262. }
  263. ~CProtectedLong()
  264. {
  265. DeleteCriticalSection(&_cs);
  266. }
  267. long operator++(int)
  268. {
  269. EnterCriticalSection(&_cs);
  270. long tmp = _value++;
  271. LeaveCriticalSection(&_cs);
  272. return tmp;
  273. }
  274. long operator--(int)
  275. {
  276. EnterCriticalSection(&_cs);
  277. long tmp = _value--;
  278. LeaveCriticalSection(&_cs);
  279. return tmp;
  280. }
  281. long operator+=(long incr)
  282. {
  283. EnterCriticalSection(&_cs);
  284. long tmp = (_value += incr);
  285. LeaveCriticalSection(&_cs);
  286. return tmp;
  287. }
  288. long operator=(long val)
  289. {
  290. EnterCriticalSection(&_cs);
  291. _value = val;
  292. LeaveCriticalSection(&_cs);
  293. return val;
  294. }
  295. bool operator==(CProtectedLong& rhs)
  296. {
  297. return _value == rhs._value;
  298. }
  299. operator long() { return _value; }
  300. operator int() { return _value; }
  301. };
  302. /////////////////////////////////////////////////////////////////////////
  303. // CHandle: a convenience class for storing HANDLE objects. When destructed
  304. // or set to another value, the current handle is closed. Helps prevent
  305. // handle leaks.
  306. class CHandle {
  307. HANDLE _h;
  308. public:
  309. CHandle() : _h(INVALID_HANDLE_VALUE) {}
  310. ~CHandle()
  311. {
  312. if (_h != INVALID_HANDLE_VALUE && _h != NULL)
  313. CloseHandle(_h);
  314. }
  315. HANDLE operator=(HANDLE h)
  316. {
  317. if (_h != INVALID_HANDLE_VALUE && _h != NULL)
  318. CloseHandle(_h);
  319. _h = h;
  320. return _h;
  321. }
  322. BOOL operator==(HANDLE h) { return h == _h ? TRUE : FALSE; }
  323. BOOL operator!=(HANDLE h) { return h != _h ? TRUE : FALSE; }
  324. operator HANDLE() { return _h; };
  325. };
  326. /////////////////////////////////////////////////////////////////////////
  327. // WorkObject: a wrapper class for elements used by WorkQueue. Requires
  328. // children classes to implement Dump if debug and keeps track of a _next
  329. // for use by WorkQueue.
  330. template <typename TWorkObject>
  331. class WorkObject {
  332. public:
  333. TWorkObject* _next;
  334. public:
  335. #ifndef NODEBUG
  336. virtual void Dump() = 0;
  337. #endif
  338. };
  339. /////////////////////////////////////////////////////////////////////////
  340. // WorkQueue: a generic class for keeping track of WorkObjects which need
  341. // to be queued and worked on.
  342. template <typename TWorkObject>
  343. class WorkQueue {
  344. protected:
  345. int _length;
  346. TWorkObject* _head;
  347. TWorkObject* _tail;
  348. CRITICAL_SECTION _cs; // ensure proper synchronized access
  349. CHandle _hWorkAvailSem; // signalled whenever there's work on the list
  350. CHandle _hMaxWorkQueueSem; // used to control length of work queue
  351. public:
  352. WorkQueue()
  353. : _head(NULL), _tail(NULL), _length(0)
  354. {
  355. SECURITY_ATTRIBUTES sa;
  356. InitializeCriticalSection(&_cs);
  357. /*
  358. * Create the semaphores for the work lists
  359. */
  360. memset(&sa, 0, sizeof(sa));
  361. sa.nLength = sizeof(sa);
  362. sa.lpSecurityDescriptor = NULL;
  363. sa.bInheritHandle = TRUE;
  364. _hWorkAvailSem = CreateSemaphoreW(&sa, 0, 100000, NULL);
  365. if (_hWorkAvailSem == NULL)
  366. Fatal("Unable to create semaphore (err %u)!\n", GetLastError());
  367. _hMaxWorkQueueSem = CreateSemaphoreW(&sa, MAXQUEUE, MAXQUEUE, NULL);
  368. if (_hMaxWorkQueueSem == NULL)
  369. Fatal("Unable to create queue length semaphore (err %u)!\n", GetLastError());
  370. }
  371. ~WorkQueue()
  372. {
  373. // The CHandle objects clean up after themselves.
  374. DeleteCriticalSection(&_cs);
  375. }
  376. virtual TWorkObject* Pop() = 0;
  377. TWorkObject* Append(TWorkObject* pNew)
  378. {
  379. if (WaitForSingleObject(_hMaxWorkQueueSem, INFINITE) != WAIT_OBJECT_0) {
  380. Fatal("Semaphore wait failed, can't add to work list");
  381. }
  382. EnterCriticalSection(&_cs);
  383. if (_tail == NULL) {
  384. _head = _tail = pNew;
  385. } else {
  386. _tail->_next = pNew;
  387. _tail = pNew;
  388. }
  389. pNew->_next = NULL;
  390. ++_length;
  391. LeaveCriticalSection(&_cs);
  392. ReleaseSemaphore(_hWorkAvailSem, 1, NULL);
  393. return pNew;
  394. }
  395. int Length()
  396. {
  397. int tmp;
  398. EnterCriticalSection(&_cs);
  399. tmp = _length;
  400. LeaveCriticalSection(&_cs);
  401. return tmp;
  402. }
  403. DWORD WaitForWork(DWORD dwMilliseconds)
  404. {
  405. return WaitForSingleObject(_hWorkAvailSem, dwMilliseconds);
  406. }
  407. // The queue work available semaphore has a count for every
  408. // directory. When the queue is exhausted, each thread waits on
  409. // this semaphore again. So at the end, everyone will still be waiting!
  410. // So, add the number of threads to the count, so each thread
  411. // notices, one by one, that everything's done.
  412. void AdjustWaitForThreadCount()
  413. {
  414. ReleaseSemaphore(_hWorkAvailSem, (int)NumberOfThreads, NULL);
  415. }
  416. TWorkObject* GetNextItem()
  417. {
  418. DWORD dwWait = 0;
  419. TWorkObject* toReturn = NULL;
  420. while (TRUE)
  421. {
  422. dwWait = this->WaitForWork(1000);
  423. if (dwWait == WAIT_OBJECT_0) {
  424. // pick an item off the head of the work list
  425. toReturn = this->Pop();
  426. break;
  427. } else if (dwWait == WAIT_TIMEOUT) {
  428. if (bThreadStop)
  429. break;
  430. } else {
  431. LogError("Thread %d: Semaphore wait failed\n", ThreadId);
  432. break;
  433. }
  434. }
  435. if (dwWait != WAIT_OBJECT_0)
  436. return NULL;
  437. if (bThreadStop)
  438. return NULL;
  439. return toReturn;
  440. }
  441. #ifndef NODEBUG
  442. void Dump()
  443. {
  444. TWorkObject* tmp;
  445. EnterCriticalSection(&_cs);
  446. printf("WorkQueue, length %d\n", _length);
  447. for (tmp = _head; tmp != NULL; tmp = tmp->_next) {
  448. tmp->Dump();
  449. }
  450. LeaveCriticalSection(&_cs);
  451. }
  452. #endif
  453. };
  454. /////////////////////////////////////////////////////////////////////////
  455. // CDirectory: represents a single directory and the tests that need to
  456. // be run within it.
  457. class CDirectory : public WorkObject<CDirectory> {
  458. friend class CDirectoryQueue;
  459. TestList _testList; // list of files in directory
  460. Test * _pDir; // directory info
  461. CHandle _dirLock; // the directory lock file
  462. bool _isDiffDirectory; // directory is for doing diffs, not masters
  463. bool _isDirStarted; // indicates if the directory has begun executing
  464. time_t start_dir; // time when dir began executing
  465. time_t elapsed_dir; // time taken for dir to execute.
  466. // initialized to 0 but set to a value upon directory finish.
  467. CRITICAL_SECTION _cs; // ensure proper synchronized access
  468. // Try to lock the directory. If we successfully got the lock without
  469. // waiting, return true.
  470. // Note that since we use FILE_FLAG_DELETE_ON_CLOSE, the lock file should
  471. // go away if the process dies because of ctrl-c.
  472. bool TryLock();
  473. // Lock the directory; wait on the lock until it's available
  474. void WaitLock();
  475. // Output begin/finish summaries if all tests in the directory are executed.
  476. void WriteDirectoryBeginSummary();
  477. void WriteDirectoryFinishSummary();
  478. public:
  479. // Multiple threads can be working in a single directory,
  480. // we'll need to make these CProtectedLong.
  481. CProtectedLong NumVariations, NumVariationsRun, NumFailures, NumDiffs;
  482. RL_STATS stat; // which mode stat to update
  483. CDirectory(Test * pDir, TestList testList)
  484. : _pDir(pDir), _testList(testList), _isDiffDirectory(false), _isDirStarted(false), elapsed_dir(0)
  485. {
  486. InitializeCriticalSection(&_cs);
  487. }
  488. ~CDirectory();
  489. TestList * GetTestList() { return &_testList; }
  490. char* GetDirectoryName() { return _pDir->name; }
  491. char* GetDirectoryPath() { return _pDir->fullPath; }
  492. int GetDirectoryNumber() { return _pDir->num; }
  493. bool IsBaseline() { return !_isDiffDirectory; }
  494. void SetDiffFlag() { _isDiffDirectory = true; }
  495. void InitStats(int run);
  496. long IncRun(int inc = 1);
  497. long IncFailures(int inc = 1);
  498. long IncDiffs();
  499. // Trigger update of directory state.
  500. void UpdateState();
  501. void TryBeginDirectory();
  502. void TryEndDirectory();
  503. int Count(); // return count of tests in the directory
  504. #ifndef NODEBUG
  505. void Dump();
  506. #endif
  507. };
  508. /////////////////////////////////////////////////////////////////////////
  509. // CDirectoryQueue: a queue of directories that need to have work done.
  510. class CDirectoryQueue : public WorkQueue<CDirectory> {
  511. public:
  512. ~CDirectoryQueue();
  513. // Return a directory to use. Normally, just peel the first one off the
  514. // work queue. However, if that directory is locked by another copy of
  515. // rl.exe, then skip it and try the next directory, until there are no
  516. // directories left. If that happens, just wait on the first locked
  517. // directory.
  518. CDirectory* Pop();
  519. };
  520. /////////////////////////////////////////////////////////////////////////
  521. // CDirectoryAndTestCase: Keep track of directory and test case in a class for
  522. // use in CDirectoryAndTestCaseQueue.
  523. // Reuse CDirectory because it has all the nice profiling data already.
  524. class CDirectoryAndTestCase : public WorkObject<CDirectoryAndTestCase> {
  525. public:
  526. CDirectory* _pDir;
  527. Test* _pTest;
  528. public:
  529. CDirectoryAndTestCase(CDirectory* pDir, Test* pTest)
  530. : _pDir(pDir), _pTest(pTest)
  531. {
  532. _next = NULL;
  533. }
  534. ~CDirectoryAndTestCase()
  535. {
  536. // This class is just a container for CDirectory and Test.
  537. // We don't want to clean up the objects here,
  538. // CDirectory will be cleaned up via ~CDirectoryQueue.
  539. }
  540. #ifndef NODEBUG
  541. void Dump()
  542. {
  543. _pDir->Dump();
  544. }
  545. #endif
  546. };
  547. /////////////////////////////////////////////////////////////////////////
  548. // CDirectoryAndTestCaseQueue: a simple queue to hold CDirectoryAndTestCase objects.
  549. class CDirectoryAndTestCaseQueue : public WorkQueue<CDirectoryAndTestCase> {
  550. public:
  551. CDirectoryAndTestCase* Pop();
  552. };
  553. /////////////////////////////////////////////////////////////////////////
  554. // CThreadInfo: a class with various bits of information about the current
  555. // state of a thread. An array of these objects is created before the worker
  556. // threads are started. This array is accessed like this: ThreadInfo[ThreadId],
  557. // where ThreadId is a __declspec(thread) TLS variable. The status update
  558. // thread uses the info here to construct the title bar.
  559. class CThreadInfo
  560. {
  561. CRITICAL_SECTION _cs;
  562. char _currentTest[BUFFER_SIZE];
  563. bool _isDone;
  564. struct TmpFileList
  565. {
  566. TmpFileList* _next;
  567. char* const _fullPath;
  568. TmpFileList(TmpFileList* next, char* fullPath)
  569. : _next(next), _fullPath(_strdup(fullPath))
  570. {
  571. }
  572. ~TmpFileList()
  573. {
  574. free(_fullPath);
  575. }
  576. TmpFileList(const TmpFileList&) = delete;
  577. void operator=(const TmpFileList&) = delete;
  578. };
  579. TmpFileList* _head;
  580. public:
  581. CThreadInfo()
  582. : _head(NULL), _isDone(false)
  583. {
  584. InitializeCriticalSection(&_cs);
  585. _currentTest[0] = '\0';
  586. }
  587. ~CThreadInfo()
  588. {
  589. ClearTmpFileList();
  590. DeleteCriticalSection(&_cs);
  591. }
  592. bool IsDone() { return _isDone; }
  593. void Done();
  594. // Track current test, for use in creating the title bar
  595. void SetCurrentTest(char* dir, char* test, bool isBaseline);
  596. template <size_t bufSize>
  597. void GetCurrentTest(char (&currentTest)[bufSize])
  598. {
  599. EnterCriticalSection(&_cs);
  600. strcpy_s(currentTest, _currentTest);
  601. LeaveCriticalSection(&_cs);
  602. }
  603. // Track currently in-use temp files, so we can clean them up if we exit
  604. // by ctrl-c.
  605. void AddToTmpFileList(char* fullPath);
  606. void ClearTmpFileList();
  607. void DeleteTmpFileList();
  608. };
  609. /////////////////////////////////////////////////////////////////////////
  610. // COutputBuffer: a buffered output class. Store up output so it can
  611. // all be flushed at once. Used to keep per-thread output from
  612. // interleaving too much and becoming unreadable. This class is
  613. // not synchronized. It is expected that there is one of these objects per
  614. // output location (stdout, file, etc) per thread. Flushing the output *is*
  615. // synchronized on a critical section that should be used around *all*
  616. // worker thread stdio. (Actually, all normal output should go through this
  617. // class.) A NULL file or filename is allowed, in which case everything
  618. // happens as normal, but the Flush() operation doesn't display anything or
  619. // send anything to disk.
  620. class COutputBuffer
  621. {
  622. char* _start;
  623. char* _end;
  624. bool _buffered; // true == buffer output; false == flush immediately (e.g., primary thread)
  625. bool _textGrabbed; // true == someone grabbed the text, used for asserting
  626. size_t _bufSize;
  627. enum { OUT_ILLEGAL=0, OUT_FILE, OUT_FILENAME } _type;
  628. union { // output type info
  629. FILE* _pfile; // OUT_FILE
  630. char* _filename; // OUT_FILENAME
  631. };
  632. // Set the pointers to indicate the buffer is empty. Don't reallocate
  633. // or free the buffer, though---it will get reused.
  634. void Reset();
  635. // Flush the output; synchronizes printf output using csStdio
  636. void Flush(FILE* pfile);
  637. public:
  638. COutputBuffer(char* logfile, bool buffered = true);
  639. COutputBuffer(FILE* pfile, bool buffered = true);
  640. ~COutputBuffer();
  641. const char *GetText() { ASSERTNR(_type == OUT_FILE); _textGrabbed = true; return _start; }
  642. // Add without doing varargs formatting (avoids local buffer size problems)
  643. void AddDirect(char* string);
  644. // Add text to the output buffer. Just like printf.
  645. void Add(const char* fmt, ...);
  646. // Flush the output to wherever it's going
  647. void Flush();
  648. };
  649. /////////////////////////////////////////////////////////////////////////
  650. extern char *REGRESS, *MASTER_DIR, *DIFF_DIR;
  651. extern char *REGR_CL, *REGR_DIFF, *REGR_ASM, *REGR_SHOWD;
  652. extern char *EXTRA_CC_FLAGS, *EXEC_TESTS_FLAGS, *TARGET_VM;
  653. extern char *LINKER, *LINKFLAGS;
  654. extern char *JCBinary;
  655. extern BOOL FBaseline;
  656. extern BOOL FRebase; // Whether creates .rebase file if testout mismatches baseline
  657. extern BOOL FDiff;
  658. extern BOOL FBaseDiff;
  659. extern BOOL FVerbose;
  660. extern BOOL FSummary;
  661. extern BOOL FNoDelete;
  662. extern BOOL FCopyOnFail;
  663. extern BOOL FParallel;
  664. extern BOOL FSyncEnumDirs;
  665. extern BOOL FNogpfnt;
  666. extern BOOL FTest;
  667. extern BOOL FAppendTestNameToExtraCCFlags;
  668. #define MAXOPTIONS 60
  669. extern char *OptFlags[MAXOPTIONS + 1], *PogoOptFlags[MAXOPTIONS + 1];
  670. #ifndef NODEBUG
  671. extern BOOL FDebug;
  672. #endif
  673. extern BOOL bThreadStop;
  674. extern BOOL FSyncImmediate;
  675. extern BOOL FSyncVariation;
  676. extern BOOL FSyncTest;
  677. extern BOOL FSyncDir;
  678. extern BOOL FNoThreadId;
  679. extern char* BaseCompiler;
  680. extern char* DiffCompiler;
  681. extern CDirectoryQueue DiffDirectoryQueue;
  682. extern unsigned NumberOfThreads;
  683. extern CRITICAL_SECTION csCurrentDirectory; // used when changing current directory
  684. extern CRITICAL_SECTION csStdio; // for printf / fprintf synchronization
  685. extern __declspec(thread) int ThreadId;
  686. extern __declspec(thread) char *TargetVM;
  687. extern __declspec(thread) COutputBuffer* ThreadOut; // stdout
  688. extern __declspec(thread) COutputBuffer* ThreadLog; // log file
  689. extern __declspec(thread) COutputBuffer* ThreadFull; // full log file
  690. extern CThreadInfo* ThreadInfo;
  691. extern CProtectedLong NumVariationsRun[RLS_COUNT];
  692. extern CProtectedLong NumVariationsTotal[RLS_COUNT];
  693. extern CProtectedLong NumFailuresTotal[RLS_COUNT];
  694. extern CProtectedLong NumDiffsTotal[RLS_COUNT];
  695. extern BOOL FRLFE;
  696. extern char *RLFEOpts;
  697. extern const char * const ModeNames[];
  698. // rl.cpp
  699. extern void __cdecl Fatal(const char *fmt, ...);
  700. extern void __cdecl Warning(const char *fmt, ...);
  701. extern void __cdecl Message(const char *fmt, ...);
  702. extern void __cdecl WriteLog(const char *fmt, ...);
  703. extern void __cdecl LogOut(const char *fmt, ...);
  704. extern void __cdecl LogError(const char *fmt, ...);
  705. extern void FlushOutput(void);
  706. extern char *mytmpnam(char* directory, char *prefix, char *filename);
  707. extern int DoCompare(char *file1, char *file2);
  708. extern void UpdateTitleStatus();
  709. extern int mystrcmp(char *a, char *b);
  710. extern char * mystrtok(char *s, char *delim, char *term);
  711. extern void FreeTestList(TestList * pTestList);
  712. #ifndef NODEBUG
  713. extern void DumpTestList(TestList * pTestList);
  714. #endif
  715. extern void DeleteMultipleFiles(CDirectory* pDir, char *pattern);
  716. extern char *GetFilenamePtr(char *path);
  717. extern const char* GetFilenameExt(const char *path);
  718. extern void DeleteFileMsg(char *filename);
  719. extern BOOL DeleteFileIfFound(char *filename);
  720. extern void DeleteFileRetryMsg(char *filename);
  721. extern StringList * ParseStringList(char* p, char* delim);
  722. extern StringList * AppendStringList(StringList * stringList, StringList * appendList);
  723. extern StringList * AppendStringListCopy(StringList * stringList, StringList * appendList);
  724. extern void PrintTagsList(Tags* pTagsList);
  725. extern void AddTagToTagsList(Tags** pTagsList, Tags** pTagsLast, const char* str, BOOL fInclude);
  726. extern BOOL
  727. SuppressNoGPF(
  728. Test * pTest
  729. );
  730. extern BOOL
  731. HasInfo
  732. (
  733. const char * szInfoList,
  734. const char * delim,
  735. const char * szInfo
  736. );
  737. extern BOOL
  738. HasInfoList
  739. (
  740. const char * szInfoList1,
  741. const char * delim1,
  742. const char * szInfoList2,
  743. const char * delim2,
  744. bool allMustMatch
  745. );
  746. extern BOOL
  747. GetTestInfoFromNode
  748. (
  749. const char * fileName,
  750. Xml::Node * node,
  751. TestInfo * testInfo
  752. );
  753. extern char * getenv_unsafe(const char *);
  754. extern FILE * fopen_unsafe(const char *, const char *);
  755. extern char* strerror_unsafe(int errnum);
  756. // rlregr.cpp
  757. extern void RegrInit(void);
  758. extern BOOL RegrStartDir(char* path);
  759. extern BOOL RegrEndDir(char* path);
  760. extern int RegrFile(CDirectory* pDir, Test * pTest, TestVariant * pTestVariant);
  761. // rlrun.cpp
  762. extern void RunInit(void);
  763. extern BOOL IsPogoTest(Test * pFilename);
  764. extern BOOL RunStartDir(char *dir);
  765. extern int ExecTest(CDirectory* pDir, Test * pTest, TestVariant * pTestVariant);
  766. // rlmp.cpp
  767. extern int ExecuteCommand(char* path, char* CommandLine, DWORD millisecTimeout = INFINITE, void* localEnvVars = NULL);
  768. extern int DoOneExternalTest(
  769. CDirectory* pDir,
  770. TestVariant* pTestVariant,
  771. char *optFlags,
  772. char *inCCFlags,
  773. char *inLinkFlags,
  774. char *testCmd,
  775. ExternalTestKind kind,
  776. BOOL fSyncVariationWhenFinished,
  777. BOOL fCleanBefore,
  778. BOOL fCleanAfter,
  779. BOOL fSuppressNoGPF,
  780. void *localEnvVars = NULL
  781. );
  782. extern void
  783. WriteSummary(
  784. const char *name,
  785. BOOL fBaseline,
  786. int tests,
  787. int diffs,
  788. int failures
  789. );
  790. // rlfeint.cpp
  791. extern void RLFEInit(BYTE numThreads, int numDirs);
  792. extern void RLFEAddRoot(RL_STATS stat, DWORD total);
  793. extern void RLFEAddTest(RL_STATS stat, CDirectory *pDir);
  794. extern void RLFEAddLog(CDirectory *pDir, RLFE_STATUS rlfeStatus, const char *testName, const char *subTestName, const char *logText);
  795. extern void RLFETestStatus(CDirectory *pDir);
  796. extern void RLFEThreadDir(CDirectory *pDir, BYTE num);
  797. extern void RLFEThreadStatus(BYTE num, const char *text);
  798. extern BOOL RLFEConnect(const char *prefix);
  799. extern void RLFEDisconnect(BOOL fKilled);