[gamecode] Add some math tests

Hit a show stopper when it came to swizzle (not implemented yet). I
guess I know what I need to do next :P.
This commit is contained in:
Bill Currie 2022-01-03 17:58:16 +09:00
parent 9084121ad2
commit b8d04874c3
3 changed files with 99 additions and 7 deletions

View File

@ -1,5 +1,6 @@
libs_gamecode_tests = \ libs_gamecode_tests = \
libs/gamecode/test/test-load \ libs/gamecode/test/test-load \
libs/gamecode/test/test-math \
libs/gamecode/test/test-stack \ libs/gamecode/test/test-stack \
libs/gamecode/test/test-store libs/gamecode/test/test-store
@ -18,6 +19,11 @@ libs_gamecode_test_test_load_SOURCES= \
libs_gamecode_test_test_load_LDADD= $(test_gamecode_libs) libs_gamecode_test_test_load_LDADD= $(test_gamecode_libs)
libs_gamecode_test_test_load_DEPENDENCIES= $(test_gamecode_libs) libs_gamecode_test_test_load_DEPENDENCIES= $(test_gamecode_libs)
libs_gamecode_test_test_math_SOURCES= \
libs/gamecode/test/test-math.c
libs_gamecode_test_test_math_LDADD= $(test_gamecode_libs)
libs_gamecode_test_test_math_DEPENDENCIES= $(test_gamecode_libs)
libs_gamecode_test_test_stack_SOURCES= \ libs_gamecode_test_test_stack_SOURCES= \
libs/gamecode/test/test-stack.c libs/gamecode/test/test-stack.c
libs_gamecode_test_test_stack_LDADD= $(test_gamecode_libs) libs_gamecode_test_test_stack_LDADD= $(test_gamecode_libs)

View File

@ -107,6 +107,21 @@ setup_test (test_t *test)
(dstatement_t) { OP_BREAK, 0, 0, 0 }; (dstatement_t) { OP_BREAK, 0, 0, 0 };
} }
static int
check_result (test_t *test)
{
int ret = 0;
if (memcmp (test_pr.pr_globals, test->expect_globals,
test->num_globals * sizeof (pr_int_t)) == 0) {
ret = 1;
printf ("test #%zd: %s: OK\n", test - tests, test->desc);
} else {
printf ("test #%zd: %s: words differ\n", test - tests, test->desc);
}
return ret;
}
static int static int
run_test (test_t *test) run_test (test_t *test)
{ {
@ -120,13 +135,7 @@ run_test (test_t *test)
printf ("returned from progs\n"); printf ("returned from progs\n");
} }
if (jump_ret == 1) { if (jump_ret == 1) {
if (memcmp (test_pr.pr_globals, test->expect_globals, ret = check_result (test);
test->num_globals * sizeof (pr_int_t)) == 0) {
ret = 1;
printf ("test #%zd: %s: OK\n", test - tests, test->desc);
} else {
printf ("test #%zd: %s: words differ\n", test - tests, test->desc);
}
} else { } else {
printf ("test #%zd: %s: critical failure\n", test - tests, test->desc); printf ("test #%zd: %s: critical failure\n", test - tests, test->desc);
} }

View File

@ -0,0 +1,77 @@
#include "head.c"
static pr_vec4_t float_globals_init[] = {
{3, 4, 5, 12},
{0, 0, 0, 0},
{1, 2, 3, 8},
{4, 5, 6, 8},
{0, 0, 0, 7},
{0, 0, 0, 7},
{1, 2, 3, 4},
{5, 6, 7, 8},
{2, 3, 4, 0},
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 7},
{0, 0, 0, 7},
{0, 0, 0, 7},
{0, 0, 0, 7},
{0, 0, 0, 0},
{0, 0, 0, 0},
};
static pr_vec4_t float_globals_expect[] = {
{3, 4, 5, 12},
{63, 63, -33, 56},
{1, 2, 3, 8},
{4, 5, 6, 8},
{32, 32, 32, 7},
{-3, 6, -3, 7},
{1, 2, 3, 4},
{5, 6, 7, 8},
{2, 3, 4, 0},
{70, 70, 70, 70},
{24, 48, 48, -6},
{36, 102, 120, 7},
{52, 70, 136, 7},
{160, 160, 160, 160},
{9, 10, 17, 20},
{-1, -2, -3, 4},
{-1, -2, -3, 4},
};
static dstatement_t store_A_statements[] = {
{ OP(0, 0, 0, OP_DOT_CC_F), 0, 2, 4 },
{ OP(0, 0, 0, OP_MUL_CC_F), 0, 2, 6 },
{ OP(0, 0, 0, OP_DOT_VV_F), 8, 12, 16 },
{ OP(0, 0, 0, OP_CROSS_VV_F), 8, 12, 20 },
{ OP(0, 0, 0, OP_DOT_QQ_F), 24, 28, 36 },
{ OP(0, 0, 0, OP_MUL_QQ_F), 24, 28, 40 },
{ OP(0, 0, 0, OP_MUL_QV_F), 24, 32, 44 },
{ OP(0, 0, 0, OP_MUL_VQ_F), 32, 24, 48 },
{ OP(0, 0, 0, OP_DOT_QQ_F), 24, 32, 52 },
{ OP(0, 0, 0, OP_SWIZZLE_F), 24, 0x07e4, 60 },
{ OP(0, 0, 0, OP_DOT_QQ_F), 52, 60, 52 },
{ OP(0, 0, 0, OP_SWIZZLE_F), 24, 0x07e4, 64 },
{ OP(0, 0, 0, OP_MUL_QQ_F), 60, 32, 56 },
{ OP(0, 0, 0, OP_DOT_QQ_F), 56, 24, 52 },
};
test_t tests[] = {
{
.desc = "float vector",
.num_globals = 4*num_globals(float_globals_init, float_globals_expect),
.num_statements = num_statements (store_A_statements),
.statements = store_A_statements,
.init_globals = (pr_int_t *) float_globals_init,
.expect_globals = (pr_int_t *) float_globals_expect,
},
};
#include "main.c"