VirtualBox

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

Last change on this file since 25877 was 25458, checked in by vboxsync, 15 years ago

VBoxTestOGL: fix logging

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 10.5 KB
Line 
1/* $Id: OpenGLTestApp.cpp 25458 2009-12-17 12:26:14Z 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 return VINF_SUCCESS;
189 }
190
191 return vrc;
192}
193#endif
194
195static int vboxInitQuietMode()
196{
197#if !defined(RT_OS_WINDOWS) && !defined(RT_OS_OS2)
198 /* This small test application might crash on some hosts. Do never
199 * generate a core dump as most likely some OpenGL library is
200 * responsible. */
201 struct rlimit lim = { 0, 0 };
202 setrlimit(RLIMIT_CORE, &lim);
203
204 /* Redirect stderr to /dev/null */
205 int fd = open("/dev/null", O_WRONLY);
206 if (fd != -1)
207 dup2(fd, STDERR_FILENO);
208#endif
209 return 0;
210}
211
212int main(int argc, char **argv)
213{
214 int rc = 0;
215
216 RTR3Init();
217
218 if(argc < 2)
219 {
220#ifdef VBOX_WITH_CROGL
221 /* backwards compatibility: check 3D */
222 rc = vboxCheck3DAccelerationSupported();
223#endif
224 }
225 else
226 {
227 static const RTGETOPTDEF s_aOptionDefs[] =
228 {
229 { "--test", 't', RTGETOPT_REQ_STRING },
230 { "-test", 't', RTGETOPT_REQ_STRING },
231#ifdef VBOXGLTEST_WITH_LOGGING
232 { "--log", 'l', RTGETOPT_REQ_STRING },
233#endif
234 { "--help", 'h', RTGETOPT_REQ_NOTHING },
235 };
236
237 RTGETOPTSTATE State;
238 rc = RTGetOptInit(&State, argc-1, argv+1, &s_aOptionDefs[0], RT_ELEMENTS(s_aOptionDefs), 0, 0);
239 AssertRCReturn(rc, 49);
240
241#ifdef VBOX_WITH_VIDEOHWACCEL
242 bool bTest2D = false;
243#endif
244#ifdef VBOX_WITH_CROGL
245 bool bTest3D = false;
246#endif
247#ifdef VBOXGLTEST_WITH_LOGGING
248 bool bLog = false;
249 bool bLogSuffix = false;
250 const char * pLog = NULL;
251#endif
252
253 for (;;)
254 {
255 RTGETOPTUNION Val;
256 rc = RTGetOpt(&State, &Val);
257 if (!rc)
258 break;
259 switch (rc)
260 {
261 case 't':
262#ifdef VBOX_WITH_CROGL
263 if (!strcmp(Val.psz, "3D") || !strcmp(Val.psz, "3d"))
264 {
265 bTest3D = true;
266 rc = 0;
267 break;
268 }
269#endif
270#ifdef VBOX_WITH_VIDEOHWACCEL
271 if (!strcmp(Val.psz, "2D") || !strcmp(Val.psz, "2d"))
272 {
273 bTest2D = true;
274 rc = 0;
275 break;
276 }
277#endif
278 rc = 1;
279 break;
280#ifdef VBOXGLTEST_WITH_LOGGING
281 case 'l':
282 bLog = true;
283 pLog = Val.psz;
284 rc = 0;
285 break;
286#endif
287 case 'h':
288 RTPrintf("VirtualBox Helper for testing 2D/3D OpenGL capabilities %u.%u.%u\n"
289 "(C) 2009 Sun Microsystems, Inc.\n"
290 "All rights reserved.\n"
291 "\n"
292 "Parameters:\n"
293#ifdef VBOX_WITH_VIDEOHWACCEL
294 " --test 2D test for 2D (video) OpenGL capabilities\n"
295#endif
296#ifdef VBOX_WITH_CROGL
297 " --test 3D test for 3D OpenGL capabilities\n"
298#endif
299#ifdef VBOXGLTEST_WITH_LOGGING
300 " --log <log_file_name> log the GL test result to the given file\n"
301 "\n"
302 "Logging can alternatively be enabled by specifying the VBOXGLTEST_LOG=<log_file_name> env variable\n"
303
304#endif
305 "\n",
306 RTBldCfgVersionMajor(), RTBldCfgVersionMinor(), RTBldCfgVersionBuild());
307 break;
308
309 case VERR_GETOPT_UNKNOWN_OPTION:
310 case VINF_GETOPT_NOT_OPTION:
311 rc = 1;
312
313 default:
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