[42214] | 1 | /* $Id: tstGuestCtrlContextID.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * Context ID makeup/extraction test cases.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2012-2023 Oracle and/or its affiliates.
|
---|
[42214] | 8 | *
|
---|
[96407] | 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 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[42214] | 26 | */
|
---|
| 27 |
|
---|
| 28 | #define LOG_ENABLED
|
---|
| 29 | #define LOG_GROUP LOG_GROUP_MAIN
|
---|
| 30 | #include <VBox/log.h>
|
---|
| 31 |
|
---|
| 32 | #include "../include/GuestCtrlImplPrivate.h"
|
---|
| 33 |
|
---|
| 34 | using namespace com;
|
---|
| 35 |
|
---|
| 36 | #include <iprt/env.h>
|
---|
| 37 | #include <iprt/rand.h>
|
---|
| 38 | #include <iprt/stream.h>
|
---|
| 39 | #include <iprt/test.h>
|
---|
| 40 |
|
---|
| 41 | int main()
|
---|
| 42 | {
|
---|
| 43 | RTTEST hTest;
|
---|
[45415] | 44 | int rc = RTTestInitAndCreate("tstGuestCtrlContextID", &hTest);
|
---|
[42214] | 45 | if (rc)
|
---|
| 46 | return rc;
|
---|
| 47 | RTTestBanner(hTest);
|
---|
| 48 |
|
---|
| 49 | RTTestIPrintf(RTTESTLVL_DEBUG, "Initializing COM...\n");
|
---|
| 50 | HRESULT hrc = com::Initialize();
|
---|
| 51 | if (FAILED(hrc))
|
---|
| 52 | {
|
---|
| 53 | RTTestFailed(hTest, "Failed to initialize COM (%Rhrc)!\n", hrc);
|
---|
| 54 | return RTEXITCODE_FAILURE;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | /* Don't let the assertions trigger here
|
---|
| 58 | * -- we rely on the return values in the test(s) below. */
|
---|
| 59 | RTAssertSetQuiet(true);
|
---|
| 60 |
|
---|
[44863] | 61 | #if 0
|
---|
| 62 | for (int t = 0; t < 4 && !RTTestErrorCount(hTest); t++)
|
---|
| 63 | {
|
---|
| 64 | uint32_t uSession = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_SESSIONS - 1);
|
---|
| 65 | uint32_t uFilter = VBOX_GUESTCTRL_CONTEXTID_MAKE_SESSION(uSession);
|
---|
| 66 | RTTestIPrintf(RTTESTLVL_INFO, "Session: %RU32, Filter: %x\n", uSession, uFilter);
|
---|
| 67 |
|
---|
| 68 | uint32_t uSession2 = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_SESSIONS - 1);
|
---|
| 69 | uint32_t uCID = VBOX_GUESTCTRL_CONTEXTID_MAKE(uSession2,
|
---|
| 70 | RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_OBJECTS - 1),
|
---|
| 71 | RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_CONTEXTS - 1));
|
---|
| 72 | RTTestIPrintf(RTTESTLVL_INFO, "CID: %x (Session: %d), Masked: %x\n",
|
---|
| 73 | uCID, VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(uCID), uCID & uFilter);
|
---|
| 74 | if ((uCID & uFilter) == uCID)
|
---|
| 75 | {
|
---|
| 76 | RTTestIPrintf(RTTESTLVL_INFO, "=========== Masking works: %x vs. %x\n",
|
---|
| 77 | uCID & uFilter, uFilter);
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 | #endif
|
---|
| 81 |
|
---|
[42214] | 82 | uint32_t uContextMax = UINT32_MAX;
|
---|
| 83 | RTTestIPrintf(RTTESTLVL_DEBUG, "Max context is: %RU32\n", uContextMax);
|
---|
| 84 |
|
---|
[45415] | 85 | /* Do 4048 tests total. */
|
---|
| 86 | for (int t = 0; t < 4048 && !RTTestErrorCount(hTest); t++)
|
---|
[42214] | 87 | {
|
---|
[43036] | 88 | /* VBOX_GUESTCTRL_MAX_* includes 0 as an object, so subtract one. */
|
---|
| 89 | uint32_t s = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_SESSIONS - 1);
|
---|
| 90 | uint32_t p = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_OBJECTS - 1);
|
---|
| 91 | uint32_t c = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_CONTEXTS - 1);
|
---|
[42214] | 92 |
|
---|
| 93 | uint64_t uContextID = VBOX_GUESTCTRL_CONTEXTID_MAKE(s, p, c);
|
---|
| 94 | RTTestIPrintf(RTTESTLVL_DEBUG, "ContextID (%d,%d,%d) = %RU32\n", s, p, c, uContextID);
|
---|
| 95 | if (s != VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(uContextID))
|
---|
| 96 | {
|
---|
| 97 | RTTestFailed(hTest, "%d,%d,%d: Session is %d, expected %d -> %RU64\n",
|
---|
| 98 | s, p, c, VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(uContextID), s, uContextID);
|
---|
| 99 | }
|
---|
[42897] | 100 | else if (p != VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(uContextID))
|
---|
[42214] | 101 | {
|
---|
[42897] | 102 | RTTestFailed(hTest, "%d,%d,%d: Object is %d, expected %d -> %RU64\n",
|
---|
| 103 | s, p, c, VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(uContextID), p, uContextID);
|
---|
[42214] | 104 | }
|
---|
| 105 | if (c != VBOX_GUESTCTRL_CONTEXTID_GET_COUNT(uContextID))
|
---|
| 106 | {
|
---|
| 107 | RTTestFailed(hTest, "%d,%d,%d: Count is %d, expected %d -> %RU64\n",
|
---|
| 108 | s, p, c, VBOX_GUESTCTRL_CONTEXTID_GET_COUNT(uContextID), c, uContextID);
|
---|
| 109 | }
|
---|
| 110 | if (uContextID > UINT32_MAX)
|
---|
| 111 | {
|
---|
| 112 | RTTestFailed(hTest, "%d,%d,%d: Value overflow; does not fit anymore: %RU64\n",
|
---|
| 113 | s, p, c, uContextID);
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | RTTestIPrintf(RTTESTLVL_DEBUG, "Shutting down COM...\n");
|
---|
| 118 | com::Shutdown();
|
---|
| 119 |
|
---|
| 120 | /*
|
---|
| 121 | * Summary.
|
---|
| 122 | */
|
---|
| 123 | return RTTestSummaryAndDestroy(hTest);
|
---|
| 124 | }
|
---|
| 125 |
|
---|