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
23int __cdecl main(int argc, char **argv)
24{
25
26//Declare local variables
27STARTUPINFO si;
28PROCESS_INFORMATION pi;
29
30DWORD dwWaitResult=0;
31
32//Initialize PAL
33if(0 != (PAL_Initialize(argc, argv)))
34 {
35 return ( FAIL );
36 }
37
38
39ZeroMemory( &si, sizeof(si) );
40si.cb = sizeof(si);
41ZeroMemory( &pi, sizeof(pi) );
42
43// Start the child process.
44if( !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{
57Fail ( "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 );
63switch (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
102if (0==CloseHandle(pi.hProcess))
103 {
104 Trace("Could not close process handle\n");
105 Fail ( "GetLastError returned %d\n", GetLastError());
106 }
107
108
109PAL_Terminate();
110return ( PASS );
111
112}
113
114
115
116
117
118
119
120