Commit fd9e86e8 authored by Dāvis Mosāns's avatar Dāvis Mosāns Committed by Brad King

ConsoleBuf: Use two separate events for test sync

Split the before-input and after-output cases since the parent must
act between them.

Change-Id: I14b704ea927c7ce7258d40ac105577a355cdcd13
parent f53440fe
......@@ -44,7 +44,8 @@ static UINT TestCodepage = KWSYS_ENCODING_DEFAULT_CODEPAGE;
static const DWORD waitTimeout = 10 * 1000;
static STARTUPINFO startupInfo;
static PROCESS_INFORMATION processInfo;
static HANDLE syncEvent;
static HANDLE beforeInputEvent;
static HANDLE afterOutputEvent;
static std::string encodedInputTestString;
static std::string encodedTestString;
......@@ -259,9 +260,8 @@ static int testPipe()
if (createProcess(inPipeRead, outPipeWrite, errPipeWrite)) {
try {
Sleep(100);
DWORD status;
if ((status = WaitForSingleObject(syncEvent, waitTimeout)) != WAIT_OBJECT_0) {
if ((status = WaitForSingleObject(afterOutputEvent, waitTimeout)) != WAIT_OBJECT_0) {
std::cerr.setf(std::ios::hex, std::ios::basefield);
std::cerr << "WaitForSingleObject returned unexpected status 0x" << status << std::endl;
std::cerr.unsetf(std::ios::hex);
......@@ -347,9 +347,8 @@ static int testFile()
if (createProcess(inFile, outFile, errFile)) {
DWORD bytesRead = 0;
try {
Sleep(100);
DWORD status;
if ((status = WaitForSingleObject(syncEvent, waitTimeout)) != WAIT_OBJECT_0) {
if ((status = WaitForSingleObject(afterOutputEvent, waitTimeout)) != WAIT_OBJECT_0) {
std::cerr.setf(std::ios::hex, std::ios::basefield);
std::cerr << "WaitForSingleObject returned unexpected status 0x" << status << std::endl;
std::cerr.unsetf(std::ios::hex);
......@@ -540,7 +539,7 @@ static int testConsole()
if (createProcess(NULL, NULL, NULL)) {
try {
DWORD status;
if ((status = WaitForSingleObject(syncEvent, waitTimeout)) != WAIT_OBJECT_0) {
if ((status = WaitForSingleObject(beforeInputEvent, waitTimeout)) != WAIT_OBJECT_0) {
std::cerr.setf(std::ios::hex, std::ios::basefield);
std::cerr << "WaitForSingleObject returned unexpected status 0x" << status << std::endl;
std::cerr.unsetf(std::ios::hex);
......@@ -561,7 +560,7 @@ static int testConsole()
&eventsWritten) || eventsWritten == 0) {
throw std::runtime_error("WriteConsoleInput failed!");
}
if ((status = WaitForSingleObject(syncEvent, waitTimeout)) != WAIT_OBJECT_0) {
if ((status = WaitForSingleObject(afterOutputEvent, waitTimeout)) != WAIT_OBJECT_0) {
std::cerr.setf(std::ios::hex, std::ios::basefield);
std::cerr << "WaitForSingleObject returned unexpected status 0x" << status << std::endl;
std::cerr.unsetf(std::ios::hex);
......@@ -625,12 +624,18 @@ int testConsoleBuf(int, char*[])
int ret = 0;
#if defined(_WIN32)
syncEvent = CreateEventW(NULL,
FALSE, // auto-reset event
FALSE, // initial state is nonsignaled
SyncEventName); // object name
if (!syncEvent) {
std::cerr << "CreateEvent failed " << GetLastError() << std::endl;
beforeInputEvent = CreateEventW(NULL,
FALSE, // auto-reset event
FALSE, // initial state is nonsignaled
BeforeInputEventName); // object name
if (!beforeInputEvent) {
std::cerr << "CreateEvent#1 failed " << GetLastError() << std::endl;
return 1;
}
afterOutputEvent = CreateEventW(NULL, FALSE, FALSE, AfterOutputEventName);
if (!afterOutputEvent) {
std::cerr << "CreateEvent#2 failed " << GetLastError() << std::endl;
return 1;
}
......@@ -642,7 +647,8 @@ int testConsoleBuf(int, char*[])
ret |= testFile();
ret |= testConsole();
CloseHandle(syncEvent);
CloseHandle(beforeInputEvent);
CloseHandle(afterOutputEvent);
#endif
return ret;
......
......@@ -14,7 +14,8 @@
static const wchar_t cmdConsoleBufChild[] = L"testConsoleBufChild";
static const wchar_t SyncEventName[] = L"SyncEvent";
static const wchar_t BeforeInputEventName[] = L"BeforeInputEvent";
static const wchar_t AfterOutputEventName[] = L"AfterOutputEvent";
// यूनिकोड είναι здорово!
static const wchar_t UnicodeTestString[] = L"\u092F\u0942\u0928\u093F\u0915\u094B\u0921 "
......
......@@ -42,16 +42,18 @@ int main(int argc, const char* argv[])
}
std::string input;
HANDLE syncEvent = OpenEventW(EVENT_MODIFY_STATE, FALSE, SyncEventName);
if (syncEvent) {
SetEvent(syncEvent);
HANDLE event = OpenEventW(EVENT_MODIFY_STATE, FALSE, BeforeInputEventName);
if (event) {
SetEvent(event);
CloseHandle(event);
}
std::cin >> input;
std::cout << input << std::endl;
if (syncEvent) {
SetEvent(syncEvent);
CloseHandle(syncEvent);
event = OpenEventW(EVENT_MODIFY_STATE, FALSE, AfterOutputEventName);
if (event) {
SetEvent(event);
CloseHandle(event);
}
#else
static_cast<void>(argc);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment