Move more common code into testcommon.c

This commit is contained in:
Aaron Culliney 2014-04-26 15:43:40 -07:00
parent 14ca3c788a
commit f99f283ff2
5 changed files with 111 additions and 155 deletions

View File

@ -11,6 +11,13 @@
#include "testcommon.h"
static char input_str[TESTBUF_SZ]; // ASCII
static unsigned int input_length = 0;
static unsigned int input_counter = 0;
static struct timespec t0 = { 0 };
static struct timespec ti = { 0 };
// ----------------------------------------------------------------------------
// Stub functions because I've reached diminishing returns with the build system ...
//
@ -37,6 +44,59 @@ void c_interface_print(int x, int y, const int cs, const char *s) {
// ----------------------------------------------------------------------------
void test_common_setup() {
input_counter = 0;
input_length = 0;
input_str[0] = '\0';
clock_gettime(CLOCK_MONOTONIC, &t0);
}
// ----------------------------------------------------------------------------
// test video functions and stubs
void testing_video_sync() {
#if !HEADLESS
if (!is_headless) {
clock_gettime(CLOCK_MONOTONIC, &ti);
struct timespec deltat = timespec_diff(t0, ti, NULL);
if (deltat.tv_sec || (deltat.tv_nsec >= NANOSECONDS/15) ) {
video_sync(0);
ti = t0;
}
}
#endif
if (!input_length) {
input_length = strlen(input_str);
}
if (input_counter >= input_length) {
return;
}
uint8_t ch = (uint8_t)input_str[input_counter];
if (ch == '\n') {
ch = '\r';
}
if ( (apple_ii_64k[0][0xC000] & 0x80) || (apple_ii_64k[1][0xC000] & 0x80) ) {
// last character typed not processed by emulator...
return;
}
apple_ii_64k[0][0xC000] = ch | 0x80;
apple_ii_64k[1][0xC000] = ch | 0x80;
++input_counter;
}
void test_type_input(const char *input) {
strcat(input_str, input);
}
// ----------------------------------------------------------------------------
void test_breakpoint(void *arg) {
fprintf(GREATEST_STDOUT, "set breakpoint on test_breakpoint to check for problems...\n");
#if !HEADLESS
@ -46,6 +106,8 @@ void test_breakpoint(void *arg) {
#endif
}
// ----------------------------------------------------------------------------
void test_common_init(bool do_cputhread) {
GREATEST_SET_BREAKPOINT_CB(test_breakpoint, NULL);
@ -69,7 +131,9 @@ void test_common_init(bool do_cputhread) {
if (is_headless) {
c_debugger_set_timeout(5);
} else {
fprintf(stderr, "NOTE : RUNNING WITH DISPLAY ... pass HEADLESS=1 to environment to run test in faster headless mode\n");
c_debugger_set_timeout(0);
}
}
}

View File

@ -44,8 +44,9 @@
apple_ii_64k[0][WATCHPOINT_ADDR] = 0x00; \
}
void test_breakpoint(void *arg);
void test_common_init(bool do_cputhread);
void test_common_setup();
void test_type_input(const char *input);
#endif // whole file

View File

@ -48,10 +48,6 @@
snprintf(msgbuf, MSG_SIZE, MSG_FLAGS0, regA, val, result, buf0, cpu65_current.a, buf1); \
ASSERTm(msgbuf, cpu65_current.f == flags);
void testing_video_sync() {
// user input and video output not simulated in this test
}
static void testcpu_setup(void *arg) {
//reinitialize();

View File

@ -17,21 +17,14 @@
#error "these tests require OpenSSL libraries"
#endif
static char *input_str = NULL; // ASCII
static unsigned int input_length = 0;
static unsigned int input_counter = 0;
static bool test_do_reboot = true;
static struct timespec t0 = { 0 };
static struct timespec ti = { 0 };
extern unsigned char joy_button0;
static void testdisplay_setup(void *arg) {
test_common_setup();
apple_ii_64k[0][MIXSWITCH_ADDR] = 0x00;
apple_ii_64k[0][WATCHPOINT_ADDR] = 0x00;
input_counter = 0;
input_length = 0;
joy_button0 = 0xff; // OpenApple
if (test_do_reboot) {
cpu65_interrupt(ResetSig);
@ -39,10 +32,6 @@ static void testdisplay_setup(void *arg) {
}
static void testdisplay_teardown(void *arg) {
if (input_str) {
free(input_str);
}
input_str = NULL;
}
static void sha1_to_str(const uint8_t * const md, char *buf) {
@ -53,45 +42,6 @@ static void sha1_to_str(const uint8_t * const md, char *buf) {
sprintf(buf+i, "%c", '\0');
}
// ----------------------------------------------------------------------------
// test video functions and stubs
void testing_video_sync(int ignored) {
#if !HEADLESS
if (!is_headless) {
clock_gettime(CLOCK_MONOTONIC, &ti);
struct timespec deltat = timespec_diff(t0, ti, NULL);
if (deltat.tv_sec || (deltat.tv_nsec >= NANOSECONDS/15) ) {
video_sync(0);
ti = t0;
}
}
#endif
if (input_counter >= input_length) {
return;
}
uint8_t ch = (uint8_t)input_str[input_counter];
if (ch == '\n') {
fprintf(stderr, "converting '\\n' to '\\r' in test input string...");
ch = '\r';
}
if ( (apple_ii_64k[0][0xC000] & 0x80) || (apple_ii_64k[1][0xC000] & 0x80) ) {
// last character typed not processed by emulator...
return;
}
apple_ii_64k[0][0xC000] = ch | 0x80;
apple_ii_64k[1][0xC000] = ch | 0x80;
++input_counter;
}
// ----------------------------------------------------------------------------
TEST test_boot_disk() {
char *disk = "./disks/testdisplay1.dsk.gz";
ASSERT(!c_new_diskette_6(0, disk, 0));
@ -108,8 +58,7 @@ TEST test_40col_normal() {
BOOT_TO_DOS();
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] != TEST_FINISHED);
input_str = strdup("RUN TESTNORMALTEXT\r");
input_length = strlen(input_str);
test_type_input("RUN TESTNORMALTEXT\r");
c_debugger_go();
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
@ -122,8 +71,7 @@ TEST test_80col_normal() {
BOOT_TO_DOS();
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] != TEST_FINISHED);
input_str = strdup("PR#3\rRUN TESTNORMALTEXT\r");
input_length = strlen(input_str);
test_type_input("PR#3\rRUN TESTNORMALTEXT\r");
c_debugger_go();
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
@ -136,8 +84,7 @@ TEST test_40col_inverse() {
BOOT_TO_DOS();
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] != TEST_FINISHED);
input_str = strdup("RUN TESTINVERSETEXT\r");
input_length = strlen(input_str);
test_type_input("RUN TESTINVERSETEXT\r");
c_debugger_go();
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
@ -150,8 +97,7 @@ TEST test_80col_inverse() {
BOOT_TO_DOS();
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] != TEST_FINISHED);
input_str = strdup("PR#3\rRUN TESTINVERSETEXT\r");
input_length = strlen(input_str);
test_type_input("PR#3\rRUN TESTINVERSETEXT\r");
c_debugger_go();
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
@ -173,8 +119,7 @@ TEST test_lores_with_80col() {
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] != TEST_FINISHED);
input_str = strdup("TEXT\rPR#3\rRUN TESTLORES\r");
input_length = strlen(input_str);
test_type_input("TEXT\rPR#3\rRUN TESTLORES\r");
c_debugger_go();
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
@ -188,8 +133,7 @@ TEST test_lores_with_40col() {
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] != TEST_FINISHED);
input_str = strdup("TEXT\rHOME\rLOAD TESTLORES\rLIST\rLIST\rRUN\r");
input_length = strlen(input_str);
test_type_input("TEXT\rHOME\rLOAD TESTLORES\rLIST\rLIST\rRUN\r");
c_debugger_go();
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
@ -203,8 +147,7 @@ TEST test_lores_40colmix_normal() {
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] != TEST_FINISHED);
input_str = strdup("TEXT\rHOME\rLOAD TESTLORES\rLIST\rLIST\rPOKE 7986,127\rRUN\r");
input_length = strlen(input_str);
test_type_input("TEXT\rHOME\rLOAD TESTLORES\rLIST\rLIST\rPOKE 7986,127\rRUN\r");
c_debugger_go();
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
@ -218,8 +161,7 @@ TEST test_lores_40colmix_inverse() {
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] != TEST_FINISHED);
input_str = strdup("TEXT\rINVERSE\rHOME\rLOAD TESTLORES\rLIST\rLIST\rPOKE 7986,127\rRUN\r");
input_length = strlen(input_str);
test_type_input("TEXT\rINVERSE\rHOME\rLOAD TESTLORES\rLIST\rLIST\rPOKE 7986,127\rRUN\r");
c_debugger_go();
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
@ -233,8 +175,7 @@ TEST test_lores_80colmix_normal() {
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] != TEST_FINISHED);
input_str = strdup("TEXT\rPR#3\rLOAD TESTLORES\rLIST\rLIST\rPOKE 7986,127\rRUN\r");
input_length = strlen(input_str);
test_type_input("TEXT\rPR#3\rLOAD TESTLORES\rLIST\rLIST\rPOKE 7986,127\rRUN\r");
c_debugger_go();
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
@ -248,8 +189,7 @@ TEST test_lores_80colmix_inverse() {
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] != TEST_FINISHED);
input_str = strdup("TEXT\rINVERSE\rPR#3\rLOAD TESTLORES\rLIST\rLIST\rPOKE 7986,127\rRUN\r");
input_length = strlen(input_str);
test_type_input("TEXT\rINVERSE\rPR#3\rLOAD TESTLORES\rLIST\rLIST\rPOKE 7986,127\rRUN\r");
c_debugger_go();
if (test_do_reboot) {
@ -275,8 +215,7 @@ TEST test_hires_with_80col() {
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] != TEST_FINISHED);
input_str = strdup("PR#3\rRUN TESTHIRES_2\r");
input_length = strlen(input_str);
test_type_input("PR#3\rRUN TESTHIRES_2\r");
c_debugger_go();
if (test_do_reboot) {
@ -295,8 +234,7 @@ TEST test_hires_with_40col() {
BOOT_TO_DOS();
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] != TEST_FINISHED);
input_str = strdup("RUN TESTHIRES_2\r");
input_length = strlen(input_str);
test_type_input("RUN TESTHIRES_2\r");
c_debugger_go();
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
@ -309,8 +247,7 @@ TEST test_hires_40colmix_normal() {
BOOT_TO_DOS();
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] != TEST_FINISHED);
input_str = strdup("POKE 7986,127\rRUN TESTHIRES\r");
input_length = strlen(input_str);
test_type_input("POKE 7986,127\rRUN TESTHIRES\r");
c_debugger_go();
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
@ -323,8 +260,7 @@ TEST test_hires_40colmix_inverse() {
BOOT_TO_DOS();
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] != TEST_FINISHED);
input_str = strdup("INVERSE\rPOKE 7986,127\rRUN TESTHIRES\r");
input_length = strlen(input_str);
test_type_input("INVERSE\rPOKE 7986,127\rRUN TESTHIRES\r");
c_debugger_go();
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
@ -337,8 +273,7 @@ TEST test_hires_80colmix_normal() {
BOOT_TO_DOS();
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] != TEST_FINISHED);
input_str = strdup("PR#3\rLOAD TESTHIRES\rLIST\rLIST\rPOKE 7986,127\rRUN\r");
input_length = strlen(input_str);
test_type_input("PR#3\rLOAD TESTHIRES\rLIST\rLIST\rPOKE 7986,127\rRUN\r");
c_debugger_go();
if (test_do_reboot) {
@ -357,8 +292,7 @@ TEST test_hires_80colmix_inverse() {
BOOT_TO_DOS();
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] != TEST_FINISHED);
input_str = strdup("INVERSE\rPR#3\rLOAD TESTHIRES\rLIST\rLIST\rPOKE 7986,127\rRUN\r");
input_length = strlen(input_str);
test_type_input("INVERSE\rPR#3\rLOAD TESTHIRES\rLIST\rLIST\rPOKE 7986,127\rRUN\r");
c_debugger_go();
if (test_do_reboot) {

View File

@ -11,10 +11,7 @@
#include "testcommon.h"
#define RESET_INPUT() \
input_counter = 0; \
input_length = 0; \
input_str[0] = '\0'
#define RESET_INPUT() test_common_setup()
#ifdef HAVE_OPENSSL
#include <openssl/sha.h>
@ -22,26 +19,19 @@
#error "these tests require OpenSSL libraries (SHA)"
#endif
static char input_str[TESTBUF_SZ]; // ASCII
static unsigned int input_length = 0;
static unsigned int input_counter = 0;
static bool test_do_reboot = true;
static struct timespec t0 = { 0 };
static struct timespec ti = { 0 };
extern unsigned char joy_button0;
static void testvm_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;
RESET_INPUT();
joy_button0 = 0xff; // OpenApple
if (test_do_reboot) {
cpu65_interrupt(ResetSig);
}
clock_gettime(CLOCK_MONOTONIC, &t0);
}
static void testvm_teardown(void *arg) {
@ -55,46 +45,6 @@ static void sha1_to_str(const uint8_t * const md, char *buf) {
sprintf(buf+i, "%c", '\0');
}
// ----------------------------------------------------------------------------
// test video functions and stubs
void testing_video_sync() {
#if !HEADLESS
if (!is_headless) {
clock_gettime(CLOCK_MONOTONIC, &ti);
struct timespec deltat = timespec_diff(t0, ti, NULL);
if (deltat.tv_sec || (deltat.tv_nsec >= NANOSECONDS/15) ) {
video_sync(0);
ti = t0;
}
}
#endif
if (!input_length) {
input_length = strlen(input_str);
}
if (input_counter >= input_length) {
return;
}
uint8_t ch = (uint8_t)input_str[input_counter];
if (ch == '\n') {
ch = '\r';
}
if ( (apple_ii_64k[0][0xC000] & 0x80) || (apple_ii_64k[1][0xC000] & 0x80) ) {
// last character typed not processed by emulator...
return;
}
apple_ii_64k[0][0xC000] = ch | 0x80;
apple_ii_64k[1][0xC000] = ch | 0x80;
++input_counter;
}
// ----------------------------------------------------------------------------
// VM TESTS ...
@ -113,8 +63,7 @@ TEST test_read_keyboard() {
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] != TEST_FINISHED);
ASSERT(apple_ii_64k[0][TESTOUT_ADDR] == 0x00);
strcpy(input_str, "RUN TESTGETKEY\rZ");
input_length = strlen(input_str);
test_type_input("RUN TESTGETKEY\rZ");
c_debugger_go();
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
@ -129,7 +78,7 @@ TEST test_clear_keyboard() {
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] != TEST_FINISHED);
ASSERT(apple_ii_64k[0][TESTOUT_ADDR] == 0x00);
strcpy(input_str, "RUN TESTCLEARKEY\rZA");
test_type_input("RUN TESTCLEARKEY\rZA");
c_debugger_go();
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
@ -146,7 +95,7 @@ TEST test_read_random() {
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] != TEST_FINISHED);
ASSERT(apple_ii_64k[0][TESTOUT_ADDR] == 0x00);
strcpy(input_str, "RUN TESTRND\r");
test_type_input("RUN TESTRND\r");
c_debugger_go();
ASSERT(apple_ii_64k[0][WATCHPOINT_ADDR] == TEST_FINISHED);
@ -158,26 +107,38 @@ TEST test_read_random() {
// ----------------------------------------------------------------------------
// Softswitch tests
#define TYPE_PAGE2_OFF() \
strcat(input_str, "POKE49236,0\r") /* C054 */
#define TYPE_PAGE2_ON() \
strcat(input_str, "POKE49237,0\r") /* C055 */
#define TYPE_80STORE_OFF() \
strcat(input_str, "POKE49152,0\r") /* C000 */
test_type_input("POKE49152,0:REM C000 80STORE OFF\r")
#define TYPE_80STORE_ON() \
strcat(input_str, "POKE49153,0\r") /* C001 */
test_type_input("POKE49153,0:REM C001 80STORE ON\r")
#define TYPE_TEXT_OFF() \
test_type_input("POKE49232,0:REM C050 TEXT OFF\r")
#define TYPE_TEXT_ON() \
test_type_input("POKE49233,0:REM C051 TEXT ON\r")
#define TYPE_MIXED_OFF() \
test_type_input("POKE49234,0:REM C052 MIXED OFF\r")
#define TYPE_MIXED_ON() \
test_type_input("POKE49235,0:REM C053 MIXED ON\r")
#define TYPE_PAGE2_OFF() \
test_type_input("POKE49236,0:REM C054 PAGE2 OFF\r")
#define TYPE_PAGE2_ON() \
test_type_input("POKE49237,0:REM C055 PAGE2 ON\r")
#define TYPE_HIRES_OFF() \
strcat(input_str, "POKE49238,0\r") /* C056 */
test_type_input("POKE49238,0:REM C056 SS_HIRES OFF\r")
#define TYPE_HIRES_ON() \
strcat(input_str, "POKE49239,0\r") /* C057 */
test_type_input("POKE49239,0:REM C057 SS_HIRES ON\r")
#define TYPE_TRIGGER_WATCHPT() \
strcat(input_str, "POKE7987,255\r")
test_type_input("POKE7987,255:REM TRIGGER DEBUGGER\r")
TEST test_PAGE2_on(bool ss_80store, bool ss_hires) {
BOOT_TO_DOS();