--- /dev/null
+/*\r
+ * NTOSKRNL Executive Regressions KM-Test\r
+ * ReactOS Kernel Mode Regression Testing framework\r
+ *\r
+ * Copyright 2006 Aleksey Bragin <aleksey@reactos.org>\r
+ *\r
+ * This library is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU Library General Public\r
+ * License as published by the Free Software Foundation; either\r
+ * version 2 of the License, or (at your option) any later version.\r
+ *\r
+ * This library is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * Library General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Library General Public\r
+ * License along with this library; see the file COPYING.LIB.\r
+ * If not, write to the Free Software Foundation,\r
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+ */\r
+\r
+/* INCLUDES *******************************************************************/\r
+\r
+#include <ddk/ntddk.h>\r
+#include <ntifs.h>\r
+#include <ndk/ntndk.h>\r
+#include "kmtest.h"\r
+\r
+#define NDEBUG\r
+#include "debug.h"\r
+\r
+/* PRIVATE FUNCTIONS ***********************************************************/\r
+\r
+VOID\r
+ExTimerTest()\r
+{\r
+ UNICODE_STRING TimerName;\r
+ OBJECT_ATTRIBUTES ObjectAttributes;\r
+ HANDLE TimerHandle;\r
+ HANDLE HandleOpened;\r
+ LARGE_INTEGER DueTime;\r
+ BOOLEAN PreviousState, CurrentState;\r
+ NTSTATUS Status;\r
+\r
+ StartTest();\r
+\r
+ // Create the timer\r
+ RtlInitUnicodeString(&TimerName, L"\\TestTimer");\r
+ InitializeObjectAttributes(&ObjectAttributes, &TimerName, 0, NULL, NULL);\r
+ Status = ZwCreateTimer(&TimerHandle, TIMER_ALL_ACCESS,\r
+ &ObjectAttributes, NotificationTimer);\r
+ ok(Status == STATUS_SUCCESS, "ZwCreateTimer failed with Status=0x%08lX", Status);\r
+\r
+ // Open the timer\r
+ Status = ZwOpenTimer(&HandleOpened, TIMER_ALL_ACCESS, &ObjectAttributes);\r
+ ok(Status == STATUS_SUCCESS, "ZwOpenTimer failed with Status=0x%08lX", Status);\r
+\r
+ // Set the timer, to some rather high value so it doesn't expire\r
+ DueTime.LowPart = -10000;\r
+ DueTime.HighPart = -10;\r
+ PreviousState = TRUE;\r
+ Status = ZwSetTimer(HandleOpened, &DueTime, NULL, NULL, FALSE, 0L, &PreviousState);\r
+ ok(Status == STATUS_SUCCESS, "ZwSetTimer failed with Status=0x%08lX", Status);\r
+ ok(PreviousState == FALSE, "Incorrect PreviousState returned when setting the timer");\r
+\r
+ // Cancel the timer\r
+ CurrentState = TRUE;\r
+ Status = ZwCancelTimer(HandleOpened, &CurrentState);\r
+ ok(Status == STATUS_SUCCESS, "ZwCancelTimer failed with Status=0x%08lX", Status);\r
+ ok(CurrentState == FALSE, "Incorrect CurrentState returned when canceling the timer");\r
+\r
+ // Set the timer to some small value, because we'll wait for it to expire\r
+ DueTime.LowPart = -100;\r
+ DueTime.HighPart = -1;\r
+ PreviousState = TRUE;\r
+ Status = ZwSetTimer(HandleOpened, &DueTime, NULL, NULL, FALSE, 0L, &PreviousState);\r
+ ok(Status == STATUS_SUCCESS, "ZwSetTimer failed with Status=0x%08lX", Status);\r
+ ok(PreviousState == FALSE, "Incorrect PreviousState returned when setting the timer");\r
+\r
+ // Wait until it expires\r
+ Status = ZwWaitForSingleObject(HandleOpened, FALSE, NULL);\r
+ ok(Status == STATUS_SUCCESS, "ZwWaitForSingleObject failed with Status=0x%08lX", Status);\r
+\r
+ // And cancel it\r
+ CurrentState = FALSE;\r
+ Status = ZwCancelTimer(HandleOpened, &CurrentState);\r
+ ok(Status == STATUS_SUCCESS, "ZwCancelTimer failed with Status=0x%08lX", Status);\r
+ ok(CurrentState == TRUE, "Incorrect CurrentState returned when setting the timer");\r
+\r
+ // TODO: Add tests for a timer with APC routines\r
+\r
+ // Cleanup...\r
+ Status = ZwClose(HandleOpened);\r
+ ok(Status == STATUS_SUCCESS, "ZwClose failed with Status=0x%08lX", Status);\r
+\r
+ Status = ZwClose(TimerHandle);\r
+ ok(Status == STATUS_SUCCESS, "ZwClose failed with Status=0x%08lX", Status);\r
+\r
+ FinishTest("NTOSKRNL Executive Timer");\r
+}\r
+\r
+/* PUBLIC FUNCTIONS ***********************************************************/\r
+\r
+VOID\r
+FASTCALL\r
+NtoskrnlExecutiveTests()\r
+{\r
+ ExTimerTest();\r
+}\r