2 * NTOSKRNL Executive Regressions KM-Test
3 * ReactOS Kernel Mode Regression Testing framework
5 * Copyright 2006 Aleksey Bragin <aleksey@reactos.org>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; see the file COPYING.LIB.
19 * If not, write to the Free Software Foundation,
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 /* INCLUDES *******************************************************************/
25 #include <ddk/ntddk.h>
27 #include <ndk/ntndk.h>
33 /* PRIVATE FUNCTIONS ***********************************************************/
37 TestTimerApcRoutine(IN PVOID TimerContext
,
38 IN ULONG TimerLowValue
,
39 IN LONG TimerHighValue
)
42 ULONG
*ApcCount
= (ULONG
*)TimerContext
;
43 DPRINT("Timer Apc called!\n");
47 /* PUBLIC FUNCTIONS *************************************************************/
50 ExTimerTest(HANDLE KeyHandle
)
52 UNICODE_STRING TimerName
;
53 OBJECT_ATTRIBUTES ObjectAttributes
;
56 LARGE_INTEGER DueTime
;
57 BOOLEAN PreviousState
, CurrentState
;
64 RtlInitUnicodeString(&TimerName
, L
"\\TestTimer");
65 InitializeObjectAttributes(&ObjectAttributes
, &TimerName
, 0, NULL
, NULL
);
66 Status
= ZwCreateTimer(&TimerHandle
, TIMER_ALL_ACCESS
,
67 &ObjectAttributes
, NotificationTimer
);
68 ok(Status
== STATUS_SUCCESS
, "ZwCreateTimer failed with Status=0x%08lX", Status
);
71 Status
= ZwOpenTimer(&HandleOpened
, TIMER_ALL_ACCESS
, &ObjectAttributes
);
72 ok(Status
== STATUS_SUCCESS
, "ZwOpenTimer failed with Status=0x%08lX", Status
);
74 // Set the timer, to some rather high value so it doesn't expire
75 DPRINT("Set timer 1\n");
76 DueTime
.LowPart
= -10000;
77 DueTime
.HighPart
= -10;
79 Status
= ZwSetTimer(HandleOpened
, &DueTime
, NULL
, NULL
, FALSE
, 0L, &PreviousState
);
80 ok(Status
== STATUS_SUCCESS
, "ZwSetTimer failed with Status=0x%08lX", Status
);
81 ok(PreviousState
== FALSE
, "Incorrect PreviousState returned when setting the timer");
85 Status
= ZwCancelTimer(HandleOpened
, &CurrentState
);
86 ok(Status
== STATUS_SUCCESS
, "ZwCancelTimer failed with Status=0x%08lX", Status
);
87 ok(CurrentState
== FALSE
, "Incorrect CurrentState returned when canceling the timer");
89 // Set the timer to some small value, because we'll wait for it to expire
90 DPRINT("Set timer 2\n");
91 DueTime
.LowPart
= -100;
92 DueTime
.HighPart
= -1;
94 Status
= ZwSetTimer(HandleOpened
, &DueTime
, NULL
, NULL
, FALSE
, 0L, &PreviousState
);
95 ok(Status
== STATUS_SUCCESS
, "ZwSetTimer failed with Status=0x%08lX", Status
);
96 ok(PreviousState
== FALSE
, "Incorrect PreviousState returned when setting the timer");
98 // Wait until it expires
99 DPRINT("Wait till timer expires\n");
100 Status
= ZwWaitForSingleObject(HandleOpened
, FALSE
, NULL
);
101 ok(Status
== STATUS_SUCCESS
, "ZwWaitForSingleObject failed with Status=0x%08lX", Status
);
104 DPRINT("Cancel it\n");
105 CurrentState
= FALSE
;
106 Status
= ZwCancelTimer(HandleOpened
, &CurrentState
);
107 ok(Status
== STATUS_SUCCESS
, "ZwCancelTimer failed with Status=0x%08lX", Status
);
108 ok(CurrentState
== TRUE
, "Incorrect CurrentState returned when setting the timer");
110 // Test it with APC: Set, Cancel, check if APC has been called
111 DPRINT("Set timer with Apc (3)\n");
113 DueTime
.LowPart
= -10000;
114 DueTime
.HighPart
= -10;
115 PreviousState
= FALSE
;
116 Status
= ZwSetTimer(HandleOpened
, &DueTime
,
117 (PTIMER_APC_ROUTINE
)TestTimerApcRoutine
, &ApcCount
, FALSE
,
120 ok(Status
== STATUS_SUCCESS
, "ZwSetTimer failed with Status=0x%08lX", Status
);
121 ok(PreviousState
== TRUE
, "Incorrect PreviousState returned when setting the timer");
123 DPRINT("Cancel it\n");
125 Status
= ZwCancelTimer(HandleOpened
, &CurrentState
);
126 ok(Status
== STATUS_SUCCESS
, "ZwCancelTimer failed with Status=0x%08lX", Status
);
127 ok(CurrentState
== FALSE
, "Incorrect CurrentState returned when cancelling the timer");
128 ok(ApcCount
== 0, "Incorrect count of TimerApcRoutine calls: %ld, should be 0\n", ApcCount
);
130 // Test setting the timer two times in a row, APC routine must not be called
131 DPRINT("Set timer with Apc (4)\n");
133 DueTime
.LowPart
= -10000;
134 DueTime
.HighPart
= -10;
135 PreviousState
= TRUE
;
136 Status
= ZwSetTimer(HandleOpened
, &DueTime
,
137 (PTIMER_APC_ROUTINE
)TestTimerApcRoutine
, &ApcCount
, FALSE
,
139 ok(Status
== STATUS_SUCCESS
, "ZwSetTimer failed with Status=0x%08lX", Status
);
140 ok(PreviousState
== FALSE
, "Incorrect PreviousState returned when setting the timer");
142 // Set small due time, since we have to wait for timer to finish
143 DPRINT("Set timer with Apc (5)\n");
144 DueTime
.LowPart
= -10;
145 DueTime
.HighPart
= -1;
146 PreviousState
= TRUE
;
147 Status
= ZwSetTimer(HandleOpened
, &DueTime
,
148 (PTIMER_APC_ROUTINE
)TestTimerApcRoutine
, &ApcCount
, FALSE
,
150 ok(Status
== STATUS_SUCCESS
, "ZwSetTimer failed with Status=0x%08lX", Status
);
151 ok(PreviousState
== FALSE
, "Incorrect PreviousState returned when setting the timer");
153 // Now wait till it's finished, and then check APC call
154 DPRINT("Wait for it\n");
155 Status
= ZwWaitForSingleObject(HandleOpened
, FALSE
, NULL
);
156 ok(Status
== STATUS_SUCCESS
, "ZwWaitForSingleObject failed with Status=0x%08lX", Status
);
158 CurrentState
= FALSE
;
159 Status
= ZwCancelTimer(HandleOpened
, &CurrentState
);
160 ok(Status
== STATUS_SUCCESS
, "ZwCancelTimer failed with Status=0x%08lX", Status
);
161 ok(CurrentState
== TRUE
, "Incorrect CurrentState returned when cancelling the timer");
162 ok(ApcCount
== 1, "Incorrect count of TimerApcRoutine calls: %ld, should be 1\n", ApcCount
);
165 Status
= ZwClose(HandleOpened
);
166 ok(Status
== STATUS_SUCCESS
, "ZwClose failed with Status=0x%08lX", Status
);
168 Status
= ZwClose(TimerHandle
);
169 ok(Status
== STATUS_SUCCESS
, "ZwClose failed with Status=0x%08lX", Status
);
171 FinishTest(KeyHandle
, L
"ExTimerTest");