From 5ddc9cede5bc286f4be54c4510ed36f88e0d2756 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Mon, 25 Mar 2019 20:31:16 -0400 Subject: yuzu_tester: Add 'yuzutest' service --- src/yuzu_tester/service/yuzutest.cpp | 104 +++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/yuzu_tester/service/yuzutest.cpp (limited to 'src/yuzu_tester/service/yuzutest.cpp') diff --git a/src/yuzu_tester/service/yuzutest.cpp b/src/yuzu_tester/service/yuzutest.cpp new file mode 100644 index 000000000..026582027 --- /dev/null +++ b/src/yuzu_tester/service/yuzutest.cpp @@ -0,0 +1,104 @@ +// Copyright 2019 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include "common/string_util.h" +#include "core/hle/ipc_helpers.h" +#include "core/hle/service/service.h" +#include "core/hle/service/sm/sm.h" +#include "yuzu_tester/service/yuzutest.h" + +namespace Service::Yuzu { + +constexpr u64 SERVICE_VERSION = 1; + +class YuzuTest final : public ServiceFramework { +public: + explicit YuzuTest(std::string data, std::function finish_callback) + : ServiceFramework{"yuzutest"}, data(std::move(data)), + finish_callback(std::move(finish_callback)) { + static const FunctionInfo functions[] = { + {0, &YuzuTest::Initialize, "Initialize"}, + {1, &YuzuTest::GetServiceVersion, "GetServiceVersion"}, + {2, &YuzuTest::GetData, "GetData"}, + {3, &YuzuTest::SetResultCode, "SetResultCode"}, + {4, &YuzuTest::SetResultData, "SetResultData"}, + {5, &YuzuTest::Finish, "Finish"}, + }; + + RegisterHandlers(functions); + } + +private: + void Initialize(Kernel::HLERequestContext& ctx) { + LOG_DEBUG(Frontend, "called"); + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(RESULT_SUCCESS); + } + + void GetServiceVersion(Kernel::HLERequestContext& ctx) { + LOG_DEBUG(Frontend, "called"); + IPC::ResponseBuilder rb{ctx, 4}; + rb.Push(RESULT_SUCCESS); + rb.Push(SERVICE_VERSION); + } + + void GetData(Kernel::HLERequestContext& ctx) { + LOG_DEBUG(Frontend, "called"); + const auto size = ctx.GetWriteBufferSize(); + const auto write_size = std::min(size, data.size()); + ctx.WriteBuffer(data.data(), write_size); + + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(RESULT_SUCCESS); + rb.Push(write_size); + } + + void SetResultCode(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + const auto code = rp.PopRaw(); + + LOG_INFO(Frontend, "called with result_code={:08X}", code); + result_code = code; + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(RESULT_SUCCESS); + } + + void SetResultData(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + const auto buffer = ctx.ReadBuffer(); + std::string data = Common::StringFromFixedZeroTerminatedBuffer( + reinterpret_cast(buffer.data()), buffer.size()); + + LOG_INFO(Frontend, "called with string={}", data); + result_string = data; + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(RESULT_SUCCESS); + } + + void Finish(Kernel::HLERequestContext& ctx) { + LOG_DEBUG(Frontend, "called"); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(RESULT_SUCCESS); + + finish_callback(result_code, result_string); + } + + std::string data; + + u32 result_code = 0; + std::string result_string; + + std::function finish_callback; +}; + +void InstallInterfaces(SM::ServiceManager& sm, std::string data, + std::function finish_callback) { + std::make_shared(data, finish_callback)->InstallAsService(sm); +} + +} // namespace Service::Yuzu -- cgit v1.2.3 From f279e792b7c23a9fabce7c56c53c01fcf4e87547 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Thu, 4 Apr 2019 18:05:57 -0400 Subject: yuzutest: Support multiple tests per executable --- .../emu_window/emu_window_sdl2_hide.cpp | 13 +++--- src/yuzu_tester/service/yuzutest.cpp | 51 ++++++++++++---------- src/yuzu_tester/service/yuzutest.h | 8 +++- src/yuzu_tester/yuzu.cpp | 2 +- 4 files changed, 41 insertions(+), 33 deletions(-) (limited to 'src/yuzu_tester/service/yuzutest.cpp') diff --git a/src/yuzu_tester/emu_window/emu_window_sdl2_hide.cpp b/src/yuzu_tester/emu_window/emu_window_sdl2_hide.cpp index 3775a51e0..e7fe8decf 100644 --- a/src/yuzu_tester/emu_window/emu_window_sdl2_hide.cpp +++ b/src/yuzu_tester/emu_window/emu_window_sdl2_hide.cpp @@ -63,13 +63,12 @@ EmuWindow_SDL2_Hide::EmuWindow_SDL2_Hide() { std::string window_title = fmt::format("yuzu-tester {} | {}-{}", Common::g_build_fullname, Common::g_scm_branch, Common::g_scm_desc); - render_window = - SDL_CreateWindow(window_title.c_str(), - SDL_WINDOWPOS_UNDEFINED, // x position - SDL_WINDOWPOS_UNDEFINED, // y position - Layout::ScreenUndocked::Width, Layout::ScreenUndocked::Height, - SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); - SDL_HideWindow(render_window); + render_window = SDL_CreateWindow(window_title.c_str(), + SDL_WINDOWPOS_UNDEFINED, // x position + SDL_WINDOWPOS_UNDEFINED, // y position + Layout::ScreenUndocked::Width, Layout::ScreenUndocked::Height, + SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | + SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_HIDDEN); if (render_window == nullptr) { LOG_CRITICAL(Frontend, "Failed to create SDL2 window! {}", SDL_GetError()); diff --git a/src/yuzu_tester/service/yuzutest.cpp b/src/yuzu_tester/service/yuzutest.cpp index 026582027..c25ab4aba 100644 --- a/src/yuzu_tester/service/yuzutest.cpp +++ b/src/yuzu_tester/service/yuzutest.cpp @@ -11,20 +11,21 @@ namespace Service::Yuzu { -constexpr u64 SERVICE_VERSION = 1; +constexpr u64 SERVICE_VERSION = 0x00000002; class YuzuTest final : public ServiceFramework { public: - explicit YuzuTest(std::string data, std::function finish_callback) + explicit YuzuTest(std::string data, + std::function)> finish_callback) : ServiceFramework{"yuzutest"}, data(std::move(data)), finish_callback(std::move(finish_callback)) { static const FunctionInfo functions[] = { {0, &YuzuTest::Initialize, "Initialize"}, {1, &YuzuTest::GetServiceVersion, "GetServiceVersion"}, {2, &YuzuTest::GetData, "GetData"}, - {3, &YuzuTest::SetResultCode, "SetResultCode"}, - {4, &YuzuTest::SetResultData, "SetResultData"}, - {5, &YuzuTest::Finish, "Finish"}, + {10, &YuzuTest::StartIndividual, "StartIndividual"}, + {20, &YuzuTest::FinishIndividual, "FinishIndividual"}, + {100, &YuzuTest::ExitProgram, "ExitProgram"}, }; RegisterHandlers(functions); @@ -55,49 +56,51 @@ private: rb.Push(write_size); } - void SetResultCode(Kernel::HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto code = rp.PopRaw(); - - LOG_INFO(Frontend, "called with result_code={:08X}", code); - result_code = code; + void StartIndividual(Kernel::HLERequestContext& ctx) { + LOG_DEBUG(Frontend, "called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); } - void SetResultData(Kernel::HLERequestContext& ctx) { + void FinishIndividual(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto buffer = ctx.ReadBuffer(); - std::string data = Common::StringFromFixedZeroTerminatedBuffer( - reinterpret_cast(buffer.data()), buffer.size()); - LOG_INFO(Frontend, "called with string={}", data); - result_string = data; + const auto code = rp.PopRaw(); + + const auto result_data_raw = ctx.ReadBuffer(); + const auto test_name_raw = ctx.ReadBuffer(1); + + const auto data = Common::StringFromFixedZeroTerminatedBuffer( + reinterpret_cast(result_data_raw.data()), result_data_raw.size()); + const auto test_name = Common::StringFromFixedZeroTerminatedBuffer( + reinterpret_cast(test_name_raw.data()), test_name_raw.size()); + + LOG_INFO(Frontend, "called, result_code={:08X}, data={}, name={}", code, data, test_name); + + results.push_back({code, data, test_name}); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); } - void Finish(Kernel::HLERequestContext& ctx) { + void ExitProgram(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Frontend, "called"); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); - finish_callback(result_code, result_string); + finish_callback(results); } std::string data; - u32 result_code = 0; - std::string result_string; - - std::function finish_callback; + std::vector results; + std::function)> finish_callback; }; void InstallInterfaces(SM::ServiceManager& sm, std::string data, - std::function finish_callback) { + std::function)> finish_callback) { std::make_shared(data, finish_callback)->InstallAsService(sm); } diff --git a/src/yuzu_tester/service/yuzutest.h b/src/yuzu_tester/service/yuzutest.h index e68a24544..eca129c8c 100644 --- a/src/yuzu_tester/service/yuzutest.h +++ b/src/yuzu_tester/service/yuzutest.h @@ -13,7 +13,13 @@ class ServiceManager; namespace Service::Yuzu { +struct TestResult { + u32 code; + std::string data; + std::string name; +}; + void InstallInterfaces(SM::ServiceManager& sm, std::string data, - std::function finish_callback); + std::function)> finish_callback); } // namespace Service::Yuzu diff --git a/src/yuzu_tester/yuzu.cpp b/src/yuzu_tester/yuzu.cpp index 84d277fcf..0f7067541 100644 --- a/src/yuzu_tester/yuzu.cpp +++ b/src/yuzu_tester/yuzu.cpp @@ -170,7 +170,7 @@ int main(int argc, char** argv) { bool finished = false; int return_value = 0; - const auto callback = [&finished, &return_value](u32 code, std::string string) { + const auto callback = [&finished, &return_value](std::vector) { finished = true; return_value = code & 0xFF; const auto text = fmt::format("Test Finished [Result Code: {:08X}]\n{}", code, string); -- cgit v1.2.3 From 511bf3435d698662f4f95fbd4722c9a6052680f8 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Sun, 26 May 2019 13:59:48 -0400 Subject: yuzu_tester: Display results in table format --- src/yuzu_tester/config.cpp | 1 - src/yuzu_tester/service/yuzutest.cpp | 7 ++++- src/yuzu_tester/yuzu.cpp | 54 +++++++++++++++++++++++++++++------- 3 files changed, 50 insertions(+), 12 deletions(-) (limited to 'src/yuzu_tester/service/yuzutest.cpp') diff --git a/src/yuzu_tester/config.cpp b/src/yuzu_tester/config.cpp index 62407efac..d7e0d408d 100644 --- a/src/yuzu_tester/config.cpp +++ b/src/yuzu_tester/config.cpp @@ -93,7 +93,6 @@ void Config::ReadValues() { // System Settings::values.use_docked_mode = sdl2_config->GetBoolean("System", "use_docked_mode", false); - Settings::values.enable_nfc = sdl2_config->GetBoolean("System", "enable_nfc", true); const auto size = sdl2_config->GetInteger("System", "users_size", 0); Settings::values.current_user = std::clamp( diff --git a/src/yuzu_tester/service/yuzutest.cpp b/src/yuzu_tester/service/yuzutest.cpp index c25ab4aba..a5e5bddb2 100644 --- a/src/yuzu_tester/service/yuzutest.cpp +++ b/src/yuzu_tester/service/yuzutest.cpp @@ -57,7 +57,12 @@ private: } void StartIndividual(Kernel::HLERequestContext& ctx) { - LOG_DEBUG(Frontend, "called"); + const auto name_raw = ctx.ReadBuffer(); + + const auto name = Common::StringFromFixedZeroTerminatedBuffer( + reinterpret_cast(name_raw.data()), name_raw.size()); + + LOG_DEBUG(Frontend, "called, name={}", name); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); diff --git a/src/yuzu_tester/yuzu.cpp b/src/yuzu_tester/yuzu.cpp index 0f7067541..4b4e3d4fc 100644 --- a/src/yuzu_tester/yuzu.cpp +++ b/src/yuzu_tester/yuzu.cpp @@ -32,11 +32,6 @@ #include "yuzu_tester/emu_window/emu_window_sdl2_hide.h" #include "yuzu_tester/service/yuzutest.h" -#include -#ifndef _MSC_VER -#include -#endif - #ifdef _WIN32 // windows.h needs to be included before shellapi.h #include @@ -44,6 +39,12 @@ #include #endif +#undef _UNICODE +#include +#ifndef _MSC_VER +#include +#endif + #ifdef _WIN32 extern "C" { // tells Nvidia and AMD drivers to use the dedicated GPU by default on laptops with switchable @@ -170,12 +171,45 @@ int main(int argc, char** argv) { bool finished = false; int return_value = 0; - const auto callback = [&finished, &return_value](std::vector) { + const auto callback = [&finished, + &return_value](std::vector results) { finished = true; - return_value = code & 0xFF; - const auto text = fmt::format("Test Finished [Result Code: {:08X}]\n{}", code, string); - LOG_INFO(Frontend, text.c_str()); - std::cout << text << std::endl; + return_value = 0; + + const auto len = + std::max(std::max_element(results.begin(), results.end(), + [](const auto& lhs, const auto& rhs) { + return lhs.name.size() < rhs.name.size(); + }) + ->name.size(), + 9ull); + + std::size_t passed = 0; + std::size_t failed = 0; + + std::cout << fmt::format("Result [Res Code] | {:<{}} | Extra Data", "Test Name", len) + << std::endl; + + for (const auto& res : results) { + const auto main_res = res.code == 0 ? "PASSED" : "FAILED"; + if (res.code == 0) + ++passed; + else + ++failed; + std::cout << fmt::format("{} [{:08X}] | {:<{}} | {}", main_res, res.code, res.name, len, + res.data) + << std::endl; + } + + std::cout << std::endl + << fmt::format("{:4d} Passed | {:4d} Failed | {:4d} Total | {:2.2f} Passed Ratio", + passed, failed, passed + failed, + static_cast(passed) / (passed + failed)) + << std::endl + << (failed == 0 ? "PASSED" : "FAILED") << std::endl; + + if (failed > 0) + return_value = -1; }; Core::System& system{Core::System::GetInstance()}; -- cgit v1.2.3 From 3a26b49c2cfb50f312bca63b897480c10bc6329c Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Mon, 10 Jun 2019 00:31:49 -0400 Subject: yuzutest: Add minor comments --- src/yuzu_tester/service/yuzutest.cpp | 2 +- src/yuzu_tester/yuzu.cpp | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src/yuzu_tester/service/yuzutest.cpp') diff --git a/src/yuzu_tester/service/yuzutest.cpp b/src/yuzu_tester/service/yuzutest.cpp index a5e5bddb2..85d3f436b 100644 --- a/src/yuzu_tester/service/yuzutest.cpp +++ b/src/yuzu_tester/service/yuzutest.cpp @@ -95,7 +95,7 @@ private: IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); - finish_callback(results); + finish_callback(std::move(results)); } std::string data; diff --git a/src/yuzu_tester/yuzu.cpp b/src/yuzu_tester/yuzu.cpp index 4b4e3d4fc..b589c3de3 100644 --- a/src/yuzu_tester/yuzu.cpp +++ b/src/yuzu_tester/yuzu.cpp @@ -176,7 +176,10 @@ int main(int argc, char** argv) { finished = true; return_value = 0; - const auto len = + // Find the minimum length needed to fully enclose all test names (and the header field) in + // the fmt::format column by first finding the maximum size of any test name and comparing + // that to 9, the string length of 'Test Name' + const auto needed_length_name = std::max(std::max_element(results.begin(), results.end(), [](const auto& lhs, const auto& rhs) { return lhs.name.size() < rhs.name.size(); @@ -187,7 +190,8 @@ int main(int argc, char** argv) { std::size_t passed = 0; std::size_t failed = 0; - std::cout << fmt::format("Result [Res Code] | {:<{}} | Extra Data", "Test Name", len) + std::cout << fmt::format("Result [Res Code] | {:<{}} | Extra Data", "Test Name", + needed_length_name) << std::endl; for (const auto& res : results) { @@ -196,8 +200,8 @@ int main(int argc, char** argv) { ++passed; else ++failed; - std::cout << fmt::format("{} [{:08X}] | {:<{}} | {}", main_res, res.code, res.name, len, - res.data) + std::cout << fmt::format("{} [{:08X}] | {:<{}} | {}", main_res, res.code, res.name, + needed_length_name, res.data) << std::endl; } @@ -230,9 +234,6 @@ int main(int argc, char** argv) { case Core::System::ResultStatus::ErrorNotInitialized: LOG_CRITICAL(Frontend, "CPUCore not initialized"); return -1; - case Core::System::ResultStatus::ErrorSystemMode: - LOG_CRITICAL(Frontend, "Failed to determine system mode!"); - return -1; case Core::System::ResultStatus::ErrorVideoCore: LOG_CRITICAL(Frontend, "Failed to initialize VideoCore!"); return -1; -- cgit v1.2.3