1*c2c66affSColin Finck /*
2*c2c66affSColin Finck  * PROJECT:         ReactOS kernel-mode tests
3*c2c66affSColin Finck  * LICENSE:         GPLv2+ - See COPYING in the top level directory
4*c2c66affSColin Finck  * PURPOSE:         Kernel-Mode Test Suite Process Notification Routines test
5*c2c66affSColin Finck  * PROGRAMMER:      Thomas Faber <thomas.faber@reactos.org>
6*c2c66affSColin Finck  */
7*c2c66affSColin Finck 
8*c2c66affSColin Finck #include <kmt_test.h>
9*c2c66affSColin Finck 
10*c2c66affSColin Finck //#define NDEBUG
11*c2c66affSColin Finck #include <debug.h>
12*c2c66affSColin Finck 
13*c2c66affSColin Finck static
14*c2c66affSColin Finck VOID
15*c2c66affSColin Finck NTAPI
CreateProcessNotifyRoutine(IN HANDLE ParentId,IN HANDLE ProcessId,IN BOOLEAN Create)16*c2c66affSColin Finck CreateProcessNotifyRoutine(
17*c2c66affSColin Finck     IN HANDLE ParentId,
18*c2c66affSColin Finck     IN HANDLE ProcessId,
19*c2c66affSColin Finck     IN BOOLEAN Create)
20*c2c66affSColin Finck {
21*c2c66affSColin Finck     ok_irql(PASSIVE_LEVEL);
22*c2c66affSColin Finck     if (!Create)
23*c2c66affSColin Finck         ok_eq_pointer(ProcessId, PsGetCurrentProcessId());
24*c2c66affSColin Finck     else
25*c2c66affSColin Finck         ok(ProcessId != PsGetCurrentProcessId(),
26*c2c66affSColin Finck            "ProcessId %p equals current\n", ProcessId);
27*c2c66affSColin Finck     DPRINT("%s(%p, %p, %d)\n", __FUNCTION__, ParentId, ProcessId, Create);
28*c2c66affSColin Finck }
29*c2c66affSColin Finck 
30*c2c66affSColin Finck static
31*c2c66affSColin Finck VOID
TestCreateProcessNotify(VOID)32*c2c66affSColin Finck TestCreateProcessNotify(VOID)
33*c2c66affSColin Finck {
34*c2c66affSColin Finck     NTSTATUS Status;
35*c2c66affSColin Finck 
36*c2c66affSColin Finck     Status = PsSetCreateProcessNotifyRoutine(NULL, TRUE);
37*c2c66affSColin Finck     ok_eq_hex(Status, STATUS_PROCEDURE_NOT_FOUND);
38*c2c66affSColin Finck 
39*c2c66affSColin Finck     Status = PsSetCreateProcessNotifyRoutine(NULL, FALSE);
40*c2c66affSColin Finck     ok_eq_hex(Status, STATUS_SUCCESS);
41*c2c66affSColin Finck 
42*c2c66affSColin Finck     Status = PsSetCreateProcessNotifyRoutine(NULL, TRUE);
43*c2c66affSColin Finck     ok_eq_hex(Status, STATUS_SUCCESS);
44*c2c66affSColin Finck 
45*c2c66affSColin Finck     Status = PsSetCreateProcessNotifyRoutine(NULL, TRUE);
46*c2c66affSColin Finck     ok_eq_hex(Status, STATUS_PROCEDURE_NOT_FOUND);
47*c2c66affSColin Finck 
48*c2c66affSColin Finck     Status = PsSetCreateProcessNotifyRoutine(CreateProcessNotifyRoutine, TRUE);
49*c2c66affSColin Finck     ok_eq_hex(Status, STATUS_PROCEDURE_NOT_FOUND);
50*c2c66affSColin Finck 
51*c2c66affSColin Finck     Status = PsSetCreateProcessNotifyRoutine(CreateProcessNotifyRoutine, FALSE);
52*c2c66affSColin Finck     ok_eq_hex(Status, STATUS_SUCCESS);
53*c2c66affSColin Finck 
54*c2c66affSColin Finck     /* TODO: test whether the callback is notified on process creation */
55*c2c66affSColin Finck 
56*c2c66affSColin Finck     Status = PsSetCreateProcessNotifyRoutine(CreateProcessNotifyRoutine, TRUE);
57*c2c66affSColin Finck     ok_eq_hex(Status, STATUS_SUCCESS);
58*c2c66affSColin Finck 
59*c2c66affSColin Finck     Status = PsSetCreateProcessNotifyRoutine(CreateProcessNotifyRoutine, TRUE);
60*c2c66affSColin Finck     ok_eq_hex(Status, STATUS_PROCEDURE_NOT_FOUND);
61*c2c66affSColin Finck 
62*c2c66affSColin Finck     /* TODO: register the same routine twice */
63*c2c66affSColin Finck     /* TODO: register more than the maximum number of notifications */
64*c2c66affSColin Finck }
65*c2c66affSColin Finck 
66*c2c66affSColin Finck static
67*c2c66affSColin Finck VOID
68*c2c66affSColin Finck NTAPI
CreateThreadNotifyRoutine(IN HANDLE ProcessId,IN HANDLE ThreadId,IN BOOLEAN Create)69*c2c66affSColin Finck CreateThreadNotifyRoutine(
70*c2c66affSColin Finck     IN HANDLE ProcessId,
71*c2c66affSColin Finck     IN HANDLE ThreadId,
72*c2c66affSColin Finck     IN BOOLEAN Create)
73*c2c66affSColin Finck {
74*c2c66affSColin Finck     ok_irql(PASSIVE_LEVEL);
75*c2c66affSColin Finck     if (!Create)
76*c2c66affSColin Finck     {
77*c2c66affSColin Finck         ok_eq_pointer(ProcessId, PsGetCurrentProcessId());
78*c2c66affSColin Finck         ok_eq_pointer(ThreadId, PsGetCurrentThreadId());
79*c2c66affSColin Finck     }
80*c2c66affSColin Finck     else
81*c2c66affSColin Finck     {
82*c2c66affSColin Finck         ok(ThreadId != PsGetCurrentThreadId(),
83*c2c66affSColin Finck            "ThreadId %p equals current\n", ThreadId);
84*c2c66affSColin Finck     }
85*c2c66affSColin Finck     DPRINT("%s(%p, %p, %d)\n", __FUNCTION__, ProcessId, ThreadId, Create);
86*c2c66affSColin Finck }
87*c2c66affSColin Finck 
88*c2c66affSColin Finck static
89*c2c66affSColin Finck VOID
TestCreateThreadNotify(VOID)90*c2c66affSColin Finck TestCreateThreadNotify(VOID)
91*c2c66affSColin Finck {
92*c2c66affSColin Finck     NTSTATUS Status;
93*c2c66affSColin Finck 
94*c2c66affSColin Finck     Status = PsRemoveCreateThreadNotifyRoutine(NULL);
95*c2c66affSColin Finck     ok_eq_hex(Status, STATUS_PROCEDURE_NOT_FOUND);
96*c2c66affSColin Finck 
97*c2c66affSColin Finck     Status = PsSetCreateThreadNotifyRoutine(NULL);
98*c2c66affSColin Finck     ok_eq_hex(Status, STATUS_SUCCESS);
99*c2c66affSColin Finck 
100*c2c66affSColin Finck     Status = PsRemoveCreateThreadNotifyRoutine(NULL);
101*c2c66affSColin Finck     ok_eq_hex(Status, STATUS_SUCCESS);
102*c2c66affSColin Finck 
103*c2c66affSColin Finck     Status = PsRemoveCreateThreadNotifyRoutine(NULL);
104*c2c66affSColin Finck     ok_eq_hex(Status, STATUS_PROCEDURE_NOT_FOUND);
105*c2c66affSColin Finck 
106*c2c66affSColin Finck     Status = PsRemoveCreateThreadNotifyRoutine(CreateThreadNotifyRoutine);
107*c2c66affSColin Finck     ok_eq_hex(Status, STATUS_PROCEDURE_NOT_FOUND);
108*c2c66affSColin Finck 
109*c2c66affSColin Finck     Status = PsSetCreateThreadNotifyRoutine(CreateThreadNotifyRoutine);
110*c2c66affSColin Finck     ok_eq_hex(Status, STATUS_SUCCESS);
111*c2c66affSColin Finck 
112*c2c66affSColin Finck     /* TODO: test whether the callback is notified on thread creation */
113*c2c66affSColin Finck 
114*c2c66affSColin Finck     Status = PsRemoveCreateThreadNotifyRoutine(CreateThreadNotifyRoutine);
115*c2c66affSColin Finck     ok_eq_hex(Status, STATUS_SUCCESS);
116*c2c66affSColin Finck 
117*c2c66affSColin Finck     Status = PsRemoveCreateThreadNotifyRoutine(CreateThreadNotifyRoutine);
118*c2c66affSColin Finck     ok_eq_hex(Status, STATUS_PROCEDURE_NOT_FOUND);
119*c2c66affSColin Finck 
120*c2c66affSColin Finck     /* TODO: register the same routine twice */
121*c2c66affSColin Finck     /* TODO: register more than the maximum number of notifications */
122*c2c66affSColin Finck }
123*c2c66affSColin Finck 
124*c2c66affSColin Finck static
125*c2c66affSColin Finck VOID
126*c2c66affSColin Finck NTAPI
LoadImageNotifyRoutine(IN PUNICODE_STRING FullImageName OPTIONAL,IN HANDLE ProcessId,IN PIMAGE_INFO ImageInfo)127*c2c66affSColin Finck LoadImageNotifyRoutine(
128*c2c66affSColin Finck     IN PUNICODE_STRING FullImageName OPTIONAL,
129*c2c66affSColin Finck     IN HANDLE ProcessId,
130*c2c66affSColin Finck     IN PIMAGE_INFO ImageInfo)
131*c2c66affSColin Finck {
132*c2c66affSColin Finck     ok_irql(PASSIVE_LEVEL);
133*c2c66affSColin Finck     DPRINT("%s('%wZ', %p, %p)\n", __FUNCTION__, FullImageName, ProcessId, ImageInfo);
134*c2c66affSColin Finck }
135*c2c66affSColin Finck 
136*c2c66affSColin Finck static
137*c2c66affSColin Finck VOID
TestLoadImageNotify(VOID)138*c2c66affSColin Finck TestLoadImageNotify(VOID)
139*c2c66affSColin Finck {
140*c2c66affSColin Finck     NTSTATUS Status;
141*c2c66affSColin Finck 
142*c2c66affSColin Finck     Status = PsRemoveLoadImageNotifyRoutine(NULL);
143*c2c66affSColin Finck     ok_eq_hex(Status, STATUS_PROCEDURE_NOT_FOUND);
144*c2c66affSColin Finck 
145*c2c66affSColin Finck     Status = PsSetLoadImageNotifyRoutine(NULL);
146*c2c66affSColin Finck     ok_eq_hex(Status, STATUS_SUCCESS);
147*c2c66affSColin Finck 
148*c2c66affSColin Finck     Status = PsRemoveLoadImageNotifyRoutine(NULL);
149*c2c66affSColin Finck     ok_eq_hex(Status, STATUS_SUCCESS);
150*c2c66affSColin Finck 
151*c2c66affSColin Finck     Status = PsRemoveLoadImageNotifyRoutine(NULL);
152*c2c66affSColin Finck     ok_eq_hex(Status, STATUS_PROCEDURE_NOT_FOUND);
153*c2c66affSColin Finck 
154*c2c66affSColin Finck     Status = PsRemoveLoadImageNotifyRoutine(LoadImageNotifyRoutine);
155*c2c66affSColin Finck     ok_eq_hex(Status, STATUS_PROCEDURE_NOT_FOUND);
156*c2c66affSColin Finck 
157*c2c66affSColin Finck     Status = PsSetLoadImageNotifyRoutine(LoadImageNotifyRoutine);
158*c2c66affSColin Finck     ok_eq_hex(Status, STATUS_SUCCESS);
159*c2c66affSColin Finck 
160*c2c66affSColin Finck     /* TODO: test whether the callback is notified on image load */
161*c2c66affSColin Finck 
162*c2c66affSColin Finck     Status = PsRemoveLoadImageNotifyRoutine(LoadImageNotifyRoutine);
163*c2c66affSColin Finck     ok_eq_hex(Status, STATUS_SUCCESS);
164*c2c66affSColin Finck 
165*c2c66affSColin Finck     Status = PsRemoveLoadImageNotifyRoutine(LoadImageNotifyRoutine);
166*c2c66affSColin Finck     ok_eq_hex(Status, STATUS_PROCEDURE_NOT_FOUND);
167*c2c66affSColin Finck 
168*c2c66affSColin Finck     /* TODO: register the same routine twice */
169*c2c66affSColin Finck     /* TODO: register more than the maximum number of notifications */
170*c2c66affSColin Finck }
171*c2c66affSColin Finck 
START_TEST(PsNotify)172*c2c66affSColin Finck START_TEST(PsNotify)
173*c2c66affSColin Finck {
174*c2c66affSColin Finck     TestCreateProcessNotify();
175*c2c66affSColin Finck     TestCreateThreadNotify();
176*c2c66affSColin Finck     TestLoadImageNotify();
177*c2c66affSColin Finck }
178