From 1beadbf871244917a4b875bc3c91b4a22c78d6e0 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 17 Jan 2022 09:57:54 +0900 Subject: [PATCH] [gamecode] Add tests for the branch instructions --- libs/gamecode/test/Makemodule.am | 6 + libs/gamecode/test/test-branch.c | 193 +++++++++++++++++++++++++++++++ 2 files changed, 199 insertions(+) create mode 100644 libs/gamecode/test/test-branch.c diff --git a/libs/gamecode/test/Makemodule.am b/libs/gamecode/test/Makemodule.am index 9a5b9bf04..b70014d48 100644 --- a/libs/gamecode/test/Makemodule.am +++ b/libs/gamecode/test/Makemodule.am @@ -1,4 +1,5 @@ libs_gamecode_tests = \ + libs/gamecode/test/test-branch \ libs/gamecode/test/test-bitops \ libs/gamecode/test/test-conv0 \ libs/gamecode/test/test-conv1 \ @@ -37,6 +38,11 @@ test_gamecode_libs= \ libs/gamecode/libQFgamecode.la \ libs/util/libQFutil.la +libs_gamecode_test_test_branch_SOURCES= \ + libs/gamecode/test/test-branch.c +libs_gamecode_test_test_branch_LDADD= $(test_gamecode_libs) +libs_gamecode_test_test_branch_DEPENDENCIES=$(test_gamecode_libs) + libs_gamecode_test_test_bitops_SOURCES= \ libs/gamecode/test/test-bitops.c libs_gamecode_test_test_bitops_LDADD= $(test_gamecode_libs) diff --git a/libs/gamecode/test/test-branch.c b/libs/gamecode/test/test-branch.c new file mode 100644 index 000000000..e02f229ba --- /dev/null +++ b/libs/gamecode/test/test-branch.c @@ -0,0 +1,193 @@ +#include "head.c" + +#define DB 0xdeadbeef + +static pr_int_t test_globals_init[] = { + -1, 1, 0, DB, DB, +}; + +static pr_int_t test_globals_expect[] = { + -1, 1, 0, DB, 1, +}; + +static dstatement_t ifz_taken_statements[] = { + { OP_IFZ, 4, 0, 2 }, + { OP_LEA_A, 1, 0, 3 }, + { OP_LEA_A, 1, 0, 4 }, + { OP_BREAK }, + { OP_IFZ, -2, 0, 2 }, +}; + +static dstatement_t ifb_taken_statements[] = { + { OP_IFB, 4, 0, 0 }, + { OP_LEA_A, 1, 0, 3 }, + { OP_LEA_A, 1, 0, 4 }, + { OP_BREAK }, + { OP_IFB, -2, 0, 0 }, +}; + +static dstatement_t ifa_taken_statements[] = { + { OP_IFA, 4, 0, 1 }, + { OP_LEA_A, 1, 0, 3 }, + { OP_LEA_A, 1, 0, 4 }, + { OP_BREAK }, + { OP_IFA, -2, 0, 1 }, +}; + +static dstatement_t ifnz_taken_statements[] = { + { OP_IFNZ, 4, 0, 0 }, + { OP_LEA_A, 1, 0, 3 }, + { OP_LEA_A, 1, 0, 4 }, + { OP_BREAK }, + { OP_IFNZ, -2, 0, 1 }, +}; + +static dstatement_t ifae_taken_statements[] = { + { OP_IFAE, 4, 0, 1 }, + { OP_LEA_A, 1, 0, 3 }, + { OP_LEA_A, 1, 0, 4 }, + { OP_BREAK }, + { OP_IFAE, -2, 0, 2 }, +}; + +static dstatement_t ifbe_taken_statements[] = { + { OP_IFBE, 4, 0, 0 }, + { OP_LEA_A, 1, 0, 3 }, + { OP_LEA_A, 1, 0, 4 }, + { OP_BREAK }, + { OP_IFBE, -2, 0, 2 }, +}; + +static dstatement_t ifz_not_taken_statements[] = { + { OP_IFZ, 3, 0, 0 }, + { OP_IFZ, 2, 0, 1 }, + { OP_LEA_A, 1, 0, 4 }, +}; + +static dstatement_t ifb_not_taken_statements[] = { + { OP_IFB, 3, 0, 2 }, + { OP_IFB, 2, 0, 1 }, + { OP_LEA_A, 1, 0, 4 }, +}; + +static dstatement_t ifa_not_taken_statements[] = { + { OP_IFA, 3, 0, 2 }, + { OP_IFA, 2, 0, 0 }, + { OP_LEA_A, 1, 0, 4 }, +}; + +static dstatement_t ifnz_not_taken_statements[] = { + { OP_IFNZ, 3, 0, 2 }, + { OP_LEA_A, 1, 0, 4 }, +}; + +static dstatement_t ifae_not_taken_statements[] = { + { OP_IFAE, 2, 0, 0 }, + { OP_LEA_A, 1, 0, 4 }, +}; + +static dstatement_t ifbe_not_taken_statements[] = { + { OP_IFBE, 2, 0, 1 }, + { OP_LEA_A, 1, 0, 4 }, +}; + +test_t tests[] = { + { + .desc = "ifz taken", + .num_globals = num_globals (test_globals_init, test_globals_expect), + .num_statements = num_statements (ifz_taken_statements), + .statements = ifz_taken_statements, + .init_globals = test_globals_init, + .expect_globals = test_globals_expect, + }, + { + .desc = "ifb taken", + .num_globals = num_globals (test_globals_init, test_globals_expect), + .num_statements = num_statements (ifb_taken_statements), + .statements = ifb_taken_statements, + .init_globals = test_globals_init, + .expect_globals = test_globals_expect, + }, + { + .desc = "ifa taken", + .num_globals = num_globals (test_globals_init, test_globals_expect), + .num_statements = num_statements (ifa_taken_statements), + .statements = ifa_taken_statements, + .init_globals = test_globals_init, + .expect_globals = test_globals_expect, + }, + { + .desc = "ifnz taken", + .num_globals = num_globals (test_globals_init, test_globals_expect), + .num_statements = num_statements (ifnz_taken_statements), + .statements = ifnz_taken_statements, + .init_globals = test_globals_init, + .expect_globals = test_globals_expect, + }, + { + .desc = "ifae taken", + .num_globals = num_globals (test_globals_init, test_globals_expect), + .num_statements = num_statements (ifae_taken_statements), + .statements = ifae_taken_statements, + .init_globals = test_globals_init, + .expect_globals = test_globals_expect, + }, + { + .desc = "ifbe taken", + .num_globals = num_globals (test_globals_init, test_globals_expect), + .num_statements = num_statements (ifbe_taken_statements), + .statements = ifbe_taken_statements, + .init_globals = test_globals_init, + .expect_globals = test_globals_expect, + }, + { + .desc = "ifz not taken", + .num_globals = num_globals (test_globals_init, test_globals_expect), + .num_statements = num_statements (ifz_not_taken_statements), + .statements = ifz_not_taken_statements, + .init_globals = test_globals_init, + .expect_globals = test_globals_expect, + }, + { + .desc = "ifb not taken", + .num_globals = num_globals (test_globals_init, test_globals_expect), + .num_statements = num_statements (ifb_not_taken_statements), + .statements = ifb_not_taken_statements, + .init_globals = test_globals_init, + .expect_globals = test_globals_expect, + }, + { + .desc = "ifa not taken", + .num_globals = num_globals (test_globals_init, test_globals_expect), + .num_statements = num_statements (ifa_not_taken_statements), + .statements = ifa_not_taken_statements, + .init_globals = test_globals_init, + .expect_globals = test_globals_expect, + }, + { + .desc = "ifnz not taken", + .num_globals = num_globals (test_globals_init, test_globals_expect), + .num_statements = num_statements (ifnz_not_taken_statements), + .statements = ifnz_not_taken_statements, + .init_globals = test_globals_init, + .expect_globals = test_globals_expect, + }, + { + .desc = "ifae not taken", + .num_globals = num_globals (test_globals_init, test_globals_expect), + .num_statements = num_statements (ifae_not_taken_statements), + .statements = ifae_not_taken_statements, + .init_globals = test_globals_init, + .expect_globals = test_globals_expect, + }, + { + .desc = "ifbe not taken", + .num_globals = num_globals (test_globals_init, test_globals_expect), + .num_statements = num_statements (ifbe_not_taken_statements), + .statements = ifbe_not_taken_statements, + .init_globals = test_globals_init, + .expect_globals = test_globals_expect, + }, +}; + +#include "main.c"