[NTOSKRNL] Add a raw implementation of !irpfind in kdbg
[reactos.git] / ntoskrnl / tests / tests / VirtualMemory.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/tests/tests/VirtualMemory.c
5 * PURPOSE: No purpose listed.
6 *
7 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 */
9
10 #include <ntoskrnl.h>
11 #include "regtests.h"
12
13 #define TestProcessHandle (HANDLE) 1
14 #define TestProcessObject (PVOID) 0x2
15 #define TestBaseAddress (PVOID) 0x1000
16 #define TestNumberOfBytesToLock 0x2000
17 #define TestMdl (PMDL) 0xD0000000
18
19 static BOOLEAN MockExFreePoolCalled = FALSE;
20
21 static VOID NTAPI
22 MockExFreePool(PVOID Block)
23 {
24 _AssertFalse(MockExFreePoolCalled);
25 _AssertEqualValue(TestMdl, Block);
26 MockExFreePoolCalled = TRUE;
27 }
28
29 static BOOLEAN MockMmCreateMdlCalled = FALSE;
30
31 static PMDL NTAPI
32 MockMmCreateMdl(PMDL Mdl,
33 PVOID Base,
34 ULONG Length)
35 {
36 _AssertFalse(MockMmCreateMdlCalled);
37 _AssertEqualValue(TestBaseAddress, Base);
38 _AssertEqualValue(TestNumberOfBytesToLock, Length);
39 MockMmCreateMdlCalled = TRUE;
40 return TestMdl;
41 }
42
43 static BOOLEAN MockMmProbeAndLockPagesCalled = FALSE;
44
45 static VOID NTAPI
46 MockMmProbeAndLockPages(PMDL Mdl,
47 KPROCESSOR_MODE AccessMode,
48 LOCK_OPERATION Operation)
49 {
50 _AssertFalse(MockMmProbeAndLockPagesCalled);
51 _AssertEqualValue(TestMdl, Mdl);
52 _AssertEqualValue(UserMode, AccessMode);
53 _AssertEqualValue(IoWriteAccess, Operation);
54 MockMmProbeAndLockPagesCalled = TRUE;
55 }
56
57 static BOOLEAN MockObDereferenceObjectCalled = FALSE;
58
59 static VOID FASTCALL
60 MockObDereferenceObject(PVOID Object)
61 {
62 _AssertFalse(MockObDereferenceObjectCalled);
63 _AssertEqualValue(TestProcessObject, Object);
64 MockObDereferenceObjectCalled = TRUE;
65 }
66
67 static BOOLEAN MockObReferenceObjectByHandleCalled = FALSE;
68
69 static NTSTATUS NTAPI
70 MockObReferenceObjectByHandle(HANDLE Handle,
71 ACCESS_MASK DesiredAccess,
72 POBJECT_TYPE ObjectType,
73 KPROCESSOR_MODE AccessMode,
74 PVOID* Object,
75 POBJECT_HANDLE_INFORMATION HandleInformation)
76 {
77 _AssertFalse(MockObReferenceObjectByHandleCalled);
78 _AssertEqualValue(TestProcessHandle, Handle);
79 _AssertEqualValue(PROCESS_VM_WRITE, DesiredAccess);
80 _AssertEqualValue(NULL, ObjectType);
81 _AssertEqualValue(UserMode, AccessMode);
82 _AssertNotEqualValue(NULL, Object);
83 _AssertEqualValue(NULL, HandleInformation);
84 *Object = TestProcessObject;
85 MockObReferenceObjectByHandleCalled = TRUE;
86 return STATUS_SUCCESS;
87 }
88
89 static void RunTest()
90 {
91 ULONG NumberOfBytesLocked;
92 NTSTATUS status;
93
94 status = MiLockVirtualMemory(TestProcessHandle,
95 TestBaseAddress,
96 TestNumberOfBytesToLock,
97 &NumberOfBytesLocked,
98 MockObReferenceObjectByHandle,
99 MockMmCreateMdl,
100 MockObDereferenceObject,
101 MockMmProbeAndLockPages,
102 MockExFreePool);
103 _AssertEqualValue(STATUS_SUCCESS, status);
104 _AssertTrue(MockObReferenceObjectByHandleCalled);
105 _AssertTrue(MockMmCreateMdlCalled);
106 _AssertTrue(MockMmProbeAndLockPagesCalled);
107 _AssertTrue(MockExFreePoolCalled);
108 _AssertTrue(MockObDereferenceObjectCalled);
109 _AssertEqualValue(TestNumberOfBytesToLock, NumberOfBytesLocked);
110 }
111
112 _Dispatcher(VirtualmemoryTest, "Virtual memory")