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