From 7d3b39926c23fe71cf190f965369c3cf18dbadc4 Mon Sep 17 00:00:00 2001 From: Aaron Culliney Date: Sun, 28 Dec 2014 14:50:43 -0800 Subject: [PATCH] Disk testing is separate from vm testing - Breaks out disk testing into its own suite - Misc testing and build-system tweaks --- Makefile.am | 25 +++- configure.ac | 2 + src/test/testcommon.c | 11 ++ src/test/testcommon.h | 12 +- src/test/testdisk.c | 298 +++++++++++++++++++++++++++++++++++++++++ src/test/testdisplay.c | 16 --- src/test/testvm.c | 207 ---------------------------- 7 files changed, 338 insertions(+), 233 deletions(-) create mode 100644 src/test/testdisk.c diff --git a/Makefile.am b/Makefile.am index 28a5dce7..73edf4ae 100644 --- a/Makefile.am +++ b/Makefile.am @@ -94,8 +94,8 @@ LOG_DRIVER = testcpu ## hack TODO/FIXME ... should be wrapper shell script acce A2_TEST_SOURCES = $(apple2ix_SOURCES) src/test/testcommon.c A2_TEST_CFLAGS = -DTESTING=1 -DCPU_TRACING=1 -DDISK_TRACING=1 -DVM_TRACING=1 -Isrc/test -TESTS = testcpu testdisplay testvm -check_PROGRAMS = testcpu testdisplay testvm +TESTS = testcpu testdisplay testvm testdisk +check_PROGRAMS = testcpu testdisplay testvm testdisk testcpu_SOURCES = src/test/testcpu.c $(A2_TEST_SOURCES) $(META_SRC) testcpu_CFLAGS = $(apple2ix_CFLAGS) $(A2_TEST_CFLAGS) -UAUDIO_ENABLED -UINTERFACE_CLASSIC -DHEADLESS=1 @@ -125,6 +125,16 @@ testvm_DEPENDENCIES = @TESTVM_ASM_O@ @META_O@ @VIDEO_O@ EXTRA_testvm_SOURCES = $(ASM_SRC_x86) $(VIDEO_SRC) +testdisk_SOURCES = src/test/testdisk.c $(A2_TEST_SOURCES) $(META_SRC) +testdisk_CFLAGS = $(apple2ix_CFLAGS) $(A2_TEST_CFLAGS) -UAUDIO_ENABLED -UINTERFACE_CLASSIC -DHEADLESS=0 +testdisk_CCASFLAGS = $(testdisk_CFLAGS) +testdisk_LDFLAGS = $(apple2ix_LDFLAGS) +# HACK FIXME TODO NOTE: specify testdisk_ASM_O to force it to rebuild with proper CCASFLAGS ... automake bug? +testdisk_LDADD = @TESTDISK_ASM_O@ @VIDEO_O@ +testdisk_DEPENDENCIES = @TESTDISK_ASM_O@ @META_O@ @VIDEO_O@ + +EXTRA_testdisk_SOURCES = $(ASM_SRC_x86) $(VIDEO_SRC) + ############################################################################### # Misc & Installation @@ -139,19 +149,20 @@ shaders_DATA = src/video/Basic.vsh src/video/Basic.fsh disksdir = @datadir@/@PACKAGE@/disks disks_DATA = \ disks/README disks/blank.dsk.gz disks/blank.nib.gz disks/etc.dsk.gz \ - disks/mystery.dsk.gz disks/speedtest.dsk.gz disks/speedtest.txt + disks/mystery.dsk.gz disks/speedtest.dsk.gz disks/speedtest.txt \ + disks/flapple140.po.gz disks/testdisplay1.dsk.gz disks/testvm1.dsk.gz + # Extra distribution stuff EXTRA_DIST = reconf.sh configure README.debugger PROBLEMS .apple2 \ \ - disks/README disks/blank.dsk.gz disks/blank.nib.gz disks/etc.dsk.gz \ - disks/mystery.dsk.gz disks/speedtest.dsk.gz disks/speedtest.txt \ + $(disks_DATA) \ \ - docs/apple2ix.6 \ + $(man_MANS) \ \ src/font.txt \ src/x86/genglue \ \ - src/video/Basic.vsh src/video/Basic.fsh + $(shaders_DATA) CLEANFILES = src/font.c src/rom.c src/meta/debug.c src/x86/glue.S diff --git a/configure.ac b/configure.ac index 763e3048..4249485f 100644 --- a/configure.ac +++ b/configure.ac @@ -21,6 +21,7 @@ dnl Arch checks ASM_O="src/x86/glue.o src/x86/cpu.o" TESTVM_ASM_O="src/x86/testvm-glue.o src/x86/testvm-cpu.o" +TESTDISK_ASM_O="src/x86/testdisk-glue.o src/x86/testdisk-cpu.o" arch='' case $target in x86_64-*-*) @@ -75,6 +76,7 @@ fi AC_SUBST(ASM_O) AC_SUBST(TESTVM_ASM_O) +AC_SUBST(TESTDISK_ASM_O) AC_SUBST([AM_CFLAGS]) diff --git a/src/test/testcommon.c b/src/test/testcommon.c index 311588b3..d489855d 100644 --- a/src/test/testcommon.c +++ b/src/test/testcommon.c @@ -17,6 +17,8 @@ #define TESTBUF_SZ 1024 +bool test_do_reboot = true; + static char input_str[TESTBUF_SZ]; // ASCII static unsigned int input_length = 0; static unsigned int input_counter = 0; @@ -165,3 +167,12 @@ int test_setup_boot_disk(const char *fileName, int readonly) { FREE(disk); return err; } + +void sha1_to_str(const uint8_t * const md, char *buf) { + int i=0; + for (int j=0; j -#define SHA_DIGEST_LENGTH CC_SHA1_DIGEST_LENGTH -#define SHA1 CC_SHA1 +# include +# define SHA_DIGEST_LENGTH CC_SHA1_DIGEST_LENGTH +# define SHA1 CC_SHA1 +#elif HAVE_OPENSSL +# include +#else +# error "these tests require OpenSSL libraries (SHA)" #endif #define TEST_FINISHED 0xff @@ -48,10 +52,12 @@ apple_ii_64k[0][WATCHPOINT_ADDR] = 0x00; \ } +extern bool test_do_reboot; void test_breakpoint(void *arg); void test_common_init(bool do_cputhread); void test_common_setup(); void test_type_input(const char *input); int test_setup_boot_disk(const char *fileName, int readonly); +void sha1_to_str(const uint8_t * const md, char *buf); #endif // whole file diff --git a/src/test/testdisk.c b/src/test/testdisk.c new file mode 100644 index 00000000..710559e3 --- /dev/null +++ b/src/test/testdisk.c @@ -0,0 +1,298 @@ +/* + * 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" + +#define RESET_INPUT() test_common_setup() + +#define TESTING_DISK "testvm1.dsk.gz" +#define BLANK_DSK "blank.dsk.gz" +#define BLANK_NIB "blank.nib.gz" +#define REBOOT_TO_DOS() \ + do { \ + apple_ii_64k[0][TESTOUT_ADDR] = 0x00; \ + joy_button0 = 0xff; \ + cpu65_interrupt(ResetSig); \ + } while (0) + +#define TYPE_TRIGGER_WATCHPT() \ + test_type_input("POKE7987,255:REM TRIGGER DEBUGGER\r") + +static void testdisk_setup(void *arg) { + RESET_INPUT(); + apple_ii_64k[0][MIXSWITCH_ADDR] = 0x00; + apple_ii_64k[0][WATCHPOINT_ADDR] = 0x00; + apple_ii_64k[0][TESTOUT_ADDR] = 0x00; + joy_button0 = 0xff; // OpenApple + test_setup_boot_disk(TESTING_DISK, 1); + if (test_do_reboot) { + cpu65_interrupt(ResetSig); + } +} + +static void testdisk_teardown(void *arg) { +} + +// ---------------------------------------------------------------------------- +// Disk TESTS ... + +#define EXPECTED_DISK_TRACE_FILE_SIZE 141350 +#define EXPECTED_DISK_TRACE_SHA "471EB3D01917B1C6EF9F13C5C7BC1ACE4E74C851" +TEST test_boot_disk_bytes() { + char *homedir = getenv("HOME"); + char *disk = NULL; + asprintf(&disk, "%s/a2_read_disk_test.txt", homedir); + if (disk) { + unlink(disk); + c_begin_disk_trace_6(disk, NULL); + } + + BOOT_TO_DOS(); + + c_end_disk_trace_6(); + c_eject_6(0); + + do { + uint8_t md[SHA_DIGEST_LENGTH]; + char mdstr[(SHA_DIGEST_LENGTH*2)+1]; + + FILE *fp = fopen(disk, "r"); + char *buf = malloc(EXPECTED_DISK_TRACE_FILE_SIZE); + if (fread(buf, 1, EXPECTED_DISK_TRACE_FILE_SIZE, fp) != EXPECTED_DISK_TRACE_FILE_SIZE) { + ASSERT(false); + } + fclose(fp); fp = NULL; + SHA1(buf, EXPECTED_DISK_TRACE_FILE_SIZE, md); + FREE(buf); + + sha1_to_str(md, mdstr); + ASSERT(strcmp(mdstr, EXPECTED_DISK_TRACE_SHA) == 0); + } while(0); + + unlink(disk); + FREE(disk); + + PASS(); +} + +// This test is majorly abusive ... it creates an ~800MB file in $HOME +// ... but if it's correct, you're fairly assured the cpu/vm is working =) +#if ABUSIVE_TESTS +#define EXPECTED_CPU_TRACE_FILE_SIZE 809430487 +TEST test_boot_disk_cputrace() { + char *homedir = getenv("HOME"); + char *output = NULL; + asprintf(&output, "%s/a2_cputrace.txt", homedir); + if (output) { + unlink(output); + cpu65_trace_begin(output); + } + + BOOT_TO_DOS(); + + cpu65_trace_end(); + c_eject_6(0); + + do { + uint8_t md[SHA_DIGEST_LENGTH]; + char mdstr[(SHA_DIGEST_LENGTH*2)+1]; + + FILE *fp = fopen(output, "r"); + fseek(fp, 0, SEEK_END); + long expectedSize = ftell(fp); + ASSERT(expectedSize == EXPECTED_CPU_TRACE_FILE_SIZE); + fseek(fp, 0, SEEK_SET); + char *buf = malloc(EXPECTED_CPU_TRACE_FILE_SIZE); + if (fread(buf, 1, EXPECTED_CPU_TRACE_FILE_SIZE, fp) != EXPECTED_CPU_TRACE_FILE_SIZE) { + ASSERT(false); + } + fclose(fp); fp = NULL; + SHA1(buf, EXPECTED_CPU_TRACE_FILE_SIZE, md); + FREE(buf); + +#if 0 + // this is no longer a stable value to check due to random return values from disk VM routines + sha1_to_str(md, mdstr); + ASSERT(strcmp(mdstr, EXPECTED_CPU_TRACE_SHA) == 0); +#endif + } while(0); + + unlink(output); + FREE(output); + + PASS(); +} +#endif + +#define EXPECTED_VM_TRACE_FILE_SIZE 2830810 +TEST test_boot_disk_vmtrace() { + char *homedir = getenv("HOME"); + char *disk = NULL; + asprintf(&disk, "%s/a2_vmtrace.txt", homedir); + if (disk) { + unlink(disk); + vm_trace_begin(disk); + } + + BOOT_TO_DOS(); + + vm_trace_end(); + c_eject_6(0); + + do { + uint8_t md[SHA_DIGEST_LENGTH]; + char mdstr[(SHA_DIGEST_LENGTH*2)+1]; + + FILE *fp = fopen(disk, "r"); + char *buf = malloc(EXPECTED_VM_TRACE_FILE_SIZE); + if (fread(buf, 1, EXPECTED_VM_TRACE_FILE_SIZE, fp) != EXPECTED_VM_TRACE_FILE_SIZE) { + ASSERT(false); + } + fclose(fp); fp = NULL; + SHA1(buf, EXPECTED_VM_TRACE_FILE_SIZE, md); + FREE(buf); + +#if 0 + // this is no longer a stable value to check due to random return values from disk VM routines + sha1_to_str(md, mdstr); + ASSERT(strcmp(mdstr, EXPECTED_VM_TRACE_SHA) == 0); +#endif + } while(0); + + unlink(disk); + FREE(disk); + + PASS(); +} + +TEST test_boot_disk() { + BOOT_TO_DOS(); + PASS(); +} + +TEST test_inithello_dsk() { + + test_setup_boot_disk(BLANK_DSK, 0); + BOOT_TO_DOS(); + + ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] != TEST_FINISHED); + ASSERT(apple_ii_64k[0][TESTOUT_ADDR] == 0x00); + + test_type_input("INIT HELLO\r"); + TYPE_TRIGGER_WATCHPT(); + + c_debugger_go(); + + ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED); + ASSERT_SHA("10F15B516E4CF2FC5B1712951A6F9C3D90BF595C"); + + REBOOT_TO_DOS(); + c_eject_6(0); + + PASS(); +} + +TEST test_inithello_nib() { + + test_setup_boot_disk(BLANK_NIB, 0); + BOOT_TO_DOS(); + + ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] != TEST_FINISHED); + + test_type_input("INIT HELLO\r"); + TYPE_TRIGGER_WATCHPT(); + + c_debugger_go(); + + ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED); + ASSERT_SHA("10F15B516E4CF2FC5B1712951A6F9C3D90BF595C"); + + REBOOT_TO_DOS(); + c_eject_6(0); + + PASS(); +} + +// ---------------------------------------------------------------------------- +// Test Suite + +static int begin_video = -1; + +GREATEST_SUITE(test_suite_disk) { + GREATEST_SET_SETUP_CB(testdisk_setup, NULL); + GREATEST_SET_TEARDOWN_CB(testdisk_teardown, NULL); + + // TESTS -------------------------- + begin_video=!is_headless; + + RUN_TESTp(test_boot_disk_bytes); +#if ABUSIVE_TESTS + RUN_TESTp(test_boot_disk_cputrace); +#endif + RUN_TESTp(test_boot_disk_vmtrace); + RUN_TESTp(test_boot_disk); + + RUN_TESTp(test_inithello_dsk); + RUN_TESTp(test_inithello_nib); + + // ... + c_eject_6(0); + pthread_mutex_unlock(&interface_mutex); +} + +SUITE(test_suite_disk); +GREATEST_MAIN_DEFS(); + +static char **test_argv = NULL; +static int test_argc = 0; + +static int _test_disk(void) { + int argc = test_argc; + char **argv = test_argv; + GREATEST_MAIN_BEGIN(); + RUN_SUITE(test_suite_disk); + GREATEST_MAIN_END(); +} + +static void *test_thread(void *dummyptr) { + _test_disk(); + return NULL; +} + +void test_disk(int argc, char **argv) { + test_argc = argc; + test_argv = argv; + + c_read_random(0x0); + srandom(0); // force a known sequence + + pthread_mutex_lock(&interface_mutex); + + test_common_init(/*cputhread*/true); + + pthread_t p; + pthread_create(&p, NULL, (void *)&test_thread, (void *)NULL); + + while (begin_video < 0) { + struct timespec ts = { .tv_sec=0, .tv_nsec=33333333 }; + nanosleep(&ts, NULL); + } + if (begin_video) { + video_main_loop(); + } + pthread_join(p, NULL); +} + +#if !defined(__APPLE__) +int main(int argc, char **argv) { + test_disk(argc, argv); +} +#endif diff --git a/src/test/testdisplay.c b/src/test/testdisplay.c index 510d8a8f..7efd334d 100644 --- a/src/test/testdisplay.c +++ b/src/test/testdisplay.c @@ -11,14 +11,6 @@ #include "testcommon.h" -#ifdef HAVE_OPENSSL -#include -#elif !defined(__APPLE__) -#error "these tests require OpenSSL libraries" -#endif - -static bool test_do_reboot = true; - static void testdisplay_setup(void *arg) { test_common_setup(); apple_ii_64k[0][MIXSWITCH_ADDR] = 0x00; @@ -32,14 +24,6 @@ static void testdisplay_setup(void *arg) { static void testdisplay_teardown(void *arg) { } -static void sha1_to_str(const uint8_t * const md, char *buf) { - int i=0; - for (int j=0; j -#elif !defined(__APPLE__) -#error "these tests require OpenSSL libraries (SHA)" -#endif #define TYPE_TRIGGER_WATCHPT() \ test_type_input("POKE7987,255:REM TRIGGER DEBUGGER\r") -static bool test_do_reboot = true; - static void testvm_setup(void *arg) { RESET_INPUT(); apple_ii_64k[0][MIXSWITCH_ADDR] = 0x00; @@ -49,192 +33,9 @@ static void testvm_setup(void *arg) { static void testvm_teardown(void *arg) { } -static void sha1_to_str(const uint8_t * const md, char *buf) { - int i=0; - for (int j=0; j