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: test1.c
8**
9** Purpose: Test for ResumeThread. Create a suspended Thread.
10** First, ensure that it is indeed suspended. Then call resumethread
11** and check to ensure that the function has now run.
12**
13**
14**=========================================================*/
15
16#include <palsuite.h>
17
18DWORD dwResumeThreadTestParameter = 0;
19
20DWORD PALAPI ResumeThreadTestThread( LPVOID lpParameter)
21{
22 DWORD dwRet = 0;
23
24 /* Save parameter so we can check and ensure this function ran
25 properly.
26 */
27
28 dwResumeThreadTestParameter = (DWORD)lpParameter;
29
30 return dwRet;
31}
32
33BOOL ResumeThreadTest()
34{
35 BOOL bRet = FALSE;
36 DWORD dwRet = 0;
37
38 LPSECURITY_ATTRIBUTES lpThreadAttributes = NULL;
39 DWORD dwStackSize = 0;
40 LPTHREAD_START_ROUTINE lpStartAddress = &ResumeThreadTestThread;
41 LPVOID lpParameter = (LPVOID)lpStartAddress;
42 DWORD dwCreationFlags = CREATE_SUSPENDED;
43 DWORD dwThreadId = 0;
44
45 HANDLE hThread = 0;
46
47 dwResumeThreadTestParameter = 0;
48
49 /* Create a thread, with CREATE_SUSPENDED, so we can resume it! */
50
51 hThread = CreateThread( lpThreadAttributes,
52 dwStackSize, lpStartAddress, lpParameter,
53 dwCreationFlags, &dwThreadId );
54
55 if (hThread != INVALID_HANDLE_VALUE)
56 {
57 /* Wait for one second. This should return WAIT_TIMEOUT */
58 dwRet = WaitForSingleObject(hThread,1000);
59
60 if (dwRet != WAIT_TIMEOUT)
61 {
62 Trace("ResumeThreadTest:WaitForSingleObject "
63 "failed (%x)\n",GetLastError());
64 }
65 else
66 {
67 /* Check to ensure the parameter hasn't changed. The
68 function shouldn't have occurred yet.
69 */
70 if (dwResumeThreadTestParameter != 0)
71 {
72 Trace("ResumeThreadTest:parameter error\n");
73 }
74 else
75 {
76 /* Call ResumeThread and ensure the return value is
77 correct.
78 */
79
80 dwRet = ResumeThread(hThread);
81
82 if (dwRet != 1)
83 {
84 Trace("ResumeThreadTest:ResumeThread "
85 "failed (%x)\n",GetLastError());
86 }
87 else
88 {
89 /* Wait again, now that the thread has been
90 resumed, and the return should be WAIT_OBJECT_0
91 */
92 dwRet = WaitForSingleObject(hThread,INFINITE);
93
94 if (dwRet != WAIT_OBJECT_0)
95 {
96 Trace("ResumeThreadTest:WaitForSingleObject "
97 "failed (%x)\n",GetLastError());
98 }
99 else
100 {
101 /* Check the param now and it should have been
102 set.
103 */
104 if (dwResumeThreadTestParameter != (DWORD)lpParameter)
105 {
106 Trace("ResumeThreadTest:parameter error\n");
107 }
108 else
109 {
110 bRet = TRUE;
111 }
112 }
113 }
114 }
115 }
116 }
117 else
118 {
119 Trace("ResumeThreadTest:CreateThread failed (%x)\n",GetLastError());
120 }
121
122 return bRet;
123}
124
125int __cdecl main(int argc, char **argv)
126{
127
128 if(0 != (PAL_Initialize(argc, argv)))
129 {
130 return ( FAIL );
131 }
132
133 if(!ResumeThreadTest())
134 {
135 Fail("Test Failed\n");
136 }
137
138 PAL_Terminate();
139 return (PASS);
140
141}
142