CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/android/jni/TestRunner.cpp
Views: 1401
1
// Copyright (c) 2012- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
// TO USE:
19
// Simply copy pspautotests to the root of the USB memory / SD card of your android device.
20
// Then go to Settings / Developer Menu / Run CPU tests.
21
// It currently just runs one test but that can be easily changed.
22
23
#include <string>
24
#include <sstream>
25
#include <iostream>
26
27
#include "ppsspp_config.h"
28
#include "Common/System/Display.h"
29
30
#include "Common/File/FileUtil.h"
31
#include "Common/Log.h"
32
#include "Core/Core.h"
33
#include "Core/System.h"
34
#include "Core/Config.h"
35
#include "Core/CoreTiming.h"
36
#include "Core/MIPS/MIPS.h"
37
#include "TestRunner.h"
38
39
static const char * const testsToRun[] = {
40
"cpu/cpu_alu/cpu_alu",
41
"cpu/fpu/fpu",
42
"cpu/icache/icache",
43
"cpu/lsu/lsu",
44
"cpu/vfpu/vector",
45
"cpu/vfpu/matrix",
46
"cpu/vfpu/convert",
47
"cpu/vfpu/colors",
48
"cpu/vfpu/prefixes",
49
"cpu/vfpu/gum",
50
};
51
52
static std::string TrimNewlines(const std::string &s) {
53
size_t p = s.find_last_not_of("\r\n");
54
if (p == s.npos) {
55
return "";
56
}
57
return s.substr(0, p + 1);
58
}
59
60
bool TestsAvailable() {
61
#if PPSSPP_PLATFORM(IOS)
62
Path testDirectory = g_Config.flash0Directory / "..";
63
#else
64
Path testDirectory = g_Config.memStickDirectory;
65
#endif
66
// Hack to easily run the tests on Windows from the submodule
67
if (File::IsDirectory(Path("../pspautotests"))) {
68
testDirectory = Path("..");
69
} else if (File::IsDirectory(Path("pspautotests"))) {
70
testDirectory = Path(".");
71
}
72
return File::Exists(testDirectory / "pspautotests" / "tests");
73
}
74
75
bool RunTests() {
76
std::string output;
77
78
#if PPSSPP_PLATFORM(IOS)
79
Path baseDirectory = g_Config.flash0Directory / "..";
80
#else
81
Path baseDirectory = g_Config.memStickDirectory;
82
// Hack to easily run the tests on Windows from the submodule
83
if (File::IsDirectory(Path("../pspautotests"))) {
84
baseDirectory = Path("..");
85
} else if (File::IsDirectory(Path("pspautotests"))) {
86
baseDirectory = Path(".");
87
}
88
#endif
89
90
GraphicsContext *tempCtx = PSP_CoreParameter().graphicsContext;
91
// Clear the context during tests. We set it back later.
92
PSP_CoreParameter().graphicsContext = nullptr;
93
94
CoreParameter coreParam;
95
coreParam.cpuCore = (CPUCore)g_Config.iCpuCore;
96
coreParam.gpuCore = GPUCORE_SOFTWARE;
97
coreParam.enableSound = g_Config.bEnableSound;
98
coreParam.graphicsContext = nullptr;
99
coreParam.mountIso.clear();
100
coreParam.mountRoot = baseDirectory / "pspautotests";
101
coreParam.startBreak = false;
102
coreParam.headLess = true;
103
coreParam.renderWidth = 480;
104
coreParam.renderHeight = 272;
105
coreParam.pixelWidth = 480;
106
coreParam.pixelHeight = 272;
107
coreParam.collectDebugOutput = &output;
108
coreParam.fastForward = true;
109
coreParam.updateRecent = false;
110
111
// Never report from tests.
112
std::string savedReportHost = g_Config.sReportHost;
113
g_Config.sReportHost.clear();
114
115
for (size_t i = 0; i < ARRAY_SIZE(testsToRun); i++) {
116
std::string testName = testsToRun[i];
117
coreParam.fileToStart = baseDirectory / "pspautotests" / "tests" / (testName + ".prx");
118
Path expectedFile = baseDirectory / "pspautotests" / "tests" / (testName + ".expected");
119
120
INFO_LOG(Log::System, "Preparing to execute '%s'", testName.c_str());
121
std::string error_string;
122
output.clear();
123
if (!PSP_Init(coreParam, &error_string)) {
124
ERROR_LOG(Log::System, "Failed to init unittest %s : %s", testsToRun[i], error_string.c_str());
125
PSP_CoreParameter().pixelWidth = g_display.pixel_xres;
126
PSP_CoreParameter().pixelHeight = g_display.pixel_yres;
127
return false;
128
}
129
130
PSP_BeginHostFrame();
131
132
// Run the emu until the test exits
133
INFO_LOG(Log::System, "Test: Entering runloop.");
134
while (true) {
135
int blockTicks = (int)usToCycles(1000000 / 10);
136
while (coreState == CORE_RUNNING) {
137
PSP_RunLoopFor(blockTicks);
138
}
139
// Hopefully coreState is now CORE_NEXTFRAME
140
if (coreState == CORE_NEXTFRAME) {
141
// set back to running for the next frame
142
coreState = CORE_RUNNING;
143
} else if (coreState == CORE_POWERDOWN) {
144
INFO_LOG(Log::System, "Finished running test %s", testName.c_str());
145
break;
146
}
147
}
148
PSP_EndHostFrame();
149
150
std::string expect_results;
151
if (!File::ReadTextFileToString(expectedFile, &expect_results)) {
152
ERROR_LOG(Log::System, "Error opening expectedFile %s", expectedFile.c_str());
153
break;
154
}
155
156
std::istringstream expected(expect_results);
157
std::istringstream logoutput(output);
158
159
int line = 0;
160
while (true) {
161
++line;
162
std::string e, o;
163
std::getline(expected, e);
164
std::getline(logoutput, o);
165
// Remove stray returns
166
e = TrimNewlines(e);
167
o = TrimNewlines(o);
168
if (e != o) {
169
ERROR_LOG(Log::System, "DIFF on line %i!", line);
170
ERROR_LOG(Log::System, "O: %s", o.c_str());
171
ERROR_LOG(Log::System, "E: %s", e.c_str());
172
}
173
if (expected.eof()) {
174
break;
175
}
176
if (logoutput.eof()) {
177
break;
178
}
179
}
180
PSP_Shutdown();
181
}
182
PSP_CoreParameter().pixelWidth = g_display.pixel_xres;
183
PSP_CoreParameter().pixelHeight = g_display.pixel_yres;
184
PSP_CoreParameter().headLess = false;
185
PSP_CoreParameter().graphicsContext = tempCtx;
186
187
g_Config.sReportHost = savedReportHost;
188
return true; // Managed to execute the tests. Says nothing about the result.
189
}
190
191