/** * 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; stringstream ss, ssFinish; DWORD StartTime; float TotalTime; string tailString; CPipe Pipe; char Buffer[1024]; ss << "Running Wine Test, Module: " << TestInfo->Module << ", Test: " << TestInfo->Test << endl; StringOut(ss.str()); StartTime = GetTickCount(); try { /* Execute the test */ CPipedProcess Process(TestInfo->CommandLine, Pipe); /* Receive all the data from the pipe */ while(Pipe.Read(Buffer, sizeof(Buffer) - 1, &BytesAvailable) && BytesAvailable) { /* Output text through StringOut, even while the test is still running */ Buffer[BytesAvailable] = 0; tailString = StringOut(tailString.append(string(Buffer)), false); if(Configuration.DoSubmit()) TestInfo->Log += Buffer; } if(GetLastError() != ERROR_BROKEN_PIPE) TESTEXCEPTION("CPipe::Read failed for the test run\n"); } catch(CTestException& e) { if(!tailString.empty()) StringOut(tailString); tailString.clear(); StringOut(e.GetMessage()); TestInfo->Log += e.GetMessage(); } /* Print what's left */ if(!tailString.empty()) StringOut(tailString); TotalTime = ((float)GetTickCount() - StartTime)/1000; ssFinish << "Test " << TestInfo->Test << " completed in "; ssFinish << setprecision(2) << fixed << TotalTime << " seconds." << endl; StringOut(ssFinish.str()); TestInfo->Log += ssFinish.str(); }
/** * 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; CPipe Pipe; /* Build the command line */ CommandLine = m_TestPath; CommandLine += m_CurrentFile; CommandLine += L" --list"; { /* Start the process for getting all available tests */ CPipedProcess Process(CommandLine, Pipe); /* Wait till this process ended */ if(WaitForSingleObject(Process.GetProcessHandle(), ListTimeout) == WAIT_FAILED) TESTEXCEPTION("WaitForSingleObject failed for the test list\n"); } /* Read the output data into a buffer */ if(!Pipe.Peek(NULL, 0, NULL, &BytesAvailable)) TESTEXCEPTION("CPipe::Peek failed for the test list\n"); /* Check if we got any */ if(!BytesAvailable) { stringstream ss; ss << "The --list command did not return any data for " << UnicodeToAscii(m_CurrentFile) << endl; TESTEXCEPTION(ss.str()); } /* Read the data */ m_ListBuffer = new char[BytesAvailable]; if(!Pipe.Read(m_ListBuffer, BytesAvailable, &Temp)) TESTEXCEPTION("CPipe::Read failed\n"); return BytesAvailable; }