Skip to content

Commit

Permalink
tests: add a Jak2 FormRegressionTest fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
xTVaser committed Aug 4, 2022
1 parent 5148523 commit 8560d9a
Show file tree
Hide file tree
Showing 11 changed files with 532 additions and 517 deletions.
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ add_executable(goalc-test
${CMAKE_CURRENT_LIST_DIR}/decompiler/test_FormExpressionBuildLong.cpp
${CMAKE_CURRENT_LIST_DIR}/decompiler/test_InstructionDecode.cpp
${CMAKE_CURRENT_LIST_DIR}/decompiler/test_InstructionParser.cpp
${CMAKE_CURRENT_LIST_DIR}/decompiler/test_gkernel_decomp.cpp
${CMAKE_CURRENT_LIST_DIR}/decompiler/test_gkernel_jak1_decomp.cpp
${CMAKE_CURRENT_LIST_DIR}/decompiler/test_math_decomp.cpp
${CMAKE_CURRENT_LIST_DIR}/decompiler/test_DataParser.cpp
${CMAKE_CURRENT_LIST_DIR}/decompiler/test_DisasmVifDecompile.cpp
Expand Down
24 changes: 15 additions & 9 deletions test/decompiler/FormRegressionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@

using namespace decompiler;

void FormRegressionTest::SetUpTestCase() {
void FormRegressionTestJak1::SetUpTestCase() {
parser = std::make_unique<InstructionParser>();
dts = std::make_unique<DecompilerTypeSystem>(GameVersion::Jak1);
dts = std::make_unique<DecompilerTypeSystem>(game_version);
dts->parse_type_defs({"decompiler", "config", "all-types.gc"});
}

void FormRegressionTestJak2::SetUpTestCase() {
parser = std::make_unique<InstructionParser>();
dts = std::make_unique<DecompilerTypeSystem>(game_version);
dts->parse_type_defs({"decompiler", "config", "jak2", "all-types.gc"});
}

void FormRegressionTest::TearDownTestCase() {
parser.reset();
dts.reset();
Expand Down Expand Up @@ -280,7 +286,7 @@ void FormRegressionTest::test(const std::string& code,
EXPECT_TRUE(expected_form == actual_form);
}

void FormRegressionTest::test_final_function_jak1(
void FormRegressionTest::test_final_function(
const std::string& code,
const std::string& type,
const std::string& expected,
Expand Down Expand Up @@ -311,12 +317,12 @@ void FormRegressionTest::test_final_function_jak1(
EXPECT_TRUE(expected_form == actual_form);
}

void FormRegressionTest::test_with_stack_structures_jak1(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) {
void FormRegressionTest::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) {
TestSettings settings;
settings.do_expressions = true;
settings.stack_structure_json = stack_map_json;
Expand Down
80 changes: 46 additions & 34 deletions test/decompiler/FormRegressionTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ struct TestSettings {
GameVersion version = GameVersion::Jak1;
};

class FormRegressionTest : public ::testing::Test {
class FormRegressionTest : public ::testing::TestWithParam<GameVersion> {
protected:
static std::unique_ptr<decompiler::InstructionParser> parser;
static std::unique_ptr<decompiler::DecompilerTypeSystem> dts;

static void SetUpTestCase();
static void TearDownTestCase();

struct TestData {
Expand All @@ -47,23 +46,22 @@ class FormRegressionTest : public ::testing::Test {
const std::string& expected,
const TestSettings& settings);

void test_final_function_jak1(
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_jak1(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 = "") {
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;
Expand All @@ -74,14 +72,14 @@ class FormRegressionTest : public ::testing::Test {
test(code, type, expected, settings);
}

void test_with_expr_jak1(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 = "") {
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;
Expand All @@ -92,10 +90,24 @@ class FormRegressionTest : public ::testing::Test {
test(code, type, expected, settings);
}

void test_with_stack_structures_jak1(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 = "");
};
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();
};
30 changes: 15 additions & 15 deletions test/decompiler/test_DisasmVifDecompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

using namespace decompiler;

TEST_F(FormRegressionTest, ExprDisasmVif) {
TEST_F(FormRegressionTestJak1, ExprDisasmVif) {
std::string func =
" sll r0, r0, 0\n"
"L53:\n"
Expand Down Expand Up @@ -681,17 +681,17 @@ TEST_F(FormRegressionTest, ExprDisasmVif) {
" )\n"
" (- gp-0 (* arg1 4))\n"
" )";
test_with_expr_jak1(func, type, expected, false, "",
{{"L139", " #x~X:"},
{"L138", " (~s :irq ~D)~%"},
{"L137", " (~s :irq ~D :~s #x~X)~%"},
{"L136", " (~s :irq ~D :wl ~D :cl ~D)~%"},
{"L135", " (~s :irq ~D :~s "},
{"L134", "#x~X #x~X #x~X #x~X)~%"},
{"L133", " (~s :irq ~D :instructions #x~D :addr #x~X)~%"},
{"L132", " (~s :irq ~D :qwc #x~D)~%"},
{"L145", " #x~X: #x~8x #x~8x #x~8x #x~8x~%"},
{"L131", " (~s :irq ~D :num ~D :addr #x~X "},
{"L130", ":msk ~D :flg ~D :usn ~D [skip ~d])~%"},
{"L129", " (*unknown* vif-tag #x~X)~%"}});
}
test_with_expr(func, type, expected, false, "",
{{"L139", " #x~X:"},
{"L138", " (~s :irq ~D)~%"},
{"L137", " (~s :irq ~D :~s #x~X)~%"},
{"L136", " (~s :irq ~D :wl ~D :cl ~D)~%"},
{"L135", " (~s :irq ~D :~s "},
{"L134", "#x~X #x~X #x~X #x~X)~%"},
{"L133", " (~s :irq ~D :instructions #x~D :addr #x~X)~%"},
{"L132", " (~s :irq ~D :qwc #x~D)~%"},
{"L145", " #x~X: #x~8x #x~8x #x~8x #x~8x~%"},
{"L131", " (~s :irq ~D :num ~D :addr #x~X "},
{"L130", ":msk ~D :flg ~D :usn ~D [skip ~d])~%"},
{"L129", " (*unknown* vif-tag #x~X)~%"}});
}
Loading

0 comments on commit 8560d9a

Please sign in to comment.