VirtualBox

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

Last change on this file since 25414 was 24836, checked in by vboxsync, 15 years ago

gcc warning

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

© 2023 Oracle
ContactPrivacy policyTerms of Use