2009-03-21 01:39:04 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Automatic Testing Utility
|
|
|
|
* LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation
|
|
|
|
* PURPOSE: Class implementing functions for handling Wine tests
|
2015-02-28 02:39:14 +00:00
|
|
|
* COPYRIGHT: Copyright 2009-2015 Colin Finck <colin@reactos.org>
|
2009-03-21 01:39:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
|
|
|
static const DWORD ListTimeout = 10000;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs a CWineTest object.
|
|
|
|
*/
|
|
|
|
CWineTest::CWineTest()
|
2015-02-28 02:39:14 +00:00
|
|
|
: m_hFind(NULL), m_ListBuffer(NULL)
|
2009-03-21 01:39:04 +00:00
|
|
|
{
|
2015-02-28 02:39:14 +00:00
|
|
|
WCHAR wszDirectory[MAX_PATH];
|
2009-03-21 01:39:04 +00:00
|
|
|
|
|
|
|
/* Set up m_TestPath */
|
2015-02-28 02:39:14 +00:00
|
|
|
if (GetEnvironmentVariableW(L"ROSAUTOTEST_DIR", wszDirectory, MAX_PATH))
|
|
|
|
{
|
|
|
|
m_TestPath = wszDirectory;
|
|
|
|
if (*m_TestPath.rbegin() != L'\\')
|
|
|
|
m_TestPath += L'\\';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!GetWindowsDirectoryW(wszDirectory, MAX_PATH))
|
|
|
|
FATAL("GetWindowsDirectoryW failed");
|
|
|
|
|
|
|
|
m_TestPath = wszDirectory;
|
|
|
|
m_TestPath += L"\\bin\\";
|
|
|
|
}
|
2009-03-21 01:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructs a CWineTest object.
|
|
|
|
*/
|
|
|
|
CWineTest::~CWineTest()
|
|
|
|
{
|
|
|
|
if(m_hFind)
|
|
|
|
FindClose(m_hFind);
|
|
|
|
|
|
|
|
if(m_ListBuffer)
|
|
|
|
delete m_ListBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the next module test file using the FindFirstFileW/FindNextFileW API.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* true if we found a next file, otherwise false.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
CWineTest::GetNextFile()
|
|
|
|
{
|
|
|
|
bool FoundFile = false;
|
|
|
|
WIN32_FIND_DATAW fd;
|
|
|
|
|
|
|
|
/* Did we already begin searching for files? */
|
|
|
|
if(m_hFind)
|
|
|
|
{
|
|
|
|
/* Then get the next file (if any) */
|
|
|
|
if(FindNextFileW(m_hFind, &fd))
|
|
|
|
FoundFile = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Start searching for test files */
|
|
|
|
wstring FindPath = m_TestPath;
|
|
|
|
|
|
|
|
/* Did the user specify a module? */
|
|
|
|
if(Configuration.GetModule().empty())
|
|
|
|
{
|
|
|
|
/* No module, so search for all files in that directory */
|
|
|
|
FindPath += L"*.exe";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Search for files with the pattern "modulename_*" */
|
|
|
|
FindPath += Configuration.GetModule();
|
|
|
|
FindPath += L"_*.exe";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Search for the first file and check whether we got one */
|
|
|
|
m_hFind = FindFirstFileW(FindPath.c_str(), &fd);
|
|
|
|
|
|
|
|
if(m_hFind != INVALID_HANDLE_VALUE)
|
|
|
|
FoundFile = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(FoundFile)
|
|
|
|
m_CurrentFile = fd.cFileName;
|
|
|
|
|
|
|
|
return FoundFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes the --list command of a module test file to get information about the available tests.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* The number of bytes we read into the m_ListBuffer member variable by capturing the output of the --list command.
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
CWineTest::DoListCommand()
|
|
|
|
{
|
|
|
|
DWORD BytesAvailable;
|
|
|
|
DWORD Temp;
|
|
|
|
wstring CommandLine;
|
2015-02-16 13:17:04 +00:00
|
|
|
CPipe Pipe;
|
2009-03-21 01:39:04 +00:00
|
|
|
|
|
|
|
/* Build the command line */
|
|
|
|
CommandLine = m_TestPath;
|
|
|
|
CommandLine += m_CurrentFile;
|
|
|
|
CommandLine += L" --list";
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Start the process for getting all available tests */
|
2015-02-16 13:17:04 +00:00
|
|
|
CPipedProcess Process(CommandLine, Pipe);
|
2009-03-21 01:39:04 +00:00
|
|
|
|
|
|
|
/* Wait till this process ended */
|
|
|
|
if(WaitForSingleObject(Process.GetProcessHandle(), ListTimeout) == WAIT_FAILED)
|
2015-02-28 21:12:25 +00:00
|
|
|
TESTEXCEPTION("WaitForSingleObject failed for the test list\n");
|
2009-03-21 01:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the output data into a buffer */
|
2015-02-16 13:17:04 +00:00
|
|
|
if(!Pipe.Peek(NULL, 0, NULL, &BytesAvailable))
|
2015-02-28 21:12:25 +00:00
|
|
|
TESTEXCEPTION("CPipe::Peek failed for the test list\n");
|
2009-03-21 01:39:04 +00:00
|
|
|
|
|
|
|
/* Check if we got any */
|
|
|
|
if(!BytesAvailable)
|
|
|
|
{
|
|
|
|
stringstream ss;
|
|
|
|
|
|
|
|
ss << "The --list command did not return any data for " << UnicodeToAscii(m_CurrentFile) << endl;
|
2015-02-28 21:12:25 +00:00
|
|
|
TESTEXCEPTION(ss.str());
|
2009-03-21 01:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the data */
|
|
|
|
m_ListBuffer = new char[BytesAvailable];
|
|
|
|
|
2015-02-16 13:17:04 +00:00
|
|
|
if(!Pipe.Read(m_ListBuffer, BytesAvailable, &Temp))
|
2015-02-28 21:12:25 +00:00
|
|
|
TESTEXCEPTION("CPipe::Read failed\n");
|
2009-03-21 01:39:04 +00:00
|
|
|
|
|
|
|
return BytesAvailable;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the next test from m_ListBuffer, which was filled with information from the --list command.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* true if a next test was found, otherwise false.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
CWineTest::GetNextTest()
|
|
|
|
{
|
|
|
|
PCHAR pEnd;
|
|
|
|
static DWORD BufferSize;
|
|
|
|
static PCHAR pStart;
|
|
|
|
|
|
|
|
if(!m_ListBuffer)
|
|
|
|
{
|
|
|
|
/* Perform the --list command */
|
|
|
|
BufferSize = DoListCommand();
|
|
|
|
|
|
|
|
/* Move the pointer to the first test */
|
|
|
|
pStart = strchr(m_ListBuffer, '\n');
|
|
|
|
pStart += 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we reach the buffer size, we finished analyzing the output of this test */
|
|
|
|
if(pStart >= (m_ListBuffer + BufferSize))
|
|
|
|
{
|
|
|
|
/* Clear m_CurrentFile to indicate that */
|
|
|
|
m_CurrentFile.clear();
|
|
|
|
|
|
|
|
/* Also free the memory for the list buffer */
|
2014-04-05 21:56:15 +00:00
|
|
|
delete[] m_ListBuffer;
|
2009-03-21 01:39:04 +00:00
|
|
|
m_ListBuffer = NULL;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get start and end of this test name */
|
|
|
|
pEnd = pStart;
|
|
|
|
|
|
|
|
while(*pEnd != '\r')
|
|
|
|
++pEnd;
|
|
|
|
|
|
|
|
/* Store the test name */
|
|
|
|
m_CurrentTest = string(pStart, pEnd);
|
|
|
|
|
|
|
|
/* Move the pointer to the next test */
|
|
|
|
pStart = pEnd + 6;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interface to CTestList-derived classes for getting all information about the next test to be run.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* Returns a pointer to a CTestInfo object containing all available information about the next test.
|
|
|
|
*/
|
|
|
|
CTestInfo*
|
|
|
|
CWineTest::GetNextTestInfo()
|
|
|
|
{
|
|
|
|
while(!m_CurrentFile.empty() || GetNextFile())
|
|
|
|
{
|
2015-02-28 21:12:25 +00:00
|
|
|
try
|
2009-03-21 01:39:04 +00:00
|
|
|
{
|
2015-02-28 21:12:25 +00:00
|
|
|
while(GetNextTest())
|
2009-03-21 01:39:04 +00:00
|
|
|
{
|
2015-02-28 21:12:25 +00:00
|
|
|
/* If the user specified a test through the command line, check this here */
|
|
|
|
if(!Configuration.GetTest().empty() && Configuration.GetTest() != m_CurrentTest)
|
|
|
|
continue;
|
2009-03-21 01:39:04 +00:00
|
|
|
|
2015-02-28 21:12:25 +00:00
|
|
|
{
|
|
|
|
auto_ptr<CTestInfo> TestInfo(new CTestInfo());
|
|
|
|
size_t UnderscorePosition;
|
2009-03-21 01:39:04 +00:00
|
|
|
|
2015-02-28 21:12:25 +00:00
|
|
|
/* Build the command line */
|
|
|
|
TestInfo->CommandLine = m_TestPath;
|
|
|
|
TestInfo->CommandLine += m_CurrentFile;
|
|
|
|
TestInfo->CommandLine += ' ';
|
|
|
|
TestInfo->CommandLine += AsciiToUnicode(m_CurrentTest);
|
2009-03-21 01:39:04 +00:00
|
|
|
|
2015-02-28 21:12:25 +00:00
|
|
|
/* Store the Module name */
|
|
|
|
UnderscorePosition = m_CurrentFile.find_last_of('_');
|
2009-03-21 01:39:04 +00:00
|
|
|
|
2015-02-28 21:12:25 +00:00
|
|
|
if(UnderscorePosition == m_CurrentFile.npos)
|
|
|
|
{
|
|
|
|
stringstream ss;
|
|
|
|
|
|
|
|
ss << "Invalid test file name: " << UnicodeToAscii(m_CurrentFile) << endl;
|
|
|
|
SSEXCEPTION;
|
|
|
|
}
|
2009-03-21 01:39:04 +00:00
|
|
|
|
2015-02-28 21:12:25 +00:00
|
|
|
TestInfo->Module = UnicodeToAscii(m_CurrentFile.substr(0, UnderscorePosition));
|
2009-03-21 01:39:04 +00:00
|
|
|
|
2015-02-28 21:12:25 +00:00
|
|
|
/* Store the test */
|
|
|
|
TestInfo->Test = m_CurrentTest;
|
2009-03-21 01:39:04 +00:00
|
|
|
|
2015-02-28 21:12:25 +00:00
|
|
|
return TestInfo.release();
|
|
|
|
}
|
2009-03-21 01:39:04 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-28 21:12:25 +00:00
|
|
|
catch(CTestException& e)
|
|
|
|
{
|
2015-02-28 21:29:44 +00:00
|
|
|
stringstream ss;
|
|
|
|
|
|
|
|
ss << "An exception occurred trying to list tests for: " << UnicodeToAscii(m_CurrentFile) << endl;
|
|
|
|
StringOut(ss.str());
|
2015-02-28 21:12:25 +00:00
|
|
|
StringOut(e.GetMessage());
|
2015-02-28 21:29:44 +00:00
|
|
|
StringOut("\n");
|
2015-02-28 21:12:25 +00:00
|
|
|
m_CurrentFile.clear();
|
2015-02-28 21:29:44 +00:00
|
|
|
delete[] m_ListBuffer;
|
2015-02-28 21:12:25 +00:00
|
|
|
}
|
2009-03-21 01:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Runs a Wine test and captures the output
|
|
|
|
*
|
|
|
|
* @param TestInfo
|
|
|
|
* Pointer to a CTestInfo object containing information about the test.
|
|
|
|
* Will contain the test log afterwards if the user wants to submit data.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
CWineTest::RunTest(CTestInfo* TestInfo)
|
|
|
|
{
|
|
|
|
DWORD BytesAvailable;
|
2012-02-05 20:56:21 +00:00
|
|
|
stringstream ss, ssFinish;
|
2015-02-18 19:52:04 +00:00
|
|
|
DWORD StartTime;
|
2012-02-05 20:56:21 +00:00
|
|
|
float TotalTime;
|
2015-06-23 09:54:46 +00:00
|
|
|
string tailString;
|
2015-02-16 13:17:04 +00:00
|
|
|
CPipe Pipe;
|
|
|
|
char Buffer[1024];
|
2009-03-21 01:39:04 +00:00
|
|
|
|
|
|
|
ss << "Running Wine Test, Module: " << TestInfo->Module << ", Test: " << TestInfo->Test << endl;
|
2012-08-14 20:25:58 +00:00
|
|
|
StringOut(ss.str());
|
2009-03-21 01:39:04 +00:00
|
|
|
|
2012-02-05 20:56:21 +00:00
|
|
|
StartTime = GetTickCount();
|
|
|
|
|
2015-02-28 21:12:25 +00:00
|
|
|
try
|
2009-03-21 01:39:04 +00:00
|
|
|
{
|
|
|
|
/* Execute the test */
|
2015-02-16 13:17:04 +00:00
|
|
|
CPipedProcess Process(TestInfo->CommandLine, Pipe);
|
2009-03-21 01:39:04 +00:00
|
|
|
|
|
|
|
/* Receive all the data from the pipe */
|
2015-02-16 13:17:04 +00:00
|
|
|
while(Pipe.Read(Buffer, sizeof(Buffer) - 1, &BytesAvailable) && BytesAvailable)
|
2009-03-21 01:39:04 +00:00
|
|
|
{
|
2015-02-16 13:17:04 +00:00
|
|
|
/* Output text through StringOut, even while the test is still running */
|
|
|
|
Buffer[BytesAvailable] = 0;
|
2015-06-23 09:54:46 +00:00
|
|
|
tailString = StringOut(tailString.append(string(Buffer)), false);
|
2009-03-21 01:39:04 +00:00
|
|
|
|
2015-02-16 13:17:04 +00:00
|
|
|
if(Configuration.DoSubmit())
|
|
|
|
TestInfo->Log += Buffer;
|
2009-03-21 01:39:04 +00:00
|
|
|
}
|
2015-02-16 13:17:04 +00:00
|
|
|
if(GetLastError() != ERROR_BROKEN_PIPE)
|
2015-02-28 21:12:25 +00:00
|
|
|
TESTEXCEPTION("CPipe::Read failed for the test run\n");
|
|
|
|
}
|
|
|
|
catch(CTestException& e)
|
|
|
|
{
|
2015-06-23 09:54:46 +00:00
|
|
|
if(!tailString.empty())
|
|
|
|
StringOut(tailString);
|
|
|
|
tailString.clear();
|
2015-02-28 21:12:25 +00:00
|
|
|
StringOut(e.GetMessage());
|
|
|
|
TestInfo->Log += e.GetMessage();
|
2009-03-21 01:39:04 +00:00
|
|
|
}
|
2012-02-05 20:56:21 +00:00
|
|
|
|
2015-06-23 09:54:46 +00:00
|
|
|
/* Print what's left */
|
|
|
|
if(!tailString.empty())
|
|
|
|
StringOut(tailString);
|
|
|
|
|
2012-02-05 20:56:21 +00:00
|
|
|
TotalTime = ((float)GetTickCount() - StartTime)/1000;
|
|
|
|
ssFinish << "Test " << TestInfo->Test << " completed in ";
|
|
|
|
ssFinish << setprecision(2) << fixed << TotalTime << " seconds." << endl;
|
2012-08-14 20:25:58 +00:00
|
|
|
StringOut(ssFinish.str());
|
2015-02-28 21:12:25 +00:00
|
|
|
TestInfo->Log += ssFinish.str();
|
2009-03-21 01:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interface to other classes for running all desired Wine tests.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
CWineTest::Run()
|
|
|
|
{
|
|
|
|
auto_ptr<CTestList> TestList;
|
|
|
|
auto_ptr<CWebService> WebService;
|
|
|
|
CTestInfo* TestInfo;
|
2015-02-28 21:29:44 +00:00
|
|
|
DWORD ErrorMode;
|
2009-03-21 01:39:04 +00:00
|
|
|
|
|
|
|
/* The virtual test list is of course faster, so it should be preferred over
|
|
|
|
the journaled one.
|
|
|
|
Enable the journaled one only in case ...
|
|
|
|
- we're running under ReactOS (as the journal is only useful in conjunction with sysreg2)
|
|
|
|
- we shall keep information for Crash Recovery
|
|
|
|
- and the user didn't specify a module (then doing Crash Recovery doesn't really make sense) */
|
|
|
|
if(Configuration.IsReactOS() && Configuration.DoCrashRecovery() && Configuration.GetModule().empty())
|
|
|
|
{
|
|
|
|
/* Use a test list with a permanent journal */
|
|
|
|
TestList.reset(new CJournaledTestList(this));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Use the fast virtual test list with no additional overhead */
|
|
|
|
TestList.reset(new CVirtualTestList(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the Web Service interface if required */
|
|
|
|
if(Configuration.DoSubmit())
|
|
|
|
WebService.reset(new CWebService());
|
|
|
|
|
2015-02-28 21:29:44 +00:00
|
|
|
/* Disable error dialogs if we're running in non-interactive mode */
|
|
|
|
if(!Configuration.IsInteractive())
|
|
|
|
ErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
|
|
|
|
|
2009-03-21 01:39:04 +00:00
|
|
|
/* Get information for each test to run */
|
|
|
|
while((TestInfo = TestList->GetNextTestInfo()) != 0)
|
|
|
|
{
|
|
|
|
auto_ptr<CTestInfo> TestInfoPtr(TestInfo);
|
|
|
|
|
|
|
|
RunTest(TestInfo);
|
|
|
|
|
|
|
|
if(Configuration.DoSubmit() && !TestInfo->Log.empty())
|
|
|
|
WebService->Submit("wine", TestInfo);
|
|
|
|
|
2012-08-14 20:25:58 +00:00
|
|
|
StringOut("\n\n");
|
2009-03-21 01:39:04 +00:00
|
|
|
}
|
2015-02-28 21:29:44 +00:00
|
|
|
|
2015-03-01 11:19:30 +00:00
|
|
|
/* We're done with all tests. Finish this run */
|
|
|
|
if(Configuration.DoSubmit())
|
|
|
|
WebService->Finish("wine");
|
|
|
|
|
2015-02-28 21:29:44 +00:00
|
|
|
/* Restore the original error mode */
|
|
|
|
if(!Configuration.IsInteractive())
|
|
|
|
SetErrorMode(ErrorMode);
|
2009-03-21 01:39:04 +00:00
|
|
|
}
|