1 | /* $Id: tstGuestCtrlContextID.cpp 44863 2013-02-28 12:18:17Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | *
|
---|
5 | * Context ID makeup/extraction test cases.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2012 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #define LOG_ENABLED
|
---|
21 | #define LOG_GROUP LOG_GROUP_MAIN
|
---|
22 | #define LOG_INSTANCE NULL
|
---|
23 | #include <VBox/log.h>
|
---|
24 |
|
---|
25 | #include "../include/GuestCtrlImplPrivate.h"
|
---|
26 |
|
---|
27 | using namespace com;
|
---|
28 |
|
---|
29 | #include <iprt/env.h>
|
---|
30 | #include <iprt/rand.h>
|
---|
31 | #include <iprt/stream.h>
|
---|
32 | #include <iprt/test.h>
|
---|
33 |
|
---|
34 | int main()
|
---|
35 | {
|
---|
36 | RTTEST hTest;
|
---|
37 | int rc = RTTestInitAndCreate("tstMakeup", &hTest);
|
---|
38 | if (rc)
|
---|
39 | return rc;
|
---|
40 | RTTestBanner(hTest);
|
---|
41 |
|
---|
42 | RTTestIPrintf(RTTESTLVL_DEBUG, "Initializing COM...\n");
|
---|
43 | HRESULT hrc = com::Initialize();
|
---|
44 | if (FAILED(hrc))
|
---|
45 | {
|
---|
46 | RTTestFailed(hTest, "Failed to initialize COM (%Rhrc)!\n", hrc);
|
---|
47 | return RTEXITCODE_FAILURE;
|
---|
48 | }
|
---|
49 |
|
---|
50 | /* Don't let the assertions trigger here
|
---|
51 | * -- we rely on the return values in the test(s) below. */
|
---|
52 | RTAssertSetQuiet(true);
|
---|
53 |
|
---|
54 | #if 0
|
---|
55 | for (int t = 0; t < 4 && !RTTestErrorCount(hTest); t++)
|
---|
56 | {
|
---|
57 | uint32_t uSession = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_SESSIONS - 1);
|
---|
58 | uint32_t uFilter = VBOX_GUESTCTRL_CONTEXTID_MAKE_SESSION(uSession);
|
---|
59 | RTTestIPrintf(RTTESTLVL_INFO, "Session: %RU32, Filter: %x\n", uSession, uFilter);
|
---|
60 |
|
---|
61 | uint32_t uSession2 = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_SESSIONS - 1);
|
---|
62 | uint32_t uCID = VBOX_GUESTCTRL_CONTEXTID_MAKE(uSession2,
|
---|
63 | RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_OBJECTS - 1),
|
---|
64 | RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_CONTEXTS - 1));
|
---|
65 | RTTestIPrintf(RTTESTLVL_INFO, "CID: %x (Session: %d), Masked: %x\n",
|
---|
66 | uCID, VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(uCID), uCID & uFilter);
|
---|
67 | if ((uCID & uFilter) == uCID)
|
---|
68 | {
|
---|
69 | RTTestIPrintf(RTTESTLVL_INFO, "=========== Masking works: %x vs. %x\n",
|
---|
70 | uCID & uFilter, uFilter);
|
---|
71 | }
|
---|
72 | }
|
---|
73 | #endif
|
---|
74 |
|
---|
75 | uint32_t uContextMax = UINT32_MAX;
|
---|
76 | RTTestIPrintf(RTTESTLVL_DEBUG, "Max context is: %RU32\n", uContextMax);
|
---|
77 |
|
---|
78 | /* Do 64 tests total. */
|
---|
79 | for (int t = 0; t < 64 && !RTTestErrorCount(hTest); t++)
|
---|
80 | {
|
---|
81 | /* VBOX_GUESTCTRL_MAX_* includes 0 as an object, so subtract one. */
|
---|
82 | uint32_t s = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_SESSIONS - 1);
|
---|
83 | uint32_t p = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_OBJECTS - 1);
|
---|
84 | uint32_t c = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_CONTEXTS - 1);
|
---|
85 |
|
---|
86 | uint64_t uContextID = VBOX_GUESTCTRL_CONTEXTID_MAKE(s, p, c);
|
---|
87 | RTTestIPrintf(RTTESTLVL_DEBUG, "ContextID (%d,%d,%d) = %RU32\n", s, p, c, uContextID);
|
---|
88 | if (s != VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(uContextID))
|
---|
89 | {
|
---|
90 | RTTestFailed(hTest, "%d,%d,%d: Session is %d, expected %d -> %RU64\n",
|
---|
91 | s, p, c, VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(uContextID), s, uContextID);
|
---|
92 | }
|
---|
93 | else if (p != VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(uContextID))
|
---|
94 | {
|
---|
95 | RTTestFailed(hTest, "%d,%d,%d: Object is %d, expected %d -> %RU64\n",
|
---|
96 | s, p, c, VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(uContextID), p, uContextID);
|
---|
97 | }
|
---|
98 | if (c != VBOX_GUESTCTRL_CONTEXTID_GET_COUNT(uContextID))
|
---|
99 | {
|
---|
100 | RTTestFailed(hTest, "%d,%d,%d: Count is %d, expected %d -> %RU64\n",
|
---|
101 | s, p, c, VBOX_GUESTCTRL_CONTEXTID_GET_COUNT(uContextID), c, uContextID);
|
---|
102 | }
|
---|
103 | if (uContextID > UINT32_MAX)
|
---|
104 | {
|
---|
105 | RTTestFailed(hTest, "%d,%d,%d: Value overflow; does not fit anymore: %RU64\n",
|
---|
106 | s, p, c, uContextID);
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | RTTestIPrintf(RTTESTLVL_DEBUG, "Shutting down COM...\n");
|
---|
111 | com::Shutdown();
|
---|
112 |
|
---|
113 | /*
|
---|
114 | * Summary.
|
---|
115 | */
|
---|
116 | return RTTestSummaryAndDestroy(hTest);
|
---|
117 | }
|
---|
118 |
|
---|