ReactOS  0.4.15-dev-4927-gfe8f806
KeEvent.c File Reference
#include <kmt_test.h>
Include dependency graph for KeEvent.c:

Go to the source code of this file.

Classes

struct  THREAD_DATA
 
struct  COUNT_THREAD_DATA
 

Macros

#define CheckEvent(Event, ExpectedType, State, ExpectedWaitNext, Irql, ThreadList, ThreadCount)
 
#define NUM_SCHED_TESTS   1000
 

Typedefs

typedef struct THREAD_DATAPTHREAD_DATA
 
typedef LONG(NTAPIPSET_EVENT_FUNCTION) (PRKEVENT, KPRIORITY, BOOLEAN)
 
typedef struct COUNT_THREAD_DATAPCOUNT_THREAD_DATA
 

Functions

static VOID TestEventFunctional (IN PKEVENT Event, IN EVENT_TYPE Type, IN KIRQL OriginalIrql)
 
static VOID NTAPI WaitForEventThread (IN OUT PVOID Context)
 
static VOID TestEventConcurrent (IN PKEVENT Event, IN EVENT_TYPE Type, IN KIRQL OriginalIrql, PSET_EVENT_FUNCTION SetEvent, KPRIORITY PriorityIncrement, LONG ExpectedState, BOOLEAN SatisfiesAll)
 
static VOID NTAPI CountThread (IN OUT PVOID Context)
 
static VOID NTAPI TestEventScheduling (_In_ PVOID Context)
 
 START_TEST (KeEvent)
 

Macro Definition Documentation

◆ CheckEvent

#define CheckEvent (   Event,
  ExpectedType,
  State,
  ExpectedWaitNext,
  Irql,
  ThreadList,
  ThreadCount 
)
Value:
do \
{ \
INT TheIndex; \
PLIST_ENTRY TheEntry; \
PKTHREAD TheThread; \
ok_eq_uint((Event)->Header.Type, ExpectedType); \
ok_eq_uint((Event)->Header.Hand, sizeof *(Event) / sizeof(ULONG)); \
ok_eq_hex((Event)->Header.Lock & 0xFF00FF00L, 0x55005500L); \
ok_eq_long((Event)->Header.SignalState, State); \
TheEntry = (Event)->Header.WaitListHead.Flink; \
for (TheIndex = 0; TheIndex < (ThreadCount); ++TheIndex) \
{ \
TheThread = CONTAINING_RECORD(TheEntry, KTHREAD, \
WaitBlock[0].WaitListEntry); \
ok_eq_pointer(TheThread, (ThreadList)[TheIndex]); \
ok_eq_pointer(TheEntry->Flink->Blink, TheEntry); \
TheEntry = TheEntry->Flink; \
} \
ok_eq_pointer(TheEntry, &(Event)->Header.WaitListHead); \
ok_eq_pointer(TheEntry->Flink->Blink, TheEntry); \
ok_eq_long(KeReadStateEvent(Event), State); \
ok_eq_bool(Thread->WaitNext, ExpectedWaitNext); \
ok_irql(Irql); \
} while (0)
_Out_ PKIRQL Irql
Definition: csq.h:179
Definition: Header.h:8
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:467
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define for
Definition: utility.h:88
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
LONG NTAPI KeReadStateEvent(IN PKEVENT Event)
Definition: eventobj.c:120
unsigned int ULONG
Definition: retypes.h:1

Definition at line 10 of file KeEvent.c.

◆ NUM_SCHED_TESTS

#define NUM_SCHED_TESTS   1000

Definition at line 231 of file KeEvent.c.

Typedef Documentation

◆ PCOUNT_THREAD_DATA

◆ PSET_EVENT_FUNCTION

typedef LONG(NTAPI * PSET_EVENT_FUNCTION) (PRKEVENT, KPRIORITY, BOOLEAN)

Definition at line 135 of file KeEvent.c.

◆ PTHREAD_DATA

Function Documentation

◆ CountThread()

static VOID NTAPI CountThread ( IN OUT PVOID  Context)
static

Definition at line 245 of file KeEvent.c.

247 {
249  PKEVENT Event = &ThreadData->Event;
250  volatile ULONG *Counter = &ThreadData->Counter;
251  ULONG *CounterValue = ThreadData->CounterValues;
253 
255  ok_eq_long(Priority, 8L);
256 
257  while (CounterValue < &ThreadData->CounterValues[NUM_SCHED_TESTS])
258  {
259  KeSetEvent(&ThreadData->WaitEvent, IO_NO_INCREMENT, TRUE);
261  *CounterValue++ = *Counter;
262  }
263 
265  ok_eq_long(Priority, 8L + min(ThreadData->PriorityIncrement, 7));
266 }
#define TRUE
Definition: types.h:120
KPRIORITY NTAPI KeQueryPriorityThread(IN PKTHREAD Thread)
Definition: thrdobj.c:1017
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
LONG KPRIORITY
Definition: compat.h:662
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
_In_ WDFINTERRUPT _In_ WDF_INTERRUPT_POLICY _In_ WDF_INTERRUPT_PRIORITY Priority
Definition: wdfinterrupt.h:651
#define min(a, b)
Definition: monoChain.cc:55
#define NULL
Definition: types.h:112
static LARGE_INTEGER Counter
Definition: clock.c:43
struct tagContext Context
Definition: acpixf.h:1034
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define KeGetCurrentThread
Definition: hal.h:55
#define ok_eq_long(value, expected)
Definition: kmt_test.h:240
#define NUM_SCHED_TESTS
Definition: KeEvent.c:231

Referenced by TestEventScheduling().

◆ START_TEST()

START_TEST ( KeEvent  )

Definition at line 353 of file KeEvent.c.

354 {
356  KEVENT Event;
357  KIRQL Irql;
359  ULONG i;
360  KPRIORITY PriorityIncrement;
361 
362  for (i = 0; i < RTL_NUMBER_OF(Irqls); ++i)
363  {
364  KeRaiseIrql(Irqls[i], &Irql);
367  KeLowerIrql(Irql);
368  }
369 
370  for (i = 0; i < RTL_NUMBER_OF(Irqls); ++i)
371  {
372  /* creating threads above DISPATCH_LEVEL... nope */
373  if (Irqls[i] >= DISPATCH_LEVEL)
374  continue;
375  KeRaiseIrql(Irqls[i], &Irql);
376  trace("IRQL: %u\n", Irqls[i]);
377  for (PriorityIncrement = -1; PriorityIncrement <= 8; ++PriorityIncrement)
378  {
379  if (PriorityIncrement < 0 && KmtIsCheckedBuild)
380  continue;
381  trace("PriorityIncrement: %ld\n", PriorityIncrement);
382  trace("-> Checking KeSetEvent, NotificationEvent\n");
383  TestEventConcurrent(&Event, NotificationEvent, Irqls[i], KeSetEvent, PriorityIncrement, 1, TRUE);
384  trace("-> Checking KeSetEvent, SynchronizationEvent\n");
385  TestEventConcurrent(&Event, SynchronizationEvent, Irqls[i], KeSetEvent, PriorityIncrement, 0, FALSE);
386  trace("-> Checking KePulseEvent, NotificationEvent\n");
387  TestEventConcurrent(&Event, NotificationEvent, Irqls[i], KePulseEvent, PriorityIncrement, 0, TRUE);
388  trace("-> Checking KePulseEvent, SynchronizationEvent\n");
389  TestEventConcurrent(&Event, SynchronizationEvent, Irqls[i], KePulseEvent, PriorityIncrement, 0, FALSE);
390  }
391  KeLowerIrql(Irql);
392  }
393 
394  ok_irql(PASSIVE_LEVEL);
396 
399 }
PKTHREAD KmtStartThread(IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext OPTIONAL)
#define TRUE
Definition: types.h:120
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
_Out_ PKIRQL Irql
Definition: csq.h:179
LONG KPRIORITY
Definition: compat.h:662
UCHAR KIRQL
Definition: env_spec_w32.h:591
BOOLEAN KmtIsCheckedBuild
#define FALSE
Definition: types.h:117
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:467
VOID KmtSetIrql(IN KIRQL NewIrql)
LONG NTAPI KePulseEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:68
#define trace
Definition: atltest.h:70
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
static VOID TestEventFunctional(IN PKEVENT Event, IN EVENT_TYPE Type, IN KIRQL OriginalIrql)
Definition: KeEvent.c:38
static VOID NTAPI TestEventScheduling(_In_ PVOID Context)
Definition: KeEvent.c:271
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
VOID KmtFinishThread(IN PKTHREAD Thread OPTIONAL, IN PKEVENT Event OPTIONAL)
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
static VOID TestEventConcurrent(IN PKEVENT Event, IN EVENT_TYPE Type, IN KIRQL OriginalIrql, PSET_EVENT_FUNCTION SetEvent, KPRIORITY PriorityIncrement, LONG ExpectedState, BOOLEAN SatisfiesAll)
Definition: KeEvent.c:139
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define NULL
Definition: types.h:112
VOID NTAPI KeRaiseIrql(KIRQL NewIrql, PKIRQL OldIrql)
Definition: spinlock.c:27
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI KeLowerIrql(KIRQL NewIrql)
Definition: spinlock.c:39
#define APC_LEVEL
Definition: env_spec_w32.h:695

◆ TestEventConcurrent()

static VOID TestEventConcurrent ( IN PKEVENT  Event,
IN EVENT_TYPE  Type,
IN KIRQL  OriginalIrql,
PSET_EVENT_FUNCTION  SetEvent,
KPRIORITY  PriorityIncrement,
LONG  ExpectedState,
BOOLEAN  SatisfiesAll 
)
static

Definition at line 139 of file KeEvent.c.

147 {
149  THREAD_DATA Threads[5];
150  const INT ThreadCount = sizeof Threads / sizeof Threads[0];
152  LARGE_INTEGER LongTimeout, ShortTimeout;
153  INT i;
154  KWAIT_BLOCK WaitBlock[RTL_NUMBER_OF(Threads)];
155  PVOID ThreadObjects[RTL_NUMBER_OF(Threads)];
156  LONG State;
159 
160  LongTimeout.QuadPart = -100 * MILLISECOND;
161  ShortTimeout.QuadPart = -1 * MILLISECOND;
162 
164 
165  for (i = 0; i < ThreadCount; ++i)
166  {
167  Threads[i].Event = Event;
168  Threads[i].Signal = FALSE;
170  NULL,
172  NULL,
173  NULL);
178  ThreadObjects[i] = Threads[i].Thread;
180  ok_eq_long(Priority, 8L);
181  while (!Threads[i].Signal)
182  {
183  Status = KeDelayExecutionThread(KernelMode, FALSE, &ShortTimeout);
184  if (Status != STATUS_SUCCESS)
185  {
187  }
188  }
189  CheckEvent(Event, Type, 0L, FALSE, OriginalIrql, ThreadObjects, i + 1);
190  }
191 
192  /* the threads shouldn't wake up on their own */
193  Status = KeDelayExecutionThread(KernelMode, FALSE, &ShortTimeout);
195 
196  for (i = 0; i < ThreadCount; ++i)
197  {
198  CheckEvent(Event, Type, 0L, FALSE, OriginalIrql, ThreadObjects + i, ThreadCount - i);
199  State = SetEvent(Event, PriorityIncrement + i, FALSE);
200 
201  ok_eq_long(State, 0L);
202  CheckEvent(Event, Type, ExpectedState, FALSE, OriginalIrql, ThreadObjects + i + 1, SatisfiesAll ? 0 : ThreadCount - i - 1);
203  Status = KeWaitForMultipleObjects(ThreadCount, ThreadObjects, SatisfiesAll ? WaitAll : WaitAny, Executive, KernelMode, FALSE, &LongTimeout, WaitBlock);
205  if (SatisfiesAll)
206  {
207  for (; i < ThreadCount; ++i)
208  {
210  ok_eq_long(Priority, max(min(8L + PriorityIncrement, 15L), 8L));
211  }
212  break;
213  }
215  ok_eq_long(Priority, max(min(8L + PriorityIncrement + i, 15L), 8L));
216  /* replace the thread with the current thread - which will never signal */
217  if (!skip((Status & 0x3F) < ThreadCount, "Index out of bounds\n"))
218  ThreadObjects[Status & 0x3F] = Thread;
219  Status = KeWaitForMultipleObjects(ThreadCount, ThreadObjects, WaitAny, Executive, KernelMode, FALSE, &ShortTimeout, WaitBlock);
221  }
222 
223  for (i = 0; i < ThreadCount; ++i)
224  {
225  ObDereferenceObject(Threads[i].Thread);
226  Status = ZwClose(Threads[i].Handle);
228  }
229 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define MILLISECOND
Definition: kmt_test.h:271
#define max(a, b)
Definition: svc.c:63
#define GENERIC_ALL
Definition: nt_native.h:92
#define CheckEvent(Event, ExpectedType, State, ExpectedWaitNext, Irql, ThreadList, ThreadCount)
Definition: KeEvent.c:10
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
_In_ ULONG _In_ ULONG State
Definition: potypes.h:516
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
KPRIORITY NTAPI KeQueryPriorityThread(IN PKTHREAD Thread)
Definition: thrdobj.c:1017
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
int32_t INT
Definition: typedefs.h:58
LONG KPRIORITY
Definition: compat.h:662
PKTHREAD Thread
Definition: ExFastMutex.c:143
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
#define STATUS_WAIT_0
Definition: ntstatus.h:237
#define L(x)
Definition: ntvdm.h:50
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
NTSTATUS NTAPI KeDelayExecutionThread(IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Interval OPTIONAL)
Definition: wait.c:283
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:467
volatile BOOLEAN Signal
Definition: KeEvent.c:116
Status
Definition: gdiplustypes.h:24
PKEVENT Event
Definition: KeEvent.c:115
#define ObDereferenceObject
Definition: obfuncs.h:203
Type
Definition: Type.h:6
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
NTSTATUS NTAPI KeWaitForMultipleObjects(IN ULONG Count, IN PVOID Object[], IN WAIT_TYPE WaitType, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL, OUT PKWAIT_BLOCK WaitBlockArray OPTIONAL)
Definition: wait.c:586
_In_ WDFINTERRUPT _In_ WDF_INTERRUPT_POLICY _In_ WDF_INTERRUPT_PRIORITY Priority
Definition: wdfinterrupt.h:651
POBJECT_TYPE PsThreadType
Definition: thread.c:20
#define SYNCHRONIZE
Definition: nt_native.h:61
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
#define min(a, b)
Definition: monoChain.cc:55
#define NULL
Definition: types.h:112
#define skip(...)
Definition: atltest.h:64
static VOID NTAPI WaitForEventThread(IN OUT PVOID Context)
Definition: KeEvent.c:122
_In_ HANDLE Handle
Definition: extypes.h:390
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define ok_eq_hex(value, expected)
#define STATUS_SUCCESS
Definition: shellext.h:65
#define KeGetCurrentThread
Definition: hal.h:55
#define ok_eq_long(value, expected)
Definition: kmt_test.h:240
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by START_TEST().

◆ TestEventFunctional()

static VOID TestEventFunctional ( IN PKEVENT  Event,
IN EVENT_TYPE  Type,
IN KIRQL  OriginalIrql 
)
static

Definition at line 38 of file KeEvent.c.

42 {
43  LONG State;
45 
46  memset(Event, 0x55, sizeof *Event);
48  CheckEvent(Event, Type, 0L, FALSE, OriginalIrql, (PVOID *)NULL, 0);
49 
50  memset(Event, 0x55, sizeof *Event);
52  CheckEvent(Event, Type, 1L, FALSE, OriginalIrql, (PVOID *)NULL, 0);
53 
54  Event->Header.SignalState = 0x12345678L;
55  CheckEvent(Event, Type, 0x12345678L, FALSE, OriginalIrql, (PVOID *)NULL, 0);
56 
58  CheckEvent(Event, Type, 0L, FALSE, OriginalIrql, (PVOID *)NULL, 0);
59  ok_eq_long(State, 0x12345678L);
60 
61  Event->Header.SignalState = 0x12345678L;
63  CheckEvent(Event, Type, 0L, FALSE, OriginalIrql, (PVOID *)NULL, 0);
64 
65  State = KeSetEvent(Event, 0, FALSE);
66  CheckEvent(Event, Type, 1L, FALSE, OriginalIrql, (PVOID *)NULL, 0);
67  ok_eq_long(State, 0L);
68 
70  CheckEvent(Event, Type, 0L, FALSE, OriginalIrql, (PVOID *)NULL, 0);
71  ok_eq_long(State, 1L);
72 
73  Event->Header.SignalState = 0x23456789L;
74  State = KeSetEvent(Event, 0, FALSE);
75  CheckEvent(Event, Type, 1L, FALSE, OriginalIrql, (PVOID *)NULL, 0);
76  ok_eq_long(State, 0x23456789L);
77 
78  Event->Header.SignalState = 0x3456789AL;
80  CheckEvent(Event, Type, 0L, FALSE, OriginalIrql, (PVOID *)NULL, 0);
81  ok_eq_long(State, 0x3456789AL);
82 
83  /* Irql is raised to DISPATCH_LEVEL here, which kills checked build,
84  * a spinlock is acquired and never released, which kills MP build */
85  if ((OriginalIrql <= DISPATCH_LEVEL || !KmtIsCheckedBuild) &&
87  {
88  Event->Header.SignalState = 0x456789ABL;
89  State = KeSetEvent(Event, 0, TRUE);
91  ok_eq_long(State, 0x456789ABL);
92  ok_eq_uint(Thread->WaitIrql, OriginalIrql);
93  /* repair the "damage" */
94  Thread->WaitNext = FALSE;
95  KmtSetIrql(OriginalIrql);
96 
97  Event->Header.SignalState = 0x56789ABCL;
100  ok_eq_long(State, 0x56789ABCL);
101  ok_eq_uint(Thread->WaitIrql, OriginalIrql);
102  /* repair the "damage" */
103  Thread->WaitNext = FALSE;
104  KmtSetIrql(OriginalIrql);
105  }
106 
107  ok_irql(OriginalIrql);
108  KmtSetIrql(OriginalIrql);
109 }
#define CheckEvent(Event, ExpectedType, State, ExpectedWaitNext, Irql, ThreadList, ThreadCount)
Definition: KeEvent.c:10
#define TRUE
Definition: types.h:120
_In_ ULONG _In_ ULONG State
Definition: potypes.h:516
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
BOOLEAN KmtIsCheckedBuild
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
VOID KmtSetIrql(IN KIRQL NewIrql)
BOOLEAN KmtIsMultiProcessorBuild
LONG NTAPI KePulseEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:68
Type
Definition: Type.h:6
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define NULL
Definition: types.h:112
LONG NTAPI KeResetEvent(IN PKEVENT Event)
Definition: eventobj.c:133
#define ok_eq_uint(value, expected)
Definition: kmt_test.h:239
#define KeGetCurrentThread
Definition: hal.h:55
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
#define memset(x, y, z)
Definition: compat.h:39
#define ok_eq_long(value, expected)
Definition: kmt_test.h:240

Referenced by START_TEST().

◆ TestEventScheduling()

static VOID NTAPI TestEventScheduling ( _In_ PVOID  Context)
static

Definition at line 271 of file KeEvent.c.

273 {
278  ULONG i;
279  volatile ULONG *Counter;
280  KPRIORITY PriorityIncrement;
282 
284 
286  if (skip(ThreadData != NULL, "Out of memory\n"))
287  {
288  return;
289  }
292  Counter = &ThreadData->Counter;
293 
294  for (PriorityIncrement = 0; PriorityIncrement <= 8; PriorityIncrement++)
295  {
296  ThreadData->PriorityIncrement = PriorityIncrement;
297  ThreadData->Counter = 0;
298  RtlFillMemory(ThreadData->CounterValues,
299  sizeof(ThreadData->CounterValues),
300  0xFE);
303  ok(Priority == 8, "[%lu] Priority = %lu\n", PriorityIncrement, Priority);
304  for (i = 1; i <= NUM_SCHED_TESTS; i++)
305  {
308  PreviousState = KeSetEvent(&ThreadData->Event, PriorityIncrement, FALSE);
309  *Counter = i;
311  }
313  ok(Priority == 8, "[%lu] Priority = %lu\n", PriorityIncrement, Priority);
315 
316  if (PriorityIncrement == 0)
317  {
318  /* Both threads have the same priority, so either can win the race */
319  ok(ThreadData->CounterValues[0] == 0 || ThreadData->CounterValues[0] == 1,
320  "[%lu] Counter 0 = %lu\n",
321  PriorityIncrement, ThreadData->CounterValues[0]);
322  }
323  else
324  {
325  /* CountThread has the higher priority, it will always win */
326  ok(ThreadData->CounterValues[0] == 0,
327  "[%lu] Counter 0 = %lu\n",
328  PriorityIncrement, ThreadData->CounterValues[0]);
329  }
330  for (i = 1; i < NUM_SCHED_TESTS; i++)
331  {
332  if (PriorityIncrement == 0)
333  {
334  ok(ThreadData->CounterValues[i] == i ||
335  ThreadData->CounterValues[i] == i + 1,
336  "[%lu] Counter %lu = %lu, expected %lu or %lu\n",
337  PriorityIncrement, i,
338  ThreadData->CounterValues[i], i, i + 1);
339  }
340  else
341  {
342  ok(ThreadData->CounterValues[i] == ThreadData->CounterValues[i - 1] + 1,
343  "[%lu] Counter %lu = %lu, expected %lu\n",
344  PriorityIncrement, i,
345  ThreadData->CounterValues[i], ThreadData->CounterValues[i - 1] + 1);
346  }
347  }
348  }
349 
350  ExFreePoolWithTag(ThreadData, 'CEmK');
351 }
PKTHREAD KmtStartThread(IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext OPTIONAL)
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
LONG NTSTATUS
Definition: precomp.h:26
KPRIORITY NTAPI KeQueryPriorityThread(IN PKTHREAD Thread)
Definition: thrdobj.c:1017
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
LONG KPRIORITY
Definition: compat.h:662
#define L(x)
Definition: ntvdm.h:50
static VOID NTAPI CountThread(IN OUT PVOID Context)
Definition: KeEvent.c:245
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
Status
Definition: gdiplustypes.h:24
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_In_ WDFINTERRUPT _In_ WDF_INTERRUPT_POLICY _In_ WDF_INTERRUPT_PRIORITY Priority
Definition: wdfinterrupt.h:651
VOID KmtFinishThread(IN PKTHREAD Thread OPTIONAL, IN PKEVENT Event OPTIONAL)
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
static LARGE_INTEGER Counter
Definition: clock.c:43
#define skip(...)
Definition: atltest.h:64
unsigned int ULONG
Definition: retypes.h:1
#define ok_eq_hex(value, expected)
#define STATUS_SUCCESS
Definition: shellext.h:65
#define KeGetCurrentThread
Definition: hal.h:55
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define ok_eq_long(value, expected)
Definition: kmt_test.h:240
#define NUM_SCHED_TESTS
Definition: KeEvent.c:231
_In_ WDF_POWER_DEVICE_STATE PreviousState
Definition: wdfdevice.h:829

Referenced by START_TEST().

◆ WaitForEventThread()

static VOID NTAPI WaitForEventThread ( IN OUT PVOID  Context)
static

Definition at line 122 of file KeEvent.c.

124 {
127 
128  ok_irql(PASSIVE_LEVEL);
129  ThreadData->Signal = TRUE;
132  ok_irql(PASSIVE_LEVEL);
133 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define FALSE
Definition: types.h:117
Status
Definition: gdiplustypes.h:24
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define NULL
Definition: types.h:112
struct tagContext Context
Definition: acpixf.h:1034
#define ok_eq_hex(value, expected)
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by TestEventConcurrent().