VirtualBox

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

Last change on this file since 78138 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • 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 76553 2019-01-01 01:45:53Z vboxsync $ */
2/** @file
3 * SUP Testcase - Low (<4GB) Memory Allocate interface (ring 3).
4 */
5
6/*
7 * Copyright (C) 2006-2019 Oracle Corporation
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
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include <VBox/sup.h>
32#include <VBox/param.h>
33#include <iprt/errcore.h>
34#include <iprt/initterm.h>
35#include <iprt/stream.h>
36#include <iprt/string.h>
37
38
39int main(int argc, char **argv)
40{
41 int rc;
42 int rcRet = 0;
43
44 RTR3InitExe(argc, &argv, 0);
45 RTPrintf("tstLow: TESTING...\n");
46
47 rc = SUPR3Init(NULL);
48 if (RT_SUCCESS(rc))
49 {
50 /*
51 * Allocate a bit of contiguous memory.
52 */
53 SUPPAGE aPages0[128];
54 void *pvPages0 = (void *)0x77777777;
55 memset(&aPages0[0], 0x8f, sizeof(aPages0));
56 rc = SUPR3LowAlloc(RT_ELEMENTS(aPages0), &pvPages0, NULL, aPages0);
57 if (RT_SUCCESS(rc))
58 {
59 /* check that the pages are below 4GB and valid. */
60 for (unsigned iPage = 0; iPage < RT_ELEMENTS(aPages0); iPage++)
61 {
62 RTPrintf("%-4d: Phys=%RHp Reserved=%p\n", iPage, aPages0[iPage].Phys, aPages0[iPage].uReserved);
63 if (aPages0[iPage].uReserved != 0)
64 {
65 rcRet++;
66 RTPrintf("tstLow: error: aPages0[%d].uReserved=%#x expected 0!\n", iPage, aPages0[iPage].uReserved);
67 }
68 if ( aPages0[iPage].Phys >= _4G
69 || (aPages0[iPage].Phys & PAGE_OFFSET_MASK))
70 {
71 rcRet++;
72 RTPrintf("tstLow: error: aPages0[%d].Phys=%RHp!\n", iPage, aPages0[iPage].Phys);
73 }
74 }
75 if (!rcRet)
76 {
77 for (unsigned iPage = 0; iPage < RT_ELEMENTS(aPages0); iPage++)
78 memset((char *)pvPages0 + iPage * PAGE_SIZE, iPage, PAGE_SIZE);
79 for (unsigned iPage = 0; iPage < RT_ELEMENTS(aPages0); iPage++)
80 for (uint8_t *pu8 = (uint8_t *)pvPages0 + iPage * PAGE_SIZE, *pu8End = pu8 + PAGE_SIZE; pu8 < pu8End; pu8++)
81 if (*pu8 != (uint8_t)iPage)
82 {
83 RTPrintf("tstLow: error: invalid page content %02x != %02x. iPage=%u off=%#x\n",
84 *pu8, (uint8_t)iPage, iPage, (uintptr_t)pu8 & PAGE_OFFSET_MASK);
85 rcRet++;
86 }
87 }
88 SUPR3LowFree(pvPages0, RT_ELEMENTS(aPages0));
89 }
90 else
91 {
92 RTPrintf("SUPR3LowAlloc(%d,,) failed -> rc=%Rrc\n", RT_ELEMENTS(aPages0), rc);
93 rcRet++;
94 }
95
96 /*
97 * Allocate odd amounts in from 1 to 127.
98 */
99 for (unsigned cPages = 1; cPages <= 127; cPages++)
100 {
101 SUPPAGE aPages1[128];
102 void *pvPages1 = (void *)0x77777777;
103 memset(&aPages1[0], 0x8f, sizeof(aPages1));
104 rc = SUPR3LowAlloc(cPages, &pvPages1, NULL, aPages1);
105 if (RT_SUCCESS(rc))
106 {
107 /* check that the pages are below 4GB and valid. */
108 for (unsigned iPage = 0; iPage < cPages; iPage++)
109 {
110 RTPrintf("%-4d::%-4d: Phys=%RHp Reserved=%p\n", cPages, iPage, aPages1[iPage].Phys, aPages1[iPage].uReserved);
111 if (aPages1[iPage].uReserved != 0)
112 {
113 rcRet++;
114 RTPrintf("tstLow: error: aPages1[%d].uReserved=%#x expected 0!\n", iPage, aPages1[iPage].uReserved);
115 }
116 if ( aPages1[iPage].Phys >= _4G
117 || (aPages1[iPage].Phys & PAGE_OFFSET_MASK))
118 {
119 rcRet++;
120 RTPrintf("tstLow: error: aPages1[%d].Phys=%RHp!\n", iPage, aPages1[iPage].Phys);
121 }
122 }
123 if (!rcRet)
124 {
125 for (unsigned iPage = 0; iPage < cPages; iPage++)
126 memset((char *)pvPages1 + iPage * PAGE_SIZE, iPage, PAGE_SIZE);
127 for (unsigned iPage = 0; iPage < cPages; iPage++)
128 for (uint8_t *pu8 = (uint8_t *)pvPages1 + iPage * PAGE_SIZE, *pu8End = pu8 + PAGE_SIZE; pu8 < pu8End; pu8++)
129 if (*pu8 != (uint8_t)iPage)
130 {
131 RTPrintf("tstLow: error: invalid page content %02x != %02x. iPage=%p off=%#x\n",
132 *pu8, (uint8_t)iPage, iPage, (uintptr_t)pu8 & PAGE_OFFSET_MASK);
133 rcRet++;
134 }
135 }
136 SUPR3LowFree(pvPages1, cPages);
137 }
138 else
139 {
140 RTPrintf("SUPR3LowAlloc(%d,,) failed -> rc=%Rrc\n", cPages, rc);
141 rcRet++;
142 }
143 }
144
145 }
146 else
147 {
148 RTPrintf("SUPR3Init -> rc=%Rrc\n", rc);
149 rcRet++;
150 }
151
152
153 return rcRet;
154}
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