ReactOS 0.4.15-dev-8102-g108db8f
ExTimer.c
Go to the documentation of this file.
1/*
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>
6 */
7
8#include <kmt_test.h>
9
10#define NDEBUG
11#include <debug.h>
12
13static
14VOID
17 IN ULONG TimerLowValue,
18 IN LONG TimerHighValue)
19
20{
21 ULONG *ApcCount = (ULONG *)TimerContext;
22 DPRINT("Timer Apc called!\n");
23 (*ApcCount)++;
24}
25
26START_TEST(ExTimer)
27{
28 UNICODE_STRING TimerName;
30 HANDLE TimerHandle;
31 HANDLE HandleOpened;
35 ULONG ApcCount;
36
37 // Create the timer
38 RtlInitUnicodeString(&TimerName, L"\\TestTimer");
40 Status = ZwCreateTimer(&TimerHandle, TIMER_ALL_ACCESS,
42 ok(Status == STATUS_SUCCESS, "ZwCreateTimer failed with Status=0x%08lX", Status);
43
44 // Open the timer
45 Status = ZwOpenTimer(&HandleOpened, TIMER_ALL_ACCESS, &ObjectAttributes);
46 ok(Status == STATUS_SUCCESS, "ZwOpenTimer failed with Status=0x%08lX", Status);
47
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");
56
57 // Cancel 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");
62
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");
71
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);
76
77 // And cancel it
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");
83
84 // Test it with APC: Set, Cancel, check if APC has been called
85 DPRINT("Set timer with Apc (3)\n");
86 ApcCount = 0;
87 DueTime.LowPart = -10000;
88 DueTime.HighPart = -10;
90 Status = ZwSetTimer(HandleOpened, &DueTime,
92 0L, &PreviousState);
93
94 ok(Status == STATUS_SUCCESS, "ZwSetTimer failed with Status=0x%08lX", Status);
95 ok(PreviousState == TRUE, "Incorrect PreviousState returned when setting the timer");
96
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);
103
104 // Test setting the timer two times in a row, APC routine must not be called
105 DPRINT("Set timer with Apc (4)\n");
106 ApcCount = 0;
107 DueTime.LowPart = -10000;
108 DueTime.HighPart = -10;
110 Status = ZwSetTimer(HandleOpened, &DueTime,
112 0L, &PreviousState);
113 ok(Status == STATUS_SUCCESS, "ZwSetTimer failed with Status=0x%08lX", Status);
114 ok(PreviousState == FALSE, "Incorrect PreviousState returned when setting the timer");
115
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;
121 Status = ZwSetTimer(HandleOpened, &DueTime,
123 0L, &PreviousState);
124 ok(Status == STATUS_SUCCESS, "ZwSetTimer failed with Status=0x%08lX", Status);
125 ok(PreviousState == FALSE, "Incorrect PreviousState returned when setting the timer");
126
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);
131
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);
137
138 // Cleanup...
139 Status = ZwClose(HandleOpened);
140 ok(Status == STATUS_SUCCESS, "ZwClose failed with Status=0x%08lX", Status);
141
142 Status = ZwClose(TimerHandle);
143 ok(Status == STATUS_SUCCESS, "ZwClose failed with Status=0x%08lX", Status);
144}
static VOID NTAPI TestTimerApcRoutine(IN PVOID TimerContext, IN ULONG TimerLowValue, IN LONG TimerHighValue)
Definition: ExTimer.c:16
unsigned char BOOLEAN
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
LONG NTSTATUS
Definition: precomp.h:26
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
Status
Definition: gdiplustypes.h:25
VOID(CALLBACK * PTIMER_APC_ROUTINE)(PVOID, ULONG, LONG)
Definition: winternl.h:2018
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define TIMER_ALL_ACCESS
Definition: extypes.h:116
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
@ NotificationTimer
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDF_POWER_DEVICE_STATE PreviousState
Definition: wdfdevice.h:829
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:190
_In_ PLARGE_INTEGER _In_opt_ PTIMER_APC_ROUTINE _In_opt_ PVOID TimerContext
Definition: zwfuncs.h:430
_Out_opt_ PBOOLEAN CurrentState
Definition: zwfuncs.h:393