1 | /* $Id: OpenGLTestApp.cpp 78410 2019-05-06 21:44:47Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox host opengl support test application.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #include <iprt/assert.h>
|
---|
19 | #include <iprt/buildconfig.h>
|
---|
20 | #include <iprt/errcore.h>
|
---|
21 | #include <iprt/getopt.h>
|
---|
22 | #include <iprt/initterm.h>
|
---|
23 | #include <iprt/stream.h>
|
---|
24 | #ifdef RT_OS_WINDOWS
|
---|
25 | # include <iprt/win/windows.h>
|
---|
26 | #endif
|
---|
27 | #if !defined(RT_OS_WINDOWS) && !defined(RT_OS_OS2)
|
---|
28 | # include <sys/resource.h>
|
---|
29 | # include <fcntl.h>
|
---|
30 | # include <unistd.h>
|
---|
31 | #endif
|
---|
32 |
|
---|
33 | #include <string.h>
|
---|
34 |
|
---|
35 | #define VBOXGLTEST_WITH_LOGGING
|
---|
36 |
|
---|
37 | #ifdef VBOXGLTEST_WITH_LOGGING
|
---|
38 | #include "package-generated.h"
|
---|
39 |
|
---|
40 | #include <iprt/log.h>
|
---|
41 | #include <iprt/param.h>
|
---|
42 | #include <iprt/time.h>
|
---|
43 | #include <iprt/system.h>
|
---|
44 | #include <iprt/process.h>
|
---|
45 | #include <iprt/env.h>
|
---|
46 |
|
---|
47 | #include <VBox/log.h>
|
---|
48 | #include <VBox/version.h>
|
---|
49 | #endif
|
---|
50 |
|
---|
51 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
52 | #include <QGLWidget>
|
---|
53 | #include <QApplication>
|
---|
54 | #include <VBox/VBoxGL2D.h>
|
---|
55 | #endif
|
---|
56 |
|
---|
57 | #ifdef VBOX_WITH_CROGL
|
---|
58 | #include <cr_spu.h>
|
---|
59 |
|
---|
60 | static int vboxCheck3DAccelerationSupported()
|
---|
61 | {
|
---|
62 | LogRel(("Testing 3D Support:\n"));
|
---|
63 | PCSPUREG aSpuRegs[] = { &g_RenderSpuReg, &g_ErrorSpuReg, NULL};
|
---|
64 | SPU *spu = crSPUInitFromReg(NULL, 0, "render", NULL, &aSpuRegs[0]);
|
---|
65 | if (spu)
|
---|
66 | {
|
---|
67 | crSPUUnloadChain(spu);
|
---|
68 | LogRel(("Testing 3D Succeeded!\n"));
|
---|
69 | return 0;
|
---|
70 | }
|
---|
71 | LogRel(("Testing 3D Failed\n"));
|
---|
72 | return 1;
|
---|
73 | }
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
77 | static int vboxCheck2DVideoAccelerationSupported()
|
---|
78 | {
|
---|
79 | LogRel(("Testing 2D Support:\n"));
|
---|
80 | static int dummyArgc = 1;
|
---|
81 | static char * dummyArgv = (char*)"GlTest";
|
---|
82 | QApplication app (dummyArgc, &dummyArgv);
|
---|
83 |
|
---|
84 | VBoxGLTmpContext ctx;
|
---|
85 | const QGLContext *pContext = ctx.makeCurrent();
|
---|
86 | if(pContext)
|
---|
87 | {
|
---|
88 | VBoxVHWAInfo supportInfo;
|
---|
89 | supportInfo.init(pContext);
|
---|
90 | if(supportInfo.isVHWASupported())
|
---|
91 | {
|
---|
92 | LogRel(("Testing 2D Succeeded!\n"));
|
---|
93 | return 0;
|
---|
94 | }
|
---|
95 | }
|
---|
96 | else
|
---|
97 | {
|
---|
98 | LogRel(("Failed to create gl context\n"));
|
---|
99 | }
|
---|
100 | LogRel(("Testing 2D Failed\n"));
|
---|
101 | return 1;
|
---|
102 | }
|
---|
103 | #endif
|
---|
104 |
|
---|
105 | #ifdef VBOXGLTEST_WITH_LOGGING
|
---|
106 | static int vboxInitLogging(const char *pszFilename, bool bGenNameSuffix)
|
---|
107 | {
|
---|
108 | PRTLOGGER loggerRelease;
|
---|
109 | static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES;
|
---|
110 | RTUINT fFlags = RTLOGFLAGS_PREFIX_TIME_PROG;
|
---|
111 | #if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
|
---|
112 | fFlags |= RTLOGFLAGS_USECRLF;
|
---|
113 | #endif
|
---|
114 | const char * pszFilenameFmt;
|
---|
115 | RTLOGDEST enmLogDest;
|
---|
116 | if(pszFilename)
|
---|
117 | {
|
---|
118 | if(bGenNameSuffix)
|
---|
119 | pszFilenameFmt = "%s.%ld.log";
|
---|
120 | else
|
---|
121 | pszFilenameFmt = "%s";
|
---|
122 | enmLogDest = RTLOGDEST_FILE;
|
---|
123 | }
|
---|
124 | else
|
---|
125 | {
|
---|
126 | pszFilenameFmt = NULL;
|
---|
127 | enmLogDest = RTLOGDEST_STDOUT;
|
---|
128 | }
|
---|
129 |
|
---|
130 | int vrc = RTLogCreateEx(&loggerRelease, fFlags, "all",
|
---|
131 | "VBOX_RELEASE_LOG", RT_ELEMENTS(s_apszGroups), s_apszGroups, UINT32_MAX, enmLogDest,
|
---|
132 | NULL /* pfnBeginEnd */, 0 /* cHistory */, 0 /* cbHistoryFileMax */, 0 /* uHistoryTimeMax */,
|
---|
133 | NULL /* pErrInfo */, pszFilenameFmt, pszFilename, RTTimeMilliTS());
|
---|
134 | if (RT_SUCCESS(vrc))
|
---|
135 | {
|
---|
136 | /* some introductory information */
|
---|
137 | RTTIMESPEC timeSpec;
|
---|
138 | char szTmp[256];
|
---|
139 | RTTimeSpecToString(RTTimeNow(&timeSpec), szTmp, sizeof(szTmp));
|
---|
140 | RTLogRelLogger(loggerRelease, 0, ~0U,
|
---|
141 | "VBoxTestGL %s r%u %s (%s %s) release log\n"
|
---|
142 | #ifdef VBOX_BLEEDING_EDGE
|
---|
143 | "EXPERIMENTAL build " VBOX_BLEEDING_EDGE "\n"
|
---|
144 | #endif
|
---|
145 | "Log opened %s\n",
|
---|
146 | VBOX_VERSION_STRING, RTBldCfgRevision(), VBOX_BUILD_TARGET,
|
---|
147 | __DATE__, __TIME__, szTmp);
|
---|
148 |
|
---|
149 | vrc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szTmp, sizeof(szTmp));
|
---|
150 | if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
|
---|
151 | RTLogRelLogger(loggerRelease, 0, ~0U, "OS Product: %s\n", szTmp);
|
---|
152 | vrc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szTmp, sizeof(szTmp));
|
---|
153 | if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
|
---|
154 | RTLogRelLogger(loggerRelease, 0, ~0U, "OS Release: %s\n", szTmp);
|
---|
155 | vrc = RTSystemQueryOSInfo(RTSYSOSINFO_VERSION, szTmp, sizeof(szTmp));
|
---|
156 | if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
|
---|
157 | RTLogRelLogger(loggerRelease, 0, ~0U, "OS Version: %s\n", szTmp);
|
---|
158 | vrc = RTSystemQueryOSInfo(RTSYSOSINFO_SERVICE_PACK, szTmp, sizeof(szTmp));
|
---|
159 | if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW)
|
---|
160 | RTLogRelLogger(loggerRelease, 0, ~0U, "OS Service Pack: %s\n", szTmp);
|
---|
161 | // RTLogRelLogger(loggerRelease, 0, ~0U, "Host RAM: %uMB RAM, available: %uMB\n",
|
---|
162 | // uHostRamMb, uHostRamAvailMb);
|
---|
163 | /* the package type is interesting for Linux distributions */
|
---|
164 | char szExecName[RTPATH_MAX];
|
---|
165 | char *pszExecName = RTProcGetExecutablePath(szExecName, sizeof(szExecName));
|
---|
166 | RTLogRelLogger(loggerRelease, 0, ~0U,
|
---|
167 | "Executable: %s\n"
|
---|
168 | "Process ID: %u\n"
|
---|
169 | "Package type: %s"
|
---|
170 | #ifdef VBOX_OSE
|
---|
171 | " (OSE)"
|
---|
172 | #endif
|
---|
173 | "\n",
|
---|
174 | pszExecName ? pszExecName : "unknown",
|
---|
175 | RTProcSelf(),
|
---|
176 | VBOX_PACKAGE_STRING);
|
---|
177 |
|
---|
178 | /* register this logger as the release logger */
|
---|
179 | RTLogRelSetDefaultInstance(loggerRelease);
|
---|
180 |
|
---|
181 | return VINF_SUCCESS;
|
---|
182 | }
|
---|
183 |
|
---|
184 | return vrc;
|
---|
185 | }
|
---|
186 | #endif
|
---|
187 |
|
---|
188 | static int vboxInitQuietMode()
|
---|
189 | {
|
---|
190 | #if !defined(RT_OS_WINDOWS) && !defined(RT_OS_OS2)
|
---|
191 | /* This small test application might crash on some hosts. Do never
|
---|
192 | * generate a core dump as most likely some OpenGL library is
|
---|
193 | * responsible. */
|
---|
194 | struct rlimit lim = { 0, 0 };
|
---|
195 | setrlimit(RLIMIT_CORE, &lim);
|
---|
196 |
|
---|
197 | /* Redirect stderr to /dev/null */
|
---|
198 | int fd = open("/dev/null", O_WRONLY);
|
---|
199 | if (fd != -1)
|
---|
200 | dup2(fd, STDERR_FILENO);
|
---|
201 | #endif
|
---|
202 | return 0;
|
---|
203 | }
|
---|
204 |
|
---|
205 | int main(int argc, char **argv)
|
---|
206 | {
|
---|
207 | int rc = 0;
|
---|
208 |
|
---|
209 | RTR3InitExe(argc, &argv, 0);
|
---|
210 |
|
---|
211 | if(argc < 2)
|
---|
212 | {
|
---|
213 | #ifdef VBOX_WITH_CROGL
|
---|
214 | /* backwards compatibility: check 3D */
|
---|
215 | rc = vboxCheck3DAccelerationSupported();
|
---|
216 | #endif
|
---|
217 | }
|
---|
218 | else
|
---|
219 | {
|
---|
220 | static const RTGETOPTDEF s_aOptionDefs[] =
|
---|
221 | {
|
---|
222 | { "--test", 't', RTGETOPT_REQ_STRING },
|
---|
223 | { "-test", 't', RTGETOPT_REQ_STRING },
|
---|
224 | #ifdef VBOXGLTEST_WITH_LOGGING
|
---|
225 | { "--log", 'l', RTGETOPT_REQ_STRING },
|
---|
226 | #endif
|
---|
227 | };
|
---|
228 |
|
---|
229 | RTGETOPTSTATE State;
|
---|
230 | rc = RTGetOptInit(&State, argc-1, argv+1, &s_aOptionDefs[0], RT_ELEMENTS(s_aOptionDefs), 0, 0);
|
---|
231 | AssertRCReturn(rc, 49);
|
---|
232 |
|
---|
233 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
234 | bool bTest2D = false;
|
---|
235 | #endif
|
---|
236 | #ifdef VBOX_WITH_CROGL
|
---|
237 | bool bTest3D = false;
|
---|
238 | #endif
|
---|
239 | #ifdef VBOXGLTEST_WITH_LOGGING
|
---|
240 | bool bLog = false;
|
---|
241 | bool bLogSuffix = false;
|
---|
242 | const char * pLog = NULL;
|
---|
243 | #endif
|
---|
244 |
|
---|
245 | for (;;)
|
---|
246 | {
|
---|
247 | RTGETOPTUNION Val;
|
---|
248 | rc = RTGetOpt(&State, &Val);
|
---|
249 | if (!rc)
|
---|
250 | break;
|
---|
251 | switch (rc)
|
---|
252 | {
|
---|
253 | case 't':
|
---|
254 | #ifdef VBOX_WITH_CROGL
|
---|
255 | if (!strcmp(Val.psz, "3D") || !strcmp(Val.psz, "3d"))
|
---|
256 | {
|
---|
257 | bTest3D = true;
|
---|
258 | rc = 0;
|
---|
259 | break;
|
---|
260 | }
|
---|
261 | #endif
|
---|
262 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
263 | if (!strcmp(Val.psz, "2D") || !strcmp(Val.psz, "2d"))
|
---|
264 | {
|
---|
265 | bTest2D = true;
|
---|
266 | rc = 0;
|
---|
267 | break;
|
---|
268 | }
|
---|
269 | #endif
|
---|
270 | rc = 1;
|
---|
271 | break;
|
---|
272 | #ifdef VBOXGLTEST_WITH_LOGGING
|
---|
273 | case 'l':
|
---|
274 | bLog = true;
|
---|
275 | pLog = Val.psz;
|
---|
276 | rc = 0;
|
---|
277 | break;
|
---|
278 | #endif
|
---|
279 | case 'h':
|
---|
280 | RTPrintf(VBOX_PRODUCT " Helper for testing 2D/3D OpenGL capabilities %u.%u.%u\n"
|
---|
281 | "(C) 2009-" VBOX_C_YEAR " " VBOX_VENDOR "\n"
|
---|
282 | "All rights reserved.\n"
|
---|
283 | "\n"
|
---|
284 | "Parameters:\n"
|
---|
285 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
286 | " --test 2D test for 2D (video) OpenGL capabilities\n"
|
---|
287 | #endif
|
---|
288 | #ifdef VBOX_WITH_CROGL
|
---|
289 | " --test 3D test for 3D OpenGL capabilities\n"
|
---|
290 | #endif
|
---|
291 | #ifdef VBOXGLTEST_WITH_LOGGING
|
---|
292 | " --log <log_file_name> log the GL test result to the given file\n"
|
---|
293 | "\n"
|
---|
294 | "Logging can alternatively be enabled by specifying the VBOXGLTEST_LOG=<log_file_name> env variable\n"
|
---|
295 |
|
---|
296 | #endif
|
---|
297 | "\n",
|
---|
298 | RTBldCfgVersionMajor(), RTBldCfgVersionMinor(), RTBldCfgVersionBuild());
|
---|
299 | break;
|
---|
300 |
|
---|
301 | case 'V':
|
---|
302 | RTPrintf("$Revision: 78410 $\n");
|
---|
303 | return 0;
|
---|
304 |
|
---|
305 | case VERR_GETOPT_UNKNOWN_OPTION:
|
---|
306 | case VINF_GETOPT_NOT_OPTION:
|
---|
307 | rc = 1;
|
---|
308 |
|
---|
309 | default:
|
---|
310 | /* complain? RTGetOptPrintError(rc, &Val); */
|
---|
311 | break;
|
---|
312 | }
|
---|
313 |
|
---|
314 | if (rc)
|
---|
315 | break;
|
---|
316 | }
|
---|
317 |
|
---|
318 | if(!rc)
|
---|
319 | {
|
---|
320 | #ifdef VBOXGLTEST_WITH_LOGGING
|
---|
321 | if(!bLog)
|
---|
322 | {
|
---|
323 | /* check the VBOXGLTEST_LOG env var */
|
---|
324 | pLog = RTEnvGet("VBOXGLTEST_LOG");
|
---|
325 | if(pLog)
|
---|
326 | bLog = true;
|
---|
327 | bLogSuffix = true;
|
---|
328 | }
|
---|
329 | if(bLog)
|
---|
330 | rc = vboxInitLogging(pLog, bLogSuffix);
|
---|
331 | else
|
---|
332 | #endif
|
---|
333 | rc = vboxInitQuietMode();
|
---|
334 |
|
---|
335 | #ifdef VBOX_WITH_CROGL
|
---|
336 | if(!rc && bTest3D)
|
---|
337 | rc = vboxCheck3DAccelerationSupported();
|
---|
338 | #endif
|
---|
339 |
|
---|
340 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
341 | if(!rc && bTest2D)
|
---|
342 | rc = vboxCheck2DVideoAccelerationSupported();
|
---|
343 | #endif
|
---|
344 |
|
---|
345 | }
|
---|
346 | }
|
---|
347 |
|
---|
348 | /*RTR3Term();*/
|
---|
349 | return rc;
|
---|
350 |
|
---|
351 | }
|
---|
352 |
|
---|
353 | #ifdef RT_OS_WINDOWS
|
---|
354 | extern "C" int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
|
---|
355 | {
|
---|
356 | RT_NOREF(hInstance, hPrevInstance, lpCmdLine, nShowCmd);
|
---|
357 | return main(__argc, __argv);
|
---|
358 | }
|
---|
359 | #endif
|
---|
360 |
|
---|