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