From 2169ecbab6eccbc8a52860b906894ac1cea34418 Mon Sep 17 00:00:00 2001 From: Aaron Culliney Date: Sat, 26 Apr 2014 14:01:26 -0700 Subject: [PATCH] Refactor tests to use common code --- Makefile.am | 2 +- src/test/testcommon.c | 75 ++++++++++++++++++++++++++++++++++++++++++ src/test/testcommon.h | 5 +++ src/test/testcpu.c | 38 ++------------------- src/test/testdisplay.c | 60 ++------------------------------- src/test/testvm.c | 64 +++-------------------------------- 6 files changed, 89 insertions(+), 155 deletions(-) create mode 100644 src/test/testcommon.c diff --git a/Makefile.am b/Makefile.am index d1ff72bb..ffbf2b87 100644 --- a/Makefile.am +++ b/Makefile.am @@ -80,7 +80,7 @@ src/asm386/glue.S: src/disk.c src/misc.c src/display.c @AUDIO_GLUE_C@ LOG_DRIVER = testcpu ## hack TODO/FIXME ... should be wrapper shell script accepting standard GNU testing API args ... -A2_TEST_SOURCES = $(apple2ix_SOURCES) +A2_TEST_SOURCES = $(apple2ix_SOURCES) src/test/testcommon.c A2_TEST_CFLAGS = -DTESTING=1 -Isrc/greatest TESTS = testcpu testdisplay testvm diff --git a/src/test/testcommon.c b/src/test/testcommon.c new file mode 100644 index 00000000..b8dc51e6 --- /dev/null +++ b/src/test/testcommon.c @@ -0,0 +1,75 @@ +/* + * Apple // emulator for *nix + * + * This software package is subject to the GNU General Public License + * version 2 or later (your choice) as published by the Free Software + * Foundation. + * + * THERE ARE NO WARRANTIES WHATSOEVER. + * + */ + +#include "testcommon.h" + +// ---------------------------------------------------------------------------- +// Stub functions because I've reached diminishing returns with the build system ... +// +// NOTE: You'd think the commandline CFLAGS set specifically for this test program would pass down to the sources in +// subdirectories, but it apparently isn't. GNU buildsystem bug? Also see HACK FIXME TODO NOTE in Makefile.am +// + +uint8_t c_MB_Read(uint16_t addr) { + return 0x0; +} + +void c_MB_Write(uint16_t addr, uint8_t byte) { +} + +uint8_t c_PhasorIO(uint16_t addr) { + return 0x0; +} + +void SpkrToggle() { +} + +void c_interface_print(int x, int y, const int cs, const char *s) { +} + +// ---------------------------------------------------------------------------- + +void test_breakpoint(void *arg) { + fprintf(GREATEST_STDOUT, "set breakpoint on test_breakpoint to check for problems...\n"); +#if !HEADLESS + if (!is_headless) { + video_sync(0); + } +#endif +} + +void test_common_init(bool do_cputhread) { + GREATEST_SET_BREAKPOINT_CB(test_breakpoint, NULL); + + do_logging = false;// silence regular emulator logging + setenv("APPLE2IXCFG", "nosuchconfigfile", 1); + + load_settings(); + c_initialize_firsttime(); + + // kludgey set max CPU speed... + cpu_scale_factor = CPU_SCALE_FASTEST; + cpu_altscale_factor = CPU_SCALE_FASTEST; + g_bFullSpeed = true; + + caps_lock = true; + + if (do_cputhread) { + // spin off cpu thread + pthread_create(&cpu_thread_id, NULL, (void *) &cpu_thread, (void *)NULL); + c_debugger_set_watchpoint(WATCHPOINT_ADDR); + if (is_headless) { + c_debugger_set_timeout(5); + } else { + c_debugger_set_timeout(0); + } + } +} diff --git a/src/test/testcommon.h b/src/test/testcommon.h index f0456205..83dd110a 100644 --- a/src/test/testcommon.h +++ b/src/test/testcommon.h @@ -13,6 +13,7 @@ #define _TESTCOMMON_H_ #include "common.h" +#include "greatest.h" #define TEST_FINISHED 0xff #define MIXSWITCH_ADDR 0x1f32 // PEEK(7986) @@ -43,4 +44,8 @@ apple_ii_64k[0][WATCHPOINT_ADDR] = 0x00; \ } + +void test_breakpoint(void *arg); +void test_common_init(bool do_cputhread); + #endif // whole file diff --git a/src/test/testcpu.c b/src/test/testcpu.c index 567bb9da..f2246445 100644 --- a/src/test/testcpu.c +++ b/src/test/testcpu.c @@ -13,7 +13,6 @@ // Tests for virtual 65c02 CPU (opcodes and addressing modes) // -#include "greatest.h" #include "testcommon.h" #define MSG_SIZE 256 @@ -83,10 +82,6 @@ static void testcpu_teardown(void *arg) { // ... } -static void testcpu_breakpoint(void *arg) { - fprintf(GREATEST_STDOUT, "set breakpoint on testcpu_breakpoint to check for problems...\n"); -} - static void testcpu_set_opcode3(uint8_t op, uint8_t val, uint8_t arg1) { apple_ii_64k[0][TEST_LOC+0] = op; apple_ii_64k[0][TEST_LOC+1] = val; @@ -134,30 +129,6 @@ static void flags_to_string(uint8_t flags, char *buf) { (flags & C_Flag_6502) ? 'C' : '-' ); } -// ---------------------------------------------------------------------------- -// Stub functions because I've reached diminishing returns with the build system ... -// -// NOTE: You'd think the commandline CFLAGS set specifically for this test program would pass down to the sources in -// subdirectories, but it apparently isn't. GNU buildsystem bug? Also see HACK FIXME TODO NOTE in Makefile.am -// - -uint8_t c_MB_Read(uint16_t addr) { - return 0x0; -} - -void c_MB_Write(uint16_t addr, uint8_t byte) { -} - -uint8_t c_PhasorIO(uint16_t addr) { - return 0x0; -} - -void SpkrToggle() { -} - -void c_interface_print(int x, int y, const int cs, const char *s) { -} - // ---------------------------------------------------------------------------- // ADC instructions @@ -7340,17 +7311,12 @@ static test_func_t *test_funcs = NULL; GREATEST_SUITE(test_suite_cpu) { - srandom(time(NULL)); - GREATEST_SET_SETUP_CB(testcpu_setup, NULL); GREATEST_SET_TEARDOWN_CB(testcpu_teardown, NULL); - GREATEST_SET_BREAKPOINT_CB(testcpu_breakpoint, NULL); - load_settings(); - sound_volume = 0; - do_logging = false;// silence regular emulator logging + srandom(time(NULL)); - c_initialize_firsttime(); + test_common_init(/*cputhread*/false); test_func_t *func=NULL, *tmp=NULL; diff --git a/src/test/testdisplay.c b/src/test/testdisplay.c index 3b17b248..a3dfc867 100644 --- a/src/test/testdisplay.c +++ b/src/test/testdisplay.c @@ -9,7 +9,6 @@ * */ -#include "greatest.h" #include "testcommon.h" #ifdef HAVE_OPENSSL @@ -46,15 +45,6 @@ static void testdisplay_teardown(void *arg) { input_str = NULL; } -static void testdisplay_breakpoint(void *arg) { - fprintf(GREATEST_STDOUT, "set breakpoint on testdisplay_breakpoint to check for problems...\n"); -#if !HEADLESS - if (!is_headless) { - video_sync(0); - } -#endif -} - static void sha1_to_str(const uint8_t * const md, char *buf) { int i=0; for (int j=0; j