2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: LGPLv2+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Kernel-Mode Test Suite Executive Regressions KM-Test
5 * PROGRAMMER: Aleksey Bragin <aleksey@reactos.org>
16 TestTimerApcRoutine(IN PVOID TimerContext
,
17 IN ULONG TimerLowValue
,
18 IN LONG TimerHighValue
)
21 ULONG
*ApcCount
= (ULONG
*)TimerContext
;
22 DPRINT("Timer Apc called!\n");
28 UNICODE_STRING TimerName
;
29 OBJECT_ATTRIBUTES ObjectAttributes
;
32 LARGE_INTEGER DueTime
;
33 BOOLEAN PreviousState
, CurrentState
;
38 RtlInitUnicodeString(&TimerName
, L
"\\TestTimer");
39 InitializeObjectAttributes(&ObjectAttributes
, &TimerName
, 0, NULL
, NULL
);
40 Status
= ZwCreateTimer(&TimerHandle
, TIMER_ALL_ACCESS
,
41 &ObjectAttributes
, NotificationTimer
);
42 ok(Status
== STATUS_SUCCESS
, "ZwCreateTimer failed with Status=0x%08lX", Status
);
45 Status
= ZwOpenTimer(&HandleOpened
, TIMER_ALL_ACCESS
, &ObjectAttributes
);
46 ok(Status
== STATUS_SUCCESS
, "ZwOpenTimer failed with Status=0x%08lX", Status
);
48 // Set the timer, to some rather high value so it doesn't expire
49 DPRINT("Set timer 1\n");
50 DueTime
.LowPart
= -10000;
51 DueTime
.HighPart
= -10;
53 Status
= ZwSetTimer(HandleOpened
, &DueTime
, NULL
, NULL
, FALSE
, 0L, &PreviousState
);
54 ok(Status
== STATUS_SUCCESS
, "ZwSetTimer failed with Status=0x%08lX", Status
);
55 ok(PreviousState
== FALSE
, "Incorrect PreviousState returned when setting the timer");
59 Status
= ZwCancelTimer(HandleOpened
, &CurrentState
);
60 ok(Status
== STATUS_SUCCESS
, "ZwCancelTimer failed with Status=0x%08lX", Status
);
61 ok(CurrentState
== FALSE
, "Incorrect CurrentState returned when canceling the timer");
63 // Set the timer to some small value, because we'll wait for it to expire
64 DPRINT("Set timer 2\n");
65 DueTime
.LowPart
= -100;
66 DueTime
.HighPart
= -1;
68 Status
= ZwSetTimer(HandleOpened
, &DueTime
, NULL
, NULL
, FALSE
, 0L, &PreviousState
);
69 ok(Status
== STATUS_SUCCESS
, "ZwSetTimer failed with Status=0x%08lX", Status
);
70 ok(PreviousState
== FALSE
, "Incorrect PreviousState returned when setting the timer");
72 // Wait until it expires
73 DPRINT("Wait till timer expires\n");
74 Status
= ZwWaitForSingleObject(HandleOpened
, FALSE
, NULL
);
75 ok(Status
== STATUS_SUCCESS
, "ZwWaitForSingleObject failed with Status=0x%08lX", Status
);
78 DPRINT("Cancel it\n");
80 Status
= ZwCancelTimer(HandleOpened
, &CurrentState
);
81 ok(Status
== STATUS_SUCCESS
, "ZwCancelTimer failed with Status=0x%08lX", Status
);
82 ok(CurrentState
== TRUE
, "Incorrect CurrentState returned when setting the timer");
84 // Test it with APC: Set, Cancel, check if APC has been called
85 DPRINT("Set timer with Apc (3)\n");
87 DueTime
.LowPart
= -10000;
88 DueTime
.HighPart
= -10;
89 PreviousState
= FALSE
;
90 Status
= ZwSetTimer(HandleOpened
, &DueTime
,
91 (PTIMER_APC_ROUTINE
)TestTimerApcRoutine
, &ApcCount
, FALSE
,
94 ok(Status
== STATUS_SUCCESS
, "ZwSetTimer failed with Status=0x%08lX", Status
);
95 ok(PreviousState
== TRUE
, "Incorrect PreviousState returned when setting the timer");
97 DPRINT("Cancel it\n");
99 Status
= ZwCancelTimer(HandleOpened
, &CurrentState
);
100 ok(Status
== STATUS_SUCCESS
, "ZwCancelTimer failed with Status=0x%08lX", Status
);
101 ok(CurrentState
== FALSE
, "Incorrect CurrentState returned when cancelling the timer");
102 ok(ApcCount
== 0, "Incorrect count of TimerApcRoutine calls: %ld, should be 0\n", ApcCount
);
104 // Test setting the timer two times in a row, APC routine must not be called
105 DPRINT("Set timer with Apc (4)\n");
107 DueTime
.LowPart
= -10000;
108 DueTime
.HighPart
= -10;
109 PreviousState
= TRUE
;
110 Status
= ZwSetTimer(HandleOpened
, &DueTime
,
111 (PTIMER_APC_ROUTINE
)TestTimerApcRoutine
, &ApcCount
, FALSE
,
113 ok(Status
== STATUS_SUCCESS
, "ZwSetTimer failed with Status=0x%08lX", Status
);
114 ok(PreviousState
== FALSE
, "Incorrect PreviousState returned when setting the timer");
116 // Set small due time, since we have to wait for timer to finish
117 DPRINT("Set timer with Apc (5)\n");
118 DueTime
.LowPart
= -10;
119 DueTime
.HighPart
= -1;
120 PreviousState
= TRUE
;
121 Status
= ZwSetTimer(HandleOpened
, &DueTime
,
122 (PTIMER_APC_ROUTINE
)TestTimerApcRoutine
, &ApcCount
, FALSE
,
124 ok(Status
== STATUS_SUCCESS
, "ZwSetTimer failed with Status=0x%08lX", Status
);
125 ok(PreviousState
== FALSE
, "Incorrect PreviousState returned when setting the timer");
127 // Now wait till it's finished, and then check APC call
128 DPRINT("Wait for it\n");
129 Status
= ZwWaitForSingleObject(HandleOpened
, FALSE
, NULL
);
130 ok(Status
== STATUS_SUCCESS
, "ZwWaitForSingleObject failed with Status=0x%08lX", Status
);
132 CurrentState
= FALSE
;
133 Status
= ZwCancelTimer(HandleOpened
, &CurrentState
);
134 ok(Status
== STATUS_SUCCESS
, "ZwCancelTimer failed with Status=0x%08lX", Status
);
135 ok(CurrentState
== TRUE
, "Incorrect CurrentState returned when cancelling the timer");
136 ok(ApcCount
== 1, "Incorrect count of TimerApcRoutine calls: %ld, should be 1\n", ApcCount
);
139 Status
= ZwClose(HandleOpened
);
140 ok(Status
== STATUS_SUCCESS
, "ZwClose failed with Status=0x%08lX", Status
);
142 Status
= ZwClose(TimerHandle
);
143 ok(Status
== STATUS_SUCCESS
, "ZwClose failed with Status=0x%08lX", Status
);