From 00ff9f069dd8e62d19435110546ab9d074b1b161 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Wed, 6 Dec 2017 15:57:15 -0600 Subject: [PATCH] Vastly simplify unit tests for mos6502 Criterion's init and fini config options allow us to register setup and teardown functions. We now use this to register the common cpu variable for the mos6502 tests, albeit through the use of a global variable. Doing so necessitated that each of the different test files have their own suites, due to some implementation details in Criterion, but this is No Big Deal. --- include/mos6502.h | 14 ----- include/mos6502.tests.h | 18 ++++++ tests/mos6502.addr.c | 117 ++++++++++++--------------------------- tests/mos6502.arith.c | 69 +++++------------------ tests/mos6502.bits.c | 51 ++++------------- tests/mos6502.branch.c | 51 ++++------------- tests/mos6502.c | 44 ++------------- tests/mos6502.exec.c | 35 +++--------- tests/mos6502.loadstor.c | 99 +++++++-------------------------- tests/mos6502.stat.c | 46 ++++----------- 10 files changed, 134 insertions(+), 410 deletions(-) create mode 100644 include/mos6502.tests.h diff --git a/include/mos6502.h b/include/mos6502.h index 5c3f257..86c7d09 100644 --- a/include/mos6502.h +++ b/include/mos6502.h @@ -21,20 +21,6 @@ #define SET_PC_BYTE(cpu, off, byte) \ vm_segment_set(cpu->memory, cpu->PC + off, byte) -#define INIT_ADDR_MODE() \ - mos6502 *cpu; \ - cpu = mos6502_create() - -#define END_ADDR_MODE() \ - mos6502_free(cpu) - -#define START_CPU_TEST(t) \ - t *cpu; \ - cpu = t##_create() - -#define END_CPU_TEST(t) \ - t##_free(cpu) - #define DEFINE_INST(inst) \ void mos6502_handle_##inst (mos6502 *cpu, vm_8bit oper) diff --git a/include/mos6502.tests.h b/include/mos6502.tests.h new file mode 100644 index 0000000..705b4a3 --- /dev/null +++ b/include/mos6502.tests.h @@ -0,0 +1,18 @@ +#ifndef _MOS6502_TESTS_H +#define _MOS6502_TESTS_H + +static mos6502 *cpu; + +static void +setup() +{ + cpu = mos6502_create(); +} + +static void +teardown() +{ + mos6502_free(cpu); +} + +#endif diff --git a/tests/mos6502.addr.c b/tests/mos6502.addr.c index 868d396..2fd03b8 100644 --- a/tests/mos6502.addr.c +++ b/tests/mos6502.addr.c @@ -2,17 +2,19 @@ #include "mos6502.h" #include "mos6502.enums.h" +#include "mos6502.tests.h" -Test(mos6502, addr_mode) +TestSuite(mos6502_addr, .init = setup, .fini = teardown); + +Test(mos6502_addr, addr_mode) { cr_assert_eq(mos6502_addr_mode(0xEA), IMP); cr_assert_eq(mos6502_addr_mode(0xD6), ZPX); cr_assert_eq(mos6502_addr_mode(0xF0), REL); } -Test(mos6502, get_address_resolver) { - INIT_ADDR_MODE(); - +Test(mos6502_addr, get_address_resolver) +{ cr_assert_eq(mos6502_get_address_resolver(0x0A), mos6502_resolve_acc); cr_assert_eq(mos6502_get_address_resolver(0x20), mos6502_resolve_abs); cr_assert_eq(mos6502_get_address_resolver(0xBC), mos6502_resolve_abx); @@ -25,118 +27,88 @@ Test(mos6502, get_address_resolver) { cr_assert_eq(mos6502_get_address_resolver(0x05), mos6502_resolve_zpg); cr_assert_eq(mos6502_get_address_resolver(0x15), mos6502_resolve_zpx); cr_assert_eq(mos6502_get_address_resolver(0x96), mos6502_resolve_zpy); - - END_ADDR_MODE(); } -Test(mos6502, addr_mode_acc) { - INIT_ADDR_MODE(); - +Test(mos6502_addr, addr_mode_acc) +{ cpu->A = 123; cr_assert_eq(mos6502_resolve_acc(cpu), 123); - - END_ADDR_MODE(); } -Test(mos6502, addr_mode_abs) { - INIT_ADDR_MODE(); - +Test(mos6502_addr, addr_mode_abs) +{ vm_segment_set(cpu->memory, 0x1234, 111); SET_PC_BYTE(cpu, 0, 0x12); SET_PC_BYTE(cpu, 1, 0x34); cr_assert_eq(mos6502_resolve_abs(cpu), 111); - - END_ADDR_MODE(); } -Test(mos6502, addr_mode_abx_carry0) { - INIT_ADDR_MODE(); - +Test(mos6502_addr, addr_mode_abx_carry0) +{ vm_segment_set(cpu->memory, 0x1234, 111); SET_PC_BYTE(cpu, 0, 0x12); SET_PC_BYTE(cpu, 1, 0x30); cpu->X = 4; cr_assert_eq(mos6502_resolve_abx(cpu), 111); - - END_ADDR_MODE(); } -Test(mos6502, addr_mode_abx_carry1) { - INIT_ADDR_MODE(); - +Test(mos6502_addr, addr_mode_abx_carry1) +{ vm_segment_set(cpu->memory, 0x1234, 111); SET_PC_BYTE(cpu, 0, 0x12); SET_PC_BYTE(cpu, 1, 0x30); cpu->X = 3; cpu->P = cpu->P | CARRY; cr_assert_eq(mos6502_resolve_abx(cpu), 111); - - END_ADDR_MODE(); } -Test(mos6502, addr_mode_aby_carry0) { - INIT_ADDR_MODE(); - +Test(mos6502_addr, addr_mode_aby_carry0) +{ vm_segment_set(cpu->memory, 0x1234, 111); SET_PC_BYTE(cpu, 0, 0x12); SET_PC_BYTE(cpu, 1, 0x30); cpu->Y = 4; cr_assert_eq(mos6502_resolve_aby(cpu), 111); - - END_ADDR_MODE(); } -Test(mos6502, addr_mode_aby_carry1) { - INIT_ADDR_MODE(); - +Test(mos6502_addr, addr_mode_aby_carry1) +{ vm_segment_set(cpu->memory, 0x1234, 111); SET_PC_BYTE(cpu, 0, 0x12); SET_PC_BYTE(cpu, 1, 0x30); cpu->Y = 3; cpu->P = cpu->P | CARRY; cr_assert_eq(mos6502_resolve_aby(cpu), 111); - - END_ADDR_MODE(); } -Test(mos6502, addr_mode_imm) { - INIT_ADDR_MODE(); - +Test(mos6502_addr, addr_mode_imm) +{ SET_PC_BYTE(cpu, 0, 0x12); cr_assert_eq(mos6502_resolve_imm(cpu), 0x12); - - END_ADDR_MODE(); } -Test(mos6502, addr_mode_idx) { - INIT_ADDR_MODE(); - +Test(mos6502_addr, addr_mode_idx) +{ vm_segment_set(cpu->memory, 0x17, 0x23); vm_segment_set(cpu->memory, 0x23, 123); SET_PC_BYTE(cpu, 0, 0x12); cpu->X = 5; cr_assert_eq(mos6502_resolve_idx(cpu), 123); - - END_ADDR_MODE(); } -Test(mos6502, addr_mode_idy) { - INIT_ADDR_MODE(); - +Test(mos6502_addr, addr_mode_idy) +{ vm_segment_set(cpu->memory, 0x12, 0x23); vm_segment_set(cpu->memory, 0x28, 123); SET_PC_BYTE(cpu, 0, 0x12); cpu->Y = 5; cr_assert_eq(mos6502_resolve_idy(cpu), 123); - - END_ADDR_MODE(); } -Test(mos6502, addr_mode_ind) { - INIT_ADDR_MODE(); - +Test(mos6502_addr, addr_mode_ind) +{ vm_segment_set(cpu->memory, 0x1234, 0x23); vm_segment_set(cpu->memory, 0x1235, 0x45); vm_segment_set(cpu->memory, 0x2345, 123); @@ -144,61 +116,44 @@ Test(mos6502, addr_mode_ind) { SET_PC_BYTE(cpu, 0, 0x12); SET_PC_BYTE(cpu, 1, 0x34); cr_assert_eq(mos6502_resolve_ind(cpu), 123); - - END_ADDR_MODE(); } -Test(mos6502, addr_mode_rel_positive) { - INIT_ADDR_MODE(); - +Test(mos6502_addr, addr_mode_rel_positive) +{ cpu->PC = 123; SET_PC_BYTE(cpu, 0, 88); cr_assert_eq(mos6502_resolve_rel(cpu), 0); cr_assert_eq(cpu->last_addr, 211); - - END_ADDR_MODE(); } -Test(mos6502, addr_mode_rel_negative) { - INIT_ADDR_MODE(); - +Test(mos6502_addr, addr_mode_rel_negative) +{ cpu->PC = 123; SET_PC_BYTE(cpu, 0, 216); cr_assert_eq(mos6502_resolve_rel(cpu), 0); cr_assert_eq(cpu->last_addr, 34); - - END_ADDR_MODE(); } -Test(mos6502, addr_mode_zpg) { - INIT_ADDR_MODE(); - +Test(mos6502_addr, addr_mode_zpg) +{ vm_segment_set(cpu->memory, 0x0034, 222); SET_PC_BYTE(cpu, 0, 0x34); cr_assert_eq(mos6502_resolve_zpg(cpu), 222); - - END_ADDR_MODE(); } -Test(mos6502, addr_mode_zpx) { - INIT_ADDR_MODE(); - +Test(mos6502_addr, addr_mode_zpx) +{ vm_segment_set(cpu->memory, 0x0034, 222); SET_PC_BYTE(cpu, 0, 0x30); cpu->X = 4; cr_assert_eq(mos6502_resolve_zpx(cpu), 222); - - END_ADDR_MODE(); } -Test(mos6502, addr_mode_zpy) { - INIT_ADDR_MODE(); - +Test(mos6502_addr, addr_mode_zpy) +{ vm_segment_set(cpu->memory, 0x0034, 222); SET_PC_BYTE(cpu, 0, 0x2F); cpu->Y = 5; cr_assert_eq(mos6502_resolve_zpy(cpu), 222); - - END_ADDR_MODE(); } diff --git a/tests/mos6502.arith.c b/tests/mos6502.arith.c index 931d5f7..052ded1 100644 --- a/tests/mos6502.arith.c +++ b/tests/mos6502.arith.c @@ -2,11 +2,12 @@ #include "mos6502.h" #include "mos6502.enums.h" +#include "mos6502.tests.h" -Test(mos6502, adc) +TestSuite(mos6502_arith, .init = setup, .fini = teardown); + +Test(mos6502_arith, adc) { - START_CPU_TEST(mos6502); - cpu->A = 5; mos6502_handle_adc(cpu, 3); cr_assert_eq(cpu->A, 8); @@ -14,14 +15,10 @@ Test(mos6502, adc) cpu->P |= CARRY; mos6502_handle_adc(cpu, 64); cr_assert_eq(cpu->A, 73); - - END_CPU_TEST(mos6502); } -Test(mos6502, cmp) +Test(mos6502_arith, cmp) { - START_CPU_TEST(mos6502); - cpu->A = 5; mos6502_handle_cmp(cpu, 3); cr_assert_eq(cpu->P & CARRY, CARRY); @@ -39,40 +36,28 @@ Test(mos6502, cmp) cr_assert_eq(cpu->P & CARRY, CARRY); cr_assert_eq(cpu->P & NEGATIVE, NEGATIVE); cr_assert_eq(cpu->P & ZERO, 0); - - END_CPU_TEST(mos6502); } -Test(mos6502, cpx) +Test(mos6502_arith, cpx) { - START_CPU_TEST(mos6502); - cpu->X = 5; mos6502_handle_cpx(cpu, 3); cr_assert_eq(cpu->P & CARRY, CARRY); cr_assert_eq(cpu->P & NEGATIVE, 0); cr_assert_eq(cpu->P & ZERO, 0); - - END_CPU_TEST(mos6502); } -Test(mos6502, cpy) +Test(mos6502_arith, cpy) { - START_CPU_TEST(mos6502); - cpu->Y = 5; mos6502_handle_cpy(cpu, 3); cr_assert_eq(cpu->P & CARRY, CARRY); cr_assert_eq(cpu->P & NEGATIVE, 0); cr_assert_eq(cpu->P & ZERO, 0); - - END_CPU_TEST(mos6502); } -Test(mos6502, dec) +Test(mos6502_arith, dec) { - START_CPU_TEST(mos6502); - // Note that DEC does NOT decrement the accumulator if the last // address is not set. It does _nothing_. cpu->A = 5; @@ -87,69 +72,45 @@ Test(mos6502, dec) // necessarily need for that to be so. mos6502_handle_dec(cpu, 44); cr_assert_eq(vm_segment_get(cpu->memory, 123), 43); - - END_CPU_TEST(mos6502); } -Test(mos6502, dex) +Test(mos6502_arith, dex) { - START_CPU_TEST(mos6502); - cpu->X = 5; mos6502_handle_dex(cpu, 0); cr_assert_eq(cpu->X, 4); - - END_CPU_TEST(mos6502); } -Test(mos6502, dey) +Test(mos6502_arith, dey) { - START_CPU_TEST(mos6502); - cpu->Y = 5; mos6502_handle_dey(cpu, 0); cr_assert_eq(cpu->Y, 4); - - END_CPU_TEST(mos6502); } -Test(mos6502, inc) +Test(mos6502_arith, inc) { - START_CPU_TEST(mos6502); - cpu->last_addr = 123; mos6502_handle_inc(cpu, 55); cr_assert_eq(vm_segment_get(cpu->memory, 123), 56); - - END_CPU_TEST(mos6502); } -Test(mos6502, inx) +Test(mos6502_arith, inx) { - START_CPU_TEST(mos6502); - cpu->X = 5; mos6502_handle_inx(cpu, 0); cr_assert_eq(cpu->X, 6); - - END_CPU_TEST(mos6502); } -Test(mos6502, iny) +Test(mos6502_arith, iny) { - START_CPU_TEST(mos6502); - cpu->Y = 5; mos6502_handle_iny(cpu, 0); cr_assert_eq(cpu->Y, 6); - - END_CPU_TEST(mos6502); } -Test(mos6502, sbc) +Test(mos6502_arith, sbc) { - START_CPU_TEST(mos6502); - cpu->A = 5; mos6502_handle_sbc(cpu, 3); cr_assert_eq(cpu->A, 2); @@ -158,6 +119,4 @@ Test(mos6502, sbc) cpu->A = 16; mos6502_handle_sbc(cpu, 8); cr_assert_eq(cpu->A, 7); - - END_CPU_TEST(mos6502); } diff --git a/tests/mos6502.bits.c b/tests/mos6502.bits.c index 666f2fd..5f08c56 100644 --- a/tests/mos6502.bits.c +++ b/tests/mos6502.bits.c @@ -2,11 +2,12 @@ #include "mos6502.h" #include "mos6502.enums.h" +#include "mos6502.tests.h" -Test(mos6502, and) +TestSuite(mos6502_bits, .init = setup, .fini = teardown); + +Test(mos6502_bits, and) { - START_CPU_TEST(mos6502); - cpu->A = 5; mos6502_handle_and(cpu, 1); cr_assert_eq(cpu->A, 1); @@ -14,28 +15,20 @@ Test(mos6502, and) cpu->A = 5; mos6502_handle_and(cpu, 4); cr_assert_eq(cpu->A, 4); - - END_CPU_TEST(mos6502); } -Test(mos6502, asl) +Test(mos6502_bits, asl) { - START_CPU_TEST(mos6502); - mos6502_handle_asl(cpu, 5); cr_assert_eq(cpu->A, 10); cpu->last_addr = 123; mos6502_handle_asl(cpu, 22); cr_assert_eq(vm_segment_get(cpu->memory, 123), 44); - - END_CPU_TEST(mos6502); } -Test(mos6502, bit) +Test(mos6502_bits, bit) { - START_CPU_TEST(mos6502); - cpu->A = 5; mos6502_handle_bit(cpu, 129); cr_assert_eq(cpu->P & NEGATIVE, NEGATIVE); @@ -61,14 +54,10 @@ Test(mos6502, bit) cr_assert_eq(cpu->P & NEGATIVE, 0); cr_assert_eq(cpu->P & OVERFLOW, 0); cr_assert_eq(cpu->P & ZERO, ZERO); - - END_CPU_TEST(mos6502); } -Test(mos6502, eor) +Test(mos6502_bits, eor) { - START_CPU_TEST(mos6502); - cpu->A = 5; mos6502_handle_eor(cpu, 4); cr_assert_eq(cpu->A, 1); @@ -76,14 +65,10 @@ Test(mos6502, eor) cpu->A = 5; mos6502_handle_eor(cpu, 1); cr_assert_eq(cpu->A, 4); - - END_CPU_TEST(mos6502); } -Test(mos6502, lsr) +Test(mos6502_bits, lsr) { - START_CPU_TEST(mos6502); - mos6502_handle_lsr(cpu, 5); cr_assert_eq(cpu->A, 2); cr_assert_eq(cpu->P & CARRY, CARRY); @@ -92,14 +77,10 @@ Test(mos6502, lsr) mos6502_handle_lsr(cpu, 22); cr_assert_eq(vm_segment_get(cpu->memory, 123), 11); cr_assert_eq(cpu->P & CARRY, 0); - - END_CPU_TEST(mos6502); } -Test(mos6502, ora) +Test(mos6502_bits, ora) { - START_CPU_TEST(mos6502); - cpu->A = 5; mos6502_handle_ora(cpu, 4); cr_assert_eq(cpu->A, 5); @@ -107,34 +88,24 @@ Test(mos6502, ora) cpu->A = 5; mos6502_handle_ora(cpu, 10); cr_assert_eq(cpu->A, 15); - - END_CPU_TEST(mos6502); } -Test(mos6502, rol) +Test(mos6502_bits, rol) { - START_CPU_TEST(mos6502); - mos6502_handle_rol(cpu, 8); cr_assert_eq(cpu->A, 16); cpu->last_addr = 234; mos6502_handle_rol(cpu, 128); cr_assert_eq(vm_segment_get(cpu->memory, 234), 1); - - END_CPU_TEST(mos6502); } -Test(mos6502, ror) +Test(mos6502_bits, ror) { - START_CPU_TEST(mos6502); - mos6502_handle_ror(cpu, 64); cr_assert_eq(cpu->A, 32); cpu->last_addr = 123; mos6502_handle_ror(cpu, 1); cr_assert_eq(vm_segment_get(cpu->memory, 123), 128); - - END_CPU_TEST(mos6502); } diff --git a/tests/mos6502.branch.c b/tests/mos6502.branch.c index e3f7ed1..caba64d 100644 --- a/tests/mos6502.branch.c +++ b/tests/mos6502.branch.c @@ -2,11 +2,12 @@ #include "mos6502.h" #include "mos6502.enums.h" +#include "mos6502.tests.h" -Test(mos6502, bcc) +TestSuite(mos6502_branch, .init = setup, .fini = teardown); + +Test(mos6502_branch, bcc) { - START_CPU_TEST(mos6502); - cpu->last_addr = 123; mos6502_handle_bcc(cpu, 0); cr_assert_eq(cpu->PC, 123); @@ -15,14 +16,10 @@ Test(mos6502, bcc) cpu->last_addr = 125; mos6502_handle_bcc(cpu, 0); cr_assert_neq(cpu->PC, 125); - - END_CPU_TEST(mos6502); } -Test(mos6502, bcs) +Test(mos6502_branch, bcs) { - START_CPU_TEST(mos6502); - cpu->last_addr = 123; mos6502_handle_bcs(cpu, 0); cr_assert_neq(cpu->PC, 123); @@ -31,14 +28,10 @@ Test(mos6502, bcs) cpu->last_addr = 125; mos6502_handle_bcs(cpu, 0); cr_assert_eq(cpu->PC, 125); - - END_CPU_TEST(mos6502); } -Test(mos6502, beq) +Test(mos6502_branch, beq) { - START_CPU_TEST(mos6502); - cpu->last_addr = 123; mos6502_handle_beq(cpu, 0); cr_assert_neq(cpu->PC, 123); @@ -47,14 +40,10 @@ Test(mos6502, beq) cpu->last_addr = 125; mos6502_handle_beq(cpu, 0); cr_assert_eq(cpu->PC, 125); - - END_CPU_TEST(mos6502); } -Test(mos6502, bmi) +Test(mos6502_branch, bmi) { - START_CPU_TEST(mos6502); - cpu->last_addr = 123; mos6502_handle_bmi(cpu, 0); cr_assert_neq(cpu->PC, 123); @@ -63,14 +52,10 @@ Test(mos6502, bmi) cpu->last_addr = 125; mos6502_handle_bmi(cpu, 0); cr_assert_eq(cpu->PC, 125); - - END_CPU_TEST(mos6502); } -Test(mos6502, bne) +Test(mos6502_branch, bne) { - START_CPU_TEST(mos6502); - cpu->last_addr = 123; mos6502_handle_bne(cpu, 0); cr_assert_eq(cpu->PC, 123); @@ -79,14 +64,10 @@ Test(mos6502, bne) cpu->last_addr = 125; mos6502_handle_bne(cpu, 0); cr_assert_neq(cpu->PC, 125); - - END_CPU_TEST(mos6502); } -Test(mos6502, bpl) +Test(mos6502_branch, bpl) { - START_CPU_TEST(mos6502); - cpu->last_addr = 123; mos6502_handle_bpl(cpu, 0); cr_assert_eq(cpu->PC, 123); @@ -95,14 +76,10 @@ Test(mos6502, bpl) cpu->last_addr = 125; mos6502_handle_bpl(cpu, 0); cr_assert_neq(cpu->PC, 125); - - END_CPU_TEST(mos6502); } -Test(mos6502, bvc) +Test(mos6502_branch, bvc) { - START_CPU_TEST(mos6502); - cpu->last_addr = 123; mos6502_handle_bvc(cpu, 0); cr_assert_eq(cpu->PC, 123); @@ -111,14 +88,10 @@ Test(mos6502, bvc) cpu->last_addr = 125; mos6502_handle_bvc(cpu, 0); cr_assert_neq(cpu->PC, 125); - - END_CPU_TEST(mos6502); } -Test(mos6502, bvs) +Test(mos6502_branch, bvs) { - START_CPU_TEST(mos6502); - cpu->last_addr = 123; mos6502_handle_bvs(cpu, 0); cr_assert_neq(cpu->PC, 123); @@ -127,6 +100,4 @@ Test(mos6502, bvs) cpu->last_addr = 125; mos6502_handle_bvs(cpu, 0); cr_assert_eq(cpu->PC, 125); - - END_CPU_TEST(mos6502); } diff --git a/tests/mos6502.c b/tests/mos6502.c index ba386ca..62417f6 100644 --- a/tests/mos6502.c +++ b/tests/mos6502.c @@ -2,11 +2,12 @@ #include "mos6502.h" #include "mos6502.enums.h" +#include "mos6502.tests.h" -Test(mos6502, create) { - mos6502 *cpu; +TestSuite(mos6502, .init = setup, .fini = teardown); - cpu = mos6502_create(); +Test(mos6502, create) +{ cr_assert_neq(cpu, NULL); cr_assert_eq(cpu->memory->size, MOS6502_MEMSIZE); @@ -17,13 +18,10 @@ Test(mos6502, create) { cr_assert_eq(cpu->Y, 0); cr_assert_eq(cpu->P, 0); cr_assert_eq(cpu->S, 0); - - mos6502_free(cpu); } -Test(mos6502, next_byte) { - INIT_ADDR_MODE(); - +Test(mos6502, next_byte) +{ cpu->PC = 128; vm_segment_set(cpu->memory, cpu->PC, 123); vm_segment_set(cpu->memory, cpu->PC + 1, 234); @@ -32,35 +30,23 @@ Test(mos6502, next_byte) { cr_assert_eq(mos6502_next_byte(cpu), 123); cr_assert_eq(mos6502_next_byte(cpu), 234); cr_assert_eq(mos6502_next_byte(cpu), 12); - - END_ADDR_MODE(); } Test(mos6502, push_stack) { - START_CPU_TEST(mos6502); - mos6502_push_stack(cpu, 0x1234); cr_assert_eq(vm_segment_get(cpu->memory, 0x0100), 0x12); cr_assert_eq(vm_segment_get(cpu->memory, 0x0101), 0x34); - - END_CPU_TEST(mos6502); } Test(mos6502, pop_stack) { - START_CPU_TEST(mos6502); - mos6502_push_stack(cpu, 0x1234); cr_assert_eq(mos6502_pop_stack(cpu), 0x1234); - - END_CPU_TEST(mos6502); } Test(mos6502, modify_status) { - START_CPU_TEST(mos6502); - mos6502_modify_status(cpu, NEGATIVE, 130); cr_assert_eq(cpu->P & NEGATIVE, NEGATIVE); mos6502_modify_status(cpu, NEGATIVE, 123); @@ -80,18 +66,12 @@ Test(mos6502, modify_status) cr_assert_eq(cpu->P & ZERO, ZERO); mos6502_modify_status(cpu, ZERO, 1); cr_assert_neq(cpu->P & ZERO, ZERO); - - END_CPU_TEST(mos6502); } Test(mos6502, set_status) { - START_CPU_TEST(mos6502); - mos6502_set_status(cpu, BREAK | INTERRUPT | DECIMAL); cr_assert_eq(cpu->P & (BREAK | INTERRUPT | DECIMAL), BREAK | INTERRUPT | DECIMAL); - - END_CPU_TEST(mos6502); } Test(mos6502, instruction) @@ -103,8 +83,6 @@ Test(mos6502, instruction) Test(mos6502, cycles) { - START_CPU_TEST(mos6502); - cr_assert_eq(mos6502_cycles(cpu, 0x76), 6); cr_assert_eq(mos6502_cycles(cpu, 0xBA), 2); @@ -118,8 +96,6 @@ Test(mos6502, cycles) // cycles cpu->X = 200; cr_assert_eq(mos6502_cycles(cpu, 0x1D), 5); - - END_CPU_TEST(mos6502); } Test(mos6502, get_instruction_handler) @@ -131,21 +107,13 @@ Test(mos6502, get_instruction_handler) Test(mos6502, execute) { - START_CPU_TEST(mos6502); - vm_segment_set(cpu->memory, 0, 34); mos6502_execute(cpu, 0x69); cr_assert_eq(cpu->A, 34); - - END_CPU_TEST(mos6502); } Test(mos6502, read_byte) { - START_CPU_TEST(mos6502); - vm_segment_set(cpu->memory, 0, 0x54); cr_assert_eq(mos6502_read_byte(cpu), 0x54); - - END_CPU_TEST(mos6502); } diff --git a/tests/mos6502.exec.c b/tests/mos6502.exec.c index e2954f1..25e6631 100644 --- a/tests/mos6502.exec.c +++ b/tests/mos6502.exec.c @@ -2,73 +2,56 @@ #include "mos6502.h" #include "mos6502.enums.h" +#include "mos6502.tests.h" -Test(mos6502, brk) +TestSuite(mos6502_exec, .init = setup, .fini = teardown); + +Test(mos6502_exec, brk) { - START_CPU_TEST(mos6502); - cpu->PC = 123; mos6502_handle_brk(cpu, 0); cr_assert_eq(cpu->PC, 125); cr_assert_eq(cpu->P & INTERRUPT, INTERRUPT); cr_assert_eq(mos6502_pop_stack(cpu), 123); - - END_CPU_TEST(mos6502); } -Test(mos6502, jmp) +Test(mos6502_exec, jmp) { - START_CPU_TEST(mos6502); - cpu->PC = 123; cpu->last_addr = 234; mos6502_handle_jmp(cpu, 0); cr_assert_eq(cpu->PC, 234); - - END_CPU_TEST(mos6502); } -Test(mos6502, jsr) +Test(mos6502_exec, jsr) { - START_CPU_TEST(mos6502); - cpu->PC = 123; cpu->last_addr = 235; mos6502_handle_jsr(cpu, 0); cr_assert_eq(cpu->PC, 235); cr_assert_eq(mos6502_pop_stack(cpu), 125); - - END_CPU_TEST(mos6502); } -Test(mos6502, nop) +Test(mos6502_exec, nop) { // currently this test does nothing -- we _should_ test to see if we // pass the right number of cycles, though. } -Test(mos6502, rti) +Test(mos6502_exec, rti) { - START_CPU_TEST(mos6502); - mos6502_push_stack(cpu, 222); mos6502_handle_rti(cpu, 0); cr_assert_eq(cpu->PC, 222); - - END_CPU_TEST(mos6502); } -Test(mos6502, rts) +Test(mos6502_exec, rts) { - START_CPU_TEST(mos6502); - mos6502_push_stack(cpu, 333); mos6502_handle_rti(cpu, 0); cr_assert_eq(cpu->PC, 333); - - END_CPU_TEST(mos6502); } diff --git a/tests/mos6502.loadstor.c b/tests/mos6502.loadstor.c index ae45054..a760d24 100644 --- a/tests/mos6502.loadstor.c +++ b/tests/mos6502.loadstor.c @@ -2,191 +2,130 @@ #include "mos6502.h" #include "mos6502.enums.h" +#include "mos6502.tests.h" -Test(mos6502, lda) +TestSuite(mos6502_loadstor, .init = setup, .fini = teardown); + +Test(mos6502_loadstor, lda) { - START_CPU_TEST(mos6502); - mos6502_handle_lda(cpu, 123); cr_assert_eq(cpu->A, 123); - - END_CPU_TEST(mos6502); } -Test(mos6502, ldx) +Test(mos6502_loadstor, ldx) { - START_CPU_TEST(mos6502); - mos6502_handle_ldx(cpu, 123); cr_assert_eq(cpu->X, 123); - - END_CPU_TEST(mos6502); } -Test(mos6502, ldy) +Test(mos6502_loadstor, ldy) { - START_CPU_TEST(mos6502); - mos6502_handle_ldy(cpu, 123); cr_assert_eq(cpu->Y, 123); - - END_CPU_TEST(mos6502); } -Test(mos6502, pha) +Test(mos6502_loadstor, pha) { - START_CPU_TEST(mos6502); - cpu->A = 0x24; mos6502_handle_pha(cpu, 0); cr_assert_eq(vm_segment_get(cpu->memory, 0x0100), 0x00); cr_assert_eq(vm_segment_get(cpu->memory, 0x0101), 0x24); - - END_CPU_TEST(mos6502); } -Test(mos6502, php) +Test(mos6502_loadstor, php) { - START_CPU_TEST(mos6502); - cpu->P = 0x43; mos6502_handle_php(cpu, 0); cr_assert_eq(vm_segment_get(cpu->memory, 0x0100), 0x00); cr_assert_eq(vm_segment_get(cpu->memory, 0x0101), 0x43); - - END_CPU_TEST(mos6502); } -Test(mos6502, pla) +Test(mos6502_loadstor, pla) { - START_CPU_TEST(mos6502); - mos6502_push_stack(cpu, 0x0033); mos6502_handle_pla(cpu, 0); cr_assert_eq(cpu->A, 0x33); - - END_CPU_TEST(mos6502); } -Test(mos6502, plp) +Test(mos6502_loadstor, plp) { - START_CPU_TEST(mos6502); - mos6502_push_stack(cpu, 0x0052); mos6502_handle_plp(cpu, 0); cr_assert_eq(cpu->P, 0x52); - - END_CPU_TEST(mos6502); } -Test(mos6502, sta) +Test(mos6502_loadstor, sta) { - START_CPU_TEST(mos6502); - cpu->A = 123; cpu->last_addr = 555; mos6502_handle_sta(cpu, 0); cr_assert_eq(vm_segment_get(cpu->memory, cpu->last_addr), cpu->A); - - END_CPU_TEST(mos6502); } -Test(mos6502, stx) +Test(mos6502_loadstor, stx) { - START_CPU_TEST(mos6502); - cpu->X = 222; cpu->last_addr = 444; mos6502_handle_stx(cpu, 0); cr_assert_eq(vm_segment_get(cpu->memory, cpu->last_addr), cpu->X); - - END_CPU_TEST(mos6502); } -Test(mos6502, sty) +Test(mos6502_loadstor, sty) { - START_CPU_TEST(mos6502); - cpu->Y = 111; cpu->last_addr = 253; mos6502_handle_sty(cpu, 0); cr_assert_eq(vm_segment_get(cpu->memory, cpu->last_addr), cpu->Y); - - END_CPU_TEST(mos6502); } -Test(mos6502, tax) +Test(mos6502_loadstor, tax) { - START_CPU_TEST(mos6502); - cpu->A = 111; cpu->X = 222; mos6502_handle_tax(cpu, 0); cr_assert_eq(cpu->X, 111); - - END_CPU_TEST(mos6502); } -Test(mos6502, tay) +Test(mos6502_loadstor, tay) { - START_CPU_TEST(mos6502); - cpu->A = 111; cpu->Y = 115; mos6502_handle_tay(cpu, 0); cr_assert_eq(cpu->Y, 111); - - END_CPU_TEST(mos6502); } -Test(mos6502, tsx) +Test(mos6502_loadstor, tsx) { - START_CPU_TEST(mos6502); - cpu->S = 111; cpu->X = 222; mos6502_handle_tsx(cpu, 0); cr_assert_eq(cpu->X, 111); - - END_CPU_TEST(mos6502); } -Test(mos6502, txa) +Test(mos6502_loadstor, txa) { - START_CPU_TEST(mos6502); - cpu->A = 111; cpu->X = 222; mos6502_handle_txa(cpu, 0); cr_assert_eq(cpu->A, 222); - - END_CPU_TEST(mos6502); } -Test(mos6502, txs) +Test(mos6502_loadstor, txs) { - START_CPU_TEST(mos6502); - cpu->S = 111; cpu->X = 222; mos6502_handle_txs(cpu, 0); cr_assert_eq(cpu->S, 222); - - END_CPU_TEST(mos6502); } -Test(mos6502, tya) +Test(mos6502_loadstor, tya) { - START_CPU_TEST(mos6502); - cpu->A = 111; cpu->Y = 222; mos6502_handle_tya(cpu, 0); cr_assert_eq(cpu->A, 222); - - END_CPU_TEST(mos6502); } diff --git a/tests/mos6502.stat.c b/tests/mos6502.stat.c index 47d0de8..ce51770 100644 --- a/tests/mos6502.stat.c +++ b/tests/mos6502.stat.c @@ -2,81 +2,55 @@ #include "mos6502.h" #include "mos6502.enums.h" +#include "mos6502.tests.h" -Test(mos6502, clc) +TestSuite(mos6502_stat, .init = setup, .fini = teardown); + +Test(mos6502_stat, clc) { - START_CPU_TEST(mos6502); - cpu->P = CARRY | DECIMAL; mos6502_handle_clc(cpu, 0); cr_assert_eq(cpu->P & CARRY, 0); - - END_CPU_TEST(mos6502); } -Test(mos6502, cld) +Test(mos6502_stat, cld) { - START_CPU_TEST(mos6502); - cpu->P = DECIMAL | CARRY; mos6502_handle_cld(cpu, 0); cr_assert_eq(cpu->P & DECIMAL, 0); - - END_CPU_TEST(mos6502); } -Test(mos6502, cli) +Test(mos6502_stat, cli) { - START_CPU_TEST(mos6502); - cpu->P = CARRY | INTERRUPT; mos6502_handle_cli(cpu, 0); cr_assert_eq(cpu->P & INTERRUPT, 0); - - END_CPU_TEST(mos6502); } -Test(mos6502, clv) +Test(mos6502_stat, clv) { - START_CPU_TEST(mos6502); - cpu->P = CARRY | OVERFLOW; mos6502_handle_clv(cpu, 0); cr_assert_eq(cpu->P & OVERFLOW, 0); - - END_CPU_TEST(mos6502); } -Test(mos6502, sec) +Test(mos6502_stat, sec) { - START_CPU_TEST(mos6502); - cpu->P = 0; mos6502_handle_sec(cpu, 0); cr_assert_eq(cpu->P & CARRY, CARRY); - - END_CPU_TEST(mos6502); } -Test(mos6502, sed) +Test(mos6502_stat, sed) { - START_CPU_TEST(mos6502); - cpu->P = 0; mos6502_handle_sed(cpu, 0); cr_assert_eq(cpu->P & DECIMAL, DECIMAL); - - END_CPU_TEST(mos6502); } -Test(mos6502, sei) +Test(mos6502_stat, sei) { - START_CPU_TEST(mos6502); - cpu->P = 0; mos6502_handle_sei(cpu, 0); cr_assert_eq(cpu->P & INTERRUPT, INTERRUPT); - - END_CPU_TEST(mos6502); } -