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