VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/testcase/tstContiguous.cpp

Last change on this file was 108657, checked in by vboxsync, 3 weeks ago

HostDrivers/Support/testcase/tstContiguous.cpp: Make it work for hosts where we don't know the host page size when building, bugref:10391

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1/* $Id: tstContiguous.cpp 108657 2025-03-20 15:29:22Z vboxsync $ */
2/** @file
3 * SUP Testcase - Contiguous Memory Interface (ring-3).
4 */
5
6/*
7 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include <VBox/sup.h>
42#include <VBox/param.h>
43#include <iprt/initterm.h>
44#include <iprt/stream.h>
45#include <iprt/system.h>
46#include <stdlib.h>
47#include <string.h>
48
49
50int main(int argc, char **argv)
51{
52 int rc;
53 int rcRet = 0;
54
55 RTR3InitExe(argc, &argv, 0);
56 rc = SUPR3Init(NULL);
57 RTPrintf("tstContiguous: SUPR3Init -> rc=%Rrc\n", rc);
58 rcRet += rc != 0;
59 if (!rc)
60 {
61 uint32_t const cbPage = RTSystemGetPageSize();
62
63 /*
64 * Allocate a bit of contiguous memory.
65 */
66 RTHCPHYS HCPhys;
67 void *pv = SUPR3ContAlloc(8, NULL, &HCPhys);
68 rcRet += pv == NULL || HCPhys == 0;
69 if (pv && HCPhys)
70 {
71 memset(pv, 0xff, cbPage * 8);
72 pv = SUPR3ContAlloc(5, NULL, &HCPhys);
73 rcRet += pv == NULL || HCPhys == 0;
74 if (pv && HCPhys)
75 {
76 memset(pv, 0x7f, cbPage * 5);
77 rc = SUPR3ContFree(pv, 5);
78 rcRet += rc != 0;
79 if (rc)
80 RTPrintf("tstContiguous: SUPR3ContFree failed! rc=%Rrc\n", rc);
81
82 void *apv[128];
83 for (unsigned i = 0; i < RT_ELEMENTS(apv); i++)
84 {
85 apv[i] = SUPR3ContAlloc(1 + (i % 11), NULL, &HCPhys);
86 if (!apv[i])
87 {
88 RTPrintf("tstContiguous: i=%d: failed to allocate %d pages", i, 1 + (i % 11));
89#if defined(RT_ARCH_X86) && defined(RT_OS_LINUX)
90 /* With 32-bit address spaces it's sometimes difficult
91 * to find bigger chunks of contiguous memory */
92 if (i % 11 > 7)
93 RTPrintf(" => ignoring (32-bit host)");
94 else
95#endif
96 rcRet++;
97 RTPrintf("\n");
98 }
99 }
100 for (unsigned i = 0; i < RT_ELEMENTS(apv); i++)
101 if (apv[i])
102 {
103 rc = SUPR3ContFree(apv[i], 1 + (i % 11));
104 rcRet += rc != 0;
105 if (rc)
106 RTPrintf("tstContiguous: i=%d SUPR3ContFree failed! rc=%Rrc\n", i, rc);
107 }
108 }
109 else
110 RTPrintf("tstContiguous: SUPR3ContAlloc (2nd) failed!\n");
111 }
112 else
113 RTPrintf("tstContiguous: SUPR3ContAlloc failed!\n");
114
115 rc = SUPR3Term(false /*fForced*/);
116 RTPrintf("tstContiguous: SUPR3Term -> rc=%Rrc\n", rc);
117 rcRet += rc != 0;
118 }
119
120 return rcRet ? 1 : 0;
121}
Note: See TracBrowser for help on using the repository browser.

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