[KMTESTS:MM]
[reactos.git] / rostests / kmtests / ntos_mm / MmMapLockedPagesSpecifyCache_user.c
1 /*
2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Kernel-Mode Test Suite MmMapLockedPagesSpecifyCache test user-mode part
5 * PROGRAMMER: Pierre Schweitzer <pierre@reactos.org>
6 */
7
8 #include <kmt_test.h>
9
10 #include "MmMapLockedPagesSpecifyCache.h"
11
12 #define SET_BUFFER_LENGTH(Var, Length) \
13 { \
14 C_ASSERT(((Length) % sizeof(ULONG)) == 0); \
15 Var = (Length); \
16 }
17
18 START_TEST(MmMapLockedPagesSpecifyCache)
19 {
20 QUERY_BUFFER QueryBuffer;
21 READ_BUFFER ReadBuffer;
22 DWORD Length;
23 USHORT i;
24 PULONG Buffer;
25 USHORT BufferLength;
26
27 KmtLoadDriver(L"MmMapLockedPagesSpecifyCache", FALSE);
28 KmtOpenDriver();
29
30 // Less than a page
31 SET_BUFFER_LENGTH(BufferLength, 2048);
32 QueryBuffer.Length = BufferLength;
33 QueryBuffer.Buffer = NULL;
34 QueryBuffer.Cached = FALSE;
35 Length = sizeof(QUERY_BUFFER);
36 ok(KmtSendBufferToDriver(IOCTL_QUERY_BUFFER, &QueryBuffer, sizeof(QUERY_BUFFER), &Length) == ERROR_SUCCESS, "\n");
37 ok_eq_int(QueryBuffer.Length, BufferLength);
38 ok_eq_pointer(QueryBuffer.Buffer, NULL);
39
40 ReadBuffer.Buffer = QueryBuffer.Buffer;
41 Length = 0;
42 ok(KmtSendBufferToDriver(IOCTL_READ_BUFFER, &ReadBuffer, sizeof(READ_BUFFER), &Length) == ERROR_SUCCESS, "\n");
43
44 QueryBuffer.Length = BufferLength;
45 QueryBuffer.Buffer = NULL;
46 QueryBuffer.Cached = TRUE;
47 Length = sizeof(QUERY_BUFFER);
48 ok(KmtSendBufferToDriver(IOCTL_QUERY_BUFFER, &QueryBuffer, sizeof(QUERY_BUFFER), &Length) == ERROR_SUCCESS, "\n");
49 ok_eq_int(QueryBuffer.Length, BufferLength);
50 ok(QueryBuffer.Buffer != NULL, "Buffer is NULL\n");
51
52 ReadBuffer.Buffer = QueryBuffer.Buffer;
53 if (!skip(QueryBuffer.Buffer != NULL, "Buffer is NULL\n"))
54 {
55 ReadBuffer.Pattern = WRITE_PATTERN;
56 ReadBuffer.Length = QueryBuffer.Length;
57 Buffer = QueryBuffer.Buffer;
58 for (i = 0; i < ReadBuffer.Length / sizeof(ULONG); ++i)
59 {
60 Buffer[i] = ReadBuffer.Pattern;
61 }
62 }
63
64 Length = 0;
65 ok(KmtSendBufferToDriver(IOCTL_READ_BUFFER, &ReadBuffer, sizeof(READ_BUFFER), &Length) == ERROR_SUCCESS, "\n");
66
67 // 1 page
68 SET_BUFFER_LENGTH(BufferLength, 4096);
69 QueryBuffer.Length = BufferLength;
70 QueryBuffer.Buffer = NULL;
71 QueryBuffer.Cached = FALSE;
72 Length = sizeof(QUERY_BUFFER);
73 ok(KmtSendBufferToDriver(IOCTL_QUERY_BUFFER, &QueryBuffer, sizeof(QUERY_BUFFER), &Length) == ERROR_SUCCESS, "\n");
74 ok_eq_int(QueryBuffer.Length, BufferLength);
75 ok_eq_pointer(QueryBuffer.Buffer, NULL);
76
77 ReadBuffer.Buffer = QueryBuffer.Buffer;
78 Length = 0;
79 ok(KmtSendBufferToDriver(IOCTL_READ_BUFFER, &ReadBuffer, sizeof(READ_BUFFER), &Length) == ERROR_SUCCESS, "\n");
80
81 QueryBuffer.Length = BufferLength;
82 QueryBuffer.Buffer = NULL;
83 QueryBuffer.Cached = TRUE;
84 Length = sizeof(QUERY_BUFFER);
85 ok(KmtSendBufferToDriver(IOCTL_QUERY_BUFFER, &QueryBuffer, sizeof(QUERY_BUFFER), &Length) == ERROR_SUCCESS, "\n");
86 ok_eq_int(QueryBuffer.Length, BufferLength);
87 ok(QueryBuffer.Buffer != NULL, "Buffer is NULL\n");
88
89 ReadBuffer.Buffer = QueryBuffer.Buffer;
90 if (!skip(QueryBuffer.Buffer != NULL, "Buffer is NULL\n"))
91 {
92 ReadBuffer.Pattern = WRITE_PATTERN;
93 ReadBuffer.Length = QueryBuffer.Length;
94 Buffer = QueryBuffer.Buffer;
95 for (i = 0; i < ReadBuffer.Length / sizeof(ULONG); ++i)
96 {
97 Buffer[i] = ReadBuffer.Pattern;
98 }
99 }
100
101 Length = 0;
102 ok(KmtSendBufferToDriver(IOCTL_READ_BUFFER, &ReadBuffer, sizeof(READ_BUFFER), &Length) == ERROR_SUCCESS, "\n");
103
104 // more than 1 page
105 SET_BUFFER_LENGTH(BufferLength, 4096 + 2048);
106 QueryBuffer.Length = BufferLength;
107 QueryBuffer.Buffer = NULL;
108 QueryBuffer.Cached = FALSE;
109 Length = sizeof(QUERY_BUFFER);
110 ok(KmtSendBufferToDriver(IOCTL_QUERY_BUFFER, &QueryBuffer, sizeof(QUERY_BUFFER), &Length) == ERROR_SUCCESS, "\n");
111 ok_eq_int(QueryBuffer.Length, BufferLength);
112 ok_eq_pointer(QueryBuffer.Buffer, NULL);
113
114 ReadBuffer.Buffer = QueryBuffer.Buffer;
115 Length = 0;
116 ok(KmtSendBufferToDriver(IOCTL_READ_BUFFER, &ReadBuffer, sizeof(READ_BUFFER), &Length) == ERROR_SUCCESS, "\n");
117
118 QueryBuffer.Length = BufferLength;
119 QueryBuffer.Buffer = NULL;
120 QueryBuffer.Cached = TRUE;
121 Length = sizeof(QUERY_BUFFER);
122 ok(KmtSendBufferToDriver(IOCTL_QUERY_BUFFER, &QueryBuffer, sizeof(QUERY_BUFFER), &Length) == ERROR_SUCCESS, "\n");
123 ok_eq_int(QueryBuffer.Length, BufferLength);
124 ok(QueryBuffer.Buffer != NULL, "Buffer is NULL\n");
125
126 ReadBuffer.Buffer = QueryBuffer.Buffer;
127 if (!skip(QueryBuffer.Buffer != NULL, "Buffer is NULL\n"))
128 {
129 ReadBuffer.Pattern = WRITE_PATTERN;
130 ReadBuffer.Length = QueryBuffer.Length;
131 Buffer = QueryBuffer.Buffer;
132 for (i = 0; i < ReadBuffer.Length / sizeof(ULONG); ++i)
133 {
134 Buffer[i] = ReadBuffer.Pattern;
135 }
136 }
137
138 Length = 0;
139 ok(KmtSendBufferToDriver(IOCTL_READ_BUFFER, &ReadBuffer, sizeof(READ_BUFFER), &Length) == ERROR_SUCCESS, "\n");
140
141 // 2 pages
142 SET_BUFFER_LENGTH(BufferLength, 2 * 4096);
143 QueryBuffer.Length = BufferLength;
144 QueryBuffer.Buffer = NULL;
145 QueryBuffer.Cached = FALSE;
146 Length = sizeof(QUERY_BUFFER);
147 ok(KmtSendBufferToDriver(IOCTL_QUERY_BUFFER, &QueryBuffer, sizeof(QUERY_BUFFER), &Length) == ERROR_SUCCESS, "\n");
148 ok_eq_int(QueryBuffer.Length, BufferLength);
149 ok_eq_pointer(QueryBuffer.Buffer, NULL);
150
151 ReadBuffer.Buffer = QueryBuffer.Buffer;
152 Length = 0;
153 ok(KmtSendBufferToDriver(IOCTL_READ_BUFFER, &ReadBuffer, sizeof(READ_BUFFER), &Length) == ERROR_SUCCESS, "\n");
154
155 QueryBuffer.Length = BufferLength;
156 QueryBuffer.Buffer = NULL;
157 QueryBuffer.Cached = TRUE;
158 Length = sizeof(QUERY_BUFFER);
159 ok(KmtSendBufferToDriver(IOCTL_QUERY_BUFFER, &QueryBuffer, sizeof(QUERY_BUFFER), &Length) == ERROR_SUCCESS, "\n");
160 ok_eq_int(QueryBuffer.Length, BufferLength);
161 ok(QueryBuffer.Buffer != NULL, "Buffer is NULL\n");
162
163 ReadBuffer.Buffer = QueryBuffer.Buffer;
164 if (!skip(QueryBuffer.Buffer != NULL, "Buffer is NULL\n"))
165 {
166 ReadBuffer.Pattern = WRITE_PATTERN;
167 ReadBuffer.Length = QueryBuffer.Length;
168 Buffer = QueryBuffer.Buffer;
169 for (i = 0; i < ReadBuffer.Length / sizeof(ULONG); ++i)
170 {
171 Buffer[i] = ReadBuffer.Pattern;
172 }
173 }
174
175 Length = 0;
176 ok(KmtSendBufferToDriver(IOCTL_READ_BUFFER, &ReadBuffer, sizeof(READ_BUFFER), &Length) == ERROR_SUCCESS, "\n");
177
178 // more than 2 pages
179 SET_BUFFER_LENGTH(BufferLength, 2 * 4096 + 2048);
180 QueryBuffer.Length = BufferLength;
181 QueryBuffer.Buffer = NULL;
182 QueryBuffer.Cached = FALSE;
183 Length = sizeof(QUERY_BUFFER);
184 ok(KmtSendBufferToDriver(IOCTL_QUERY_BUFFER, &QueryBuffer, sizeof(QUERY_BUFFER), &Length) == ERROR_SUCCESS, "\n");
185 ok_eq_int(QueryBuffer.Length, BufferLength);
186 ok_eq_pointer(QueryBuffer.Buffer, NULL);
187
188 ReadBuffer.Buffer = QueryBuffer.Buffer;
189 Length = 0;
190 ok(KmtSendBufferToDriver(IOCTL_READ_BUFFER, &ReadBuffer, sizeof(READ_BUFFER), &Length) == ERROR_SUCCESS, "\n");
191
192 QueryBuffer.Length = BufferLength;
193 QueryBuffer.Buffer = NULL;
194 QueryBuffer.Cached = TRUE;
195 Length = sizeof(QUERY_BUFFER);
196 ok(KmtSendBufferToDriver(IOCTL_QUERY_BUFFER, &QueryBuffer, sizeof(QUERY_BUFFER), &Length) == ERROR_SUCCESS, "\n");
197 ok_eq_int(QueryBuffer.Length, BufferLength);
198 ok(QueryBuffer.Buffer != NULL, "Buffer is NULL\n");
199
200 ReadBuffer.Buffer = QueryBuffer.Buffer;
201 if (!skip(QueryBuffer.Buffer != NULL, "Buffer is NULL\n"))
202 {
203 ReadBuffer.Pattern = WRITE_PATTERN;
204 ReadBuffer.Length = QueryBuffer.Length;
205 Buffer = QueryBuffer.Buffer;
206 for (i = 0; i < ReadBuffer.Length / sizeof(ULONG); ++i)
207 {
208 Buffer[i] = ReadBuffer.Pattern;
209 }
210 }
211
212 Length = 0;
213 ok(KmtSendBufferToDriver(IOCTL_READ_BUFFER, &ReadBuffer, sizeof(READ_BUFFER), &Length) == ERROR_SUCCESS, "\n");
214
215 KmtCloseDriver();
216 KmtUnloadDriver();
217 }