2013-03-06 23:10:53 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
// TO USE:
|
|
|
|
// Simply copy pspautotests to the root of the USB memory / SD card of your android device.
|
|
|
|
// Then go to Settings / Developer Menu / Run CPU tests.
|
|
|
|
// It currently just runs one test but that can be easily changed.
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
#include <iostream>
|
|
|
|
|
2018-01-04 17:10:41 +00:00
|
|
|
#include "ppsspp_config.h"
|
2020-10-04 08:10:55 +00:00
|
|
|
#include "Common/System/Display.h"
|
2013-03-06 23:10:53 +00:00
|
|
|
|
2020-10-04 18:48:47 +00:00
|
|
|
#include "Common/File/FileUtil.h"
|
2020-08-15 14:25:50 +00:00
|
|
|
#include "Common/Log.h"
|
2013-03-06 23:10:53 +00:00
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/System.h"
|
|
|
|
#include "Core/Config.h"
|
|
|
|
#include "Core/CoreTiming.h"
|
|
|
|
#include "Core/MIPS/MIPS.h"
|
|
|
|
#include "TestRunner.h"
|
|
|
|
|
2013-03-17 18:24:35 +00:00
|
|
|
static const char * const testsToRun[] = {
|
2013-03-06 23:10:53 +00:00
|
|
|
"cpu/cpu_alu/cpu_alu",
|
|
|
|
"cpu/fpu/fpu",
|
|
|
|
"cpu/icache/icache",
|
|
|
|
"cpu/lsu/lsu",
|
2013-03-17 18:24:35 +00:00
|
|
|
"cpu/vfpu/vector",
|
|
|
|
"cpu/vfpu/matrix",
|
|
|
|
"cpu/vfpu/convert",
|
|
|
|
"cpu/vfpu/colors",
|
2013-03-16 09:39:54 +00:00
|
|
|
"cpu/vfpu/prefixes",
|
2013-03-17 18:24:35 +00:00
|
|
|
"cpu/vfpu/gum",
|
2013-03-06 23:10:53 +00:00
|
|
|
};
|
|
|
|
|
2013-10-14 07:49:04 +00:00
|
|
|
static std::string TrimNewlines(const std::string &s) {
|
|
|
|
size_t p = s.find_last_not_of("\r\n");
|
|
|
|
if (p == s.npos) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return s.substr(0, p + 1);
|
|
|
|
}
|
|
|
|
|
2018-01-04 17:10:41 +00:00
|
|
|
bool TestsAvailable() {
|
2021-03-03 04:57:25 +00:00
|
|
|
#if PPSSPP_PLATFORM(IOS)
|
2021-05-09 13:25:12 +00:00
|
|
|
Path testDirectory = g_Config.flash0Directory / "..";
|
2018-01-04 17:10:41 +00:00
|
|
|
#else
|
2021-05-05 23:31:38 +00:00
|
|
|
Path testDirectory = g_Config.memStickDirectory;
|
2018-01-04 17:10:41 +00:00
|
|
|
#endif
|
|
|
|
// Hack to easily run the tests on Windows from the submodule
|
2021-05-05 23:31:38 +00:00
|
|
|
if (File::IsDirectory(Path("../pspautotests"))) {
|
|
|
|
testDirectory = Path("..");
|
2018-01-04 17:10:41 +00:00
|
|
|
}
|
2021-05-11 07:50:28 +00:00
|
|
|
return File::Exists(testDirectory / "pspautotests" / "tests");
|
2018-01-04 17:10:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RunTests() {
|
2013-03-06 23:10:53 +00:00
|
|
|
std::string output;
|
|
|
|
|
2021-03-03 04:57:25 +00:00
|
|
|
#if PPSSPP_PLATFORM(IOS)
|
2021-05-09 13:25:12 +00:00
|
|
|
Path baseDirectory = g_Config.flash0Directory / "..";
|
2014-04-19 19:52:43 +00:00
|
|
|
#else
|
2021-05-05 23:31:38 +00:00
|
|
|
Path baseDirectory = g_Config.memStickDirectory;
|
2018-01-04 17:10:41 +00:00
|
|
|
// Hack to easily run the tests on Windows from the submodule
|
2021-05-05 23:31:38 +00:00
|
|
|
if (File::IsDirectory(Path("../pspautotests"))) {
|
|
|
|
baseDirectory = Path("..");
|
2018-01-04 17:10:41 +00:00
|
|
|
}
|
2014-04-19 19:52:43 +00:00
|
|
|
#endif
|
|
|
|
|
2021-02-04 05:26:25 +00:00
|
|
|
GraphicsContext *tempCtx = PSP_CoreParameter().graphicsContext;
|
|
|
|
// Clear the context during tests. We set it back later.
|
|
|
|
PSP_CoreParameter().graphicsContext = nullptr;
|
|
|
|
|
2013-03-06 23:10:53 +00:00
|
|
|
CoreParameter coreParam;
|
2016-05-07 23:43:27 +00:00
|
|
|
coreParam.cpuCore = (CPUCore)g_Config.iCpuCore;
|
2021-01-02 17:36:13 +00:00
|
|
|
coreParam.gpuCore = GPUCORE_SOFTWARE;
|
2013-03-06 23:10:53 +00:00
|
|
|
coreParam.enableSound = g_Config.bEnableSound;
|
2018-01-04 17:10:41 +00:00
|
|
|
coreParam.graphicsContext = nullptr;
|
2021-05-10 00:24:04 +00:00
|
|
|
coreParam.mountIso.clear();
|
2021-05-05 23:31:38 +00:00
|
|
|
coreParam.mountRoot = baseDirectory / "pspautotests";
|
2018-06-23 17:14:36 +00:00
|
|
|
coreParam.startBreak = false;
|
2013-03-06 23:10:53 +00:00
|
|
|
coreParam.printfEmuLog = false;
|
2013-10-14 07:49:04 +00:00
|
|
|
coreParam.headLess = true;
|
2013-03-06 23:10:53 +00:00
|
|
|
coreParam.renderWidth = 480;
|
|
|
|
coreParam.renderHeight = 272;
|
|
|
|
coreParam.pixelWidth = 480;
|
|
|
|
coreParam.pixelHeight = 272;
|
|
|
|
coreParam.collectEmuLog = &output;
|
2021-08-17 14:48:47 +00:00
|
|
|
coreParam.fastForward = true;
|
2013-05-22 19:01:24 +00:00
|
|
|
coreParam.updateRecent = false;
|
2013-03-06 23:10:53 +00:00
|
|
|
|
2013-03-09 20:53:53 +00:00
|
|
|
// Never report from tests.
|
|
|
|
std::string savedReportHost = g_Config.sReportHost;
|
|
|
|
g_Config.sReportHost = "";
|
|
|
|
|
2013-04-06 03:58:35 +00:00
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(testsToRun); i++) {
|
2021-05-05 23:31:38 +00:00
|
|
|
std::string testName = testsToRun[i];
|
|
|
|
coreParam.fileToStart = baseDirectory / "pspautotests" / "tests" / (testName + ".prx");
|
|
|
|
Path expectedFile = baseDirectory / "pspautotests" / "tests" / (testName + ".expected");
|
2013-03-06 23:10:53 +00:00
|
|
|
|
2021-05-05 23:31:38 +00:00
|
|
|
INFO_LOG(SYSTEM, "Preparing to execute '%s'", testName.c_str());
|
2013-03-06 23:10:53 +00:00
|
|
|
std::string error_string;
|
|
|
|
output = "";
|
|
|
|
if (!PSP_Init(coreParam, &error_string)) {
|
2020-08-15 14:25:50 +00:00
|
|
|
ERROR_LOG(SYSTEM, "Failed to init unittest %s : %s", testsToRun[i], error_string.c_str());
|
2013-10-12 19:34:13 +00:00
|
|
|
PSP_CoreParameter().pixelWidth = pixel_xres;
|
|
|
|
PSP_CoreParameter().pixelHeight = pixel_yres;
|
2018-01-04 17:10:41 +00:00
|
|
|
return false;
|
2013-03-06 23:10:53 +00:00
|
|
|
}
|
|
|
|
|
2018-01-04 17:10:41 +00:00
|
|
|
PSP_BeginHostFrame();
|
|
|
|
|
2013-03-06 23:10:53 +00:00
|
|
|
// Run the emu until the test exits
|
2020-08-15 14:25:50 +00:00
|
|
|
INFO_LOG(SYSTEM, "Test: Entering runloop.");
|
2013-03-06 23:10:53 +00:00
|
|
|
while (true) {
|
2022-01-30 23:15:38 +00:00
|
|
|
int blockTicks = (int)usToCycles(1000000 / 10);
|
2013-03-06 23:10:53 +00:00
|
|
|
while (coreState == CORE_RUNNING) {
|
2013-08-04 22:22:30 +00:00
|
|
|
PSP_RunLoopFor(blockTicks);
|
2013-03-06 23:10:53 +00:00
|
|
|
}
|
|
|
|
// Hopefully coreState is now CORE_NEXTFRAME
|
|
|
|
if (coreState == CORE_NEXTFRAME) {
|
|
|
|
// set back to running for the next frame
|
|
|
|
coreState = CORE_RUNNING;
|
|
|
|
} else if (coreState == CORE_POWERDOWN) {
|
2021-05-05 23:31:38 +00:00
|
|
|
INFO_LOG(SYSTEM, "Finished running test %s", testName.c_str());
|
2013-03-06 23:10:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-01-04 17:10:41 +00:00
|
|
|
PSP_EndHostFrame();
|
2021-05-09 23:22:31 +00:00
|
|
|
|
|
|
|
std::string expect_results;
|
2021-05-09 13:02:46 +00:00
|
|
|
if (!File::ReadFileToString(true, expectedFile, expect_results)) {
|
2020-08-15 14:25:50 +00:00
|
|
|
ERROR_LOG(SYSTEM, "Error opening expectedFile %s", expectedFile.c_str());
|
2013-10-14 07:49:04 +00:00
|
|
|
break;
|
2013-03-06 23:10:53 +00:00
|
|
|
}
|
|
|
|
|
2021-05-09 23:22:31 +00:00
|
|
|
std::istringstream expected(expect_results);
|
2013-03-06 23:10:53 +00:00
|
|
|
std::istringstream logoutput(output);
|
|
|
|
|
2013-03-06 23:37:00 +00:00
|
|
|
int line = 0;
|
2013-03-06 23:10:53 +00:00
|
|
|
while (true) {
|
2013-03-06 23:37:00 +00:00
|
|
|
++line;
|
2013-03-06 23:10:53 +00:00
|
|
|
std::string e, o;
|
|
|
|
std::getline(expected, e);
|
|
|
|
std::getline(logoutput, o);
|
2013-03-06 23:22:39 +00:00
|
|
|
// Remove stray returns
|
2013-10-14 07:49:04 +00:00
|
|
|
e = TrimNewlines(e);
|
|
|
|
o = TrimNewlines(o);
|
2013-03-06 23:10:53 +00:00
|
|
|
if (e != o) {
|
2020-08-15 14:25:50 +00:00
|
|
|
ERROR_LOG(SYSTEM, "DIFF on line %i!", line);
|
|
|
|
ERROR_LOG(SYSTEM, "O: %s", o.c_str());
|
|
|
|
ERROR_LOG(SYSTEM, "E: %s", e.c_str());
|
2013-03-06 23:10:53 +00:00
|
|
|
}
|
|
|
|
if (expected.eof()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (logoutput.eof()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-03-06 23:22:39 +00:00
|
|
|
PSP_Shutdown();
|
2013-03-06 23:10:53 +00:00
|
|
|
}
|
2013-10-12 19:34:13 +00:00
|
|
|
PSP_CoreParameter().pixelWidth = pixel_xres;
|
|
|
|
PSP_CoreParameter().pixelHeight = pixel_yres;
|
2013-10-14 07:49:04 +00:00
|
|
|
PSP_CoreParameter().headLess = false;
|
2021-02-04 05:26:25 +00:00
|
|
|
PSP_CoreParameter().graphicsContext = tempCtx;
|
|
|
|
|
2013-03-09 20:53:53 +00:00
|
|
|
g_Config.sReportHost = savedReportHost;
|
2018-01-04 17:10:41 +00:00
|
|
|
return true; // Managed to execute the tests. Says nothing about the result.
|
2013-12-29 22:28:31 +00:00
|
|
|
}
|