| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | |
| 5 | /*============================================================= |
| 6 | ** |
| 7 | ** Source: test1.c |
| 8 | ** |
| 9 | ** Purpose: Debugs the helper application. Checks that certain events, in |
| 10 | ** particular the OUTPUT_DEBUG_STRING_EVENT, is generated correctly |
| 11 | ** and gives the correct values. |
| 12 | ** |
| 13 | ** |
| 14 | **============================================================*/ |
| 15 | |
| 16 | #include <palsuite.h> |
| 17 | |
| 18 | const int DELAY_MS = 2000; |
| 19 | |
| 20 | struct OutputCheck |
| 21 | { |
| 22 | DWORD ExpectedEventCode; |
| 23 | DWORD ExpectedUnicode; |
| 24 | char *ExpectedStr; |
| 25 | }; |
| 26 | |
| 27 | int __cdecl main(int argc, char *argv[]) |
| 28 | { |
| 29 | |
| 30 | PROCESS_INFORMATION pi; |
| 31 | STARTUPINFO si; |
| 32 | |
| 33 | if(0 != (PAL_Initialize(argc, argv))) |
| 34 | { |
| 35 | return FAIL; |
| 36 | } |
| 37 | |
| 38 | ZeroMemory( &si, sizeof(si) ); |
| 39 | si.cb = sizeof(si); |
| 40 | ZeroMemory( &pi, sizeof(pi) ); |
| 41 | |
| 42 | /* Create a new process. This is the process to be Debugged */ |
| 43 | if(!CreateProcess( NULL, "helper" , NULL, NULL, |
| 44 | FALSE, 0, NULL, NULL, &si, &pi)) |
| 45 | { |
| 46 | Fail("ERROR: CreateProcess failed to load executable 'helper'. " |
| 47 | "GetLastError() returned %d.\n" ,GetLastError()); |
| 48 | } |
| 49 | |
| 50 | /* This is the main loop. It exits when the process which is being |
| 51 | debugged is finished executing. |
| 52 | */ |
| 53 | |
| 54 | while(1) |
| 55 | { |
| 56 | DWORD dwRet = 0; |
| 57 | dwRet = WaitForSingleObject(pi.hProcess, |
| 58 | DELAY_MS /* Wait for 2 seconds max*/ |
| 59 | ); |
| 60 | |
| 61 | if (dwRet != WAIT_OBJECT_0) |
| 62 | { |
| 63 | Trace("WaitForSingleObjectTest:WaitForSingleObject " |
| 64 | "failed (%x) after waiting %d seconds for the helper\n" , |
| 65 | GetLastError(), DELAY_MS / 1000); |
| 66 | } |
| 67 | else |
| 68 | { |
| 69 | DWORD dwExitCode; |
| 70 | |
| 71 | /* check the exit code from the process */ |
| 72 | if( ! GetExitCodeProcess( pi.hProcess, &dwExitCode ) ) |
| 73 | { |
| 74 | DWORD dwError; |
| 75 | |
| 76 | dwError = GetLastError(); |
| 77 | CloseHandle ( pi.hProcess ); |
| 78 | CloseHandle ( pi.hThread ); |
| 79 | Fail( "GetExitCodeProcess call failed with error code %d\n" , |
| 80 | dwError ); |
| 81 | } |
| 82 | |
| 83 | if(dwExitCode != STILL_ACTIVE) { |
| 84 | CloseHandle(pi.hThread); |
| 85 | CloseHandle(pi.hProcess); |
| 86 | break; |
| 87 | } |
| 88 | Trace("still executing %d..\n" , dwExitCode); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | PAL_Terminate(); |
| 93 | return PASS; |
| 94 | } |
| 95 | |