Refactor tests to use common code

This commit is contained in:
Aaron Culliney 2014-04-26 14:01:26 -07:00
parent 352183cbeb
commit 2169ecbab6
6 changed files with 89 additions and 155 deletions

View File

@ -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

75
src/test/testcommon.c Normal file
View File

@ -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);
}
}
}

View File

@ -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

View File

@ -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;

View File

@ -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<SHA_DIGEST_LENGTH; j++, i+=2) {
@ -100,30 +90,6 @@ void testing_video_sync(int ignored) {
++input_counter;
}
// ----------------------------------------------------------------------------
// 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) {
}
// ----------------------------------------------------------------------------
TEST test_boot_disk() {
@ -428,37 +394,15 @@ extern void cpu_thread(void *dummyptr);
GREATEST_SUITE(test_suite_display) {
srandom(time(NULL));
GREATEST_SET_SETUP_CB(testdisplay_setup, NULL);
GREATEST_SET_TEARDOWN_CB(testdisplay_teardown, NULL);
GREATEST_SET_BREAKPOINT_CB(testdisplay_breakpoint, NULL);
do_logging = false;// silence regular emulator logging
setenv("APPLE2IXCFG", "nosuchconfigfile", 1);
srandom(time(NULL));
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;
// spin off cpu thread
pthread_create(&cpu_thread_id, NULL, (void *) &cpu_thread, (void *)NULL);
test_common_init(/*cputhread*/true);
pthread_mutex_lock(&interface_mutex);
c_debugger_set_watchpoint(WATCHPOINT_ADDR);
if (is_headless) {
c_debugger_set_timeout(5);
} else {
c_debugger_set_timeout(0);
}
// TESTS --------------------------
RUN_TESTp(test_boot_disk);

View File

@ -9,7 +9,6 @@
*
*/
#include "greatest.h"
#include "testcommon.h"
#define RESET_INPUT() \
@ -48,15 +47,6 @@ static void testvm_setup(void *arg) {
static void testvm_teardown(void *arg) {
}
static void testvm_breakpoint(void *arg) {
fprintf(GREATEST_STDOUT, "set breakpoint on testvm_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<SHA_DIGEST_LENGTH; j++, i+=2) {
@ -105,30 +95,6 @@ void testing_video_sync() {
++input_counter;
}
// ----------------------------------------------------------------------------
// 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) {
}
// ----------------------------------------------------------------------------
// VM TESTS ...
@ -294,38 +260,16 @@ extern void cpu_thread(void *dummyptr);
GREATEST_SUITE(test_suite_vm) {
GREATEST_SET_SETUP_CB(testvm_setup, NULL);
GREATEST_SET_TEARDOWN_CB(testvm_teardown, NULL);
c_read_random();
srandom(0); // force a known sequence
GREATEST_SET_SETUP_CB(testvm_setup, NULL);
GREATEST_SET_TEARDOWN_CB(testvm_teardown, NULL);
GREATEST_SET_BREAKPOINT_CB(testvm_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;
// spin off cpu thread
pthread_create(&cpu_thread_id, NULL, (void *) &cpu_thread, (void *)NULL);
test_common_init(/*cputhread*/true);
pthread_mutex_lock(&interface_mutex);
c_debugger_set_watchpoint(WATCHPOINT_ADDR);
if (is_headless) {
c_debugger_set_timeout(5);
} else {
c_debugger_set_timeout(0);
}
// TESTS --------------------------
RUN_TESTp(test_boot_disk);