mirror of
https://github.com/open-goal/jak-project.git
synced 2024-10-20 21:27:52 -04:00
8651179aa3
* tests: add a Jak2 `FormRegressionTest` fixture * tests/ci: minimize test log output and produce a readable report * improve naming of report due to underlying GitHub issue * hopefully fix windows handling of this argument * test... * final test * test linux coverage
114 lines
4.1 KiB
C++
114 lines
4.1 KiB
C++
#pragma once
|
|
|
|
#include <memory>
|
|
|
|
#include "decompiler/Disasm/InstructionParser.h"
|
|
#include "decompiler/Function/Function.h"
|
|
#include "decompiler/ObjectFile/LinkedObjectFile.h"
|
|
#include "decompiler/util/DecompilerTypeSystem.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
namespace decompiler {
|
|
struct RegisterTypeCast;
|
|
}
|
|
|
|
struct TestSettings {
|
|
bool do_expressions = false;
|
|
bool allow_pairs = false;
|
|
std::string method_name;
|
|
std::vector<std::pair<std::string, std::string>> strings;
|
|
std::string casts_json;
|
|
std::string var_map_json;
|
|
std::string stack_structure_json;
|
|
GameVersion version = GameVersion::Jak1;
|
|
};
|
|
|
|
class FormRegressionTest : public ::testing::TestWithParam<GameVersion> {
|
|
protected:
|
|
static std::unique_ptr<decompiler::InstructionParser> parser;
|
|
static std::unique_ptr<decompiler::DecompilerTypeSystem> dts;
|
|
|
|
static void TearDownTestCase();
|
|
|
|
struct TestData {
|
|
explicit TestData(int instrs, GameVersion version) : func(0, instrs, version) {}
|
|
decompiler::Function func;
|
|
decompiler::LinkedObjectFile file;
|
|
|
|
void add_string_at_label(const std::string& label_name, const std::string& data);
|
|
};
|
|
|
|
std::unique_ptr<TestData> make_function(const std::string& code,
|
|
const TypeSpec& function_type,
|
|
const TestSettings& settings);
|
|
void test(const std::string& code,
|
|
const std::string& type,
|
|
const std::string& expected,
|
|
const TestSettings& settings);
|
|
|
|
void test_final_function(const std::string& code,
|
|
const std::string& type,
|
|
const std::string& expected,
|
|
bool allow_pairs = false,
|
|
const std::vector<std::pair<std::string, std::string>>& strings = {},
|
|
const std::string& cast_json = "",
|
|
const std::string& var_map_json = "");
|
|
|
|
void test_no_expr(const std::string& code,
|
|
const std::string& type,
|
|
const std::string& expected,
|
|
bool allow_pairs = false,
|
|
const std::string& method_name = "",
|
|
const std::vector<std::pair<std::string, std::string>>& strings = {},
|
|
const std::string& cast_json = "",
|
|
const std::string& var_map_json = "") {
|
|
TestSettings settings;
|
|
settings.allow_pairs = allow_pairs;
|
|
settings.method_name = method_name;
|
|
settings.strings = strings;
|
|
settings.casts_json = cast_json;
|
|
settings.var_map_json = var_map_json;
|
|
settings.do_expressions = false;
|
|
test(code, type, expected, settings);
|
|
}
|
|
|
|
void test_with_expr(const std::string& code,
|
|
const std::string& type,
|
|
const std::string& expected,
|
|
bool allow_pairs = false,
|
|
const std::string& method_name = "",
|
|
const std::vector<std::pair<std::string, std::string>>& strings = {},
|
|
const std::string& cast_json = "",
|
|
const std::string& var_map_json = "") {
|
|
TestSettings settings;
|
|
settings.allow_pairs = allow_pairs;
|
|
settings.method_name = method_name;
|
|
settings.strings = strings;
|
|
settings.casts_json = cast_json;
|
|
settings.var_map_json = var_map_json;
|
|
settings.do_expressions = true;
|
|
test(code, type, expected, settings);
|
|
}
|
|
|
|
void test_with_stack_structures(const std::string& code,
|
|
const std::string& type,
|
|
const std::string& expected,
|
|
const std::string& stack_map_json,
|
|
const std::string& cast_json = "",
|
|
const std::string& var_map_json = "");
|
|
};
|
|
|
|
class FormRegressionTestJak1 : public FormRegressionTest {
|
|
protected:
|
|
static const GameVersion game_version = GameVersion::Jak1;
|
|
|
|
static void SetUpTestCase();
|
|
};
|
|
|
|
class FormRegressionTestJak2 : public FormRegressionTest {
|
|
protected:
|
|
static const GameVersion game_version = GameVersion::Jak2;
|
|
|
|
static void SetUpTestCase();
|
|
};
|