VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/testcase/tstLow.cpp@ 5320

Last change on this file since 5320 was 4071, checked in by vboxsync, 17 years ago

Biggest check-in ever. New source code headers for all (C) innotek files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1/** @file
2 *
3 * VBox host drivers - Ring-0 support drivers - Testcases:
4 * Test allocating physical memory below 4G
5 */
6
7/*
8 * Copyright (C) 2006-2007 innotek GmbH
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License as published by the Free Software Foundation,
14 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
15 * distribution. VirtualBox OSE is distributed in the hope that it will
16 * be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19
20/*******************************************************************************
21* Header Files *
22*******************************************************************************/
23#include <VBox/sup.h>
24#include <VBox/param.h>
25#include <VBox/err.h>
26#include <iprt/runtime.h>
27#include <iprt/stream.h>
28
29#include <string.h>
30
31int main(int argc, char **argv)
32{
33 int rc;
34 int rcRet = 0;
35
36 RTR3Init(false);
37 RTPrintf("tstLow: TESTING...\n");
38
39 rc = SUPInit();
40 if (VBOX_SUCCESS(rc))
41 {
42 /*
43 * Allocate a bit of contiguous memory.
44 */
45 SUPPAGE aPages0[128];
46 void *pvPages0 = (void *)0x77777777;
47 memset(&aPages0[0], 0x8f, sizeof(aPages0));
48 rc = SUPLowAlloc(ELEMENTS(aPages0), &pvPages0, NULL, aPages0);
49 if (VBOX_SUCCESS(rc))
50 {
51 /* check that the pages are below 4GB and valid. */
52 for (unsigned iPage = 0; iPage < ELEMENTS(aPages0); iPage++)
53 {
54 RTPrintf("%-4d: Phys=%VHp Reserved=%p\n", iPage, aPages0[iPage].Phys, aPages0[iPage].uReserved);
55 if (aPages0[iPage].uReserved != 0)
56 {
57 rcRet++;
58 RTPrintf("tstLow: error: aPages0[%d].uReserved=%#x expected 0!\n", iPage, aPages0[iPage].uReserved);
59 }
60 if ( aPages0[iPage].Phys >= _4G
61 || (aPages0[iPage].Phys & PAGE_OFFSET_MASK))
62 {
63 rcRet++;
64 RTPrintf("tstLow: error: aPages0[%d].Phys=%VHp!\n", iPage, aPages0[iPage].Phys);
65 }
66 }
67 if (!rcRet)
68 {
69 for (unsigned iPage = 0; iPage < ELEMENTS(aPages0); iPage++)
70 memset((char *)pvPages0 + iPage * PAGE_SIZE, iPage, PAGE_SIZE);
71 for (unsigned iPage = 0; iPage < ELEMENTS(aPages0); iPage++)
72 for (uint8_t *pu8 = (uint8_t *)pvPages0 + iPage * PAGE_SIZE, *pu8End = pu8 + PAGE_SIZE; pu8 < pu8End; pu8++)
73 if (*pu8 != (uint8_t)iPage)
74 {
75 RTPrintf("tstLow: error: invalid page content %02x != %02x. iPage=%p off=%#x\n",
76 *pu8, (uint8_t)iPage, iPage, (uintptr_t)pu8 & PAGE_OFFSET_MASK);
77 rcRet++;
78 }
79 }
80 SUPLowFree(pvPages0, ELEMENTS(aPages0));
81 }
82 else
83 {
84 RTPrintf("SUPLowAlloc(%d,,) failed -> rc=%Vrc\n", ELEMENTS(aPages0), rc);
85 rcRet++;
86 }
87
88 /*
89 * Allocate odd amounts in from 1 to 127.
90 */
91 for (unsigned cPages = 1; cPages <= 127; cPages++)
92 {
93 SUPPAGE aPages1[128];
94 void *pvPages1 = (void *)0x77777777;
95 memset(&aPages1[0], 0x8f, sizeof(aPages1));
96 rc = SUPLowAlloc(cPages, &pvPages1, NULL, aPages1);
97 if (VBOX_SUCCESS(rc))
98 {
99 /* check that the pages are below 4GB and valid. */
100 for (unsigned iPage = 0; iPage < cPages; iPage++)
101 {
102 RTPrintf("%-4d::%-4d: Phys=%VHp Reserved=%p\n", cPages, iPage, aPages1[iPage].Phys, aPages1[iPage].uReserved);
103 if (aPages1[iPage].uReserved != 0)
104 {
105 rcRet++;
106 RTPrintf("tstLow: error: aPages1[%d].uReserved=%#x expected 0!\n", iPage, aPages1[iPage].uReserved);
107 }
108 if ( aPages1[iPage].Phys >= _4G
109 || (aPages1[iPage].Phys & PAGE_OFFSET_MASK))
110 {
111 rcRet++;
112 RTPrintf("tstLow: error: aPages1[%d].Phys=%VHp!\n", iPage, aPages1[iPage].Phys);
113 }
114 }
115 if (!rcRet)
116 {
117 for (unsigned iPage = 0; iPage < cPages; iPage++)
118 memset((char *)pvPages1 + iPage * PAGE_SIZE, iPage, PAGE_SIZE);
119 for (unsigned iPage = 0; iPage < cPages; iPage++)
120 for (uint8_t *pu8 = (uint8_t *)pvPages1 + iPage * PAGE_SIZE, *pu8End = pu8 + PAGE_SIZE; pu8 < pu8End; pu8++)
121 if (*pu8 != (uint8_t)iPage)
122 {
123 RTPrintf("tstLow: error: invalid page content %02x != %02x. iPage=%p off=%#x\n",
124 *pu8, (uint8_t)iPage, iPage, (uintptr_t)pu8 & PAGE_OFFSET_MASK);
125 rcRet++;
126 }
127 }
128 SUPLowFree(pvPages1, cPages);
129 }
130 else
131 {
132 RTPrintf("SUPLowAlloc(%d,,) failed -> rc=%Vrc\n", cPages, rc);
133 rcRet++;
134 }
135 }
136
137 }
138 else
139 {
140 RTPrintf("SUPInit -> rc=%Vrc\n", rc);
141 rcRet++;
142 }
143
144
145 return rcRet;
146}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette