blob: 99e1a5bd1781110de411b3628d3ff789a494c08e [file] [log] [blame]
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
// rl.cpp
// To build:
// nmake RELEASE=1 rl.exe
//
// Julian Burger
// Microsoft Corporation
// 11/06/98
// Configuration files are XML
//
// rl{asm,exe}dirs.xml have directory lists
// rl{asm,exe}.xml have test lists
//
// General format:
//
// <?xml version="1.0"?>
//
// <regress-asm> // head node, tag unimportant
//
// <test> // test node, tag unimportant
//
// <default> // default test information
//
// test info // see below
//
// </default>
//
// <condition order="1" type="exclude"> // condition node
//
// <target>...</target> // list of targets this condition applies to
//
// </condition>
//
// </test>
//
//
// Test info (valid for all configuration files):
//
// <files>...</files> // list of comma-delimited files
//
// For asm regressions, files may be grouped in a single test node for
// convenience. For exe regressions, all the files comprising a single test
// should be group.
//
// <tags>...</tags> // list of comma-delimited (case-insensitive) tags
//
// Tags are intended as a proper of the test case itself. That is, they
// should be used to indicate features of a test (like C++ EH or x86 asm)
// rather than arbitrary nonsense.
//
// One tag is recognized specifically by RL: "Pogo". This indicates the test
// is a Pogo test and should be run specially. Any other tag is for explicit
// inclusion/exclusion of tests. E.g.
//
// <tags>SEH</tags>
//
// This marks a test with the SEH tag. If -tags:SEH is specified on the command
// line, only tests marked as such would be included. Similarly, -nottags:SEH
// would exclude tests so tagged.
//
// Test info (valid for asm and exe test configuration files):
//
// <compile-flags>...</compile-flags> // compilation flags for this test
// <rl>...</rl> // RL directives (case-insensitive)
//
// Test info (valid for exe test configuration files)
//
// <baseline>...</baseline> // baseline, expected test output
// <link-flags>...</link-flags> // link flags for this test
// <env> // extra env vars for this test
// <envvar1>value1</envvar1> // any number of child nodes with arbitrary data
// ... // <build>release</build>
// // will result in "set build=release" for the test task env
// </env>
//
// <condition> nodes have an explicit order of evaluation and type (action to
// take if the condition applies) which can be either "include" or "exclude".
//
// asm and exe test conditions may contain <override> nodes that allow default
// info to be overridden. E.g.
//
// <condition order="1" type="include">
//
// <target>ia64</target>
//
// <override>
//
// <baseline>ia64-result.out</baseline>
//
// </override>
//
// </condition>
//
// The above would override the default baseline with "ia64-result.out" when
// the target is ia64.
//
//
// Currently, condition nodes may have only a single condition (target or
// compile-flags) and non-target conditions must appear after target
// conditions.
// Tags processing
//
// Tags specified in the same command line argument are treated as OR clauses.
// Multiple -tags (and -nottags) switches are permitted and are processed in
// command line order as AND clauses. E.g.
//
// -tags:Pogo -nottags:SEH,CPPEH -tags:asm
//
// The -tags declarations says: match all tests with "Pogo" tags. From that
// set, exclude those that have "SEH" or "CPPEH". The next -tags arg further
// restricts the set to those with "asm". (This is a contrived example.)
//
// Note that -tags/-nottags are only applied to files. Directories may not
// have tags because they are too error prone.
// Directives
//
// The following directives are recognized in the <rl>...</rl> section of a
// test's default info:
//
// PassFo
// NoAsm
// NoGPF
// Log file format
//
// There are three output files generated by default
// 1. rl.log contains the summary of tests passed and failed in each dir
// 2. rl.results.log contains the passed/failed result of each test variation
// 3. rl.full.log contains all the output from all the tests,
// delimited by +++ <test variation> +++
// Notes:
// 1. The test output in these files is not synchronized on MP,
// without the -sync option.
// 2. rl.results.log can be used as a baseline database to track regressions,
// if -time is not used.
// -genlst mode and lst file format
//
// In -genlst -all mode, rl won't run tests but generate test.lst and env.lst
// containing the same info as in the rlexedirs.xml and rlexe.xml files
// These files are then read by the runall test harness to run the tests.
// Please refer to the runall documentation for the lst file format.
// By default, rl spawns as many threads to execute tests as there are
// processors on the system. Only one thread works per directory because
// running multiple tests in a single directory may cause conflicts in the
// presence of startdir.cmd/enddir.cmd and precompiled header flags (e.g.,
// /YX). The primary thread generates a work queue of directories and files to
// test in each directory. As soon as the tests in a directory are determined,
// the directory becomes available for worker threads.
//
// One complication is that in Windows there is only a single "current
// directory" per process. Thus, we need to synchronize as follows:
//
// 1. Worker threads grab the "directory" critical section immediately before
// spawning a process (e.g., compile, link, etc.),
//
// 2. The process is spawned with the correct current directory, which it
// inherits.
//
// 3. The lock is released and the next worker is free to change the directory.
//
// 4. The primary thread never changes the current directory, to avoid
// synchronization issues.
//
// 5. Any file access (fopen_unsafe, etc.) must use full pathnames. The only place
// relative paths may be used is in commands that are executed via
// ExecuteCommand(), which does a _chdir before creating a new process to
// execute the command.
//
// 6. Global variables used by worker threads must be thread-local or
// properly synchronized. Exceptions are: (a) variables only read, not
// written, by the worker threads, (b) bThreadStop, which is only written
// to TRUE by worker threads, so synchronization is not necessary.
//
// 7. All printf/fprintf output from the worker threads must go through
// the COutputBuffer class, to be properly synchronized. This class buffers
// up output per thread and flushes it at reasonable intervals, normally
// after a test is finished running. This includes any output generated
// by rl as well as any output captured by the pipe output filter on
// spawned processes.
//
// 8. Do not use _putenv() in the worker threads, as it sets process-wide
// state.
#include "rl.h"
#include "strsafe.h"
#pragma warning(disable: 4474) // 'fprintf' : too many arguments passed for format string
// Win64 headers (process.h) has this:
#ifndef _INTPTR_T_DEFINED
#ifdef _WIN64
typedef __int64 intptr_t;
#else
typedef int intptr_t;
#endif
#define _INTPTR_T_DEFINED
#endif
// Target machine information
// Any changes made here should have corresponding name added
// to TARGET_MACHINES in rl.h. NOTE: The TARGET_MACHINES enum is in exactly
// the same order as the TargetInfo array is initialized!
TARGETINFO TargetInfo[] = {
"unknown", TRUE, FALSE, FALSE, NULL, NULL, NULL,
"x86", FALSE, FALSE, TRUE, NULL, NULL, NULL,
"ppcwce", FALSE, FALSE, FALSE, "comcli", NULL, "x86asm",
"wvm", FALSE, FALSE, FALSE, NULL, "vccoree.lib", "x86asm",
"wvmcee", FALSE, FALSE, FALSE, NULL, NULL, "x86asm",
"wvmx86", FALSE, FALSE, FALSE, NULL, NULL, "x86asm",
"mips", FALSE, FALSE, FALSE, NULL, NULL, "x86asm",
"arm", FALSE, FALSE, FALSE, "armsd", "libcnoce.lib", "x86asm",
"thumb", FALSE, FALSE, FALSE, "armsd", "libcnocet.lib", "x86asm",
"arm64", FALSE, FALSE, FALSE, "armsd", "libcnoce.lib", "x86asm",
"sh3", FALSE, FALSE, FALSE, "sh3sim", "libcsim.lib", "x86asm",
"sh4", FALSE, FALSE, FALSE, "sh3sim", "libcsim.lib", "x86asm",
"sh5c", FALSE, FALSE, FALSE, "sh5sim", "libcsim.lib", "x86asm",
"sh5m", FALSE, FALSE, FALSE, "sh5sim", "libcsim.lib", "x86asm",
"ia64", FALSE, TRUE, TRUE, NULL, NULL, "x86asm",
"amd64", FALSE, TRUE, TRUE, NULL, NULL, "x86asm",
"amd64sys", FALSE, FALSE, TRUE, "issuerun", NULL, "x86asm",
"wvm64", FALSE, FALSE, FALSE, NULL, NULL, "x86asm",
"am33", FALSE, FALSE, FALSE, NULL, NULL, "x86asm",
"m32r", FALSE, FALSE, FALSE, NULL, NULL, "x86asm",
"msil", FALSE, FALSE, FALSE, NULL, NULL, "x86asm",
NULL
};
// Target OS information
// Any changes made here should have corresponding name added
// to TARGET_OS in rl.h. NOTE: The TARGET_OS enum is in exactly
// the same order as the TargetOSNames array is initialized
const char* const TargetOSNames[] = {
"unknown",
"win7",
"win8",
"winBlue",
"win10",
"wp8",
NULL
};
#define IS_PATH_CHAR(c) ((c == '/') || (c == '\\'))
#define LOG_FULL_SUFFIX ".full"
const char * const ModeNames[] = {
"assembly", "executable", "shouldn't be printed (RM_DIR)"
};
const char * const InternalModeCmd[] = {
"<asm regress>", "<exe regress>"
};
const char * const TestInfoKindName[] =
{
"files",
"baseline",
"compile-flags",
"link-flags",
"tags",
"rl",
"env",
"command",
"timeout",
"timeoutRetries",
"sourcepath",
"eol-normalization",
"custom-config-file",
NULL
};
static_assert((sizeof(TestInfoKindName) / sizeof(TestInfoKindName[0])) - 1 == TestInfoKind::_TIK_COUNT, "Fix the buffer size");
const char * const DirectiveNames[] =
{
"PassFo",
"NoAsm",
"NoGPF",
NULL
};
//
// Global variables set before worker threads start, and only accessed
// (not set) by the worker threads.
//
TARGET_MACHINES TargetMachine = DEFAULT_TM;
TARGET_MACHINES RLMachine = DEFAULT_TM;
TARGET_OS TargetOS = DEFAULT_OS;
Tags * TagsList = NULL;
Tags * TagsLast = NULL;
Tags* DirectoryTagsList = NULL;
Tags* DirectoryTagsLast = NULL;
char SavedConsoleTitle[BUFFER_SIZE];
const char *DIFF_DIR;
char *REGRESS = NULL, *MASTER_DIR, *TARGET_MACHINE, *RL_MACHINE, *TARGET_OS_NAME = NULL;
const char *REGR_CL, *REGR_DIFF;
char *REGR_ASM, *REGR_SHOWD;
const char *TARGET_VM;
char *EXTRA_CC_FLAGS, *EXEC_TESTS_FLAGS;
const char *LINKER, *LINKFLAGS;
char *CL, *_CL_;
const char *JCBinary = "jshost.exe";
BOOL FStatus = TRUE;
char *StatusPrefix = nullptr;
const char *StatusFormat = nullptr;
BOOL FVerbose = FALSE;
BOOL FQuiet = FALSE;
BOOL FNoWarn = FALSE;
BOOL FTest = FALSE;
BOOL FStopOnError = FALSE;
BOOL GStopDueToError = FALSE;
BOOL FLow = FALSE;
BOOL FNoDelete = FALSE;
BOOL FCopyOnFail = FALSE;
BOOL FSummary = TRUE;
BOOL FMoveDiffs = FALSE;
BOOL FNoMoveDiffsSwitch = FALSE;
BOOL FRelativeLogPath = FALSE;
BOOL FNoDirName = TRUE;
BOOL FBaseline = FALSE;
BOOL FRebase = FALSE;
BOOL FDiff = FALSE;
BOOL FBaseDiff = FALSE;
BOOL FSyncEnumDirs = FALSE;
BOOL FNogpfnt = TRUE;
BOOL FAppend = FALSE;
BOOL FAppendTestNameToExtraCCFlags = FALSE;
#ifndef NODEBUG
BOOL FDebug = FALSE;
#endif
// Output synchronization options
BOOL FSyncImmediate = FALSE; // flush output immediately---no buffering
BOOL FSyncVariation = FALSE; // flush after every test variation (default)
BOOL FSyncTest = FALSE; // flush after all variations of a test
BOOL FSyncDir = FALSE; // flush after an entire directory
BOOL FSingleThreadPerDir = FALSE; // Perform all tests within each directory on a single thread.
BOOL FSingleDir = FALSE;
BOOL FNoThreadId = FALSE;
char* ExeCompiler = NULL;
char* BaseCompiler = NULL;
char* DiffCompiler = NULL;
RLMODE Mode = DEFAULT_RLMODE;
char *DCFGfile = NULL;
char const *CFGfile = NULL;
char const *CMDfile = NULL;
#define MAX_ALLOWED_THREADS 10 // must be <= MAXIMUM_WAIT_OBJECTS (64)
unsigned NumberOfThreads = 0;
TestList DirList, ExcludeDirList;
BOOL FUserSpecifiedFiles = FALSE;
BOOL FUserSpecifiedDirs = TRUE;
BOOL FNoProgramOutput = FALSE;
BOOL FOnlyAssertOutput = FALSE;
BOOL FExcludeDirs = FALSE;
BOOL FGenLst = FALSE;
char *ResumeDir = nullptr;
char *MatchDir = nullptr;
TIME_OPTION Timing = TIME_DIR | TIME_TEST; // Default to report times at test and directory level
static const char *ProgramName = nullptr;
static const char *LogName = nullptr;
static const char *FullLogName = nullptr;
static const char *ResultsLogName = nullptr;
static const char *TestTimeout = nullptr; // Stores timeout in seconds for all tests
static const char *TestTimeoutRetries = nullptr; // Number of timeout retries for all tests
#define MAX_ALLOWED_TIMEOUT_RETRIES 100 // Arbitrary max to avoid accidentally specifying too many retries
// NOTE: this might be unused now
static char TempPath[MAX_PATH] = ""; // Path for temporary files
//
// Global variables read and written by the worker threads: these need to
// either be protected by synchronization or use thread-local storage.
//
// Ctrl-C or done? This is written by worker threads or the main thread, but
// only to TRUE. Once written to TRUE, it never changes again. Threads notice
// its new state by polling it periodically, and shutting down gracefully if
// it is TRUE.
BOOL bThreadStop = FALSE;
char TitleStatus[BUFFER_SIZE]; // protected by csTitleBar
CRITICAL_SECTION csTitleBar; // used to serialize title bar
CRITICAL_SECTION csStdio; // printf serialization
CRITICAL_SECTION csCurrentDirectory; // used when changing current directory
CProtectedLong NumVariationsRun[RLS_COUNT];
CProtectedLong NumVariationsTotal[RLS_COUNT]; // run / total is displayed
CProtectedLong NumFailuresTotal[RLS_COUNT];
CProtectedLong NumDiffsTotal[RLS_COUNT];
CProtectedLong MaxThreads;
CProtectedLong CntDeleteFileFailures;
CProtectedLong CntDeleteFileFatals;
// Under -syncdirs, enumerate all directories/files before allowing
// any work to be done. Do this by setting this event when done enumerating.
// This releases the worker threads.
CHandle heventDirsEnumerated;
CDirectoryQueue DirectoryQueue;
CDirectoryQueue DirectoryTestQueue;
CDirectoryAndTestCaseQueue DirectoryAndTestCaseQueue;
CThreadInfo* ThreadInfo = NULL;
// A per-thread id. ThreadId 0 is the primary thread, the directory/file
// enumeration thread. Other threads are numbered 1 to NumberOfThreads
__declspec(thread) int ThreadId = 0;
__declspec(thread) char *TargetVM;
__declspec(thread) COutputBuffer* ThreadOut; // stdout
__declspec(thread) COutputBuffer* ThreadLog; // log file
__declspec(thread) COutputBuffer* ThreadFull; // full log file
__declspec(thread) COutputBuffer* ThreadRes; // results log file
// Per-thread compare buffers, allocated once, deleted on thread destroy
#define CMPBUF_SIZE 65536
__declspec(thread) char *cmpbuf1 = NULL;
__declspec(thread) char *cmpbuf2 = NULL;
// Allow usage of select deprecated CRT APIs without disabling all deprecated CRT API warnings
#pragma warning (push)
#pragma warning (disable:4996)
char * getenv_unsafe(const char * varName)
{
// Use getenv instead of getenv_s or _dupenv_s to simplify calls to the API.
return getenv(varName);
}
FILE * fopen_unsafe(const char * filename, const char * mode)
{
// Using fopen_s leads to EACCES error being returned occasionally, even when contentious
// fopen/fclose pairs are wrapped in a critical section. Unclear why this is happening.
// Use deprecated fopen instead.
_set_errno(0);
return fopen(filename, mode);
}
char* strerror_unsafe(int errnum)
{
return strerror(errnum);
}
#pragma warning (pop)
//////////////////////////////////////////////////////////////////////////////
void
CleanUp(BOOL fKilled)
{
if (FStatus)
SetConsoleTitle(SavedConsoleTitle);
// Try to remove temporary files. The temp files may
// be in use, so we might not be able to.
if (ThreadInfo != NULL) { // if we've gotten through parsing commands
for (unsigned int i = 0; i <= NumberOfThreads; i++) {
ThreadInfo[i].DeleteTmpFileList();
}
}
if (FRLFE)
RLFEDisconnect(fKilled);
}
void __cdecl
NormalCleanUp(void)
{
CleanUp(FALSE);
}
int __stdcall
NT_handling_function(unsigned long /* dummy -- unused */)
{
fprintf(stderr, "Exiting...\n");
fflush(stdout);
fflush(stderr);
CleanUp(TRUE);
// For now, just exit ungracefully. This will probably cause bad
// things to happen with output filtering, since we've
// just killed the pipe.
ExitProcess(1);
#if _MSC_VER<1300
return 1; // avoid C4716 warning caused by no return on ExitProcess
#endif
}
void
assert(
const char *file,
int line
)
{
fprintf(stderr, "Assertion failed on line %d of %s\n",
line, file);
}
//////////////////////////////////////////////////////////////////////////////
//
// Output functions. All worker thread output must be generated using these
// functions, then flushed at appropriate times based on the -sync option.
//
void
__cdecl Fatal(const char *fmt, ...)
{
va_list arg_ptr;
va_start(arg_ptr, fmt);
fprintf(stderr, "Error: ");
vfprintf(stderr, fmt, arg_ptr);
fputc('\n', stderr);
exit(1);
}
void
__cdecl Warning(const char *fmt, ...)
{
va_list arg_ptr;
char buf[50], tempBuf[BUFFER_SIZE];
ASSERT(ThreadOut != NULL);
buf[0] = '\0';
if (!FNoThreadId && ThreadId != 0 && NumberOfThreads > 1) {
sprintf_s(buf, "%d>", ThreadId);
}
if (!FNoWarn) {
va_start(arg_ptr, fmt);
vsprintf_s(tempBuf, fmt, arg_ptr);
ASSERT(strlen(tempBuf) < BUFFER_SIZE);
ThreadOut->Add("%sWarning: %s\n", buf, tempBuf);
ThreadFull->Add("%sWarning: %s\n", buf, tempBuf);
}
}
void
__cdecl Message(const char *fmt, ...)
{
va_list arg_ptr;
char buf[50], tempBuf[BUFFER_SIZE];
ASSERT(ThreadOut != NULL);
buf[0] = '\0';
if (!FNoThreadId && ThreadId != 0 && NumberOfThreads > 1) {
sprintf_s(buf, "%d>", ThreadId);
}
va_start(arg_ptr, fmt);
vsprintf_s(tempBuf, fmt, arg_ptr);
ASSERT(strlen(tempBuf) < BUFFER_SIZE);
ThreadOut->Add("%s%s\n", buf, tempBuf);
ThreadFull->Add("%s%s\n", buf, tempBuf);
}
void
__cdecl WriteLog(const char *fmt, ...)
{
va_list arg_ptr;
char buf[50], tempBuf[BUFFER_SIZE];
ASSERT(ThreadLog != NULL);
buf[0] = '\0';
if (!FNoThreadId && ThreadId != 0 && NumberOfThreads > 1) {
sprintf_s(buf, "%d>", ThreadId);
}
va_start(arg_ptr, fmt);
vsprintf_s(tempBuf, fmt, arg_ptr);
ASSERT(strlen(tempBuf) < BUFFER_SIZE);
ThreadLog->Add("%s%s\n", buf, tempBuf);
}
void
__cdecl LogOut(const char *fmt, ...)
{
va_list arg_ptr;
char buf[50], tempBuf[BUFFER_SIZE];
ASSERT(ThreadOut != NULL);
ASSERT(ThreadLog != NULL);
buf[0] = '\0';
if (!FNoThreadId && ThreadId != 0 && NumberOfThreads > 1) {
sprintf_s(buf, "%d>", ThreadId);
}
va_start(arg_ptr, fmt);
vsprintf_s(tempBuf, fmt, arg_ptr);
ASSERT(strlen(tempBuf) < BUFFER_SIZE);
ThreadOut->Add("%s%s\n", buf, tempBuf);
ThreadLog->Add("%s%s\n", buf, tempBuf);
ThreadFull->Add("%s%s\n", buf, tempBuf);
}
void
__cdecl LogError(const char *fmt, ...)
{
va_list arg_ptr;
char buf[50], tempBuf[BUFFER_SIZE];
ASSERT(ThreadOut != NULL);
ASSERT(ThreadLog != NULL);
buf[0] = '\0';
if (!FNoThreadId && ThreadId != 0 && NumberOfThreads > 1) {
sprintf_s(buf, "%d>", ThreadId);
}
va_start(arg_ptr, fmt);
vsprintf_s(tempBuf, fmt, arg_ptr);
ASSERT(strlen(tempBuf) < BUFFER_SIZE);
ThreadOut->Add("%sError: %s\n", buf, tempBuf);
ThreadLog->Add("%sError: %s\n", buf, tempBuf);
ThreadFull->Add("%sError: %s\n", buf, tempBuf);
}
// Helper function to flush all thread output.
__inline void FlushOutput(
void
)
{
ThreadOut->Flush();
ThreadLog->Flush();
ThreadFull->Flush();
ThreadRes->Flush();
}
//////////////////////////////////////////////////////////////////////////////
//
// Various DeleteFile() wrappers. We have had lots of problems where
// DeleteFile() fails with error 5 -- access denied. It's not clear why this
// is: it seems like an OS bug where the handle to a process is not released
// when the process handle becomes signaled. Perhaps there is a process that
// sits around grabbing handles. It seems to be worse with CLR testing and
// issuerun/readrun cross-compiler testing. To deal with this, loop and sleep
// between delete tries for some calls. Keep track of how many failures there
// were. Don't clog the log files with "error 5" unless the
// sleep doesn't fix the problem, or the user specifies verbose.
BOOL
DeleteFileIfFoundInternal(
const char* filename
)
{
BOOL ok;
ASSERT(filename != NULL);
if (FTest)
{
return TRUE;
}
// We could see if it's there and then try to delete it. It's easier to
// just try deleting it and see what happens.
ok = DeleteFile(filename);
if (!ok && (GetLastError() != ERROR_FILE_NOT_FOUND)) {
CntDeleteFileFailures++;
return FALSE;
}
return TRUE;
}
BOOL
DeleteFileIfFound(
const char* filename
)
{
BOOL ok;
ok = DeleteFileIfFoundInternal(filename);
if (!ok) {
LogError("DeleteFileIfFound: Unable to delete file %s - error %d", filename, GetLastError());
return FALSE;
}
return TRUE;
}
// Call Win32's DeleteFile(), and print an error if it fails
void
DeleteFileMsg(
char *filename
)
{
if (FTest)
{
return;
}
BOOL ok;
ok = DeleteFile(filename);
if (!ok) {
CntDeleteFileFailures++;
LogError("DeleteFileMsg: Unable to delete file %s - error %d", filename, GetLastError());
}
}
// Call Win32's DeleteFile(), and print an error if it fails. Retry a few
// times, just to improve robustness. NOTE: This function will fail (after
// retries) if the file does not exist!
#define MAX_DELETE_FILE_TRIES 10
#define DELETE_FILE_INITIAL_INTERVAL_IN_MS 100
#define DELETE_FILE_DELTA_IN_MS 100
void
DeleteFileRetryMsg(
char *filename
)
{
unsigned tries = 1;
BOOL ok;
DWORD dwWait = DELETE_FILE_INITIAL_INTERVAL_IN_MS;
for (;;) {
ok = DeleteFileIfFoundInternal(filename);
if (ok)
break;
if (FVerbose) {
LogError("DeleteFileRetryMsg: Unable to delete file %s - error %d", filename, GetLastError());
}
if (++tries > MAX_DELETE_FILE_TRIES) {
LogError("Giving up trying to delete file %s. Further related errors are likely", filename);
CntDeleteFileFatals++;
break;
}
Sleep(dwWait);
dwWait += DELETE_FILE_DELTA_IN_MS;
}
}
void
DeleteMultipleFiles(
CDirectory* pDir,
const char* pattern
)
{
WIN32_FIND_DATA findData;
HANDLE h;
char full[MAX_PATH];
sprintf_s(full, "%s\\%s", pDir->GetDirectoryPath(), pattern);
// Read filenames...
if ((h = FindFirstFile(full, &findData)) == INVALID_HANDLE_VALUE)
return;
do {
// FindFirstFile/FindNextFile set cFileName to a file name without a
// path. We need to prepend the directory and use a full path to do
// the delete. This is because multithreaded rl might have changed the
// current directory out from underneath us.
sprintf_s(full, "%s\\%s", pDir->GetDirectoryPath(), findData.cFileName);
if (FVerbose)
Message("Deleting %s\n", full);
DeleteFileRetryMsg(full);
} while (FindNextFile(h, &findData));
FindClose(h);
}
char *
GetFilenamePtr(
char *path
)
{
char *s;
s = strrchr(path, '\\');
if (s)
return s + 1;
return path;
}
// Get extension of a filename, or "" if no extension found.
const char* GetFilenameExt(const char *path)
{
const char* ext = strrchr(path, '.');
return ext ? ext : "";
}
char *
mytmpnam(
const char *directory,
const char *prefix,
char *filename
)
{
UINT r;
char threadPrefix[MAX_PATH]; // make the prefix thread-specific
// Note that GetTempFileName only uses the first 3 characters of the
// prefix. This should be okay, because it will still create a unique
// filename.
sprintf_s(threadPrefix, "%s%X", prefix, ThreadId);
// NOTE: GetTempFileName actually creates a file when it succeeds.
r = GetTempFileNameA(directory, threadPrefix, 0, filename);
if (r == 0) {
return NULL;
}
return filename;
}
//
// It is possible antivirus program on dev box locked testout when we want to compare testout with baseline.
// If this happens, delay and try a few more times.
//
HANDLE OpenFileToCompare(char *file)
{
const int MAX_TRY = 1200;
const DWORD NEXT_TRY_SLEEP_MS = 250;
HANDLE h;
int i = 0;
for (;;)
{
// Open the files using exclusive access
h = CreateFile(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (h != INVALID_HANDLE_VALUE)
{
break;
}
DWORD lastError = GetLastError();
if (++i < MAX_TRY && lastError == ERROR_SHARING_VIOLATION)
{
Sleep(NEXT_TRY_SLEEP_MS);
continue;
}
LogError("Unable to open file %s - error %d", file, lastError);
break;
}
return h;
}
struct MyFileWithoutCarriageReturn
{
CHandle* handle;
char* buf = nullptr;
size_t i = 0;
DWORD count = 0;
MyFileWithoutCarriageReturn(CHandle* handle, char* buf) : handle(handle), buf(buf) { Read(); }
bool readingError;
void Read()
{
i = 0;
readingError = !ReadFile(*handle, buf, CMPBUF_SIZE, &count, NULL);
}
bool HasNextChar()
{
if (count == 0)
{
return false;
}
if (i == count)
{
Read();
if (readingError)
{
return false;
}
return HasNextChar();
}
while (buf[i] == '\r')
{
++i;
if (i == count)
{
Read();
if (readingError)
{
return false;
}
return HasNextChar();
}
}
return true;
}
char GetNextChar()
{
return buf[i++];
}
};
// Do a quick file equality comparison using pure Win32 functions. (Avoid
// using CRT functions; the MT CRT seems to have locking/flushing problems on
// MP boxes.)
int
DoCompare(
char *file1,
char *file2,
BOOL normalizeLineEndings
)
{
CHandle h1, h2; // automatically closes open handles
DWORD count1, count2;
BOOL b1, b2;
DWORD size1, size2;
// Allocate large buffers for doing quick file comparisons.
if (cmpbuf1 == NULL) {
// initialize the buffers
cmpbuf1 = new char[CMPBUF_SIZE];
cmpbuf2 = new char[CMPBUF_SIZE];
if ((cmpbuf1 == NULL) || (cmpbuf2 == NULL))
Fatal("new failed");
}
h1 = OpenFileToCompare(file1);
if (h1 == INVALID_HANDLE_VALUE) {
return -1;
}
h2 = OpenFileToCompare(file2);
if (h2 == INVALID_HANDLE_VALUE) {
return -1;
}
if (normalizeLineEndings)
{
MyFileWithoutCarriageReturn f1(&h1, cmpbuf1);
MyFileWithoutCarriageReturn f2(&h2, cmpbuf2);
if (f1.readingError || f2.readingError)
{
LogError("ReadFile failed doing compare of %s and %s", file1, file2);
return -1;
}
while (f1.HasNextChar() && f2.HasNextChar())
{
if (f1.readingError || f2.readingError)
{
LogError("ReadFile failed doing compare of %s and %s", file1, file2);
return -1;
}
if (f1.GetNextChar() != f2.GetNextChar())
{
#ifndef NODEBUG
if (FDebug)
printf("DoCompare shows %s and %s are NOT equal (contents differ)\n", file1, file2);
#endif
return 1;
}
}
if (f1.HasNextChar() != f2.HasNextChar())
{
#ifndef NODEBUG
if (FDebug)
printf("DoCompare shows %s and %s are NOT equal (contents differ)\n", file1, file2);
#endif
return 1;
}
return 0;
}
size1 = GetFileSize(h1, NULL); // assume < 4GB files
if (size1 == 0xFFFFFFFF) {
LogError("Unable to get file size for %s - error %d", file1, GetLastError());
return -1;
}
size2 = GetFileSize(h2, NULL);
if (size2 == 0xFFFFFFFF) {
LogError("Unable to get file size for %s - error %d", file2, GetLastError());
return -1;
}
if (size1 != size2) { // not equal; don't bother reading the files
#ifndef NODEBUG
if (FDebug)
printf("DoCompare shows %s and %s are NOT equal (different size)\n", file1, file2);
#endif
return 1;
}
do {
b1 = ReadFile(h1, cmpbuf1, CMPBUF_SIZE, &count1, NULL);
b2 = ReadFile(h2, cmpbuf2, CMPBUF_SIZE, &count2, NULL);
if (!b1 || !b2) {
LogError("ReadFile failed doing compare of %s and %s", file1, file2);
return -1;
}
if (count1 != count2 || memcmp(cmpbuf1, cmpbuf2, count1) != 0) {
#ifndef NODEBUG
if (FDebug)
printf("DoCompare shows %s and %s are NOT equal (contents differ)\n", file1, file2);
#endif
return 1;
}
} while (count1 == CMPBUF_SIZE);
#ifndef NODEBUG
if (FDebug)
printf("DoCompare shows %s and %s are equal\n", file1, file2);
#endif
return 0;
}
char *
FormatString(
const char *format
)
{
static char buf[BUFFER_SIZE + 32]; // extra in case a sprintf_s goes over
int i;
i = 0;
while (*format) {
if (*format != '%') {
buf[i++] = *format;
}
else {
switch (*++format) {
case 'd':
i += sprintf_s(&buf[i], BUFFER_SIZE + 32 - i, "%d", (int32)NumDiffsTotal[RLS_TOTAL]);
break;
case 'f':
i += sprintf_s(&buf[i], BUFFER_SIZE + 32 - i, "%d", (int32)NumFailuresTotal[RLS_TOTAL]);
break;
case 't':
i += sprintf_s(&buf[i], BUFFER_SIZE + 32 - i, "%d", (int32)NumVariationsRun[RLS_TOTAL]);
break;
case 'T':
i += sprintf_s(&buf[i], BUFFER_SIZE + 32 - i, "%d", (int32)NumVariationsTotal[RLS_TOTAL]);
break;
case 'p':
if ((int32)NumVariationsTotal[RLS_TOTAL]) {
i += sprintf_s(&buf[i], BUFFER_SIZE + 32 - i, "%d",
100 * (int32)NumVariationsRun[RLS_TOTAL] /
(int32)NumVariationsTotal[RLS_TOTAL]);
}
else {
i += sprintf_s(&buf[i], BUFFER_SIZE + 32 - i, "--");
}
break;
default:
buf[i++] = *format;
}
}
format++;
if (i > BUFFER_SIZE)
break;
}
ASSERTNR(i < BUFFER_SIZE + 32);
buf[i] = '\0';
return buf;
}
void
Usage(
BOOL fExtended
)
{
int i;
BOOL fFirst;
printf(
"Usage: %s [options] [files...] [-args ...]\n"
"Specifying files on the command line overrides the configuration file parsing\n"
"\nOptions:\n"
" -h[x]: short/extended usage info\n"
"\n"
" -base[:backend] update MASTER_DIR assembly regression baselines\n"
" -diff[:backend] assembly regressions (default if no mode option)\n"
" -exe[:backend] run executable tests\n"
"\n"
" -all to run regressions on all directories in directory config file (log files go\n"
" in %%REGRESS%%\\logs directory)\n"
, ProgramName
);
if (fExtended) {
printf(
" -dirs:dir[,dir...] only regress the specified directories\n"
" -nodirs:dir[,dir...] exclude the specified directories\n"
" -resume:dir resume from the specified directory (implies -append)\n"
" -match:dir run regressions on directories with dir as a prefix\n"
"\n"
" -tags:tag[,tag...] only regress tests with any of the specified tags\n"
" -nottags:tag[,tag...] don't regress tests with any of the specified tags\n"
" -dirtags:tag[,tag...] only regress tests within directories with any of the specified tags\n"
" -dirnottags:tag[,tag...] don't regress tests within directories with any of the specified tags\n"
"\n"
" -exeflags:flag[;flag] specify exe flags to use in place of EXEC_TESTS_FLAGS\n"
" -target:arch specify the target architecture, instead of TARGET_MACHINE\n"
" -rltarget:arch specify the target architecture, instead of RL_MACHINE\n"
" -os:name specify the target os, instead of TARGET_OS\n"
" -regress:dir specify the root dir, instead of REGRESS\n"
"\n"
" -log:file specifies log file name (default: " DEFAULT_LOG_FILE ")\n"
" -full:file specifies full log file name (default: " DEFAULT_FULL_LOG_FILE ")\n"
" -results:file specifies runall style results log name (default: " DEFAULT_RESULTS_LOG_FILE ")\n"
" -rellog to allow a relative path log file\n"
"\n"
" -status[:prefix] to track diffs/failures in title\n"
" default prefix is \"{Diffs,Exec} [target] \"\n"
" -statusformat:format to specify display of statistics\n"
" default format is \"(%%d diffs, )%%f failures, %%t/%%T (%%p%%%%)\"\n"
" where %%d = # diffs, %%f = #failures,\n"
" %%t = num tests run, %%T = num tests total,\n"
" %%p = percentage of tests completed\n"
" -rlfe[:options] launch RLFE (graphical front end)\n"
"\n"
" -nosummary disables output of summary diff/failure info (implies -dirname)\n"
" -dirname enables output of '*** dirname ***'\n"
" -stoponerror stop on first test failure\n"
" -nomovediffs to not place assembly diffs in DIFF_DIR\n"
" -nodelete to not delete objs and exes when doing -exe\n"
" (only compatible with a single EXEC_TESTS_FLAGS flags)\n"
" -copyonfail to copy *.exe *.obj to fail.(OPT) subdirectory when rl.mak\n"
" tests fail\n"
" -allowpopup to allow popup screen when tests fail to run correctly\n"
" (do not link with nogpfnt.obj)\n"
" -append to append to the log files without deleting them first\n"
"\n"
" -quiet eliminates console display of progress\n"
" -verbose displays info about regressions\n"
" -nowarn turns off warnings\n"
" -low sets RL process to a lower priority\n"
" -test just displays regression commands, doesn't execute them\n"
"\n"
" -time:variation times each variation\n"
" -time:test times each test\n"
" -time:dir times each directory\n"
" -time:all enables all timing options\n"
"\n"
" -rebase:create rebase file if testout is different to baseline\n"
" -threads:# specifies # of worker threads to use (default==processor count)\n"
" -nothreadid to omit the thread id from multithreaded output\n"
" -sync:immediate to flush output immediately---no buffering\n"
" -sync:variation (default) to flush output after a test variation\n"
" -sync:test to flush output after all variations of a test\n"
" -sync:dir to flush output after an entire directory\n"
"\n"
" -dcfg:filename override directory config file\n"
" ASM default:" DEFAULT_ASM_DCFG " EXE default:" DEFAULT_EXE_DCFG "\n"
" -cfg:filename override file config file\n"
" ASM default:" DEFAULT_ASM_CFG " EXE default:" DEFAULT_EXE_CFG "\n"
"\n"
" -genlst to generate the runall test.lst and env.lst files, and don't run rl tests\n"
"\n"
);
#ifndef NODEBUG
printf(
"DEBUG ONLY:\n"
" -debug to show debug info (implies -verbose)\n"
" -syncdirs to enumerate all dirs/files before running tests\n"
"\n"
);
#endif
printf(
"Perform %s regressions by default.\n"
, ModeNames[DEFAULT_RLMODE]
);
printf(
"Current directory assumed if -all/-dirs/-resume/-match not specified\n"
"-status is the default; use -status:- to disable\n"
"Target machine defaults to %s (option -target or environment var\n"
" TARGET_MACHINE overrides)\n"
, TargetInfo[DEFAULT_TM].name
);
printf(
" (Valid targets:");
fFirst = TRUE;
for (i = 1; TargetInfo[i].name; i++) {
if (!TargetInfo[i].fRL_MACHINEonly) {
if (!fFirst)
putchar(',');
else
fFirst = FALSE;
printf(" %s", TargetInfo[i].name);
}
}
printf(")\n");
printf(
"Option -rltarget or environment var RL_MACHINE overrides TARGET_MACHINE for\n"
" configuration checking\n"
" (Additional configurations:");
fFirst = TRUE;
for (i = 1; TargetInfo[i].name; i++) {
if (TargetInfo[i].fRL_MACHINEonly) {
if (!fFirst)
putchar(',');
else
fFirst = FALSE;
printf(" %s", TargetInfo[i].name);
}
}
printf(")\n");
printf(
"Target os defaults to %s (option -os or environment var TARGET_OS overrides)\n"
" (Valid os:"
, TargetOSNames[DEFAULT_OS]);
fFirst = TRUE;
for (i = 1; TargetOSNames[i]; i++) {
if (!fFirst)
putchar(',');
else
fFirst = FALSE;
printf(" %s", TargetOSNames[i]);
}
printf(")\n");
printf(
"MASTER_DIR env var defaults to master.<target machine>\n"
"DIFF_DIR defaults to diffs.<target machine>\n"
"\n"
"The following environment variables are recognized:\n"
"REGR_CL use the specified command instead of " DEFAULT_REGR_CL "\n"
"REGR_ASM generate assembly listings and use the specified command to\n"
" assemble them\n"
"REGR_DIFF use the specified command instead of " DEFAULT_REGR_DIFF " (asm only)\n"
"REGR_SHOWD use the specified executable instead of %s\\bin\\showd.cmd (asm only)\n"
"EXTRA_CC_FLAGS specifies additional flags to pass to REGR_CL\n"
" if EXTRA_CC_FLAGS is not specified, it is constructed from\n"
" RL_{ASM,EXE}_CFLAGS and RL_B2, if present\n"
"RL_ASM_CFLAGS specify ASM only flags (used to construct EXTRA_CC_FLAGS)\n"
"RL_EXE_CFLAGS specify EXE only flags (used to construct EXTRA_CC_FLAGS)\n"
"RL_B2 specify backend to use (appended to above to create EXTRA_CC_FLAGS)\n"
"EXEC_TESTS_FLAGS semicolon delimited list of testing options (exe only)\n"
" (overridden by -exeflags switch) (defaults to %s)\n"
, getenv_unsafe("REGRESS"), DEFAULT_EXEC_TESTS_FLAGS
);
printf(
"REGR_NOMASTERCMP specifies that the generated ASM files should not be compared\n"
"to the masters (useful if you don't care about diffs and want to save time.)\n"
"TARGET_VM specifies the program used to execute a test (exe only)\n"
);
fFirst = TRUE;
for (i = 1; TargetInfo[i].name; i++) {
if (TargetInfo[i].TARGET_VM) {
if (fFirst) {
printf(" (");
fFirst = FALSE;
}
else {
printf(", ");
}
printf("%s: %s", TargetInfo[i].name, TargetInfo[i].TARGET_VM);
}
}
if (!fFirst)
printf(")\n");
printf(
"LINKER use the specified command instead of " DEFAULT_LINKER " (exe only)\n"
"LINKFLAGS specifies additional flags to pass to LINKER (exe only)\n"
);
fFirst = TRUE;
for (i = 1; TargetInfo[i].name; i++) {
if (TargetInfo[i].LINKFLAGS) {
if (fFirst) {
printf(" (");
fFirst = FALSE;
}
else {
printf(", ");
}
printf("%s: %s", TargetInfo[i].name, TargetInfo[i].LINKFLAGS);
}
}
if (!fFirst)
printf(")\n");
}
}
TARGET_MACHINES
ParseMachine(
char *s
)
{
int i;
for (i = 1; TargetInfo[i].name; i++) {
if (!_stricmp(TargetInfo[i].name, s))
return (TARGET_MACHINES)i;
}
return TM_UNKNOWN;
}
TARGET_OS
ParseOS(
char *s
)
{
int i;
for (i = 1; TargetOSNames[i]; i++) {
if (!_stricmp(TargetOSNames[i], s))
return (TARGET_OS)i;
}
return TO_UNKNOWN;
}
// Does the config file specified target match with our regression target?
// TRUE if they are equal or regrTarget is a superset of fileTarget.
BOOL
MatchMachine(
TARGET_MACHINES fileTarget,
TARGET_MACHINES regrTarget
)
{
if (fileTarget == regrTarget)
return TRUE;
if (fileTarget == TM_WVM) {
if (regrTarget == TM_WVMCEE || regrTarget == TM_WVMX86 || regrTarget == TM_WVM64)
return TRUE;
}
return FALSE;
}
BOOL
MatchOS(
TARGET_OS fileTarget,
TARGET_OS regrTarget
)
{
if (fileTarget == regrTarget)
{
return TRUE;
}
// Apply win8 override for wp8
if (fileTarget == TO_WIN8 && regrTarget == TO_WP8)
{
return TRUE;
}
return FALSE;
}
BOOL
HasInfoList
(
const char * szInfoList1,
const char * delim1,
const char * szInfoList2,
const char * delim2,
bool allMustMatch
)
{
if (szInfoList1 == NULL)
{
return FALSE;
}
if (szInfoList2 == NULL)
{
return FALSE;
}
const char * s = szInfoList2;
BOOL fHasInfo = TRUE; // start with TRUE on each entry
for (;;)
{
// Parse an item from szInfoList2.
char * e;
for (e = const_cast<char *>(s);
(strchr(delim2, *e) == NULL) && (*e != '\0');
e++)
{
}
char c = *e;
*e = '\0';
if (allMustMatch)
{
if (delim2 && (*delim2 == ','))
fHasInfo = TRUE; // new condition after ','
const char *save;
save = strchr(s, *delim1);
while(save != NULL) {
fHasInfo = fHasInfo && HasInfoList(szInfoList1, delim1,
s, delim1, allMustMatch);
s = save + 1;
save = strchr(s, *delim1);
}
fHasInfo = fHasInfo && HasInfo(szInfoList1, delim1, s);
}
else
{
fHasInfo = HasInfo(szInfoList1, delim1, s);
}
*e = c;
if (fHasInfo)
{
return TRUE;
}
if (c == '\0')
{
break;
}
s = e + 1;
}
return FALSE;
}
const char *
stristr
(
const char * str,
const char * sub
)
{
size_t len = strlen(sub);
size_t i;
while (*str)
{
for (i = 0; i < len; i++)
{
if (tolower(str[i]) != tolower(sub[i]))
{
if ((str[i] != '/' && str[i] != '-') || (sub[i] != '-' && sub[i] != '/')) {
// if the mismatch is not between '/' and '-'
break;
}
}
}
if (i == len)
{
return str;
}
str++;
}
return NULL;
}
BOOL
HasInfo
(
const char * szInfoList,
const char * delim1,
const char * szInfo
)
{
size_t len = strlen(szInfo);
const char * s = szInfoList;
if (s != NULL)
{
for (;;)
{
s = stristr(s, szInfo);
if (s == NULL)
{
return FALSE;
}
if (((s == szInfoList) || (strchr(delim1, s[-1]) != NULL))
&& ((s[len] == '\0') || (strchr(delim1, s[len]) != NULL)))
{
return TRUE;
}
while (*s != '\0')
{
if (strchr(delim1, *s) != NULL)
{
break;
}
s++;
}
if (*s == '\0')
{
break;
}
s++;
}
}
return FALSE;
}
template<typename ListType,typename String>
ListNode<ListType> *
AddToStringList
(
ListNode<ListType> * list,
String string
)
{
ListNode<ListType> * p = new ListNode<ListType>;
p->string = string; // NOTE: we store the pointer; we don't copy the string
p->next = NULL;
if (list == NULL)
{
return p;
}
ListNode<ListType> * last = list;
while (last->next != NULL)
{
last = last->next;
}
last->next = p;
return list;
}
template<typename T>
void
FreeStringList
(
ListNode<T> * list
)
{
while (list)
{
ListNode<T> * pFree = list;
list = list->next;
delete pFree;
}
}
void
FreeVariants
(
TestVariant * list
)
{
while (list)
{
TestVariant * pFree = list;
list = list->next;
delete pFree;
}
}
StringList *
ParseStringList(const char* cp, const char* delim)
{
StringList * list = NULL;
if (cp == NULL)
{
return list;
}
char *p = _strdup(cp); // don't trash passed-in memory
p = mystrtok(p, delim, delim);
while (p != NULL)
{
list = AddToStringList(list, p);
p = mystrtok(NULL, delim, delim);
}
return list;
}
StringList *
AppendStringList
(
StringList * list,
StringList * listToAppend
)
{
StringList * p;
if (list == NULL) {
return listToAppend;
}
for (p = list; p->next != NULL; p = p->next) {
// nothing
}
p->next = listToAppend;
return list;
}
BOOL
CompareStringList
(
StringList * list1,
StringList * list2
)
{
while ((list1 != NULL) && (list2 != NULL))
{
if (_stricmp(list1->string, list2->string))
{
return FALSE;
}
list1 = list1->next;
list2 = list2->next;
}
if (list1 == list2)
{
ASSERTNR(list1 == NULL);
return TRUE;
}
return FALSE;
}
// Set three environment variables for use in suppressing GPF pop-ups:
// NOGPF -- for console-mode programs
// NOGPFWINEXE -- for Windows EXEs
// NOGPFWINDLL -- for Windows DLLs
// These are useful for either dotest.cmd tests, or rl.mak tests that don't
// use the default console-mode nogpfnt.obj.
void
SetNOGPF()
{
char tempBuf[BUFFER_SIZE];
if (FNogpfnt && TargetInfo[TargetMachine].fUseNoGPF) {
sprintf_s(tempBuf,
"NOGPF=%s\\bin\\%s\\nogpfnt.obj /entry:nogpfntStartup",
REGRESS, TargetInfo[TargetMachine].name);
if (_putenv(tempBuf))
Fatal("Couldn't set NOGPF");
sprintf_s(tempBuf,
"NOGPFWINEXE=%s\\bin\\%s\\nogpfntWinMain.obj /entry:nogpfntWinMainStartup",
REGRESS, TargetInfo[TargetMachine].name);
if (_putenv(tempBuf))
Fatal("Couldn't set NOGPFWINEXE");
sprintf_s(tempBuf,
"NOGPFWINDLL=%s\\bin\\%s\\nogpfntDllMain.obj /entry:nogpfntDllMainStartup",
REGRESS, TargetInfo[TargetMachine].name);
if (_putenv(tempBuf))
Fatal("Couldn't set NOGPFWINDLL");
} else {
if (_putenv("NOGPF="))
Fatal("Couldn't set NOGPF");
if (_putenv("NOGPFWINEXE="))
Fatal("Couldn't set NOGPFWINEXE");
if (_putenv("NOGPFWINDLL="))
Fatal("Couldn't set NOGPFWINDLL");
}
}
// Get the LINKFLAGS variable. If necessary, massage it and put it back into
// the environment for use by the regr386 scripts and makefiles. The
// manipulation includes:
// 1. add a "no access violation" object to avoid pop-ups
// 2. to make LTCG testing easier, if EXTRA_CC_FLAGS contains /B2c2.dll, we
// copy that to LINKFLAGS as -B2:c2.dll. We check that there doesn't already
// exist a -B2: on the LINKFLAGS, or that they don't conflict. If we don't
// do this manipulation, it is too easy to forget to add -B2: to LINKFLAGS
// on your own, and hence test some compiler besides the one you intend to,
// namely whatever c2.dll is on your path.
void
GetLINKFLAGS()
{
char* readLINKFLAGS;
char* s;
char* b2;
char tmpLINKFLAGS[BUFFER_SIZE];
char tmpstrtok[BUFFER_SIZE];
char* tmpstrtoknext = NULL;
char tempBuf[BUFFER_SIZE];
bool fPropagateB2;
if ((readLINKFLAGS = getenv_unsafe("LINKFLAGS")) == NULL) {
if (NULL == TargetInfo[TargetMachine].LINKFLAGS) {
tmpLINKFLAGS[0] = '\0';
} else {
strcpy_s(tmpLINKFLAGS, TargetInfo[TargetMachine].LINKFLAGS);
}
} else {
strcpy_s(tmpLINKFLAGS, readLINKFLAGS);
}
// Look for -B2 or /B2 in EXTRA_CC_FLAGS
fPropagateB2 = false;
b2 = NULL;
strcpy_s(tmpstrtok, EXTRA_CC_FLAGS);
s = strtok_s(tmpstrtok, " \t", &tmpstrtoknext);
while (s) {
#ifndef NODEBUG
if (FDebug)
printf("\tParsed '%s'\n", s);
#endif
if ((0 == _strnicmp(s, "/B2", 3)) || (0 == _strnicmp(s, "-B2", 3))) {
if (b2 == NULL) {
b2 = s + 3;
if (*b2 == '\0')
b2++;
while (isspace(*b2))
b2++;
b2 = _strdup(b2);
fPropagateB2 = true;
} else {
Warning("Two /B2 flags in EXTRA_CC_FLAGS (%s)", EXTRA_CC_FLAGS);
}
}
s = strtok_s(NULL, " \t", &tmpstrtoknext);
}
// Now look for -B2: or /B2: in LINKFLAGS to check for consistency.
strcpy_s(tmpstrtok, tmpLINKFLAGS);
tmpstrtoknext = NULL;
s = strtok_s(tmpstrtok, " \t", &tmpstrtoknext);
while (s) {
#ifndef NODEBUG
if (FDebug)
printf("\tParsed '%s'\n", s);
#endif
if ((0 == _strnicmp(s, "/B2:", 4)) || (0 == _strnicmp(s, "-B2:", 4))) {
fPropagateB2 = false;
if (b2 == NULL) {
Warning("/B2: in LINKFLAGS (%s) but not in EXTRA_CC_FLAGS (%s)", readLINKFLAGS, EXTRA_CC_FLAGS);
} else {
// Make sure they are the same
if (0 != _stricmp(s + 4, b2)) {
Warning("/B2 flags in EXTRA_CC_FLAGS (%s) conflict with -B2: in LINKFLAGS(%s)", EXTRA_CC_FLAGS, readLINKFLAGS);
}
}
}
s = strtok_s(NULL, " \t", &tmpstrtoknext);
}
if (fPropagateB2) {
// We found -B2 in EXTRA_CC_FLAGS but not in LINKFLAGS, so propagate
// it to LINKFLAGS.
sprintf_s(tempBuf, " -B2:\"%s\"", b2);
free(b2); // came from _strdup()
strcat_s(tmpLINKFLAGS, tempBuf);
}
// Now, put it back into the environment with all our changes
sprintf_s(tempBuf, "LINKFLAGS=%s", tmpLINKFLAGS);
if (_putenv(tempBuf))
Fatal("Couldn't set LINKFLAGS");
LINKFLAGS = _strdup(tmpLINKFLAGS);
}
// WARNING: we are liberally using _putenv. As a result, it is dangerous to
// hold onto a pointer returned from getenv(), so always make a copy
void
GetEnvironment(
void
)
{
char *env;
FILE *showd_fp;
char tempBuf[BUFFER_SIZE];
// Get the TARGET_MACHINE environment variable. It may have already been
// specified on the command-line by the "-target" option, in which case
// we don't get the environment variable, but we do validate what the
// user passed.
if ((TARGET_MACHINE != NULL)
|| ((TARGET_MACHINE = getenv_unsafe("TARGET_MACHINE")) != NULL))
{
TargetMachine = RLMachine = ParseMachine(TARGET_MACHINE);
if (TargetMachine == TM_UNKNOWN) {
Fatal("Unknown machine type specified by TARGET_MACHINE: %s",
TARGET_MACHINE);
}
if (TargetInfo[TargetMachine].fRL_MACHINEonly) {
Fatal("TARGET_MACHINE specified is only valid for RL_MACHINE: %s",
TARGET_MACHINE);
}
}
else {
// Set environment var in case regr scripts reference.
sprintf_s(tempBuf, "TARGET_MACHINE=%s", TargetInfo[TargetMachine].name);
if (_putenv(tempBuf))
Fatal("Couldn't set TARGET_MACHINE");
}
// Get the RL_MACHINE environment variable or option.
if ((RL_MACHINE != NULL)
|| ((RL_MACHINE = getenv_unsafe("RL_MACHINE")) != NULL))
{
RLMachine = ParseMachine(RL_MACHINE);
if (RLMachine == TM_UNKNOWN) {
Fatal("Unknown machine type specified by RL_MACHINE: %s", RL_MACHINE);
}
}
else {
// Set environment var in case regr scripts reference.
sprintf_s(tempBuf, "RL_MACHINE=%s", TargetInfo[RLMachine].name);
if (_putenv(tempBuf))
Fatal("Couldn't set RL_MACHINE");
}
// Get the TARGET_OS environment variable or option.
if (TARGET_OS_NAME != NULL
|| (TARGET_OS_NAME = getenv_unsafe("TARGET_OS")) != NULL)
{
TargetOS = ParseOS(TARGET_OS_NAME);
if (TargetOS == TO_UNKNOWN) {
Fatal("Unknown os type specified by TargetOS: %s", TARGET_OS_NAME);
}
}
// Get the EXTRA_CC_FLAGS environment variable.
if ((EXTRA_CC_FLAGS = getenv_unsafe("EXTRA_CC_FLAGS")) == NULL) {
char *cflags, *b2;
// It doesn't exist, see if we can construct from RL_{ASM,EXE}_CFLAGS.
if (Mode == RM_ASM)
cflags = getenv_unsafe("RL_ASM_CFLAGS");
else
cflags = getenv_unsafe("RL_EXE_CFLAGS");
b2 = getenv_unsafe("RL_B2");
if (BaseCompiler || DiffCompiler || ExeCompiler) {
if (FVerbose && b2)
puts("Command line specified compiler overrides RL_B2 environment variable");
if (ExeCompiler)
b2 = ExeCompiler;
else
b2 = NULL;
}
sprintf_s(tempBuf, "%s%s%s",
cflags ? cflags : "",
b2 ? " -B2 " : "",
b2 ? b2 : "");
EXTRA_CC_FLAGS = _strdup(tempBuf);
sprintf_s(tempBuf, "EXTRA_CC_FLAGS=%s", EXTRA_CC_FLAGS);
if (_putenv(tempBuf))
Fatal("Couldn't set EXTRA_CC_FLAGS");
if (FVerbose)
puts("Constructed EXTRA_CC_FLAGS from RL_{ASM,EXE}_CFLAGS and RL_B2");
} else {
EXTRA_CC_FLAGS = _strdup(EXTRA_CC_FLAGS);
}
// Get REGR_* overrides.
if ((REGR_CL = getenv_unsafe("REGR_CL")) == NULL) {
REGR_CL = DEFAULT_REGR_CL;
} else {
REGR_CL = _strdup(REGR_CL);
}
if ((REGR_DIFF = getenv_unsafe("REGR_DIFF")) == NULL) {
REGR_DIFF = DEFAULT_REGR_DIFF;
} else {
REGR_DIFF = _strdup(REGR_DIFF);
}
REGR_ASM = getenv_unsafe("REGR_ASM");
if (REGR_ASM != NULL) {
REGR_ASM = _strdup(REGR_ASM);
}
// Get/generate {MASTER,DIFF}_DIR if doing assembly tests.
if (Mode == RM_ASM) {
// Get/generate the MASTER directory.
if ((MASTER_DIR = getenv_unsafe("MASTER_DIR")) == NULL) {
if (FVerbose) {
// This should be the default, so don't warn
Warning("Generating MASTER_DIR environment variable");
}
sprintf_s(tempBuf, "master.%s", TargetInfo[RLMachine].name);
MASTER_DIR = _strdup(tempBuf);
// Set environment var in case user overrides internal regr
// with -cmd.
sprintf_s(tempBuf, "MASTER_DIR=%s", MASTER_DIR);
if (_putenv(tempBuf))
Fatal("Couldn't set MASTER_DIR");
} else {
MASTER_DIR = _strdup(MASTER_DIR);
}
// Get/generate the DIFF directory.
if (FMoveDiffs) {
if ((DIFF_DIR = getenv_unsafe("DIFF_DIR")) == NULL) {
if (FVerbose) {
// This should be the default, so don't warn
Warning("Generating DIFF_DIR environment variable");
}
sprintf_s(tempBuf, "diffs.%s", TargetInfo[RLMachine].name);
DIFF_DIR = _strdup(tempBuf);
// Set environment var in case user overrides internal regr
// with -cmd.
sprintf_s(tempBuf, "DIFF_DIR=%s", DIFF_DIR);
if (_putenv(tempBuf))
Fatal("Couldn't set DIFF_DIR");
} else {
DIFF_DIR = _strdup(DIFF_DIR);
}
}
else {
DIFF_DIR = ".";
if (_putenv("DIFF_DIR="))
Fatal("Couldn't clear DIFF_DIR");
}
// Get the REGR_SHOWD directory.
REGR_SHOWD = getenv_unsafe("REGR_SHOWD");
if (REGR_SHOWD == NULL) {
sprintf_s(tempBuf, "%s\\bin\\showd.cmd", REGRESS);
REGR_SHOWD = _strdup(tempBuf);
} else {
REGR_SHOWD = _strdup(REGR_SHOWD);
}
showd_fp = fopen_unsafe(REGR_SHOWD, "rt");
if (showd_fp == NULL) {
if (!FGenLst)
Fatal("couldn't open diff processing command file (%s) with error '%s'", REGR_SHOWD, strerror_unsafe(errno));
} else
fclose(showd_fp);
}
// Get executable test options.
else {
if (EXEC_TESTS_FLAGS == NULL) {
if ((EXEC_TESTS_FLAGS = getenv_unsafe("EXEC_TESTS_FLAGS")) == NULL)
{
EXEC_TESTS_FLAGS = _strdup(DEFAULT_EXEC_TESTS_FLAGS);
} else {
// We edit EXEC_TESTS_FLAGS, so create a copy.
EXEC_TESTS_FLAGS = _strdup(EXEC_TESTS_FLAGS);
}
}
if ((TARGET_VM = getenv_unsafe("TARGET_VM")) == NULL) {
TARGET_VM = TargetInfo[TargetMachine].TARGET_VM;
// Support automatic cross-compilation
if ((TARGET_VM == NULL) && TargetInfo[TargetMachine].fAutoCrossCompilation) {
// If the host processor is not the same as the architecture to
// test, and we support automatic cross-compilation for this
// architecture, then create the default TARGET_VM.
char* PROCESSOR_ARCHITECTURE;
PROCESSOR_ARCHITECTURE = getenv_unsafe("PROCESSOR_ARCHITECTURE");
if (PROCESSOR_ARCHITECTURE == NULL) {
Fatal("PROCESSOR_ARCHITECTURE environment variable not set (this should be set by the OS!)");
}
if (0 != _stricmp(TargetInfo[TargetMachine].name, PROCESSOR_ARCHITECTURE)) {
TARGET_VM = DEFAULT_CROSS_TARGET_VM;
}
}
}
if (TARGET_VM != NULL) {
TARGET_VM = _strdup(TARGET_VM);
}
if ((LINKER = getenv_unsafe("LINKER")) == NULL) {
LINKER = DEFAULT_LINKER;
} else {
LINKER = _strdup(LINKER);
}
GetLINKFLAGS();
SetNOGPF();
}
// Grab CL and _CL_.
CL = getenv_unsafe("CL");
if (CL != NULL)
{
CL = _strdup(CL);
}
_CL_ = getenv_unsafe("_CL_");
if (_CL_ != NULL)
{
_CL_ = _strdup(_CL_);
}
// Display all the settings.
if (FVerbose) {
if ((env = getenv_unsafe(RL_PRE_ENV_VAR)) != NULL)
printf(RL_PRE_ENV_VAR"=%s\n", env);
if ((env = getenv_unsafe(RL_POST_ENV_VAR)) != NULL)
printf(RL_POST_ENV_VAR"=%s\n", env);
printf("Target machine = %s", TargetInfo[RLMachine].name);
printf(", Target os = %s", TargetOSNames[TargetOS]);
if (Mode == RM_ASM) {
printf(", MASTER_DIR = %s", MASTER_DIR);
if (FMoveDiffs)
printf(", DIFF_DIR = %s", DIFF_DIR);
if (FBaseline)
printf(", creating baselines");
if (FDiff)
printf(", checking diffs");
}
else {
printf(", TARGET_VM = %s", TARGET_VM);
printf(", EXEC_TESTS_FLAGS = %s", EXEC_TESTS_FLAGS);
}
printf("\nEXTRA_CC_FLAGS = %s\n", EXTRA_CC_FLAGS);
printf("REGR_CL = %s, REGR_ASM = %s", REGR_CL, REGR_ASM);
if (Mode == RM_ASM) {
printf(", REGR_DIFF = %s", REGR_DIFF);
}
else {
printf("\nLINKER = %s, LINKFLAGS = %s", LINKER, LINKFLAGS);
}
putchar('\n');
if (FLow)
puts("** Running with a low process priority");
printf("CL = %s, _CL_ = %s\n", CL, _CL_);
PrintTagsList(TagsList);
PrintTagsList(DirectoryTagsList);
}
if (FStatus && (GetConsoleTitle(SavedConsoleTitle, BUFFER_SIZE) == 0))
Warning("Couldn't get console title; won't be correctly restored");
}
void
PrintTagsList(
Tags* pTagsList
)
{
if (pTagsList != NULL)
{
for (Tags * tags = pTagsList; tags != NULL; tags = tags->next)
{
printf(" %s '%s'\n", tags->fInclude ? "include" : "exclude", tags->str);
}
}
else
{
printf(" None\n");
}
}
// Initialize a file list.
void
InitTestList(
TestList * pTestList
)
{
pTestList->first = pTestList->last = NULL;
}
// Free a file list.
void
FreeTestList(
TestList * pTestList
)
{
Test * pFilename, * pFree;
pFilename = pTestList->first;
while (pFilename) {
pFree = pFilename;
pFilename = pFilename->next;
FreeStringList(pFree->files);
FreeVariants(pFree->variants);
free(pFree);
}
InitTestList(pTestList);
}
// Add one file to a file list.
Test *
AddToTestList(
TestList * pTestList,
StringList * fileList
)
{
Test * pFilename;
ASSERTNR(pTestList);
pFilename = (Test *)malloc(sizeof(Test));
memset(pFilename, 0, sizeof(Test));
pFilename->files = fileList;
if (pTestList->last) {
ASSERTNR(pTestList->first);
pTestList->last->next = pFilename;
}
else {
ASSERTNR(pTestList->first == NULL);
pTestList->first = pFilename;
}
pTestList->last = pFilename;
#ifndef NODEBUG
if (FDebug)
printf("Added %s\n", pFilename->name);
#endif
return pFilename;
}
// Add one file to a file list.
Test *
AddToTestList(
TestList * pTestList,
char * name
)
{
Test * pTest = AddToTestList(pTestList, (StringList *)NULL);
pTest->name = name;
return pTest;
}
// Add one dir to the dir list.
Test *
AddDir(
TestList * pTestList,
char *name
)
{
return AddToTestList(pTestList, name);
}
// Add the current directory to the directory list.
void
AddCurrentDir(
void
)
{
char *dir;
char tempBuf[BUFFER_SIZE];
if (!GetCurrentDirectory(BUFFER_SIZE, tempBuf))
Fatal("GetCurrentDirectory couldn't live up to its name");
// If REGRESS is not a prefix, emit a warning.
if (_strnicmp(tempBuf, REGRESS, strlen(REGRESS))) {
Warning("Current directory '%s' is not in the '%s' tree",
tempBuf, REGRESS);
AddDir(&DirList, _strdup(tempBuf));
}
else {
dir = tempBuf + strlen(REGRESS);
if (!IS_PATH_CHAR(*dir)) {
Fatal("Current directory '%s' is not a subdirectory of '%s'",
tempBuf, REGRESS);
}
else {
AddDir(&DirList, _strdup(dir + 1));
}
}
}
// Add a list of user-specified directories.
void
AddUserDirs(
TestList * pTestList,
char *s
)
{
char *context = NULL;
s = strtok_s(s, XML_DELIM, &context);
while (s) {
AddDir(pTestList, s);
s = strtok_s(NULL, XML_DELIM, &context);
}
}
#ifndef NODEBUG
void
PrintStringList
(
StringList *pList
)
{
for (StringList *cur = pList; cur != NULL; cur = cur->next) {
printf("\t%s\n", cur->string);
}
}
void
PrintTestInfo
(
TestInfo *pTestInfo
)
{
ConstStringList * GetNameDataPairs(Xml::Node * node);
for(int i=0;i < _TIK_COUNT; i++) {
if ((i == TIK_ENV) && pTestInfo->data[TIK_ENV]) {
auto pStringList = GetNameDataPairs((Xml::Node*)pTestInfo->data[TIK_ENV]);
if (pStringList) {
for(; pStringList != NULL; pStringList = pStringList->next->next) {
ASSERT(pStringList->next);
if (pStringList->next->string[0]=='%') {
char tmpBuf[BUFFER_SIZE];
strncpy_s(tmpBuf, pStringList->next->string+1, strlen(pStringList->next->string)-2);
tmpBuf[strlen(pStringList->next->string)-2]=0;
if (getenv_unsafe(tmpBuf)==NULL) {
char msgBuf[BUFFER_SIZE];
sprintf_s(msgBuf, "%s environment variable used is not set\n", tmpBuf);
Fatal(msgBuf);
} else {
printf("\t%s=%s\n",pStringList->string, getenv_unsafe(tmpBuf));
}
} else {
printf("\t%s=%s\n",pStringList->string, pStringList->next->string);
}
}
}
}else if (pTestInfo->data[i]) {
printf("\t%s\n", pTestInfo->data[i]);
}
}
}
// Display the file list.
void
DumpTestList
(
TestList * pTestList
)
{
for (Test * pTest = pTestList->first; pTest != NULL; pTest = pTest->next)
{
printf("Files:\n");
PrintStringList(pTest->files);
printf("\n");
if (pTest->fullPath)
printf("fullpath (%s):\n", pTest->fullPath);
for(ConditionNodeList * conditionNodeList = pTest->conditionNodeList;
conditionNodeList != NULL; conditionNodeList=conditionNodeList->next)
{
printf("Condition nodes\n");
conditionNodeList->node->Dump();
}
printf("Default testinfo\n");
PrintTestInfo(&pTest->defaultTestInfo);
int i=0;
for(TestVariant * variants=pTest->variants; variants!=nullptr; variants=variants->next) {
printf("variant %d\n", i++);
PrintTestInfo(&variants->testInfo);
printf("opt flag %s\n", variants->optFlags);
}
printf("\n\n");
}
}
#endif
void
PadSpecialChars
(
char * strOut,
const char * strIn
)
{
int i = 0;
while (*strIn) {
strOut[i++] = *strIn++;
if (strOut[i-1] == '\\')
strOut[i++] = '\\';
}
strOut[i] = '\0';
}
// given an xml node, returns the name-data StringList pairs for all children
ConstStringList * GetNameDataPairs
(
Xml::Node * node
)
{
ASSERT(node->ChildList != NULL);
ConstStringList *pStringList = NULL;
for (Xml::Node *ChildNode = node->ChildList; ChildNode != NULL; ChildNode = ChildNode->Next) {
pStringList = AddToStringList(pStringList, ChildNode->Name);
pStringList = AddToStringList(pStringList, ChildNode->Data);
}
return pStringList;
}
// create the file env.lst
void
WriteEnvLst
(
Test * pDir, TestList * pTestList
)
{
char comments[BUFFER_SIZE];
char envlst[BUFFER_SIZE];
char noSpecialCharsBuf[BUFFER_SIZE];
ASSERT(pDir->fullPath);
sprintf_s(envlst, "%s%s", pDir->fullPath, "\\" DEFAULT_ENVLST_CFG);
DeleteFileIfFound(envlst);
COutputBuffer *LstFilesOut = new COutputBuffer(envlst, FSyncImmediate ? false : true);
ASSERT(LstFilesOut);
for (Test * pTest = pTestList->first; pTest != NULL; pTest = pTest->next)
{
for(TestVariant * variants=pTest->variants; variants!=NULL; variants=variants->next) {
// print the tags first
if (variants->testInfo.data[TIK_TAGS]) {
LstFilesOut->Add("%s\t", variants->testInfo.data[TIK_TAGS]);
} else if (pTest->defaultTestInfo.data[TIK_TAGS]){
LstFilesOut->Add("%s\t", pTest->defaultTestInfo.data[TIK_TAGS]);
} else {
LstFilesOut->Add("\t");
}
LstFilesOut->Add("TESTNAME=%s", pTest->name);
strcpy_s(comments, pTest->name);
PadSpecialChars(noSpecialCharsBuf, EXTRA_CC_FLAGS);
if (noSpecialCharsBuf[0] != '\0') {
LstFilesOut->Add(" EXTRA_CC_FLAGS=\"%s\"", noSpecialCharsBuf);
}
LstFilesOut->Add(" REGR_CL=%s", REGR_CL);
LstFilesOut->Add(" LINKER=%s", LINKER);
PadSpecialChars(noSpecialCharsBuf, LINKFLAGS);
if (noSpecialCharsBuf[0] != '\0') {
LstFilesOut->Add(" LINKFLAGS=\"%s\"", noSpecialCharsBuf);
}
if (pTest->files) {
LstFilesOut->Add(" FILES=\"");
StringList* pStringList = pTest->files;
for(;pStringList != NULL;pStringList=pStringList->next) {
LstFilesOut->Add("%s ", pStringList->string);
}
LstFilesOut->Add("\"");
}
// how we translate testinfo into env.lst specific stuffs
const char * const TestInfoEnvLstFmt[] =
{
" TESTFILE=\"%s\"",
" BASELINE=\"%s\"",
" CFLAGS=\"%s\"",
" LFLAGS=\"%s\"",
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};
static_assert((sizeof(TestInfoEnvLstFmt) / sizeof(TestInfoEnvLstFmt[0])) == TestInfoKind::_TIK_COUNT, "Fix the buffer size");
// print the other TIK_*
for(int i=0;i < _TIK_COUNT; i++) {
if (variants->testInfo.data[i] && TestInfoEnvLstFmt[i]) {
LstFilesOut->Add(TestInfoEnvLstFmt[i], variants->testInfo.data[i]);
} else if (pTest->defaultTestInfo.data[TIK_RL_DIRECTIVES]) {
// we only handle NoGPF directive, passFo and NoAsm not used
if (SuppressNoGPF(pTest)) {
LstFilesOut->Add(" NOGPF=1");
}
}
}
LstFilesOut->Add(" optFlags=\"%s\"", variants->optFlags);
strcat_s(comments, " "); strcat_s(comments, variants->optFlags);
// print the env settings
if (variants->testInfo.data[TIK_ENV]) {
auto pStringList = GetNameDataPairs((Xml::Node*)variants->testInfo.data[TIK_ENV]);
if (pStringList) {
// assuming even number of elements
for(; pStringList != NULL; pStringList = pStringList->next->next) {
ASSERT(pStringList->next);
if (pStringList->next->string[0]=='%') {
// grab the env variable specified in the pStringList->next->string
char tmpBuf[BUFFER_SIZE];
strncpy_s(tmpBuf, pStringList->next->string+1, strlen(pStringList->next->string)-2);
tmpBuf[strlen(pStringList->next->string)-2]=0;
if (getenv_unsafe(tmpBuf)==NULL) {
char msgBuf[BUFFER_SIZE];
sprintf_s(msgBuf, "%s environment variable used in %s not set\n", tmpBuf, envlst);
Fatal(msgBuf);
} else {
LstFilesOut->Add(" %s=%s",pStringList->string, getenv_unsafe(tmpBuf));
sprintf_s(comments, "%s %s=%s", comments, pStringList->string, getenv_unsafe(tmpBuf));
}
} else {
LstFilesOut->Add(" %s=%s",pStringList->string, pStringList->next->string);
sprintf_s(comments, "%s %s=%s", comments, pStringList->string, pStringList->next->string);
}
}
FreeStringList(pStringList);
}
}
LstFilesOut->Add(" # %s\n", comments);
}
}
LstFilesOut->Flush();
delete LstFilesOut;
printf(" %s\n", envlst);
}
BOOL
IsRelativePath(
const char *path
)
{
char drive[MAX_PATH], dir[MAX_PATH];
_splitpath_s(path, drive, ARRAYLEN(drive), dir, ARRAYLEN(dir), NULL, 0, NULL, 0);
// Path is relative if neither drive nor absolute directory are specified.
if (!*drive && !IS_PATH_CHAR(dir[0]))
return TRUE;
return FALSE;
}
char*
MakeFullPath(const char* absFilePath, const char* relPath)
{
char drive[MAX_PATH], dir[MAX_PATH];
_splitpath_s(absFilePath, drive, ARRAYLEN(drive), dir, ARRAYLEN(dir), NULL, 0, NULL, 0);
char makepath[MAX_PATH + 1];
makepath[MAX_PATH] = '\0';
_makepath_s(makepath, drive, dir, relPath, NULL);
char fullpath[MAX_PATH + 1];
fullpath[MAX_PATH] = '\0';
if (_fullpath(fullpath, makepath, MAX_PATH) == NULL)
{
return NULL;
}
char* fullPathBuf = (char*)malloc(sizeof(fullpath));
sprintf_s(fullPathBuf, sizeof(fullpath), "%s", fullpath);
return fullPathBuf;
}
BOOL
VerifyOrCreateDir(
char *name,
BOOL fCreate
)
{
if (FTest)
{
return TRUE;
}
DWORD attrib;
attrib = GetFileAttributes(name);
// Already exists?
if (attrib != INVALID_FILE_ATTRIBUTES) {
// Make sure it's a directory.
if (!(attrib & FILE_ATTRIBUTE_DIRECTORY)) {
LogError("%s exists but is not a subdirectory", name);
return FALSE;
}
}
// Are we allowed to create.
else if (!fCreate) {
LogError("%s doesn't exist", name);
return FALSE;
}
// Try to create it.
else if (!CreateDirectory(name, NULL)) {
LogError("Unable to create %s", name);
return FALSE;
}
else {
Warning("Created '%s' directory", name);
}
return TRUE;
}
// Create MASTER_DIR and DIFF_DIR if non-existent.
BOOL
CreateAsmDirs(
char* root,
BOOL fBaseline
)
{
char path[_MAX_PATH];
ASSERTNR(!IsRelativePath(root));
sprintf_s(path, "%s\\%s", root, MASTER_DIR);
if (!VerifyOrCreateDir(path, fBaseline))
return FALSE;
if (FMoveDiffs && FDiff) {
sprintf_s(path, "%s\\%s", root, DIFF_DIR);
if (!VerifyOrCreateDir(path, TRUE))
return FALSE;
}
return TRUE;
}
void
PrintDirs(
void
)
{
Test * pDir;
printf("Regression directories:");
for (pDir = DirList.first; pDir; pDir = pDir->next) {
printf(" %s", pDir->name);
}
printf("\n\n");
if (ExcludeDirList.first != NULL) {
printf("Regression exclude directories:");
for (pDir = ExcludeDirList.first; pDir; pDir = pDir->next) {
printf(" %s", pDir->name);
}
printf("\n\n");
}
}
char *
GetNonEmptyArg(
char *arg
)
{
if (arg && (*arg == '\0'))
return NULL;
return arg;
}
char *
ComplainIfNoArg(
char *opt,
char *arg
)
{
if ((arg == NULL) || (*arg == '\0'))
Fatal("%s requires an argument", opt);
return arg;
}
// Parse a single command line argument. Returns 1 if -args processed.
// Returns -1 if a non-switch was processed and pTestList is NULL.
int
ParseArg(
char *arg,
TestList * pTestList
)
{
char tempBuf[BUFFER_SIZE];
char *s;
switch (arg[0]) {
case '-':
case '/':
s = strchr(arg, ':');
if (s)
*s++ = '\0';
if (!_stricmp(&arg[1], "exe")) {
Mode = RM_EXE;
ExeCompiler = GetNonEmptyArg(s);
break;
}
if (!_stricmp(&arg[1], "asm")) {
Mode = RM_ASM;
ExeCompiler = GetNonEmptyArg(s);
break;
}
if (!_stricmp(&arg[1], "log")) {
LogName = ComplainIfNoArg(arg, s);
break;
}
if (!_stricmp(&arg[1], "full")) {
FullLogName = ComplainIfNoArg(arg, s);
break;
}
if (!_stricmp(&arg[1], "results")) {
ResultsLogName = ComplainIfNoArg(arg, s);
break;
}
// For backward-compatibility, support -tee
if (!_stricmp(&arg[1], "tee")) {
Warning("-tee is deprecated; use -full instead");
FullLogName = ComplainIfNoArg(arg, s);
break;
}
if (!_stricmp(&arg[1], "all")) {
FUserSpecifiedDirs = FALSE;
break;
}
if (!_stricmp(&arg[1], "dcfg")) {
DCFGfile = ComplainIfNoArg(arg, s);
break;
}
if (!_stricmp(&arg[1], "cfg")) {
CFGfile = ComplainIfNoArg(arg, s);
break;
}
if (!_stricmp(&arg[1], "genlst")) {
FGenLst = TRUE;
Mode = RM_EXE;
break;
}
// Note: we support "-dir:" for backwards-compatibility
if (!_stricmp(&arg[1], "dir") || !_stricmp(&arg[1], "dirs")) {
AddUserDirs(&DirList, ComplainIfNoArg(arg, s));
break;
}
if (!_stricmp(&arg[1], "nodirs")) {
FExcludeDirs = TRUE;
AddUserDirs(&ExcludeDirList, ComplainIfNoArg(arg, s));
break;
}
if (!_stricmp(&arg[1], "resume")) {
ResumeDir = ComplainIfNoArg(arg, s);
FUserSpecifiedDirs = FALSE;
FAppend = TRUE;
break;
}
if (!_stricmp(&arg[1], "match")) {
MatchDir = ComplainIfNoArg(arg, s);
FUserSpecifiedDirs = FALSE;
break;
}
if (!_stricmp(&arg[1], "status")) {
// -status:- disables.
if (s && !strcmp(s, "-")) {
FStatus = FALSE;
}
else {
FStatus = TRUE;
StatusPrefix = s;
}
break;
}
if (!_stricmp(&arg[1], "statusformat")) {
s = ComplainIfNoArg(arg, s);
StatusFormat = _strdup(s);
break;
}
if (!_stricmp(&arg[1], "rlfe")) {
FRLFE = TRUE;
if (s)
RLFEOpts = s;
break;
}
if (!_stricmp(&arg[1], "verbose")) {
FVerbose = TRUE;
break;
}
if (!_stricmp(&arg[1], "quiet")) {
FQuiet = TRUE;
break;
}
if (!_stricmp(&arg[1], "summary") ||
!_stricmp(&arg[1], "nodirname") ||
!_stricmp(&arg[1], "movediffs"))
{
Warning("%s is deprecated; it is now the default\n", arg);
break;
}
if (!_stricmp(&arg[1], "nosummary")) {
FSummary = FNoDirName = FALSE;
break;
}
if (!_stricmp(&arg[1], "allowpopup")) {
FNogpfnt = FALSE;
break;
}
if (!_stricmp(&arg[1], "append")) {
FAppend = TRUE;
break;
}
if (!_stricmp(&arg[1], "appendtestnametoextraccflags")) {
FAppendTestNameToExtraCCFlags = TRUE;
break;
}
if (!_stricmp(&arg[1], "singlethreadperdir")) {
FSingleThreadPerDir = TRUE;
break;
}
if (!_stricmp(&arg[1], "dirname")) {
FNoDirName = FALSE;
break;
}
if (!_stricmp(&arg[1], "nomovediffs")) {
FNoMoveDiffsSwitch = TRUE;
break;
}
if (!_stricmp(&arg[1], "nowarn")) {
FNoWarn = TRUE;
break;
}