Index: CWineTest.cpp =================================================================== --- modules/rostests_disabled/rosautotest/CWineTest.cpp (revision 64658) +++ modules/rostests_disabled/rosautotest/CWineTest.cpp (working copy) @@ -9,6 +9,27 @@ static const DWORD ListTimeout = 10000; +void CWineTest::CreatePipes() +{ + SECURITY_ATTRIBUTES SecurityAttributes; + + if(m_hReadPipe) + CloseHandle(m_hReadPipe); + if(m_hWritePipe) + CloseHandle(m_hWritePipe); + + /* Create a pipe for getting the output of the tests */ + SecurityAttributes.nLength = sizeof(SecurityAttributes); + SecurityAttributes.bInheritHandle = TRUE; + SecurityAttributes.lpSecurityDescriptor = NULL; + + if(!CreatePipe(&m_hReadPipe, &m_hWritePipe, &SecurityAttributes, 0)) + FATAL("CreatePipe failed\n"); + + m_StartupInfo.hStdOutput = m_hWritePipe; + m_StartupInfo.hStdError = m_hWritePipe; +} + /** * Constructs a CWineTest object. */ @@ -118,8 +139,11 @@ CommandLine += L" --list"; { + CreatePipes(); /* Start the process for getting all available tests */ CProcess Process(CommandLine, &m_StartupInfo); + CloseHandle(m_hWritePipe); + m_hWritePipe = NULL; /* Wait till this process ended */ if(WaitForSingleObject(Process.GetProcessHandle(), ListTimeout) == WAIT_FAILED) @@ -260,13 +284,12 @@ void CWineTest::RunTest(CTestInfo* TestInfo) { - bool BreakLoop = false; DWORD BytesAvailable; - DWORD Temp; stringstream ss, ssFinish; DWORD StartTime = GetTickCount(); float TotalTime; string tailString; + char Buffer[1024]; ss << "Running Wine Test, Module: " << TestInfo->Module << ", Test: " << TestInfo->Test << endl; StringOut(ss.str()); @@ -275,40 +298,23 @@ { /* Execute the test */ + CreatePipes(); CProcess Process(TestInfo->CommandLine, &m_StartupInfo); + CloseHandle(m_hWritePipe); + m_hWritePipe = NULL; /* Receive all the data from the pipe */ - do + while(ReadFile(m_hReadPipe, Buffer, sizeof(Buffer) - 1, &BytesAvailable, NULL) && BytesAvailable) { - /* When the application finished, make sure that we peek the pipe one more time, so that we get all data. - If the following condition would be the while() condition, we might hit a race condition: - - We check for data with PeekNamedPipe -> no data available - - The application outputs its data and finishes - - WaitForSingleObject reports that the application has finished and we break the loop without receiving any data - */ - if(WaitForSingleObject(Process.GetProcessHandle(), 0) != WAIT_TIMEOUT) - BreakLoop = true; + /* Output text through StringOut, even while the test is still running */ + Buffer[BytesAvailable] = 0; + tailString = StringOut(tailString.append(string(Buffer)), false); - if(!PeekNamedPipe(m_hReadPipe, NULL, 0, NULL, &BytesAvailable, NULL)) - FATAL("PeekNamedPipe failed for the test run\n"); - - if(BytesAvailable) - { - /* There is data, so get it and output it */ - auto_array_ptr Buffer(new char[BytesAvailable + 1]); - - if(!ReadFile(m_hReadPipe, Buffer, BytesAvailable, &Temp, NULL)) - FATAL("ReadFile failed for the test run\n"); - - /* 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(Configuration.DoSubmit()) + TestInfo->Log += Buffer; } - while(!BreakLoop); + if(GetLastError() != ERROR_BROKEN_PIPE) + FATAL("ReadFile failed for the test run\n"); } /* Print what's left */ @@ -330,16 +336,7 @@ auto_ptr TestList; auto_ptr WebService; CTestInfo* TestInfo; - SECURITY_ATTRIBUTES SecurityAttributes; - /* Create a pipe for getting the output of the tests */ - SecurityAttributes.nLength = sizeof(SecurityAttributes); - SecurityAttributes.bInheritHandle = TRUE; - SecurityAttributes.lpSecurityDescriptor = NULL; - - if(!CreatePipe(&m_hReadPipe, &m_hWritePipe, &SecurityAttributes, 0)) - FATAL("CreatePipe failed\n"); - m_StartupInfo.cb = sizeof(m_StartupInfo); m_StartupInfo.dwFlags = STARTF_USESTDHANDLES; m_StartupInfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE); Index: CWineTest.h =================================================================== --- modules/rostests_disabled/rosautotest/CWineTest.h (revision 64658) +++ modules/rostests_disabled/rosautotest/CWineTest.h (working copy) @@ -23,6 +23,7 @@ CTestInfo* GetNextTestInfo(); DWORD DoListCommand(); void RunTest(CTestInfo* TestInfo); + void CreatePipes(); public: CWineTest(); Index: tools.cpp =================================================================== --- modules/rostests_disabled/rosautotest/tools.cpp (revision 64658) +++ modules/rostests_disabled/rosautotest/tools.cpp (working copy) @@ -143,14 +143,14 @@ } } - /* Output the string */ - cout << NewString; - size = curr_pos - start; /* Only print if forced to or if the rest is a whole line */ if(forcePrint == true || NewString[curr_pos - 1] == '\n') { + /* Output the whole string */ + cout << NewString; + memcpy(DbgString, NewString.c_str() + start, size); DbgString[size] = 0; DbgPrint(DbgString); @@ -159,6 +159,9 @@ return NewString; } + /* Output full lines only */ + cout << NewString.substr(0, start); + /* Return the remaining chunk */ return NewString.substr(start, size); }