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