VirtualBox

source: vbox/trunk/src/VBox/Main/generic/OpenGLTestApp.cpp@ 29034

Last change on this file since 29034 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette