Sync to trunk r39350.
[reactos.git] / rostests / drivers / kmtest / ntos_io.c
1 /*
2 * NTOSKRNL Io Regressions KM-Test
3 * ReactOS Kernel Mode Regression Testing framework
4 *
5 * Copyright 2006 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 "kmtest.h"
27
28 #define NDEBUG
29 #include "debug.h"
30
31 /* PUBLIC FUNCTIONS ***********************************************************/
32
33 VOID NtoskrnlIoMdlTest()
34 {
35 PMDL Mdl;
36 PIRP Irp;
37 PVOID VirtualAddress;
38 ULONG MdlSize = 2*4096+184; // 2 pages and some random value
39
40 StartTest();
41
42 // Try to alloc 2Gb MDL
43 Mdl = IoAllocateMdl(NULL, 2048UL*0x100000, FALSE, FALSE, NULL);
44
45 ok(Mdl == NULL,
46 "IoAllocateMdl should fail allocation of 2Gb or more, but got Mdl=0x%X",
47 (UINT)Mdl);
48
49 if (Mdl)
50 IoFreeMdl(Mdl);
51
52 // Now create a valid MDL
53 VirtualAddress = ExAllocatePool(NonPagedPool, MdlSize);
54 Mdl = IoAllocateMdl(VirtualAddress, MdlSize, FALSE, FALSE, NULL);
55 ok(Mdl != NULL, "Mdl allocation failed");
56 // Check fields of the allocated struct
57 ok(Mdl->Next == NULL, "Mdl->Next should be NULL, but is 0x%X",
58 (UINT)Mdl->Next);
59 ok(Mdl->ByteCount == MdlSize,
60 "Mdl->ByteCount should be equal to MdlSize, but is 0x%X",
61 (UINT)Mdl->ByteCount);
62 // TODO: Check other fields of MDL struct
63
64 IoFreeMdl(Mdl);
65 // Allocate now with pointer to an Irp
66 Irp = IoAllocateIrp(1, FALSE);
67 ok(Irp != NULL, "IRP allocation failed");
68 Mdl = IoAllocateMdl(VirtualAddress, MdlSize, FALSE, FALSE, Irp);
69 ok(Mdl != NULL, "Mdl allocation failed");
70 ok(Irp->MdlAddress == Mdl, "Irp->MdlAddress should be 0x%X, but is 0x%X",
71 (UINT)Mdl, (UINT)Irp->MdlAddress);
72
73 IoFreeMdl(Mdl);
74
75 // TODO: Check a case when SecondaryBuffer == TRUE
76
77 IoFreeIrp(Irp);
78 ExFreePool(VirtualAddress);
79
80 FinishTest("NTOSKRNL Io Mdl");
81 }