summaryrefslogtreecommitdiff
path: root/src/yuzu_tester/yuzu.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/yuzu_tester/yuzu.cpp')
-rw-r--r--src/yuzu_tester/yuzu.cpp268
1 files changed, 0 insertions, 268 deletions
diff --git a/src/yuzu_tester/yuzu.cpp b/src/yuzu_tester/yuzu.cpp
deleted file mode 100644
index 6435ffabb..000000000
--- a/src/yuzu_tester/yuzu.cpp
+++ /dev/null
@@ -1,268 +0,0 @@
1// Copyright 2019 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <chrono>
6#include <iostream>
7#include <memory>
8#include <string>
9#include <thread>
10
11#include <fmt/ostream.h>
12
13#include "common/common_paths.h"
14#include "common/detached_tasks.h"
15#include "common/file_util.h"
16#include "common/logging/backend.h"
17#include "common/logging/filter.h"
18#include "common/logging/log.h"
19#include "common/microprofile.h"
20#include "common/scm_rev.h"
21#include "common/scope_exit.h"
22#include "common/string_util.h"
23#include "common/telemetry.h"
24#include "core/core.h"
25#include "core/crypto/key_manager.h"
26#include "core/file_sys/registered_cache.h"
27#include "core/file_sys/vfs_real.h"
28#include "core/hle/service/filesystem/filesystem.h"
29#include "core/loader/loader.h"
30#include "core/settings.h"
31#include "core/telemetry_session.h"
32#include "video_core/renderer_base.h"
33#include "yuzu_tester/config.h"
34#include "yuzu_tester/emu_window/emu_window_sdl2_hide.h"
35#include "yuzu_tester/service/yuzutest.h"
36
37#ifdef _WIN32
38// windows.h needs to be included before shellapi.h
39#include <windows.h>
40
41#include <shellapi.h>
42#endif
43
44#undef _UNICODE
45#include <getopt.h>
46#ifndef _MSC_VER
47#include <unistd.h>
48#endif
49
50#ifdef _WIN32
51extern "C" {
52// tells Nvidia and AMD drivers to use the dedicated GPU by default on laptops with switchable
53// graphics
54__declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001;
55__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
56}
57#endif
58
59static void PrintHelp(const char* argv0) {
60 std::cout << "Usage: " << argv0
61 << " [options] <filename>\n"
62 "-h, --help Display this help and exit\n"
63 "-v, --version Output version information and exit\n"
64 "-d, --datastring Pass following string as data to test service command #2\n"
65 "-l, --log Log to console in addition to file (will log to file only "
66 "by default)\n";
67}
68
69static void PrintVersion() {
70 std::cout << "yuzu [Test Utility] " << Common::g_scm_branch << " " << Common::g_scm_desc
71 << std::endl;
72}
73
74static void InitializeLogging(bool console) {
75 Log::Filter log_filter(Log::Level::Debug);
76 log_filter.ParseFilterString(Settings::values.log_filter);
77 Log::SetGlobalFilter(log_filter);
78
79 if (console)
80 Log::AddBackend(std::make_unique<Log::ColorConsoleBackend>());
81
82 const std::string& log_dir = Common::FS::GetUserPath(Common::FS::UserPath::LogDir);
83 Common::FS::CreateFullPath(log_dir);
84 Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE));
85#ifdef _WIN32
86 Log::AddBackend(std::make_unique<Log::DebuggerBackend>());
87#endif
88}
89
90/// Application entry point
91int main(int argc, char** argv) {
92 Common::DetachedTasks detached_tasks;
93 Config config;
94
95 int option_index = 0;
96
97#ifdef _WIN32
98 int argc_w;
99 auto argv_w = CommandLineToArgvW(GetCommandLineW(), &argc_w);
100
101 if (argv_w == nullptr) {
102 std::cout << "Failed to get command line arguments" << std::endl;
103 return -1;
104 }
105#endif
106 std::string filepath;
107
108 static struct option long_options[] = {
109 {"help", no_argument, 0, 'h'},
110 {"version", no_argument, 0, 'v'},
111 {"datastring", optional_argument, 0, 'd'},
112 {"log", no_argument, 0, 'l'},
113 {0, 0, 0, 0},
114 };
115
116 bool console_log = false;
117 std::string datastring;
118
119 while (optind < argc) {
120 int arg = getopt_long(argc, argv, "hvdl::", long_options, &option_index);
121 if (arg != -1) {
122 switch (static_cast<char>(arg)) {
123 case 'h':
124 PrintHelp(argv[0]);
125 return 0;
126 case 'v':
127 PrintVersion();
128 return 0;
129 case 'd':
130 datastring = argv[optind];
131 ++optind;
132 break;
133 case 'l':
134 console_log = true;
135 break;
136 }
137 } else {
138#ifdef _WIN32
139 filepath = Common::UTF16ToUTF8(argv_w[optind]);
140#else
141 filepath = argv[optind];
142#endif
143 optind++;
144 }
145 }
146
147 InitializeLogging(console_log);
148
149#ifdef _WIN32
150 LocalFree(argv_w);
151#endif
152
153 MicroProfileOnThreadCreate("EmuThread");
154 SCOPE_EXIT({ MicroProfileShutdown(); });
155
156 if (filepath.empty()) {
157 LOG_CRITICAL(Frontend, "Failed to load application: No application specified");
158 std::cout << "Failed to load application: No application specified" << std::endl;
159 PrintHelp(argv[0]);
160 return -1;
161 }
162
163 Core::System& system{Core::System::GetInstance()};
164
165 Settings::Apply(system);
166
167 const auto emu_window{std::make_unique<EmuWindow_SDL2_Hide>()};
168
169 bool finished = false;
170 int return_value = 0;
171 const auto callback = [&finished,
172 &return_value](std::vector<Service::Yuzu::TestResult> results) {
173 finished = true;
174 return_value = 0;
175
176 // Find the minimum length needed to fully enclose all test names (and the header field) in
177 // the fmt::format column by first finding the maximum size of any test name and comparing
178 // that to 9, the string length of 'Test Name'
179 const auto needed_length_name =
180 std::max<u64>(std::max_element(results.begin(), results.end(),
181 [](const auto& lhs, const auto& rhs) {
182 return lhs.name.size() < rhs.name.size();
183 })
184 ->name.size(),
185 9ull);
186
187 std::size_t passed = 0;
188 std::size_t failed = 0;
189
190 std::cout << fmt::format("Result [Res Code] | {:<{}} | Extra Data", "Test Name",
191 needed_length_name)
192 << std::endl;
193
194 for (const auto& res : results) {
195 const auto main_res = res.code == 0 ? "PASSED" : "FAILED";
196 if (res.code == 0)
197 ++passed;
198 else
199 ++failed;
200 std::cout << fmt::format("{} [{:08X}] | {:<{}} | {}", main_res, res.code, res.name,
201 needed_length_name, res.data)
202 << std::endl;
203 }
204
205 std::cout << std::endl
206 << fmt::format("{:4d} Passed | {:4d} Failed | {:4d} Total | {:2.2f} Passed Ratio",
207 passed, failed, passed + failed,
208 static_cast<float>(passed) / (passed + failed))
209 << std::endl
210 << (failed == 0 ? "PASSED" : "FAILED") << std::endl;
211
212 if (failed > 0)
213 return_value = -1;
214 };
215
216 system.SetContentProvider(std::make_unique<FileSys::ContentProviderUnion>());
217 system.SetFilesystem(std::make_shared<FileSys::RealVfsFilesystem>());
218 system.GetFileSystemController().CreateFactories(*system.GetFilesystem());
219
220 SCOPE_EXIT({ system.Shutdown(); });
221
222 const Core::System::ResultStatus load_result{system.Load(*emu_window, filepath)};
223
224 switch (load_result) {
225 case Core::System::ResultStatus::ErrorGetLoader:
226 LOG_CRITICAL(Frontend, "Failed to obtain loader for {}!", filepath);
227 return -1;
228 case Core::System::ResultStatus::ErrorLoader:
229 LOG_CRITICAL(Frontend, "Failed to load ROM!");
230 return -1;
231 case Core::System::ResultStatus::ErrorNotInitialized:
232 LOG_CRITICAL(Frontend, "CPUCore not initialized");
233 return -1;
234 case Core::System::ResultStatus::ErrorVideoCore:
235 LOG_CRITICAL(Frontend, "Failed to initialize VideoCore!");
236 return -1;
237 case Core::System::ResultStatus::Success:
238 break; // Expected case
239 default:
240 if (static_cast<u32>(load_result) >
241 static_cast<u32>(Core::System::ResultStatus::ErrorLoader)) {
242 const u16 loader_id = static_cast<u16>(Core::System::ResultStatus::ErrorLoader);
243 const u16 error_id = static_cast<u16>(load_result) - loader_id;
244 LOG_CRITICAL(Frontend,
245 "While attempting to load the ROM requested, an error occured. Please "
246 "refer to the yuzu wiki for more information or the yuzu discord for "
247 "additional help.\n\nError Code: {:04X}-{:04X}\nError Description: {}",
248 loader_id, error_id, static_cast<Loader::ResultStatus>(error_id));
249 }
250 break;
251 }
252
253 Service::Yuzu::InstallInterfaces(system, datastring, callback);
254
255 system.TelemetrySession().AddField(Common::Telemetry::FieldType::App, "Frontend",
256 "SDLHideTester");
257
258 system.GPU().Start();
259
260 void(system.Run());
261 while (!finished) {
262 std::this_thread::sleep_for(std::chrono::milliseconds(1));
263 }
264 void(system.Pause());
265
266 detached_tasks.WaitForAllTasks();
267 return return_value;
268}