763aeac558982f38ea5b482f5c00cbbcb33af434
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>
18 ULONG MdlSize
= 2*4096+184; // 2 pages and some random value
19 ULONG TooLargeMdlSize
= (0x10000 - sizeof(MDL
)) / sizeof(ULONG_PTR
) * PAGE_SIZE
;
21 // Try to alloc 2Gb MDL
22 Mdl
= IoAllocateMdl(NULL
, 2048UL*0x100000, FALSE
, FALSE
, NULL
);
25 "IoAllocateMdl should fail allocation of 2Gb or more, but got Mdl=0x%X\n",
31 // Now create a valid MDL
32 VirtualAddress
= ExAllocatePool(NonPagedPool
, MdlSize
);
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",
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
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
);
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
);
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
);
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
);
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
);
72 // TODO: Check a case when SecondaryBuffer == TRUE
75 ExFreePool(VirtualAddress
);