#include #include #include #include #include #include #include #include "m68k.h" #include "run.h" #include "sym.h" #include "tests.h" int executed, bufsz, fill; static int tcalls[] = { SYM_c9version, SYM_c9auth, SYM_c9flush, SYM_c9attach, SYM_c9walk, SYM_c9open, SYM_c9create, SYM_c9read, SYM_c9write, SYM_c9wrstr, SYM_c9clunk, SYM_c9remove, SYM_c9stat, SYM_c9wstat, }; void test_c9version(void **state); void test_c9auth(void **state); void test_c9flush(void **state); void test_c9attach(void **state); void test_c9walk(void **state); void test_c9walk_0(void **state); void test_c9open(void **state); void test_c9create(void **state); void test_c9read(void **state); void test_c9write(void **state); void test_c9wrstr(void **state); void test_c9clunk(void **state); void test_c9remove(void **state); void test_c9stat(void **state); void test_c9wstat(void **state); static uint16_t getfreetag(uint8_t *ctx) { return ru16be(ctx+EXPR_C9ctx_freetag); } static void test_ctx(void **state) { (void)state; assert_int_equal(EXPR_C9ctx_tags+EXPR_C9maxtags/8, EXPR_C9ctx_dummy); assert_int_equal(EXPR_C9ctx_dummy+1, EXPR_C9ctxsz); } static void test_tag_allocation(void **state) { uint8_t *ctx; uint16_t tag, sr; uint16_t tfree[] = {17, 2, 23, 9}; uint16_t talloc[] = {2, 9, 17, 23}; int i; (void)state; ctx = mem+Ctx; initctx(ctx, 0); m68k_set_reg(M68K_REG_A0, Ctx); // use up all free tags m68k_set_reg(M68K_REG_D4, EXPR_Topen); for(i = 0; i < EXPR_C9maxtags; i++){ jsr(Progstart+SYM_newtag); tag = m68k_get_reg(NULL, M68K_REG_D5) & 0xffff; sr = m68k_get_reg(NULL, M68K_REG_SR); assert_false(sr & SR_C); assert_int_equal(tag, i); assert_int_equal(getfreetag(ctx), i+1); } // check that all masks are set to 0xffff for(i = 0; i < EXPR_C9maxtags/16; i++) assert_int_equal(ru16be(ctx+EXPR_C9ctx_tags+i*2), 0xffff); // no free tags, newtag returns an error (C=1) */ jsr(Progstart+SYM_newtag); sr = m68k_get_reg(NULL, M68K_REG_SR); assert_true(sr & SR_C); // try once again to make sure jsr(Progstart+SYM_newtag); sr = m68k_get_reg(NULL, M68K_REG_SR); assert_true(sr & SR_C); // c9* calls fail too for(i = 0; i < nelem(tcalls); i++){ if(tcalls[i] == SYM_c9version) // except this one since it doesn't allocate continue; m68k_set_reg(M68K_REG_SR, sr&~SR_C); jsr(Progstart+tcalls[i]); sr = m68k_get_reg(NULL, M68K_REG_SR); assert_true(sr & SR_C); } // now free one tag and try newtag again m68k_set_reg(M68K_REG_D5, 15); // 15st tag jsr(Progstart+SYM_freetag); // obviously, on the next newtag call we don't want to *search* for a free tag // so 15st should already be saved as a free one assert_int_equal(getfreetag(ctx), 15); // allocate it m68k_set_reg(M68K_REG_D4, EXPR_Topen); jsr(Progstart+SYM_newtag); tag = m68k_get_reg(NULL, M68K_REG_D5) & 0xffff; sr = m68k_get_reg(NULL, M68K_REG_SR); assert_false(sr & SR_C); assert_int_equal(tag, 15); // now free a few tags for(i = 0; i < nelem(tfree); i++){ m68k_set_reg(M68K_REG_D5, tfree[i]); jsr(Progstart+SYM_freetag); } // and set freetag so that we have to use the slow search wu16be(ctx+EXPR_C9ctx_freetag, 0); // now allocate them back, checking the order as well for(i = 0; i < nelem(talloc); i++){ jsr(Progstart+SYM_newtag); tag = m68k_get_reg(NULL, M68K_REG_D5) & 0xffff; sr = m68k_get_reg(NULL, M68K_REG_SR); assert_false(sr & SR_C); assert_int_equal(tag, talloc[i]); } // free all tags for(i = 0; i < EXPR_C9maxtags; i++){ m68k_set_reg(M68K_REG_D5, i); jsr(Progstart+SYM_freetag); assert_false(sr & SR_C); } // check that all masks are set to 0 for(i = 0; i < EXPR_C9maxtags/16; i++) assert_int_equal(ru16be(ctx+EXPR_C9ctx_tags+i*2), 0); } void generic_begin(void) { uint8_t *ctx; uint32_t sz; ctx = mem+m68k_get_reg(NULL, M68K_REG_A0); sz = m68k_get_reg(NULL, M68K_REG_D6); bufsz = sz; assert_ptr_equal(ctx, mem+Ctx); memset(mem+Begindst, fill, sz+1); m68k_set_reg(M68K_REG_A5, Begindst); executed |= Begin; } int runtests(void) { const struct CMUnitTest tests[] = { cmocka_unit_test(test_ctx), cmocka_unit_test(test_tag_allocation), cmocka_unit_test(test_c9version), cmocka_unit_test(test_c9auth), cmocka_unit_test(test_c9flush), cmocka_unit_test(test_c9attach), cmocka_unit_test(test_c9walk), cmocka_unit_test(test_c9walk_0), cmocka_unit_test(test_c9open), cmocka_unit_test(test_c9create), cmocka_unit_test(test_c9read), cmocka_unit_test(test_c9write), cmocka_unit_test(test_c9wrstr), cmocka_unit_test(test_c9clunk), cmocka_unit_test(test_c9remove), cmocka_unit_test(test_c9stat), cmocka_unit_test(test_c9wstat), }; srand(time(NULL)); fill = rand() & 255; return cmocka_run_group_tests(tests, NULL, NULL); };