CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/android/jni/TestRunner.cpp
Views: 1401
// Copyright (c) 2012- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617// TO USE:18// Simply copy pspautotests to the root of the USB memory / SD card of your android device.19// Then go to Settings / Developer Menu / Run CPU tests.20// It currently just runs one test but that can be easily changed.2122#include <string>23#include <sstream>24#include <iostream>2526#include "ppsspp_config.h"27#include "Common/System/Display.h"2829#include "Common/File/FileUtil.h"30#include "Common/Log.h"31#include "Core/Core.h"32#include "Core/System.h"33#include "Core/Config.h"34#include "Core/CoreTiming.h"35#include "Core/MIPS/MIPS.h"36#include "TestRunner.h"3738static const char * const testsToRun[] = {39"cpu/cpu_alu/cpu_alu",40"cpu/fpu/fpu",41"cpu/icache/icache",42"cpu/lsu/lsu",43"cpu/vfpu/vector",44"cpu/vfpu/matrix",45"cpu/vfpu/convert",46"cpu/vfpu/colors",47"cpu/vfpu/prefixes",48"cpu/vfpu/gum",49};5051static std::string TrimNewlines(const std::string &s) {52size_t p = s.find_last_not_of("\r\n");53if (p == s.npos) {54return "";55}56return s.substr(0, p + 1);57}5859bool TestsAvailable() {60#if PPSSPP_PLATFORM(IOS)61Path testDirectory = g_Config.flash0Directory / "..";62#else63Path testDirectory = g_Config.memStickDirectory;64#endif65// Hack to easily run the tests on Windows from the submodule66if (File::IsDirectory(Path("../pspautotests"))) {67testDirectory = Path("..");68} else if (File::IsDirectory(Path("pspautotests"))) {69testDirectory = Path(".");70}71return File::Exists(testDirectory / "pspautotests" / "tests");72}7374bool RunTests() {75std::string output;7677#if PPSSPP_PLATFORM(IOS)78Path baseDirectory = g_Config.flash0Directory / "..";79#else80Path baseDirectory = g_Config.memStickDirectory;81// Hack to easily run the tests on Windows from the submodule82if (File::IsDirectory(Path("../pspautotests"))) {83baseDirectory = Path("..");84} else if (File::IsDirectory(Path("pspautotests"))) {85baseDirectory = Path(".");86}87#endif8889GraphicsContext *tempCtx = PSP_CoreParameter().graphicsContext;90// Clear the context during tests. We set it back later.91PSP_CoreParameter().graphicsContext = nullptr;9293CoreParameter coreParam;94coreParam.cpuCore = (CPUCore)g_Config.iCpuCore;95coreParam.gpuCore = GPUCORE_SOFTWARE;96coreParam.enableSound = g_Config.bEnableSound;97coreParam.graphicsContext = nullptr;98coreParam.mountIso.clear();99coreParam.mountRoot = baseDirectory / "pspautotests";100coreParam.startBreak = false;101coreParam.headLess = true;102coreParam.renderWidth = 480;103coreParam.renderHeight = 272;104coreParam.pixelWidth = 480;105coreParam.pixelHeight = 272;106coreParam.collectDebugOutput = &output;107coreParam.fastForward = true;108coreParam.updateRecent = false;109110// Never report from tests.111std::string savedReportHost = g_Config.sReportHost;112g_Config.sReportHost.clear();113114for (size_t i = 0; i < ARRAY_SIZE(testsToRun); i++) {115std::string testName = testsToRun[i];116coreParam.fileToStart = baseDirectory / "pspautotests" / "tests" / (testName + ".prx");117Path expectedFile = baseDirectory / "pspautotests" / "tests" / (testName + ".expected");118119INFO_LOG(Log::System, "Preparing to execute '%s'", testName.c_str());120std::string error_string;121output.clear();122if (!PSP_Init(coreParam, &error_string)) {123ERROR_LOG(Log::System, "Failed to init unittest %s : %s", testsToRun[i], error_string.c_str());124PSP_CoreParameter().pixelWidth = g_display.pixel_xres;125PSP_CoreParameter().pixelHeight = g_display.pixel_yres;126return false;127}128129PSP_BeginHostFrame();130131// Run the emu until the test exits132INFO_LOG(Log::System, "Test: Entering runloop.");133while (true) {134int blockTicks = (int)usToCycles(1000000 / 10);135while (coreState == CORE_RUNNING) {136PSP_RunLoopFor(blockTicks);137}138// Hopefully coreState is now CORE_NEXTFRAME139if (coreState == CORE_NEXTFRAME) {140// set back to running for the next frame141coreState = CORE_RUNNING;142} else if (coreState == CORE_POWERDOWN) {143INFO_LOG(Log::System, "Finished running test %s", testName.c_str());144break;145}146}147PSP_EndHostFrame();148149std::string expect_results;150if (!File::ReadTextFileToString(expectedFile, &expect_results)) {151ERROR_LOG(Log::System, "Error opening expectedFile %s", expectedFile.c_str());152break;153}154155std::istringstream expected(expect_results);156std::istringstream logoutput(output);157158int line = 0;159while (true) {160++line;161std::string e, o;162std::getline(expected, e);163std::getline(logoutput, o);164// Remove stray returns165e = TrimNewlines(e);166o = TrimNewlines(o);167if (e != o) {168ERROR_LOG(Log::System, "DIFF on line %i!", line);169ERROR_LOG(Log::System, "O: %s", o.c_str());170ERROR_LOG(Log::System, "E: %s", e.c_str());171}172if (expected.eof()) {173break;174}175if (logoutput.eof()) {176break;177}178}179PSP_Shutdown();180}181PSP_CoreParameter().pixelWidth = g_display.pixel_xres;182PSP_CoreParameter().pixelHeight = g_display.pixel_yres;183PSP_CoreParameter().headLess = false;184PSP_CoreParameter().graphicsContext = tempCtx;185186g_Config.sReportHost = savedReportHost;187return true; // Managed to execute the tests. Says nothing about the result.188}189190191