VirtualBox

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

Last change on this file since 26600 was 22077, checked in by vboxsync, 15 years ago

HostDrivers/Support: header and svn props cleanup.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 KB
Line 
1/* $Id: tstLow.cpp 22077 2009-08-07 16:01:57Z vboxsync $ */
2/** @file
3 * SUP Testcase - Low (<4GB) Memory Allocate interface (ring 3).
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#include <VBox/sup.h>
36#include <VBox/param.h>
37#include <VBox/err.h>
38#include <iprt/initterm.h>
39#include <iprt/stream.h>
40#include <iprt/string.h>
41
42
43int main(int argc, char **argv)
44{
45 int rc;
46 int rcRet = 0;
47
48 RTR3Init();
49 RTPrintf("tstLow: TESTING...\n");
50
51 rc = SUPR3Init(NULL);
52 if (RT_SUCCESS(rc))
53 {
54 /*
55 * Allocate a bit of contiguous memory.
56 */
57 SUPPAGE aPages0[128];
58 void *pvPages0 = (void *)0x77777777;
59 memset(&aPages0[0], 0x8f, sizeof(aPages0));
60 rc = SUPR3LowAlloc(RT_ELEMENTS(aPages0), &pvPages0, NULL, aPages0);
61 if (RT_SUCCESS(rc))
62 {
63 /* check that the pages are below 4GB and valid. */
64 for (unsigned iPage = 0; iPage < RT_ELEMENTS(aPages0); iPage++)
65 {
66 RTPrintf("%-4d: Phys=%RHp Reserved=%p\n", iPage, aPages0[iPage].Phys, aPages0[iPage].uReserved);
67 if (aPages0[iPage].uReserved != 0)
68 {
69 rcRet++;
70 RTPrintf("tstLow: error: aPages0[%d].uReserved=%#x expected 0!\n", iPage, aPages0[iPage].uReserved);
71 }
72 if ( aPages0[iPage].Phys >= _4G
73 || (aPages0[iPage].Phys & PAGE_OFFSET_MASK))
74 {
75 rcRet++;
76 RTPrintf("tstLow: error: aPages0[%d].Phys=%RHp!\n", iPage, aPages0[iPage].Phys);
77 }
78 }
79 if (!rcRet)
80 {
81 for (unsigned iPage = 0; iPage < RT_ELEMENTS(aPages0); iPage++)
82 memset((char *)pvPages0 + iPage * PAGE_SIZE, iPage, PAGE_SIZE);
83 for (unsigned iPage = 0; iPage < RT_ELEMENTS(aPages0); iPage++)
84 for (uint8_t *pu8 = (uint8_t *)pvPages0 + iPage * PAGE_SIZE, *pu8End = pu8 + PAGE_SIZE; pu8 < pu8End; pu8++)
85 if (*pu8 != (uint8_t)iPage)
86 {
87 RTPrintf("tstLow: error: invalid page content %02x != %02x. iPage=%p off=%#x\n",
88 *pu8, (uint8_t)iPage, iPage, (uintptr_t)pu8 & PAGE_OFFSET_MASK);
89 rcRet++;
90 }
91 }
92 SUPR3LowFree(pvPages0, RT_ELEMENTS(aPages0));
93 }
94 else
95 {
96 RTPrintf("SUPR3LowAlloc(%d,,) failed -> rc=%Rrc\n", RT_ELEMENTS(aPages0), rc);
97 rcRet++;
98 }
99
100 /*
101 * Allocate odd amounts in from 1 to 127.
102 */
103 for (unsigned cPages = 1; cPages <= 127; cPages++)
104 {
105 SUPPAGE aPages1[128];
106 void *pvPages1 = (void *)0x77777777;
107 memset(&aPages1[0], 0x8f, sizeof(aPages1));
108 rc = SUPR3LowAlloc(cPages, &pvPages1, NULL, aPages1);
109 if (RT_SUCCESS(rc))
110 {
111 /* check that the pages are below 4GB and valid. */
112 for (unsigned iPage = 0; iPage < cPages; iPage++)
113 {
114 RTPrintf("%-4d::%-4d: Phys=%RHp Reserved=%p\n", cPages, iPage, aPages1[iPage].Phys, aPages1[iPage].uReserved);
115 if (aPages1[iPage].uReserved != 0)
116 {
117 rcRet++;
118 RTPrintf("tstLow: error: aPages1[%d].uReserved=%#x expected 0!\n", iPage, aPages1[iPage].uReserved);
119 }
120 if ( aPages1[iPage].Phys >= _4G
121 || (aPages1[iPage].Phys & PAGE_OFFSET_MASK))
122 {
123 rcRet++;
124 RTPrintf("tstLow: error: aPages1[%d].Phys=%RHp!\n", iPage, aPages1[iPage].Phys);
125 }
126 }
127 if (!rcRet)
128 {
129 for (unsigned iPage = 0; iPage < cPages; iPage++)
130 memset((char *)pvPages1 + iPage * PAGE_SIZE, iPage, PAGE_SIZE);
131 for (unsigned iPage = 0; iPage < cPages; iPage++)
132 for (uint8_t *pu8 = (uint8_t *)pvPages1 + iPage * PAGE_SIZE, *pu8End = pu8 + PAGE_SIZE; pu8 < pu8End; pu8++)
133 if (*pu8 != (uint8_t)iPage)
134 {
135 RTPrintf("tstLow: error: invalid page content %02x != %02x. iPage=%p off=%#x\n",
136 *pu8, (uint8_t)iPage, iPage, (uintptr_t)pu8 & PAGE_OFFSET_MASK);
137 rcRet++;
138 }
139 }
140 SUPR3LowFree(pvPages1, cPages);
141 }
142 else
143 {
144 RTPrintf("SUPR3LowAlloc(%d,,) failed -> rc=%Rrc\n", cPages, rc);
145 rcRet++;
146 }
147 }
148
149 }
150 else
151 {
152 RTPrintf("SUPR3Init -> rc=%Rrc\n", rc);
153 rcRet++;
154 }
155
156
157 return rcRet;
158}
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