/** * Finds the svn binary, updating g_szSvnPath and g_enmSvnVersion. */ static void scmSvnFindSvnBinary(PSCMRWSTATE pState) { /* Already been called? */ if (g_szSvnPath[0] != '\0') return; /* * Locate it. */ /** @todo code page fun... */ #ifdef RT_OS_WINDOWS const char *pszEnvVar = RTEnvGet("Path"); #else const char *pszEnvVar = RTEnvGet("PATH"); #endif if (pszEnvVar) { #if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2) int rc = RTPathTraverseList(pszEnvVar, ';', scmSvnFindSvnBinaryCallback, g_szSvnPath, (void *)sizeof(g_szSvnPath)); #else int rc = RTPathTraverseList(pszEnvVar, ':', scmSvnFindSvnBinaryCallback, g_szSvnPath, (void *)sizeof(g_szSvnPath)); #endif if (RT_FAILURE(rc)) strcpy(g_szSvnPath, "svn"); } else strcpy(g_szSvnPath, "svn"); /* * Check the version. */ const char *apszArgs[] = { g_szSvnPath, "--version", "--quiet", NULL }; char *pszVersion; int rc = scmSvnRunAndGetOutput(pState, apszArgs, false, &pszVersion); if (RT_SUCCESS(rc)) { char *pszStripped = RTStrStrip(pszVersion); if (RTStrVersionCompare(pszVersion, "1.7") >= 0) g_enmSvnVersion = kScmSvnVersion_1_7; else if (RTStrVersionCompare(pszVersion, "1.6") >= 0) g_enmSvnVersion = kScmSvnVersion_1_6; else g_enmSvnVersion = kScmSvnVersion_Ancient; RTStrFree(pszVersion); } else g_enmSvnVersion = kScmSvnVersion_Ancient; }
bool RTCALL VBoxOglIs3DAccelerationSupported() { if (RTEnvGet("VBOX_CROGL_FORCE_SUPPORTED")) { LogRel(("VBOX_CROGL_FORCE_SUPPORTED is specified, skipping 3D test, and treating as supported\n")); return true; } CGDirectDisplayID display = CGMainDisplayID (); CGOpenGLDisplayMask cglDisplayMask = CGDisplayIDToOpenGLDisplayMask (display); CGLPixelFormatObj pixelFormat = NULL; GLint numPixelFormats = 0; CGLPixelFormatAttribute attribs[] = { kCGLPFADisplayMask, (CGLPixelFormatAttribute)cglDisplayMask, kCGLPFAAccelerated, kCGLPFADoubleBuffer, kCGLPFAWindow, (CGLPixelFormatAttribute)NULL }; display = CGMainDisplayID(); cglDisplayMask = CGDisplayIDToOpenGLDisplayMask(display); CGLChoosePixelFormat(attribs, &pixelFormat, &numPixelFormats); if (pixelFormat) { CGLContextObj cglContext = 0; CGLCreateContext(pixelFormat, NULL, &cglContext); CGLDestroyPixelFormat(pixelFormat); if (cglContext) { GLboolean isSupported = GL_TRUE; #ifdef VBOX_WITH_COCOA_QT /* On the Cocoa port we depend on the GL_EXT_framebuffer_object & * the GL_EXT_texture_rectangle extension. If they are not * available, disable 3D support. */ CGLSetCurrentContext(cglContext); const GLubyte* strExt; strExt = glGetString(GL_EXTENSIONS); isSupported = gluCheckExtension((const GLubyte*)"GL_EXT_framebuffer_object", strExt); if (isSupported) { isSupported = gluCheckExtension((const GLubyte*)"GL_EXT_texture_rectangle", strExt); if (!isSupported) LogRel(("OpenGL Info: GL_EXT_texture_rectangle extension not supported\n")); } else LogRel(("OpenGL Info: GL_EXT_framebuffer_object extension not supported\n")); #endif /* VBOX_WITH_COCOA_QT */ CGLDestroyContext(cglContext); return isSupported == GL_TRUE ? true : false; } } return false; }
/** * Worker for RTPathUserHome that looks up the home directory * using the HOME environment variable. * * @returns IPRT status code. * @param pszPath The path buffer. * @param cchPath The size of the buffer. */ static int rtPathUserHomeByEnv(char *pszPath, size_t cchPath) { /* * Get HOME env. var it and validate it's existance. */ int rc = VERR_PATH_NOT_FOUND; const char *pszHome = RTEnvGet("HOME"); /** @todo Codeset confusion in RTEnv. */ if (pszHome) { struct stat st; if ( !stat(pszHome, &st) && S_ISDIR(st.st_mode)) rc = rtPathFromNativeCopy(pszPath, cchPath, pszHome, NULL); } return rc; }
/** * Worker that we can wrap with error variable saving and restoring. */ static bool rtAssertShouldPanicWorker(void) { /* * Check for the VBOX_ASSERT variable. */ const char *psz = RTEnvGet("VBOX_ASSERT"); /* not defined => default behaviour. */ if (!psz) return true; /* 'breakpoint' or 'panic' means default behaviour. */ if (!strcmp(psz, "breakpoint") || !strcmp(psz, "panic")) return true; #ifdef VBOX_RTASSERT_WITH_GDB /* 'gdb' - means try launch a gdb session in xterm. */ if (!strcmp(psz, "gdb")) { /* Did we already fire up gdb? If so, just hit the breakpoint. */ static bool volatile s_fAlreadyLaunchedGdb = false; if (ASMAtomicUoReadBool(&s_fAlreadyLaunchedGdb)) return true; /* Try find a suitable terminal program. */ const char *pszTerm = RTEnvGet("VBOX_ASSERT_TERM"); if ( !pszTerm || !RTPathExists(pszTerm)) { pszTerm = "/usr/bin/gnome-terminal"; if (!RTPathExists(pszTerm)) { pszTerm = "/usr/X11R6/bin/xterm"; if (!RTPathExists(pszTerm)) { pszTerm ="/usr/bin/xterm"; if (!RTPathExists(pszTerm)) return true; } } } /* And find gdb. */ const char *pszGdb = RTEnvGet("VBOX_ASSERT_GDB"); if ( !pszGdb || !RTPathExists(pszGdb)) { pszGdb = "/usr/bin/gdb"; if (!RTPathExists(pszGdb)) pszGdb = "gdb"; } /* Try spawn the process. */ char szCmd[512]; size_t cch = RTStrPrintf(szCmd, sizeof(szCmd), "%s -p %d ", pszGdb, RTProcSelf()); if (cch < sizeof(szCmd)) { char *pszExecName = &szCmd[cch]; if (!RTProcGetExecutablePath(pszExecName, sizeof(szCmd) - cch)) *pszExecName = '\0'; } const char *apszArgs[] = { pszTerm, "-e", szCmd, NULL }; RTPROCESS Process; int rc = RTProcCreate(apszArgs[0], &apszArgs[0], RTENV_DEFAULT, 0, &Process); if (RT_FAILURE(rc)) return false; ASMAtomicWriteBool(&s_fAlreadyLaunchedGdb, true); /* Wait for gdb to attach. */ RTThreadSleep(15000); return true; } #endif /* '*' - don't hit the breakpoint. */ return false; }
int main(int argc, char **argv) { int rc = 0; RTR3InitExe(argc, &argv, 0); if(argc < 2) { #ifdef VBOX_WITH_CROGL /* backwards compatibility: check 3D */ rc = vboxCheck3DAccelerationSupported(); #endif } else { static const RTGETOPTDEF s_aOptionDefs[] = { { "--test", 't', RTGETOPT_REQ_STRING }, { "-test", 't', RTGETOPT_REQ_STRING }, #ifdef VBOXGLTEST_WITH_LOGGING { "--log", 'l', RTGETOPT_REQ_STRING }, #endif }; RTGETOPTSTATE State; rc = RTGetOptInit(&State, argc-1, argv+1, &s_aOptionDefs[0], RT_ELEMENTS(s_aOptionDefs), 0, 0); AssertRCReturn(rc, 49); #ifdef VBOX_WITH_VIDEOHWACCEL bool bTest2D = false; #endif #ifdef VBOX_WITH_CROGL bool bTest3D = false; #endif #ifdef VBOXGLTEST_WITH_LOGGING bool bLog = false; bool bLogSuffix = false; const char * pLog = NULL; #endif for (;;) { RTGETOPTUNION Val; rc = RTGetOpt(&State, &Val); if (!rc) break; switch (rc) { case 't': #ifdef VBOX_WITH_CROGL if (!strcmp(Val.psz, "3D") || !strcmp(Val.psz, "3d")) { bTest3D = true; rc = 0; break; } #endif #ifdef VBOX_WITH_VIDEOHWACCEL if (!strcmp(Val.psz, "2D") || !strcmp(Val.psz, "2d")) { bTest2D = true; rc = 0; break; } #endif rc = 1; break; #ifdef VBOXGLTEST_WITH_LOGGING case 'l': bLog = true; pLog = Val.psz; rc = 0; break; #endif case 'h': RTPrintf(VBOX_PRODUCT " Helper for testing 2D/3D OpenGL capabilities %u.%u.%u\n" "(C) 2009-" VBOX_C_YEAR " " VBOX_VENDOR "\n" "All rights reserved.\n" "\n" "Parameters:\n" #ifdef VBOX_WITH_VIDEOHWACCEL " --test 2D test for 2D (video) OpenGL capabilities\n" #endif #ifdef VBOX_WITH_CROGL " --test 3D test for 3D OpenGL capabilities\n" #endif #ifdef VBOXGLTEST_WITH_LOGGING " --log <log_file_name> log the GL test result to the given file\n" "\n" "Logging can alternatively be enabled by specifying the VBOXGLTEST_LOG=<log_file_name> env variable\n" #endif "\n", RTBldCfgVersionMajor(), RTBldCfgVersionMinor(), RTBldCfgVersionBuild()); break; case 'V': RTPrintf("$Revision: $\n"); return 0; case VERR_GETOPT_UNKNOWN_OPTION: case VINF_GETOPT_NOT_OPTION: rc = 1; default: /* complain? RTGetOptPrintError(rc, &Val); */ break; } if (rc) break; } if(!rc) { #ifdef VBOXGLTEST_WITH_LOGGING if(!bLog) { /* check the VBOXGLTEST_LOG env var */ pLog = RTEnvGet("VBOXGLTEST_LOG"); if(pLog) bLog = true; bLogSuffix = true; } if(bLog) rc = vboxInitLogging(pLog, bLogSuffix); else #endif rc = vboxInitQuietMode(); #ifdef VBOX_WITH_CROGL if(!rc && bTest3D) rc = vboxCheck3DAccelerationSupported(); #endif #ifdef VBOX_WITH_VIDEOHWACCEL if(!rc && bTest2D) rc = vboxCheck2DVideoAccelerationSupported(); #endif } } /*RTR3Term();*/ return rc; }
RTDECL(int) RTEnvGetEx(RTENV Env, const char *pszVar, char *pszValue, size_t cbValue, size_t *pcchActual) { AssertPtrReturn(pszVar, VERR_INVALID_POINTER); AssertPtrNullReturn(pszValue, VERR_INVALID_POINTER); AssertPtrNullReturn(pcchActual, VERR_INVALID_POINTER); AssertReturn(pcchActual || (pszValue && cbValue), VERR_INVALID_PARAMETER); AssertReturn(strchr(pszVar, '=') == NULL, VERR_ENV_INVALID_VAR_NAME); if (pcchActual) *pcchActual = 0; int rc; if (Env == RTENV_DEFAULT) { #ifdef RTENV_IMPLEMENTS_UTF8_DEFAULT_ENV_API rc = RTEnvGetUtf8(pszVar, pszValue, cbValue, pcchActual); #else /* * Since RTEnvGet isn't UTF-8 clean and actually expects the strings * to be in the current code page (codeset), we'll do the necessary * conversions here. */ char *pszVarOtherCP; rc = RTStrUtf8ToCurrentCP(&pszVarOtherCP, pszVar); if (RT_SUCCESS(rc)) { const char *pszValueOtherCP = RTEnvGet(pszVarOtherCP); RTStrFree(pszVarOtherCP); if (pszValueOtherCP) { char *pszValueUtf8; rc = RTStrCurrentCPToUtf8(&pszValueUtf8, pszValueOtherCP); if (RT_SUCCESS(rc)) { rc = VINF_SUCCESS; size_t cch = strlen(pszValueUtf8); if (pcchActual) *pcchActual = cch; if (pszValue && cbValue) { if (cch < cbValue) memcpy(pszValue, pszValueUtf8, cch + 1); else rc = VERR_BUFFER_OVERFLOW; } RTStrFree(pszValueUtf8); } } else rc = VERR_ENV_VAR_NOT_FOUND; } #endif } else { PRTENVINTERNAL pIntEnv = Env; AssertPtrReturn(pIntEnv, VERR_INVALID_HANDLE); AssertReturn(pIntEnv->u32Magic == RTENV_MAGIC, VERR_INVALID_HANDLE); RTENV_LOCK(pIntEnv); /* * Locate the first variable and return it to the caller. */ rc = VERR_ENV_VAR_NOT_FOUND; const size_t cchVar = strlen(pszVar); size_t iVar; for (iVar = 0; iVar < pIntEnv->cVars; iVar++) if (!pIntEnv->pfnCompare(pIntEnv->papszEnv[iVar], pszVar, cchVar)) { if (pIntEnv->papszEnv[iVar][cchVar] == '=') { rc = VINF_SUCCESS; const char *pszValueOrg = pIntEnv->papszEnv[iVar] + cchVar + 1; size_t cch = strlen(pszValueOrg); if (pcchActual) *pcchActual = cch; if (pszValue && cbValue) { if (cch < cbValue) memcpy(pszValue, pszValueOrg, cch + 1); else rc = VERR_BUFFER_OVERFLOW; } break; } if (pIntEnv->papszEnv[iVar][cchVar] == '\0') { Assert(pIntEnv->fPutEnvBlock); rc = VERR_ENV_VAR_UNSET; break; } } RTENV_UNLOCK(pIntEnv); } return rc; }
int main(int argc, char **argv) { int rc; RTR3InitExe(argc, &argv, 0); for (int i = 1; i < argc; i++) { #ifdef VBOX_OPENGL if (strcmp(argv[i], "-gl") == 0) { gfOpenGL = 1; continue; } #endif if (strcmp(argv[i], "-loop") == 0 && ++i < argc) { guLoop = atoi(argv[i]); continue; } RTPrintf("Unrecognized option '%s'\n", argv[i]); return -1; } #ifdef RT_OS_WINDOWS /* Default to DirectX if nothing else set. "windib" would be possible. */ if (!RTEnvExist("SDL_VIDEODRIVER")) { _putenv("SDL_VIDEODRIVER=directx"); } #endif #ifdef RT_OS_WINDOWS _putenv("SDL_VIDEO_WINDOW_POS=0,0"); #else RTEnvSet("SDL_VIDEO_WINDOW_POS", "0,0"); #endif rc = SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE); if (rc != 0) { RTPrintf("Error: SDL_InitSubSystem failed with message '%s'\n", SDL_GetError()); return -1; } /* output what SDL is capable of */ const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo(); if (!videoInfo) { RTPrintf("No SDL video info available!\n"); return -1; } RTPrintf("SDL capabilities:\n"); RTPrintf(" Hardware surface support: %s\n", videoInfo->hw_available ? "yes" : "no"); RTPrintf(" Window manager available: %s\n", videoInfo->wm_available ? "yes" : "no"); RTPrintf(" Screen to screen blits accelerated: %s\n", videoInfo->blit_hw ? "yes" : "no"); RTPrintf(" Screen to screen colorkey blits accelerated: %s\n", videoInfo->blit_hw_CC ? "yes" : "no"); RTPrintf(" Screen to screen alpha blits accelerated: %s\n", videoInfo->blit_hw_A ? "yes" : "no"); RTPrintf(" Memory to screen blits accelerated: %s\n", videoInfo->blit_sw ? "yes" : "no"); RTPrintf(" Memory to screen colorkey blits accelerated: %s\n", videoInfo->blit_sw_CC ? "yes" : "no"); RTPrintf(" Memory to screen alpha blits accelerated: %s\n", videoInfo->blit_sw_A ? "yes" : "no"); RTPrintf(" Color fills accelerated: %s\n", videoInfo->blit_fill ? "yes" : "no"); RTPrintf(" Video memory in kilobytes: %d\n", videoInfo->video_mem); RTPrintf(" Optimal bpp mode: %d\n", videoInfo->vfmt->BitsPerPixel); char buf[256]; RTPrintf("Video driver SDL_VIDEODRIVER / active: %s/%s\n", RTEnvGet("SDL_VIDEODRIVER"), SDL_VideoDriverName(buf, sizeof(buf))); RTPrintf("\n" "Starting tests. Any key pressed inside the SDL window will abort this\n" "program at the end of the current test. Iterations = %u\n", guLoop); #ifdef VBOX_OPENGL RTPrintf("\n========== "ESC_BOLD"OpenGL is %s"ESC_NORM" ==========\n", gfOpenGL ? "ON" : "OFF"); #endif bench( 640, 480, 16); bench( 640, 480, 24); bench( 640, 480, 32); bench(1024, 768, 16); bench(1024, 768, 24); bench(1024, 768, 32); bench(1280, 1024, 16); bench(1280, 1024, 24); bench(1280, 1024, 32); RTPrintf("\nSuccess!\n"); return 0; }