898761cfac488a5ee68877f855250ace824990c8
[reactos.git] / rostests / kmtests / ntos_io / IoMdl.c
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;
17 PVOID VirtualAddress;
18 ULONG MdlSize = 2*4096+184; // 2 pages and some random value
19
20 // Try to alloc 2Gb MDL
21 Mdl = IoAllocateMdl(NULL, 2048UL*0x100000, FALSE, FALSE, NULL);
22
23 ok(Mdl == NULL,
24 "IoAllocateMdl should fail allocation of 2Gb or more, but got Mdl=0x%X",
25 (UINT_PTR)Mdl);
26
27 if (Mdl)
28 IoFreeMdl(Mdl);
29
30 // Now create a valid MDL
31 VirtualAddress = ExAllocatePool(NonPagedPool, MdlSize);
32 Mdl = IoAllocateMdl(VirtualAddress, MdlSize, FALSE, FALSE, NULL);
33 ok(Mdl != NULL, "Mdl allocation failed");
34 // Check fields of the allocated struct
35 ok(Mdl->Next == NULL, "Mdl->Next should be NULL, but is 0x%X",
36 (UINT_PTR)Mdl->Next);
37 ok(Mdl->ByteCount == MdlSize,
38 "Mdl->ByteCount should be equal to MdlSize, but is 0x%X",
39 (UINT_PTR)Mdl->ByteCount);
40 // TODO: Check other fields of MDL struct
41
42 IoFreeMdl(Mdl);
43 // Allocate now with pointer to an Irp
44 Irp = IoAllocateIrp(1, FALSE);
45 ok(Irp != NULL, "IRP allocation failed");
46 Mdl = IoAllocateMdl(VirtualAddress, MdlSize, FALSE, FALSE, Irp);
47 ok(Mdl != NULL, "Mdl allocation failed");
48 ok(Irp->MdlAddress == Mdl, "Irp->MdlAddress should be 0x%X, but is 0x%X",
49 (UINT_PTR)Mdl, (UINT_PTR)Irp->MdlAddress);
50
51 IoFreeMdl(Mdl);
52
53 // TODO: Check a case when SecondaryBuffer == TRUE
54
55 IoFreeIrp(Irp);
56 ExFreePool(VirtualAddress);
57 }