[KMTEST:IO]
[reactos.git] / rostests / kmtests / ntos_io / IoEvent.c
1 /*
2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Kernel-Mode Test Suite Event creation test
5 * PROGRAMMER: Thomas Faber <thfabba@gmx.de>
6 */
7
8 #include <kmt_test.h>
9
10 #ifdef _WIN64
11 #define KERNEL_HANDLE_FLAG 0xFFFFFFFF80000000ULL
12 #else
13 #define KERNEL_HANDLE_FLAG 0x80000000
14 #endif
15
16 #define CheckEventObject(Handle, Pointers, Handles) do \
17 { \
18 PUBLIC_OBJECT_BASIC_INFORMATION ObjectInfo; \
19 Status = ZwQueryObject(Handle, ObjectBasicInformation, \
20 &ObjectInfo, sizeof ObjectInfo, NULL); \
21 ok_eq_hex(Status, STATUS_SUCCESS); \
22 ok_eq_ulong(ObjectInfo.PointerCount, Pointers); \
23 ok_eq_ulong(ObjectInfo.HandleCount, Handles); \
24 ok_eq_ulong(ObjectInfo.Attributes, 0); \
25 ok_eq_ulong(ObjectInfo.GrantedAccess, EVENT_ALL_ACCESS); \
26 ok(((ULONG_PTR)Handle & KERNEL_HANDLE_FLAG) == KERNEL_HANDLE_FLAG, \
27 "Handle %p is not a kernel handle\n", Handle); \
28 } while (0)
29
30 static
31 VOID
32 TestCreateEvent(
33 PRKEVENT (NTAPI *CreateEvent)(PUNICODE_STRING, PHANDLE),
34 PUNICODE_STRING EventName,
35 EVENT_TYPE Type)
36 {
37 NTSTATUS Status;
38 NTSTATUS ExceptionStatus;
39 PKEVENT Event, Event2;
40 HANDLE EventHandle, EventHandle2;
41 LONG State;
42
43 /* Nameless event */
44 KmtStartSeh()
45 Event = CreateEvent(NULL, &EventHandle);
46 ok(Event != NULL, "Event is NULL\n");
47 ok(EventHandle != NULL, "EventHandle is NULL\n");
48 if (!skip(EventHandle != NULL, "No event\n"))
49 {
50 ok_eq_uint(Event->Header.Type, Type);
51 State = KeReadStateEvent(Event);
52 ok_eq_long(State, 1L);
53 CheckEventObject(EventHandle, 2UL, 1UL);
54 Status = ZwClose(EventHandle);
55 ok_eq_hex(Status, STATUS_SUCCESS);
56 }
57 KmtEndSeh(STATUS_SUCCESS);
58
59 /* Named event */
60 EventHandle = NULL;
61 Event = CreateEvent(EventName, &EventHandle);
62 ok(Event != NULL, "Event is NULL\n");
63 ok(EventHandle != NULL, "EventHandle is NULL\n");
64 if (!skip(EventHandle != NULL, "No event\n"))
65 {
66 ok_eq_uint(Event->Header.Type, Type);
67 State = KeReadStateEvent(Event);
68 ok_eq_long(State, 1L);
69 CheckEventObject(EventHandle, 3UL, 1UL);
70
71 /* Open the existing one */
72 EventHandle2 = NULL;
73 Event2 = CreateEvent(EventName, &EventHandle2);
74 CheckEventObject(EventHandle, 4UL, 2UL);
75 ok(Event2 != NULL, "Event is NULL\n");
76 ok(EventHandle2 != NULL, "EventHandle is NULL\n");
77 if (!skip(EventHandle2 != NULL, "No event\n"))
78 {
79 CheckEventObject(EventHandle2, 4UL, 2UL);
80 ZwClose(EventHandle2);
81 }
82
83 CheckEventObject(EventHandle, 3UL, 1UL);
84 Status = ZwClose(EventHandle);
85 ok_eq_hex(Status, STATUS_SUCCESS);
86 }
87 }
88
89 START_TEST(IoEvent)
90 {
91 PKEVENT Event, Event2;
92 HANDLE EventHandle = NULL, EventHandle2 = NULL;
93 UNICODE_STRING NotificationEventName = RTL_CONSTANT_STRING(L"\\BaseNamedObjects\\KmTestIoEventNotificationEvent");
94 UNICODE_STRING SynchronizationEventName = RTL_CONSTANT_STRING(L"\\BaseNamedObjects\\KmTestIoEventSynchronizationEvent");
95
96 TestCreateEvent(IoCreateNotificationEvent, &NotificationEventName, NotificationEvent);
97 TestCreateEvent(IoCreateSynchronizationEvent, &SynchronizationEventName, SynchronizationEvent);
98
99 /* Create different types with the same name */
100 Event = IoCreateNotificationEvent(&NotificationEventName, &EventHandle);
101 ok(Event != NULL, "Event is NULL\n");
102 ok(EventHandle != NULL, "EventHandle is NULL\n");
103 if (!skip(EventHandle != NULL, "No event\n"))
104 {
105 ok_eq_uint(Event->Header.Type, NotificationEvent);
106 Event2 = IoCreateSynchronizationEvent(&NotificationEventName, &EventHandle2);
107 ok(Event2 != NULL, "Event is NULL\n");
108 ok(EventHandle2 != NULL, "EventHandle is NULL\n");
109 if (!skip(EventHandle2 != NULL, "No event\n"))
110 {
111 ok_eq_uint(Event2->Header.Type, NotificationEvent);
112 ZwClose(EventHandle2);
113 }
114 ZwClose(EventHandle);
115 }
116
117 }
118