ReactOS 0.4.16-dev-125-g798ea90
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
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)
30
31 // Now create a valid MDL
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
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
64 ok(Irp != NULL, "IRP allocation failed\n");
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
71
72 // TODO: Check a case when SecondaryBuffer == TRUE
73
76}
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define ULONG_PTR
Definition: config.h:101
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define NonPagedPool
Definition: env_spec_w32.h:307
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define IoFreeMdl
Definition: fxmdl.h:89
#define IoAllocateMdl
Definition: fxmdl.h:88
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDMATRANSACTION _In_ PFN_WDF_PROGRAM_DMA _In_ WDF_DMA_DIRECTION _In_ PMDL _In_ PVOID VirtualAddress
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
MDL
Definition: mmtypes.h:117