diff options
| author | 2019-03-25 20:30:36 -0400 | |
|---|---|---|
| committer | 2019-06-10 00:03:11 -0400 | |
| commit | 819006d0d3232d66d303daabe701ca031e4caeae (patch) | |
| tree | 536d1a37cc7bd0f578bfdf5f8d32d81e9d6625c4 /src/yuzu_tester/yuzu.cpp | |
| parent | yuzu_tester: Add project subdirectory (diff) | |
| download | yuzu-819006d0d3232d66d303daabe701ca031e4caeae.tar.gz yuzu-819006d0d3232d66d303daabe701ca031e4caeae.tar.xz yuzu-819006d0d3232d66d303daabe701ca031e4caeae.zip | |
yuzu_tester: Use config, icon, and main from yuzu-cmd
Diffstat (limited to 'src/yuzu_tester/yuzu.cpp')
| -rw-r--r-- | src/yuzu_tester/yuzu.cpp | 232 |
1 files changed, 232 insertions, 0 deletions
diff --git a/src/yuzu_tester/yuzu.cpp b/src/yuzu_tester/yuzu.cpp new file mode 100644 index 000000000..84d277fcf --- /dev/null +++ b/src/yuzu_tester/yuzu.cpp | |||
| @@ -0,0 +1,232 @@ | |||
| 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 <iostream> | ||
| 6 | #include <memory> | ||
| 7 | #include <string> | ||
| 8 | #include <thread> | ||
| 9 | |||
| 10 | #include <fmt/ostream.h> | ||
| 11 | |||
| 12 | #include "common/common_paths.h" | ||
| 13 | #include "common/detached_tasks.h" | ||
| 14 | #include "common/file_util.h" | ||
| 15 | #include "common/logging/backend.h" | ||
| 16 | #include "common/logging/filter.h" | ||
| 17 | #include "common/logging/log.h" | ||
| 18 | #include "common/microprofile.h" | ||
| 19 | #include "common/scm_rev.h" | ||
| 20 | #include "common/scope_exit.h" | ||
| 21 | #include "common/string_util.h" | ||
| 22 | #include "common/telemetry.h" | ||
| 23 | #include "core/core.h" | ||
| 24 | #include "core/crypto/key_manager.h" | ||
| 25 | #include "core/file_sys/vfs_real.h" | ||
| 26 | #include "core/hle/service/filesystem/filesystem.h" | ||
| 27 | #include "core/loader/loader.h" | ||
| 28 | #include "core/settings.h" | ||
| 29 | #include "core/telemetry_session.h" | ||
| 30 | #include "video_core/renderer_base.h" | ||
| 31 | #include "yuzu_tester/config.h" | ||
| 32 | #include "yuzu_tester/emu_window/emu_window_sdl2_hide.h" | ||
| 33 | #include "yuzu_tester/service/yuzutest.h" | ||
| 34 | |||
| 35 | #include <getopt.h> | ||
| 36 | #ifndef _MSC_VER | ||
| 37 | #include <unistd.h> | ||
| 38 | #endif | ||
| 39 | |||
| 40 | #ifdef _WIN32 | ||
| 41 | // windows.h needs to be included before shellapi.h | ||
| 42 | #include <windows.h> | ||
| 43 | |||
| 44 | #include <shellapi.h> | ||
| 45 | #endif | ||
| 46 | |||
| 47 | #ifdef _WIN32 | ||
| 48 | extern "C" { | ||
| 49 | // tells Nvidia and AMD drivers to use the dedicated GPU by default on laptops with switchable | ||
| 50 | // graphics | ||
| 51 | __declspec(dllexport) unsigned long NvOptimusEnablement = 0x00000001; | ||
| 52 | __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; | ||
| 53 | } | ||
| 54 | #endif | ||
| 55 | |||
| 56 | static void PrintHelp(const char* argv0) { | ||
| 57 | std::cout << "Usage: " << argv0 | ||
| 58 | << " [options] <filename>\n" | ||
| 59 | "-h, --help Display this help and exit\n" | ||
| 60 | "-v, --version Output version information and exit\n" | ||
| 61 | "-d, --datastring Pass following string as data to test service command #2\n" | ||
| 62 | "-l, --log Log to console in addition to file (will log to file only " | ||
| 63 | "by default)\n"; | ||
| 64 | } | ||
| 65 | |||
| 66 | static void PrintVersion() { | ||
| 67 | std::cout << "yuzu [Test Utility] " << Common::g_scm_branch << " " << Common::g_scm_desc | ||
| 68 | << std::endl; | ||
| 69 | } | ||
| 70 | |||
| 71 | static void InitializeLogging(bool console) { | ||
| 72 | Log::Filter log_filter(Log::Level::Debug); | ||
| 73 | log_filter.ParseFilterString(Settings::values.log_filter); | ||
| 74 | Log::SetGlobalFilter(log_filter); | ||
| 75 | |||
| 76 | if (console) | ||
| 77 | Log::AddBackend(std::make_unique<Log::ColorConsoleBackend>()); | ||
| 78 | |||
| 79 | const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir); | ||
| 80 | FileUtil::CreateFullPath(log_dir); | ||
| 81 | Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE)); | ||
| 82 | #ifdef _WIN32 | ||
| 83 | Log::AddBackend(std::make_unique<Log::DebuggerBackend>()); | ||
| 84 | #endif | ||
| 85 | } | ||
| 86 | |||
| 87 | /// Application entry point | ||
| 88 | int main(int argc, char** argv) { | ||
| 89 | Common::DetachedTasks detached_tasks; | ||
| 90 | Config config; | ||
| 91 | |||
| 92 | int option_index = 0; | ||
| 93 | |||
| 94 | char* endarg; | ||
| 95 | #ifdef _WIN32 | ||
| 96 | int argc_w; | ||
| 97 | auto argv_w = CommandLineToArgvW(GetCommandLineW(), &argc_w); | ||
| 98 | |||
| 99 | if (argv_w == nullptr) { | ||
| 100 | std::cout << "Failed to get command line arguments" << std::endl; | ||
| 101 | return -1; | ||
| 102 | } | ||
| 103 | #endif | ||
| 104 | std::string filepath; | ||
| 105 | |||
| 106 | static struct option long_options[] = { | ||
| 107 | {"help", no_argument, 0, 'h'}, | ||
| 108 | {"version", no_argument, 0, 'v'}, | ||
| 109 | {"datastring", optional_argument, 0, 'd'}, | ||
| 110 | {"log", no_argument, 0, 'l'}, | ||
| 111 | {0, 0, 0, 0}, | ||
| 112 | }; | ||
| 113 | |||
| 114 | bool console_log = false; | ||
| 115 | std::string datastring; | ||
| 116 | |||
| 117 | while (optind < argc) { | ||
| 118 | int arg = getopt_long(argc, argv, "hvdl::", long_options, &option_index); | ||
| 119 | if (arg != -1) { | ||
| 120 | switch (static_cast<char>(arg)) { | ||
| 121 | case 'h': | ||
| 122 | PrintHelp(argv[0]); | ||
| 123 | return 0; | ||
| 124 | case 'v': | ||
| 125 | PrintVersion(); | ||
| 126 | return 0; | ||
| 127 | case 'd': | ||
| 128 | datastring = argv[optind]; | ||
| 129 | ++optind; | ||
| 130 | break; | ||
| 131 | case 'l': | ||
| 132 | console_log = true; | ||
| 133 | break; | ||
| 134 | } | ||
| 135 | } else { | ||
| 136 | #ifdef _WIN32 | ||
| 137 | filepath = Common::UTF16ToUTF8(argv_w[optind]); | ||
| 138 | #else | ||
| 139 | filepath = argv[optind]; | ||
| 140 | #endif | ||
| 141 | optind++; | ||
| 142 | } | ||
| 143 | } | ||
| 144 | |||
| 145 | InitializeLogging(console_log); | ||
| 146 | |||
| 147 | #ifdef _WIN32 | ||
| 148 | LocalFree(argv_w); | ||
| 149 | #endif | ||
| 150 | |||
| 151 | MicroProfileOnThreadCreate("EmuThread"); | ||
| 152 | SCOPE_EXIT({ MicroProfileShutdown(); }); | ||
| 153 | |||
| 154 | if (filepath.empty()) { | ||
| 155 | LOG_CRITICAL(Frontend, "Failed to load application: No application specified"); | ||
| 156 | std::cout << "Failed to load application: No application specified" << std::endl; | ||
| 157 | PrintHelp(argv[0]); | ||
| 158 | return -1; | ||
| 159 | } | ||
| 160 | |||
| 161 | Settings::values.use_gdbstub = false; | ||
| 162 | Settings::Apply(); | ||
| 163 | |||
| 164 | std::unique_ptr<EmuWindow_SDL2_Hide> emu_window{std::make_unique<EmuWindow_SDL2_Hide>()}; | ||
| 165 | |||
| 166 | if (!Settings::values.use_multi_core) { | ||
| 167 | // Single core mode must acquire OpenGL context for entire emulation session | ||
| 168 | emu_window->MakeCurrent(); | ||
| 169 | } | ||
| 170 | |||
| 171 | bool finished = false; | ||
| 172 | int return_value = 0; | ||
| 173 | const auto callback = [&finished, &return_value](u32 code, std::string string) { | ||
| 174 | finished = true; | ||
| 175 | return_value = code & 0xFF; | ||
| 176 | const auto text = fmt::format("Test Finished [Result Code: {:08X}]\n{}", code, string); | ||
| 177 | LOG_INFO(Frontend, text.c_str()); | ||
| 178 | std::cout << text << std::endl; | ||
| 179 | }; | ||
| 180 | |||
| 181 | Core::System& system{Core::System::GetInstance()}; | ||
| 182 | system.SetFilesystem(std::make_shared<FileSys::RealVfsFilesystem>()); | ||
| 183 | Service::FileSystem::CreateFactories(*system.GetFilesystem()); | ||
| 184 | |||
| 185 | SCOPE_EXIT({ system.Shutdown(); }); | ||
| 186 | |||
| 187 | const Core::System::ResultStatus load_result{system.Load(*emu_window, filepath)}; | ||
| 188 | |||
| 189 | switch (load_result) { | ||
| 190 | case Core::System::ResultStatus::ErrorGetLoader: | ||
| 191 | LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", filepath.c_str()); | ||
| 192 | return -1; | ||
| 193 | case Core::System::ResultStatus::ErrorLoader: | ||
| 194 | LOG_CRITICAL(Frontend, "Failed to load ROM!"); | ||
| 195 | return -1; | ||
| 196 | case Core::System::ResultStatus::ErrorNotInitialized: | ||
| 197 | LOG_CRITICAL(Frontend, "CPUCore not initialized"); | ||
| 198 | return -1; | ||
| 199 | case Core::System::ResultStatus::ErrorSystemMode: | ||
| 200 | LOG_CRITICAL(Frontend, "Failed to determine system mode!"); | ||
| 201 | return -1; | ||
| 202 | case Core::System::ResultStatus::ErrorVideoCore: | ||
| 203 | LOG_CRITICAL(Frontend, "Failed to initialize VideoCore!"); | ||
| 204 | return -1; | ||
| 205 | case Core::System::ResultStatus::Success: | ||
| 206 | break; // Expected case | ||
| 207 | default: | ||
| 208 | if (static_cast<u32>(load_result) > | ||
| 209 | static_cast<u32>(Core::System::ResultStatus::ErrorLoader)) { | ||
| 210 | const u16 loader_id = static_cast<u16>(Core::System::ResultStatus::ErrorLoader); | ||
| 211 | const u16 error_id = static_cast<u16>(load_result) - loader_id; | ||
| 212 | LOG_CRITICAL(Frontend, | ||
| 213 | "While attempting to load the ROM requested, an error occured. Please " | ||
| 214 | "refer to the yuzu wiki for more information or the yuzu discord for " | ||
| 215 | "additional help.\n\nError Code: {:04X}-{:04X}\nError Description: {}", | ||
| 216 | loader_id, error_id, static_cast<Loader::ResultStatus>(error_id)); | ||
| 217 | } | ||
| 218 | } | ||
| 219 | |||
| 220 | Service::Yuzu::InstallInterfaces(system.ServiceManager(), datastring, callback); | ||
| 221 | |||
| 222 | system.TelemetrySession().AddField(Telemetry::FieldType::App, "Frontend", "SDLHideTester"); | ||
| 223 | |||
| 224 | system.Renderer().Rasterizer().LoadDiskResources(); | ||
| 225 | |||
| 226 | while (!finished) { | ||
| 227 | system.RunLoop(); | ||
| 228 | } | ||
| 229 | |||
| 230 | detached_tasks.WaitForAllTasks(); | ||
| 231 | return return_value; | ||
| 232 | } | ||