1 | /* $Id: OpenGLTest.cpp 98281 2023-01-24 12:15:49Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox host opengl support test - generic implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-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 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #include <VBox/err.h>
|
---|
29 | #include <iprt/assert.h>
|
---|
30 | #include <iprt/env.h>
|
---|
31 | #include <iprt/param.h>
|
---|
32 | #include <iprt/path.h>
|
---|
33 | #include <iprt/process.h>
|
---|
34 | #include <iprt/string.h>
|
---|
35 | #include <iprt/time.h>
|
---|
36 | #include <iprt/thread.h>
|
---|
37 | #include <iprt/env.h>
|
---|
38 | #include <iprt/log.h>
|
---|
39 |
|
---|
40 | #include <VBox/VBoxOGL.h>
|
---|
41 |
|
---|
42 | bool RTCALL VBoxOglIs3DAccelerationSupported(void)
|
---|
43 | {
|
---|
44 | if (RTEnvExist("VBOX_3D_FORCE_SUPPORTED"))
|
---|
45 | {
|
---|
46 | LogRel(("VBOX_3D_FORCE_SUPPORTED is specified, skipping 3D test, and treating as supported\n"));
|
---|
47 | return true;
|
---|
48 | }
|
---|
49 |
|
---|
50 | static char pszVBoxPath[RTPATH_MAX];
|
---|
51 | const char *papszArgs[4] = { NULL, "-test", "3D", NULL};
|
---|
52 |
|
---|
53 | #ifdef __SANITIZE_ADDRESS__
|
---|
54 | /* The OpenGL test tool contains a number of memory leaks which cause it to
|
---|
55 | * return failure when run with ASAN unless we disable the leak detector. */
|
---|
56 | RTENV env;
|
---|
57 | if (RT_FAILURE(RTEnvClone(&env, RTENV_DEFAULT)))
|
---|
58 | return false;
|
---|
59 | RTEnvPutEx(env, "ASAN_OPTIONS=detect_leaks=0"); /* If this fails we will notice later */
|
---|
60 | #endif
|
---|
61 | int vrc = RTPathExecDir(pszVBoxPath, RTPATH_MAX);
|
---|
62 | AssertRCReturn(vrc, false);
|
---|
63 | #if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
|
---|
64 | vrc = RTPathAppend(pszVBoxPath, RTPATH_MAX, "VBoxTestOGL.exe");
|
---|
65 | #else
|
---|
66 | vrc = RTPathAppend(pszVBoxPath, RTPATH_MAX, "VBoxTestOGL");
|
---|
67 | #endif
|
---|
68 | papszArgs[0] = pszVBoxPath; /* argv[0] */
|
---|
69 | AssertRCReturn(vrc, false);
|
---|
70 |
|
---|
71 | RTPROCESS Process;
|
---|
72 | #ifndef __SANITIZE_ADDRESS__
|
---|
73 | vrc = RTProcCreate(pszVBoxPath, papszArgs, RTENV_DEFAULT, 0, &Process);
|
---|
74 | #else
|
---|
75 | vrc = RTProcCreate(pszVBoxPath, papszArgs, env, 0, &Process);
|
---|
76 | RTEnvDestroy(env);
|
---|
77 | #endif
|
---|
78 | if (RT_FAILURE(vrc))
|
---|
79 | return false;
|
---|
80 |
|
---|
81 | uint64_t StartTS = RTTimeMilliTS();
|
---|
82 |
|
---|
83 | RTPROCSTATUS ProcStatus = {0};
|
---|
84 | while (1)
|
---|
85 | {
|
---|
86 | vrc = RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, &ProcStatus);
|
---|
87 | if (vrc != VERR_PROCESS_RUNNING)
|
---|
88 | break;
|
---|
89 |
|
---|
90 | #ifndef DEBUG_misha
|
---|
91 | if (RTTimeMilliTS() - StartTS > 30*1000 /* 30 sec */)
|
---|
92 | {
|
---|
93 | RTProcTerminate(Process);
|
---|
94 | RTThreadSleep(100);
|
---|
95 | RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, &ProcStatus);
|
---|
96 | return false;
|
---|
97 | }
|
---|
98 | #endif
|
---|
99 | RTThreadSleep(100);
|
---|
100 | }
|
---|
101 |
|
---|
102 | if (RT_SUCCESS(vrc))
|
---|
103 | if ( ProcStatus.enmReason == RTPROCEXITREASON_NORMAL
|
---|
104 | && ProcStatus.iStatus == 0)
|
---|
105 | return true;
|
---|
106 |
|
---|
107 | return false;
|
---|
108 | }
|
---|
109 |
|
---|