ReactOS  0.4.14-dev-833-g5f692ed
IoMdl.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS kernel-mode tests
3  * LICENSE: LGPLv2+ - See COPYING.LIB in the top level directory
4  * PURPOSE: Kernel-Mode Test Suite Io Regressions KM-Test (Mdl)
5  * PROGRAMMER: Aleksey Bragin <aleksey@reactos.org>
6  */
7 
8 #include <kmt_test.h>
9 
10 #define NDEBUG
11 #include <debug.h>
12 
13 START_TEST(IoMdl)
14 {
15  PMDL Mdl;
16  PIRP Irp;
18  ULONG MdlSize = 2*4096+184; // 2 pages and some random value
19  ULONG TooLargeMdlSize = (0x10000 - sizeof(MDL)) / sizeof(ULONG_PTR) * PAGE_SIZE;
20 
21  // Try to alloc 2Gb MDL
22  Mdl = IoAllocateMdl(NULL, 2048UL*0x100000, FALSE, FALSE, NULL);
23 
24  ok(Mdl == NULL,
25  "IoAllocateMdl should fail allocation of 2Gb or more, but got Mdl=0x%X\n",
26  (UINT_PTR)Mdl);
27 
28  if (Mdl)
29  IoFreeMdl(Mdl);
30 
31  // Now create a valid MDL
33  Mdl = IoAllocateMdl(VirtualAddress, MdlSize, FALSE, FALSE, NULL);
34  ok(Mdl != NULL, "Mdl allocation failed\n");
35  // Check fields of the allocated struct
36  ok(Mdl->Next == NULL, "Mdl->Next should be NULL, but is 0x%X\n",
37  (UINT_PTR)Mdl->Next);
38  ok(Mdl->ByteCount == MdlSize,
39  "Mdl->ByteCount should be equal to MdlSize, but is 0x%X\n",
40  (UINT_PTR)Mdl->ByteCount);
41  // TODO: Check other fields of MDL struct
42 
43  IoFreeMdl(Mdl);
44 
45  // Test maximum size for an MDL
46  Mdl = IoAllocateMdl(NULL, TooLargeMdlSize, FALSE, FALSE, NULL);
47  ok(Mdl == NULL, "Mdl allocation for %lu bytes succeeded\n", TooLargeMdlSize);
48  if (Mdl) IoFreeMdl(Mdl);
49 
50  Mdl = IoAllocateMdl(NULL, TooLargeMdlSize - PAGE_SIZE + 1, FALSE, FALSE, NULL);
51  ok(Mdl == NULL, "Mdl allocation for %lu bytes succeeded\n", TooLargeMdlSize - PAGE_SIZE + 1);
52  if (Mdl) IoFreeMdl(Mdl);
53 
54  Mdl = IoAllocateMdl(NULL, TooLargeMdlSize - PAGE_SIZE, FALSE, FALSE, NULL);
55  ok(Mdl != NULL, "Mdl allocation for %lu bytes failed\n", TooLargeMdlSize - PAGE_SIZE);
56  if (Mdl) IoFreeMdl(Mdl);
57 
58  Mdl = IoAllocateMdl(NULL, TooLargeMdlSize / 2, FALSE, FALSE, NULL);
59  ok(Mdl != NULL, "Mdl allocation for %lu bytes failed\n", TooLargeMdlSize / 2);
60  if (Mdl) IoFreeMdl(Mdl);
61 
62  // Allocate now with pointer to an Irp
63  Irp = IoAllocateIrp(1, FALSE);
64  ok(Irp != NULL, "IRP allocation failed\n");
65  Mdl = IoAllocateMdl(VirtualAddress, MdlSize, FALSE, FALSE, Irp);
66  ok(Mdl != NULL, "Mdl allocation failed\n");
67  ok(Irp->MdlAddress == Mdl, "Irp->MdlAddress should be 0x%X, but is 0x%X\n",
68  (UINT_PTR)Mdl, (UINT_PTR)Irp->MdlAddress);
69 
70  IoFreeMdl(Mdl);
71 
72  // TODO: Check a case when SecondaryBuffer == TRUE
73 
74  IoFreeIrp(Irp);
76 }
_In_ PIRP Irp
Definition: csq.h:116
START_TEST(IoMdl)
Definition: IoMdl.c:13
smooth NULL
Definition: ftsmooth.c:416
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
MDL
Definition: mmtypes.h:117
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define PAGE_SIZE
Definition: env_spec_w32.h:49
_In_ ULONG _In_ BOOLEAN _Must_inspect_result_ PVOID * VirtualAddress
Definition: ndis.h:3791
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
#define ok(value,...)
Definition: atltest.h:57
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
#define UL
Definition: tui.h:83
#define ExFreePool(addr)
Definition: env_spec_w32.h:352