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: childprocess.c
8**
9** Purpose: Test to ensure OpenProcess works properly.
10** All this program does is return a predefined value.
11**
12** Dependencies: PAL_Initialize
13** PAL_Terminate
14** CreateMutexW
15** WaitForSingleObject
16** CloseHandle
17**
18**
19**=========================================================*/
20
21#include <palsuite.h>
22#include "myexitcode.h"
23
24
25int __cdecl main( int argc, char **argv )
26{
27 HANDLE hMutex;
28 WCHAR wszMutexName[] = { 'T','E','S','T','1','\0' };
29 DWORD dwRet;
30 int i;
31
32 /* initialize the PAL */
33 if( PAL_Initialize(argc, argv) != 0 )
34 {
35 return( FAIL );
36 }
37
38 /* open a mutex to synchronize with the parent process */
39 hMutex = CreateMutexW( NULL, FALSE, wszMutexName );
40 if( hMutex == NULL )
41 {
42 Fail( "ERROR:%lu:CreateMutex() call failed\r\n", GetLastError() );
43 }
44
45 /* acquire the mutex lock */
46 dwRet = WaitForSingleObject( hMutex, 10000 );
47 if( dwRet != WAIT_OBJECT_0 )
48 {
49 Trace( "ERROR:WaitForSingleObject() returned %lu, "
50 "expected WAIT_OBJECT_0",
51 dwRet );
52 if( ! CloseHandle( hMutex ) )
53 {
54 Trace( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() );
55 }
56 Fail( "test failed\n" );
57 }
58
59
60 /* simulate some activity */
61 for( i=0; i<50000; i++ )
62 ;
63
64 /* close our mutex handle */
65 if( ! CloseHandle( hMutex ) )
66 {
67 Fail( "ERROR:%lu:CloseHandle() call failed\n", GetLastError() );
68 }
69
70 /* terminate the PAL */
71 PAL_Terminate();
72
73 /* return the predefined exit code */
74 return TEST_EXIT_CODE;
75}
76