2019-03-26 00:31:16 +00:00
|
|
|
// Copyright 2019 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#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 {
|
|
|
|
|
2019-04-04 22:05:57 +00:00
|
|
|
constexpr u64 SERVICE_VERSION = 0x00000002;
|
2019-03-26 00:31:16 +00:00
|
|
|
|
|
|
|
class YuzuTest final : public ServiceFramework<YuzuTest> {
|
|
|
|
public:
|
2019-04-04 22:05:57 +00:00
|
|
|
explicit YuzuTest(std::string data,
|
|
|
|
std::function<void(std::vector<TestResult>)> finish_callback)
|
2019-03-26 00:31:16 +00:00
|
|
|
: 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"},
|
2019-04-04 22:05:57 +00:00
|
|
|
{10, &YuzuTest::StartIndividual, "StartIndividual"},
|
|
|
|
{20, &YuzuTest::FinishIndividual, "FinishIndividual"},
|
|
|
|
{100, &YuzuTest::ExitProgram, "ExitProgram"},
|
2019-03-26 00:31:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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<u32>(write_size);
|
|
|
|
}
|
|
|
|
|
2019-04-04 22:05:57 +00:00
|
|
|
void StartIndividual(Kernel::HLERequestContext& ctx) {
|
2019-05-26 17:59:48 +00:00
|
|
|
const auto name_raw = ctx.ReadBuffer();
|
|
|
|
|
|
|
|
const auto name = Common::StringFromFixedZeroTerminatedBuffer(
|
|
|
|
reinterpret_cast<const char*>(name_raw.data()), name_raw.size());
|
|
|
|
|
|
|
|
LOG_DEBUG(Frontend, "called, name={}", name);
|
2019-03-26 00:31:16 +00:00
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2019-04-04 22:05:57 +00:00
|
|
|
void FinishIndividual(Kernel::HLERequestContext& ctx) {
|
2019-03-26 00:31:16 +00:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
2019-04-04 22:05:57 +00:00
|
|
|
const auto code = rp.PopRaw<u32>();
|
|
|
|
|
|
|
|
const auto result_data_raw = ctx.ReadBuffer();
|
|
|
|
const auto test_name_raw = ctx.ReadBuffer(1);
|
|
|
|
|
|
|
|
const auto data = Common::StringFromFixedZeroTerminatedBuffer(
|
|
|
|
reinterpret_cast<const char*>(result_data_raw.data()), result_data_raw.size());
|
|
|
|
const auto test_name = Common::StringFromFixedZeroTerminatedBuffer(
|
|
|
|
reinterpret_cast<const char*>(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});
|
2019-03-26 00:31:16 +00:00
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2019-04-04 22:05:57 +00:00
|
|
|
void ExitProgram(Kernel::HLERequestContext& ctx) {
|
2019-03-26 00:31:16 +00:00
|
|
|
LOG_DEBUG(Frontend, "called");
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
|
2019-06-10 04:31:49 +00:00
|
|
|
finish_callback(std::move(results));
|
2019-03-26 00:31:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string data;
|
|
|
|
|
2019-04-04 22:05:57 +00:00
|
|
|
std::vector<TestResult> results;
|
|
|
|
std::function<void(std::vector<TestResult>)> finish_callback;
|
2019-03-26 00:31:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void InstallInterfaces(SM::ServiceManager& sm, std::string data,
|
2019-04-04 22:05:57 +00:00
|
|
|
std::function<void(std::vector<TestResult>)> finish_callback) {
|
2019-03-26 00:31:16 +00:00
|
|
|
std::make_shared<YuzuTest>(data, finish_callback)->InstallAsService(sm);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Service::Yuzu
|