| 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: WFSOProcessTest.c |
| 8 | ** |
| 9 | ** Purpose: Test for WaitForSingleObjectTest. |
| 10 | ** Create One Process and do some work |
| 11 | ** Use WFSO For the Process to finish |
| 12 | ** |
| 13 | ** Test Passes if the above operations are successful |
| 14 | ** |
| 15 | ** |
| 16 | ** |
| 17 | **=========================================================*/ |
| 18 | |
| 19 | |
| 20 | |
| 21 | #include <palsuite.h> |
| 22 | |
| 23 | int __cdecl main(int argc, char **argv) |
| 24 | { |
| 25 | |
| 26 | //Declare local variables |
| 27 | STARTUPINFO si; |
| 28 | PROCESS_INFORMATION pi; |
| 29 | |
| 30 | DWORD dwWaitResult=0; |
| 31 | |
| 32 | //Initialize PAL |
| 33 | if(0 != (PAL_Initialize(argc, argv))) |
| 34 | { |
| 35 | return ( FAIL ); |
| 36 | } |
| 37 | |
| 38 | |
| 39 | ZeroMemory( &si, sizeof(si) ); |
| 40 | si.cb = sizeof(si); |
| 41 | ZeroMemory( &pi, sizeof(pi) ); |
| 42 | |
| 43 | // Start the child process. |
| 44 | if( !CreateProcess( NULL, // No module name (use command line). |
| 45 | "childprocess" , // Command line. |
| 46 | NULL, // Process handle not inheritable. |
| 47 | NULL, // Thread handle not inheritable. |
| 48 | FALSE, // Set handle inheritance to FALSE. |
| 49 | 0, // No creation flags. |
| 50 | NULL, // Use parent's environment block. |
| 51 | NULL, // Use parent's starting directory. |
| 52 | &si, // Pointer to STARTUPINFO structure. |
| 53 | &pi ) // Pointer to PROCESS_INFORMATION structure. |
| 54 | ) |
| 55 | |
| 56 | { |
| 57 | Fail ( "Create Process Failed. Failing test.\n" |
| 58 | "GetLastError returned %d\n" , GetLastError()); |
| 59 | } |
| 60 | |
| 61 | // Wait until child process exits. |
| 62 | dwWaitResult = WaitForSingleObject( pi.hProcess, INFINITE ); |
| 63 | switch (dwWaitResult) |
| 64 | { |
| 65 | // The Process wait was successful |
| 66 | case WAIT_OBJECT_0: |
| 67 | { |
| 68 | |
| 69 | Trace("Wait for Process was successful\n" ); |
| 70 | break; |
| 71 | } |
| 72 | |
| 73 | // Time-out. |
| 74 | case WAIT_TIMEOUT: |
| 75 | { |
| 76 | Fail ( "Time -out. Failing test.\n" |
| 77 | "GetLastError returned %d\n" , GetLastError()); |
| 78 | return FALSE; |
| 79 | } |
| 80 | |
| 81 | // Got ownership of the abandoned process object. |
| 82 | case WAIT_ABANDONED: |
| 83 | { |
| 84 | Fail ( "Got ownership of the abandoned Process object. Failing test.\n" |
| 85 | "GetLastError returned %d\n" , GetLastError()); |
| 86 | return FALSE; |
| 87 | } |
| 88 | |
| 89 | //Error condition |
| 90 | case WAIT_FAILED: |
| 91 | { |
| 92 | Fail ( "Wait for Process Failed. Failing test.\n" |
| 93 | "GetLastError returned %d\n" , GetLastError()); |
| 94 | return FALSE; |
| 95 | } |
| 96 | |
| 97 | } |
| 98 | |
| 99 | |
| 100 | |
| 101 | // Close process handle |
| 102 | if (0==CloseHandle(pi.hProcess)) |
| 103 | { |
| 104 | Trace("Could not close process handle\n" ); |
| 105 | Fail ( "GetLastError returned %d\n" , GetLastError()); |
| 106 | } |
| 107 | |
| 108 | |
| 109 | PAL_Terminate(); |
| 110 | return ( PASS ); |
| 111 | |
| 112 | } |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |