Sync to trunk (r44371)
[reactos.git] / rostests / drivers / kmtest / ntos_pools.c
1 /*
2 * NTOSKRNL Pools test routines KM-Test
3 * ReactOS Kernel Mode Regression Testing framework
4 *
5 * Copyright 2008 Aleksey Bragin <aleksey@reactos.org>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; see the file COPYING.LIB.
19 * If not, write to the Free Software Foundation,
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 */
22
23 /* INCLUDES *******************************************************************/
24
25 #include <ddk/ntddk.h>
26 #include <ntifs.h>
27 #include <ndk/ntndk.h>
28 #include "kmtest.h"
29
30 //#define NDEBUG
31 #include "debug.h"
32
33 #define TAG_POOLTEST TAG('P','t','s','t')
34
35 /* PRIVATE FUNCTIONS ***********************************************************/
36
37 VOID
38 PoolsTest()
39 {
40 PVOID Ptr;
41 ULONG AllocSize, i, AllocNumber;
42 PVOID *Allocs;
43
44 StartTest();
45
46 // Stress-test nonpaged pool
47 for (i=1; i<10000; i++)
48 {
49 // make up some increasing, a bit irregular size
50 AllocSize = i*10;
51
52 if (i % 10)
53 AllocSize++;
54
55 if (i % 25)
56 AllocSize += 13;
57
58 // start with non-paged pool
59 Ptr = ExAllocatePoolWithTag(NonPagedPool, AllocSize, TAG_POOLTEST);
60
61 // it may fail due to no-memory condition
62 if (!Ptr) break;
63
64 // try to fully fill it
65 RtlFillMemory(Ptr, AllocSize, 0xAB);
66
67 // free it
68 ExFreePoolWithTag(Ptr, TAG_POOLTEST);
69 }
70
71 // now paged one
72 for (i=1; i<10000; i++)
73 {
74 // make up some increasing, a bit irregular size
75 AllocSize = i*50;
76
77 if (i % 10)
78 AllocSize++;
79
80 if (i % 25)
81 AllocSize += 13;
82
83 // start with non-paged pool
84 Ptr = ExAllocatePoolWithTag(PagedPool, AllocSize, TAG_POOLTEST);
85
86 // it may fail due to no-memory condition
87 if (!Ptr) break;
88
89 // try to fully fill it
90 RtlFillMemory(Ptr, AllocSize, 0xAB);
91
92 // free it
93 ExFreePoolWithTag(Ptr, TAG_POOLTEST);
94 }
95
96 // test super-big allocations
97 /*AllocSize = 2UL * 1024 * 1024 * 1024;
98 Ptr = ExAllocatePoolWithTag(NonPagedPool, AllocSize, TAG_POOLTEST);
99 ok(Ptr == NULL, "Allocating 2Gb of nonpaged pool should fail\n");
100
101 Ptr = ExAllocatePoolWithTag(PagedPool, AllocSize, TAG_POOLTEST);
102 ok(Ptr == NULL, "Allocating 2Gb of paged pool should fail\n");*/
103
104 // now test allocating lots of small/medium blocks
105 AllocNumber = 100000;
106 Allocs = ExAllocatePoolWithTag(PagedPool, sizeof(Allocs) * AllocNumber, TAG_POOLTEST);
107
108 // alloc blocks
109 for (i=0; i<AllocNumber; i++)
110 {
111 AllocSize = 42;
112 Allocs[i] = ExAllocatePoolWithTag(NonPagedPool, AllocSize, TAG_POOLTEST);
113 }
114
115 // now free them
116 for (i=0; i<AllocNumber; i++)
117 {
118 ExFreePoolWithTag(Allocs[i], TAG_POOLTEST);
119 }
120
121
122 ExFreePoolWithTag(Allocs, TAG_POOLTEST);
123
124
125 FinishTest("NTOSKRNL Pools Tests");
126 }
127
128 /* PUBLIC FUNCTIONS ***********************************************************/
129
130 VOID
131 NtoskrnlPoolsTest()
132 {
133 PoolsTest();
134 }