VirtualBox

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

Last change on this file since 103914 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1/* $Id: tstContiguous.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * SUP Testcase - Contiguous Memory Interface (ring-3).
4 */
5
6/*
7 * Copyright (C) 2006-2023 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 <stdlib.h>
46#include <string.h>
47
48
49int main(int argc, char **argv)
50{
51 int rc;
52 int rcRet = 0;
53
54 RTR3InitExe(argc, &argv, 0);
55 rc = SUPR3Init(NULL);
56 RTPrintf("tstContiguous: SUPR3Init -> rc=%Rrc\n", rc);
57 rcRet += rc != 0;
58 if (!rc)
59 {
60 /*
61 * Allocate a bit of contiguous memory.
62 */
63 RTHCPHYS HCPhys;
64 void *pv = SUPR3ContAlloc(8, NULL, &HCPhys);
65 rcRet += pv == NULL || HCPhys == 0;
66 if (pv && HCPhys)
67 {
68 memset(pv, 0xff, PAGE_SIZE * 8);
69 pv = SUPR3ContAlloc(5, NULL, &HCPhys);
70 rcRet += pv == NULL || HCPhys == 0;
71 if (pv && HCPhys)
72 {
73 memset(pv, 0x7f, PAGE_SIZE * 5);
74 rc = SUPR3ContFree(pv, 5);
75 rcRet += rc != 0;
76 if (rc)
77 RTPrintf("tstContiguous: SUPR3ContFree failed! rc=%Rrc\n", rc);
78
79 void *apv[128];
80 for (unsigned i = 0; i < RT_ELEMENTS(apv); i++)
81 {
82 apv[i] = SUPR3ContAlloc(1 + (i % 11), NULL, &HCPhys);
83 if (!apv[i])
84 {
85 RTPrintf("tstContiguous: i=%d: failed to allocate %d pages", i, 1 + (i % 11));
86#if defined(RT_ARCH_X86) && defined(RT_OS_LINUX)
87 /* With 32-bit address spaces it's sometimes difficult
88 * to find bigger chunks of contiguous memory */
89 if (i % 11 > 7)
90 RTPrintf(" => ignoring (32-bit host)");
91 else
92#endif
93 rcRet++;
94 RTPrintf("\n");
95 }
96 }
97 for (unsigned i = 0; i < RT_ELEMENTS(apv); i++)
98 if (apv[i])
99 {
100 rc = SUPR3ContFree(apv[i], 1 + (i % 11));
101 rcRet += rc != 0;
102 if (rc)
103 RTPrintf("tstContiguous: i=%d SUPR3ContFree failed! rc=%Rrc\n", i, rc);
104 }
105 }
106 else
107 RTPrintf("tstContiguous: SUPR3ContAlloc (2nd) failed!\n");
108 }
109 else
110 RTPrintf("tstContiguous: SUPR3ContAlloc failed!\n");
111
112 rc = SUPR3Term(false /*fForced*/);
113 RTPrintf("tstContiguous: SUPR3Term -> rc=%Rrc\n", rc);
114 rcRet += rc != 0;
115 }
116
117 return rcRet ? 1 : 0;
118}
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