int main(int argc, const char* argv[]) { bool fullLog = false; bool useJit = false; bool fastInterpreter = false; bool autoCompare = false; bool useGraphics = false; const char *bootFilename = 0; const char *mountIso = 0; bool readMount = false; for (int i = 1; i < argc; i++) { if (readMount) { mountIso = argv[i]; readMount = false; continue; } if (!strcmp(argv[i], "-m") || !strcmp(argv[i], "--mount")) readMount = true; else if (!strcmp(argv[i], "-l") || !strcmp(argv[i], "--log")) fullLog = true; else if (!strcmp(argv[i], "-j")) useJit = true; else if (!strcmp(argv[i], "-f")) fastInterpreter = true; else if (!strcmp(argv[i], "-c") || !strcmp(argv[i], "--compare")) autoCompare = true; else if (!strcmp(argv[i], "--graphics")) useGraphics = true; else if (bootFilename == 0) bootFilename = argv[i]; else { if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) printUsage(argv[0], NULL); else { std::string reason = "Unexpected argument " + std::string(argv[i]); printUsage(argv[0], reason.c_str()); } return 1; } } if (readMount) { printUsage(argv[0], "Missing argument after -m"); return 1; } if (!bootFilename) { printUsage(argv[0], argc <= 1 ? NULL : "No executable specified"); return 1; } HeadlessHost *headlessHost = useGraphics ? new HEADLESSHOST_CLASS() : new HeadlessHost(); host = headlessHost; host->InitGL(); LogManager::Init(); LogManager *logman = LogManager::GetInstance(); PrintfLogger *printfLogger = new PrintfLogger(); for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++) { LogTypes::LOG_TYPE type = (LogTypes::LOG_TYPE)i; logman->SetEnable(type, fullLog); logman->SetLogLevel(type, LogTypes::LDEBUG); logman->AddListener(type, printfLogger); } CoreParameter coreParameter; coreParameter.fileToStart = bootFilename; coreParameter.mountIso = mountIso ? mountIso : ""; coreParameter.startPaused = false; coreParameter.cpuCore = useJit ? CPU_JIT : (fastInterpreter ? CPU_FASTINTERPRETER : CPU_INTERPRETER); coreParameter.gpuCore = headlessHost->isGLWorking() ? GPU_GLES : GPU_NULL; coreParameter.enableSound = false; coreParameter.headLess = true; coreParameter.printfEmuLog = true; g_Config.bEnableSound = false; g_Config.bFirstRun = false; g_Config.bIgnoreBadMemAccess = true; std::string error_string; if (!PSP_Init(coreParameter, &error_string)) { fprintf(stderr, "Failed to start %s. Error: %s\n", coreParameter.fileToStart.c_str(), error_string.c_str()); printf("TESTERROR\n"); return 1; } host->BootDone(); coreState = CORE_RUNNING; while (coreState == CORE_RUNNING) { // Run for a frame at a time, just because. u64 nowTicks = CoreTiming::GetTicks(); u64 frameTicks = usToCycles(1000000/60); mipsr4k.RunLoopUntil(nowTicks + frameTicks); // If we were rendering, this might be a nice time to do something about it. if (coreState == CORE_NEXTFRAME) coreState = CORE_RUNNING; } host->ShutdownGL(); PSP_Shutdown(); delete host; host = NULL; headlessHost = NULL; if (autoCompare) { std::string expect_filename = std::string(bootFilename).substr(strlen(bootFilename - 4)) + ".expected"; if (File::Exists(expect_filename)) { // TODO: Do the compare here } else { fprintf(stderr, "Expectation file %s not found", expect_filename.c_str()); } } return 0; }
int main(int argc, const char* argv[]) { bool fullLog = false; bool useJit = true; bool autoCompare = false; bool useGraphics = false; const char *bootFilename = 0; const char *mountIso = 0; const char *screenshotFilename = 0; bool readMount = false; for (int i = 1; i < argc; i++) { if (readMount) { mountIso = argv[i]; readMount = false; continue; } if (!strcmp(argv[i], "-m") || !strcmp(argv[i], "--mount")) readMount = true; else if (!strcmp(argv[i], "-l") || !strcmp(argv[i], "--log")) fullLog = true; else if (!strcmp(argv[i], "-i")) useJit = false; else if (!strcmp(argv[i], "-j")) useJit = true; else if (!strcmp(argv[i], "-c") || !strcmp(argv[i], "--compare")) autoCompare = true; else if (!strcmp(argv[i], "--graphics")) useGraphics = true; else if (!strncmp(argv[i], "--screenshot=", strlen("--screenshot=")) && strlen(argv[i]) > strlen("--screenshot=")) screenshotFilename = argv[i] + strlen("--screenshot="); else if (bootFilename == 0) bootFilename = argv[i]; else { if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) printUsage(argv[0], NULL); else { std::string reason = "Unexpected argument " + std::string(argv[i]); printUsage(argv[0], reason.c_str()); } return 1; } } if (readMount) { printUsage(argv[0], "Missing argument after -m"); return 1; } if (!bootFilename) { printUsage(argv[0], argc <= 1 ? NULL : "No executable specified"); return 1; } HeadlessHost *headlessHost = useGraphics ? new HEADLESSHOST_CLASS() : new HeadlessHost(); host = headlessHost; std::string error_string; host->InitGL(&error_string); LogManager::Init(); LogManager *logman = LogManager::GetInstance(); PrintfLogger *printfLogger = new PrintfLogger(); for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++) { LogTypes::LOG_TYPE type = (LogTypes::LOG_TYPE)i; logman->SetEnable(type, fullLog); logman->SetLogLevel(type, LogTypes::LDEBUG); logman->AddListener(type, printfLogger); } CoreParameter coreParameter; coreParameter.fileToStart = bootFilename; coreParameter.mountIso = mountIso ? mountIso : ""; coreParameter.startPaused = false; coreParameter.cpuCore = useJit ? CPU_JIT : CPU_INTERPRETER; coreParameter.gpuCore = headlessHost->isGLWorking() ? GPU_GLES : GPU_NULL; coreParameter.enableSound = false; coreParameter.headLess = true; coreParameter.printfEmuLog = true; coreParameter.useMediaEngine = false; g_Config.bEnableSound = false; g_Config.bFirstRun = false; g_Config.bIgnoreBadMemAccess = true; // Never report from tests. g_Config.sReportHost = ""; #if defined(ANDROID) #elif defined(BLACKBERRY) || defined(__SYMBIAN32__) #elif !defined(_WIN32) g_Config.memCardDirectory = std::string(getenv("HOME"))+"/.ppsspp/"; g_Config.flashDirectory = g_Config.memCardDirectory+"/flash/"; #endif if (!PSP_Init(coreParameter, &error_string)) { fprintf(stderr, "Failed to start %s. Error: %s\n", coreParameter.fileToStart.c_str(), error_string.c_str()); printf("TESTERROR\n"); return 1; } host->BootDone(); if (screenshotFilename != 0) headlessHost->SetComparisonScreenshot(screenshotFilename); coreState = CORE_RUNNING; while (coreState == CORE_RUNNING) { // Run for a frame at a time, just because. u64 nowTicks = CoreTiming::GetTicks(); u64 frameTicks = usToCycles(1000000/60); mipsr4k.RunLoopUntil(nowTicks + frameTicks); // If we were rendering, this might be a nice time to do something about it. if (coreState == CORE_NEXTFRAME) { coreState = CORE_RUNNING; headlessHost->SwapBuffers(); } } host->ShutdownGL(); PSP_Shutdown(); delete host; host = NULL; headlessHost = NULL; if (autoCompare) CompareOutput(bootFilename); return 0; }