[gamecode] Add tests for the jump instructions

This commit is contained in:
Bill Currie 2022-01-17 09:34:16 +09:00
parent 1397c94ef5
commit 1baf17b780
2 changed files with 83 additions and 0 deletions

View file

@ -12,6 +12,7 @@ libs_gamecode_tests = \
libs/gamecode/test/test-float \
libs/gamecode/test/test-hops \
libs/gamecode/test/test-int \
libs/gamecode/test/test-jump \
libs/gamecode/test/test-lea \
libs/gamecode/test/test-load \
libs/gamecode/test/test-long \
@ -101,6 +102,11 @@ libs_gamecode_test_test_int_SOURCES= \
libs_gamecode_test_test_int_LDADD= $(test_gamecode_libs)
libs_gamecode_test_test_int_DEPENDENCIES= $(test_gamecode_libs)
libs_gamecode_test_test_jump_SOURCES= \
libs/gamecode/test/test-jump.c
libs_gamecode_test_test_jump_LDADD= $(test_gamecode_libs)
libs_gamecode_test_test_jump_DEPENDENCIES= $(test_gamecode_libs)
libs_gamecode_test_test_lea_SOURCES= \
libs/gamecode/test/test-lea.c
libs_gamecode_test_test_lea_LDADD= $(test_gamecode_libs)

View file

@ -0,0 +1,77 @@
#include "head.c"
#define DB 0xdeadbeef
static pr_int_t test_globals_init[] = {
DB, 1, 2, 3, DB,
};
static pr_int_t test_globals_expect[] = {
DB, 1, 2, 3, 1,
};
static dstatement_t jump_A_statements[] = {
{ OP(0, 0, 0, OP_JUMP_A), 4, 0, 0 },
{ OP(0, 0, 0, OP_LEA_A), 1, 0, 0 },
{ OP(0, 0, 0, OP_LEA_A), 1, 0, 4 },
{ OP(0, 0, 0, OP_JUMP_A), 2, 0, 0 },
{ OP(0, 0, 0, OP_JUMP_A), -2, 0, 0 },
};
static dstatement_t jump_B_statements[] = {
{ OP(0, 0, 0, OP_JUMP_B), 3, 0, 0 },
{ OP(0, 0, 0, OP_BREAK), 0, 0, 0 },
{ OP(0, 0, 0, OP_LEA_A), 1, 0, 0 },
{ OP(0, 0, 0, OP_LEA_A), 1, 0, 4 },
};
static dstatement_t jump_C_statements[] = {
{ OP(0, 0, 0, OP_JUMP_C), 1, 2, 0 },
{ OP(0, 0, 0, OP_BREAK), 0, 0, 0 },
{ OP(0, 0, 0, OP_LEA_A), 1, 0, 0 },
{ OP(0, 0, 0, OP_LEA_A), 1, 0, 4 },
};
static dstatement_t jump_D_statements[] = {
{ OP(0, 0, 0, OP_JUMP_D), 1, 2, 0 },
{ OP(0, 0, 0, OP_BREAK), 0, 0, 0 },
{ OP(0, 0, 0, OP_LEA_A), 1, 0, 0 },
{ OP(0, 0, 0, OP_LEA_A), 1, 0, 4 },
};
test_t tests[] = {
{
.desc = "jump A",
.num_globals = num_globals (test_globals_init, test_globals_expect),
.num_statements = num_statements (jump_A_statements),
.statements = jump_A_statements,
.init_globals = test_globals_init,
.expect_globals = test_globals_expect,
},
{
.desc = "jump B",
.num_globals = num_globals (test_globals_init, test_globals_expect),
.num_statements = num_statements (jump_B_statements),
.statements = jump_B_statements,
.init_globals = test_globals_init,
.expect_globals = test_globals_expect,
},
{
.desc = "jump C",
.num_globals = num_globals (test_globals_init, test_globals_expect),
.num_statements = num_statements (jump_C_statements),
.statements = jump_C_statements,
.init_globals = test_globals_init,
.expect_globals = test_globals_expect,
},
{
.desc = "jump D",
.num_globals = num_globals (test_globals_init, test_globals_expect),
.num_statements = num_statements (jump_D_statements),
.statements = jump_D_statements,
.init_globals = test_globals_init,
.expect_globals = test_globals_expect,
},
};
#include "main.c"