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 DPRINT("Timer Apc called!\n");
43 ULONG
*ApcCount
= (ULONG
*)TimerContext
;
51 UNICODE_STRING TimerName
;
52 OBJECT_ATTRIBUTES ObjectAttributes
;
55 LARGE_INTEGER DueTime
;
56 BOOLEAN PreviousState
, CurrentState
;
63 RtlInitUnicodeString(&TimerName
, L
"\\TestTimer");
64 InitializeObjectAttributes(&ObjectAttributes
, &TimerName
, 0, NULL
, NULL
);
65 Status
= ZwCreateTimer(&TimerHandle
, TIMER_ALL_ACCESS
,
66 &ObjectAttributes
, NotificationTimer
);
67 ok(Status
== STATUS_SUCCESS
, "ZwCreateTimer failed with Status=0x%08lX", Status
);
70 Status
= ZwOpenTimer(&HandleOpened
, TIMER_ALL_ACCESS
, &ObjectAttributes
);
71 ok(Status
== STATUS_SUCCESS
, "ZwOpenTimer failed with Status=0x%08lX", Status
);
73 // Set the timer, to some rather high value so it doesn't expire
74 DPRINT("Set timer 1\n");
75 DueTime
.LowPart
= -10000;
76 DueTime
.HighPart
= -10;
78 Status
= ZwSetTimer(HandleOpened
, &DueTime
, NULL
, NULL
, FALSE
, 0L, &PreviousState
);
79 ok(Status
== STATUS_SUCCESS
, "ZwSetTimer failed with Status=0x%08lX", Status
);
80 ok(PreviousState
== FALSE
, "Incorrect PreviousState returned when setting the timer");
84 Status
= ZwCancelTimer(HandleOpened
, &CurrentState
);
85 ok(Status
== STATUS_SUCCESS
, "ZwCancelTimer failed with Status=0x%08lX", Status
);
86 ok(CurrentState
== FALSE
, "Incorrect CurrentState returned when canceling the timer");
88 // Set the timer to some small value, because we'll wait for it to expire
89 DPRINT("Set timer 2\n");
90 DueTime
.LowPart
= -100;
91 DueTime
.HighPart
= -1;
93 Status
= ZwSetTimer(HandleOpened
, &DueTime
, NULL
, NULL
, FALSE
, 0L, &PreviousState
);
94 ok(Status
== STATUS_SUCCESS
, "ZwSetTimer failed with Status=0x%08lX", Status
);
95 ok(PreviousState
== FALSE
, "Incorrect PreviousState returned when setting the timer");
97 // Wait until it expires
98 DPRINT("Wait till timer expires\n");
99 Status
= ZwWaitForSingleObject(HandleOpened
, FALSE
, NULL
);
100 ok(Status
== STATUS_SUCCESS
, "ZwWaitForSingleObject failed with Status=0x%08lX", Status
);
103 DPRINT("Cancel it\n");
104 CurrentState
= FALSE
;
105 Status
= ZwCancelTimer(HandleOpened
, &CurrentState
);
106 ok(Status
== STATUS_SUCCESS
, "ZwCancelTimer failed with Status=0x%08lX", Status
);
107 ok(CurrentState
== TRUE
, "Incorrect CurrentState returned when setting the timer");
109 // Test it with APC: Set, Cancel, check if APC has been called
110 DPRINT("Set timer with Apc (3)\n");
112 DueTime
.LowPart
= -10000;
113 DueTime
.HighPart
= -10;
114 PreviousState
= FALSE
;
115 Status
= ZwSetTimer(HandleOpened
, &DueTime
,
116 (PTIMER_APC_ROUTINE
)TestTimerApcRoutine
, &ApcCount
, FALSE
,
119 ok(Status
== STATUS_SUCCESS
, "ZwSetTimer failed with Status=0x%08lX", Status
);
120 ok(PreviousState
== TRUE
, "Incorrect PreviousState returned when setting the timer");
122 DPRINT("Cancel it\n");
124 Status
= ZwCancelTimer(HandleOpened
, &CurrentState
);
125 ok(Status
== STATUS_SUCCESS
, "ZwCancelTimer failed with Status=0x%08lX", Status
);
126 ok(CurrentState
== FALSE
, "Incorrect CurrentState returned when cancelling the timer");
127 ok(ApcCount
== 0, "Incorrect count of TimerApcRoutine calls: %ld, should be 0\n", ApcCount
);
129 // Test setting the timer two times in a row, APC routine must not be called
130 DPRINT("Set timer with Apc (4)\n");
132 DueTime
.LowPart
= -10000;
133 DueTime
.HighPart
= -10;
134 PreviousState
= TRUE
;
135 Status
= ZwSetTimer(HandleOpened
, &DueTime
,
136 (PTIMER_APC_ROUTINE
)TestTimerApcRoutine
, &ApcCount
, FALSE
,
138 ok(Status
== STATUS_SUCCESS
, "ZwSetTimer failed with Status=0x%08lX", Status
);
139 ok(PreviousState
== FALSE
, "Incorrect PreviousState returned when setting the timer");
141 // Set small due time, since we have to wait for timer to finish
142 DPRINT("Set timer with Apc (5)\n");
143 DueTime
.LowPart
= -10;
144 DueTime
.HighPart
= -1;
145 PreviousState
= TRUE
;
146 Status
= ZwSetTimer(HandleOpened
, &DueTime
,
147 (PTIMER_APC_ROUTINE
)TestTimerApcRoutine
, &ApcCount
, FALSE
,
149 ok(Status
== STATUS_SUCCESS
, "ZwSetTimer failed with Status=0x%08lX", Status
);
150 ok(PreviousState
== FALSE
, "Incorrect PreviousState returned when setting the timer");
152 // Now wait till it's finished, and then check APC call
153 DPRINT("Wait for it\n");
154 Status
= ZwWaitForSingleObject(HandleOpened
, FALSE
, NULL
);
155 ok(Status
== STATUS_SUCCESS
, "ZwWaitForSingleObject failed with Status=0x%08lX", Status
);
157 CurrentState
= FALSE
;
158 Status
= ZwCancelTimer(HandleOpened
, &CurrentState
);
159 ok(Status
== STATUS_SUCCESS
, "ZwCancelTimer failed with Status=0x%08lX", Status
);
160 ok(CurrentState
== TRUE
, "Incorrect CurrentState returned when cancelling the timer");
161 ok(ApcCount
== 1, "Incorrect count of TimerApcRoutine calls: %ld, should be 1\n", ApcCount
);
164 Status
= ZwClose(HandleOpened
);
165 ok(Status
== STATUS_SUCCESS
, "ZwClose failed with Status=0x%08lX", Status
);
167 Status
= ZwClose(TimerHandle
);
168 ok(Status
== STATUS_SUCCESS
, "ZwClose failed with Status=0x%08lX", Status
);
170 FinishTest("NTOSKRNL Executive Timer");
173 /* PUBLIC FUNCTIONS ***********************************************************/
176 NtoskrnlExecutiveTests()