Merge aicom-network-branch (without NDIS changes for now)
[reactos.git] / rostests / tests / suspend / suspend.c
1 #define UNICODE
2 #define WIN32_NO_STATUS
3 #include <windows.h>
4 #include <stdio.h>
5 #define NTOS_MODE_USER
6 #include <ndk/ntndk.h>
7
8 #define NDEBUG
9 #include <debug.h>
10
11 static volatile DWORD z;
12 static volatile DWORD x=0;
13
14 static NTSTATUS WINAPI
15 thread_1(PVOID Param)
16 {
17 DWORD y=0;
18
19 for(;;)
20 {
21 z++;
22 if(x>50)
23 {
24 printf("I should have been suspended for years :-)\n");
25 Sleep(100);
26 x=0;y++;
27 if(y==3) ExitProcess(0);
28 }
29 }
30 }
31
32 int
33 main(int argc, char *argv[])
34 {
35 HANDLE thread;
36 DWORD thread_id;
37 CONTEXT context;
38
39 context.ContextFlags=CONTEXT_CONTROL;
40
41 z=0;
42 thread=CreateThread(NULL,
43 0x1000,
44 (LPTHREAD_START_ROUTINE)thread_1,
45 NULL,
46 0,
47 &thread_id);
48
49 if(!thread)
50 {
51 printf("Error: could not create thread ...\n");
52 ExitProcess(0);
53 }
54
55 Sleep(1000);
56
57 SuspendThread(thread);
58
59 for(;;)
60 {
61 printf("%lx ", z);
62 Sleep(100);x++;
63 if(x>100 && GetThreadContext(thread, &context))
64 {
65 printf("EIP: %lx\n", context.Eip);
66 printf("Calling resumethread ... \n");
67 ResumeThread(thread);
68 }
69 }
70
71 ExitProcess(0);
72 return(0);
73 }