Skip to content

Commit

Permalink
Improvements to the testing tools.
Browse files Browse the repository at this point in the history
  • Loading branch information
redcode committed Jan 30, 2025
1 parent f7ec2be commit 9e91b15
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 53 deletions.
89 changes: 51 additions & 38 deletions sources/step-test-Z80.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,14 @@ static Z80 cpu;
static Z80InsnClock insn_clock;
static zuint8 memory[Z_USIZE(65536)];

static Cycle *cycles;
static zuint cycles_size;
static zuint cycles_index;

static Port *ports;
static zuint ports_size;
static zuint ports_index;

static cJSON *expected_ports;
static zuint expected_port_count;
static Cycle* cycles;
static zuint cycles_size;
static zuint cycles_index;
static Port* ports;
static zuint ports_size;
static zuint ports_index;
static cJSON* expected_ports;
static zuint expected_port_count;

static zbool file_failed, test_failed, array_failed;
static char const *field_separator = "";
Expand Down Expand Up @@ -448,16 +446,21 @@ static void print_cycle_mismatch(cJSON *test, zuint index, Cycle const *actual,
field_separator = ",";
}

if (actual != Z_NULL) *(zuint16 *)actual_value = data_bus_value_to_string(actual ->value);
if (expected != Z_NULL) *(zuint16 *)expected_value = data_bus_value_to_string(expected->value);
if (actual != Z_NULL)
*(zuint16 *)actual_value = data_bus_value_to_string(actual ->value);

if (expected != Z_NULL)
*(zuint16 *)expected_value = data_bus_value_to_string(expected->value);

printf("%u", index + 1);

if (actual == Z_NULL)
printf(" ****""/%04X **""/%.2s ****""/%.4s", expected->address, expected_value, expected->pins);
printf( " ****""/%04X **""/%.2s ****""/%.4s",
expected->address, expected_value, expected->pins);

else if (expected == Z_NULL)
printf(" %04X/""**** %.2s/""** %.4s/""****", actual->address, actual_value, actual->pins);
printf( " %04X/""**** %.2s/""** %.4s/""****",
actual->address, actual_value, actual->pins);

else {
if (actual->address != expected->address)
Expand Down Expand Up @@ -487,10 +490,12 @@ static void print_port_mismatch(cJSON *test, zuint index, Port const *actual, Po
printf("%u", index + 1);

if (actual == Z_NULL)
printf(" ****""/%04X **""/%02X *""/%c", expected->port, expected->value, expected->direction);
printf( " ****""/%04X **""/%02X *""/%c",
expected->port, expected->value, expected->direction);

else if (expected == Z_NULL)
printf(" %04X/""**** %02X/""** %c/""*", actual->port, actual->value, actual->direction);
printf( " %04X/""**** %02X/""** %c/""*",
actual->port, actual->value, actual->direction);

else {
if (actual->port != expected->port)
Expand Down Expand Up @@ -540,8 +545,8 @@ static Port read_port_item(cJSON const *item)
}


static zbool string_is_option(char const* string, char const* short_option, char const* long_option)
{return !strcmp(string, short_option) || !strcmp(string, long_option);}
static zbool string_is_option(char const *string, char const *option)
{return (*string == *option && string[1] == '\0') || !strcmp(string, &option[1]);}


int main(int argc, char **argv)
Expand All @@ -551,26 +556,27 @@ int main(int argc, char **argv)
zbool test_pins = Z_FALSE;
zbool read_from_stdin = Z_FALSE;
zuint8 verbosity = 2;
zuint file_count;
zuint read_error_count = 0;
zuint bad_file_count = 0;
zuint passed_file_count = 0;
zuint failed_file_count = 0;
zuint test_count;
zuint passed_test_count = 0;
zuint failed_test_count = 0;
int i = 0;
zuint j;
char const *invalid;
zuint file_count;
zuint read_error_count;
zuint bad_file_count;
zuint passed_file_count;
zuint failed_file_count;
zuint test_count;
zuint passed_test_count;
zuint failed_test_count;
char const *option;
# define invalid option

/* The emulator is set to Zilog NMOS by default */
cpu.options = Z80_MODEL_ZILOG_NMOS;

/* Parse the command line. */

while (++i < argc && *argv[i] == '-' && argv[i][1] != '\0')
while (++i < argc && *argv[i] == '-' && *(option = &argv[i][1]) != '\0')
{
if (string_is_option(argv[i], "-V", "--version"))
if (string_is_option(option, "V-version"))
{
puts( "step-test-Z80 v" Z80_LIBRARY_VERSION_STRING "\n"
"Copyright (C) 2024-2025 Manuel Sainz de Baranda y Goñi.\n"
Expand All @@ -579,7 +585,7 @@ int main(int argc, char **argv)
return 0;
}

else if (string_is_option(argv[i], "-h", "--help"))
else if (string_is_option(option, "h-help"))
{
printf( "Usage: step-test-Z80 [options] <JSON-file>...\n"
"\n"
Expand All @@ -603,10 +609,10 @@ int main(int argc, char **argv)
return 0;
}

else if (string_is_option(argv[i], "-j", "--json-output"))
else if (string_is_option(option, "j-json-output"))
produce_json_output = Z_TRUE;

else if (string_is_option(argv[i], "-m", "--model"))
else if (string_is_option(option, "m-model"))
{
if (++i == argc) goto incomplete_option;

Expand All @@ -622,13 +628,13 @@ int main(int argc, char **argv)
cpu_model_found: continue;
}

else if (string_is_option(argv[i], "-p", "--pins"))
else if (string_is_option(option, "p-pins"))
test_pins = Z_TRUE;

else if (string_is_option(argv[i], "-t", "--test-format"))
else if (string_is_option(option, "t-test-format"))
test_format_and_exit = Z_TRUE;

else if (string_is_option(argv[i], "-v", "--verbosity"))
else if (string_is_option(option, "v-verbosity"))
{
char *end;
zulong parsed;
Expand Down Expand Up @@ -657,8 +663,15 @@ int main(int argc, char **argv)
goto bad_syntax;
}

/* Initialize the CPU emulator and the instruction clock. */
/* Initialize the result counters. */
read_error_count =
bad_file_count =
passed_file_count =
failed_file_count =
passed_test_count =
failed_test_count = 0;

/* Initialize the CPU emulator and the instruction clock. */
cpu.context = Z_NULL;
cpu.fetch_opcode = cpu_fetch_opcode;
cpu.nop = cpu_nop;
Expand All @@ -675,7 +688,7 @@ int main(int argc, char **argv)
cpu.hook = Z_NULL;
cpu.illegal = Z_NULL;

z80_insn_clock_initialize(&insn_clock, &cpu.af, &cpu.bc, &cpu.hl, &cpu, insn_clock_read);
z80_insn_clock_initialize(&insn_clock, &cpu.af, &cpu.bc, &cpu.hl, Z_NULL, insn_clock_read);

cycles = Z_NULL;
ports = Z_NULL;
Expand Down Expand Up @@ -1019,7 +1032,7 @@ int main(int argc, char **argv)
return -1;
}

/* Print results summary. */
/* Print the results. */

printf( "\nResults:%c%u file%s in total",
test_format_and_exit ? ' ' : '\n',
Expand Down
33 changes: 18 additions & 15 deletions sources/test-Z80.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@

typedef struct {
/* Name of the archive if the file is compressed; `Z_NULL` otherwise. */
char const* archive_name;
char const *archive_name;

/* Name of the file, or path to the file inside the archive if the file
* is compressed. */
char const* file_path;
char const *file_path;

/* Total number of clock cycles executed when the test passes. */
zusize cycles[1 + (Z_USIZE_WIDTH < 64)];
Expand Down Expand Up @@ -658,7 +658,7 @@ static zuint8 run_test(int test_index)
/*--------------------------------------------------------------------.
| The test is considered passed if it has reached its exit address at |
| the correct clock cycle, has not printed any unsupported characters |
| and has printed the expected output within the correct margins. |
| and has produced the expected output within the correct margins. |
'====================================================================*/

if (!completed) failure = "Aborted due to exceeding the clock cycle limit";
Expand Down Expand Up @@ -705,11 +705,11 @@ static zuint8 run_test(int test_index)
}


static zbool string_is_option(char const* string, char const* short_option, char const* long_option)
{return !strcmp(string, short_option) || !strcmp(string, long_option);}
static zbool string_is_option(char const *string, char const *option)
{return (*string == *option && string[1] == '\0') || !strcmp(string, &option[1]);}


static zbool string_to_uint8(char const* string, zuint8 maximum, zuint8 *value)
static zbool string_to_uint8(char const *string, zuint8 maximum, zuint8 *value)
{
char *end;
zulong parsed = strtoul(string, &end, 0);
Expand All @@ -726,12 +726,13 @@ int main(int argc, char **argv)
zusize maximum_search_path_size = 0;
zuint32 tests_run;
int j, i = 0;
char const *option;

/*--------------------------------------------.
| String specifying what has been detected as |
| invalid when parsing the command line. |
'============================================*/
char const *invalid;
# define invalid option

/*------------------------------.
| [0] = Number of tests failed. |
Expand All @@ -747,7 +748,9 @@ int main(int argc, char **argv)

while (++i < argc && *argv[i] == '-')
{
if (string_is_option(argv[i], "-V", "--version"))
option = &argv[i][1];

if (string_is_option(option, "V-version"))
{
puts( "test-Z80 v" Z80_LIBRARY_VERSION_STRING "\n"
"Copyright (C) 2021-2025 Manuel Sainz de Baranda y Goñi.\n"
Expand All @@ -756,7 +759,7 @@ int main(int argc, char **argv)
goto exit_without_error;
}

else if (string_is_option(argv[i], "-h", "--help"))
else if (string_is_option(option, "h-help"))
{
puts( "Usage:\n"
" test-Z80 [options] --all [<test>...]\n"
Expand Down Expand Up @@ -813,22 +816,22 @@ int main(int argc, char **argv)
goto exit_without_error;
}

else if (string_is_option(argv[i], "-0", "--in-even"))
else if (string_is_option(option, "0-in-even"))
{
if (++i == argc) goto incomplete_option;
if (!string_to_uint8(argv[i], 255, &in_values[0])) goto invalid_io_value;
}

else if (string_is_option(argv[i], "-1", "--in-odd"))
else if (string_is_option(option, "1-in-odd"))
{
if (++i == argc) goto incomplete_option;
if (!string_to_uint8(argv[i], 255, &in_values[1])) goto invalid_io_value;
}

else if (string_is_option(argv[i], "-a", "--all"))
else if (string_is_option(option, "a-all"))
all = Z_TRUE;

else if (string_is_option(argv[i], "-m", "--model"))
else if (string_is_option(option, "m-model"))
{
if (++i == argc) goto incomplete_option;

Expand All @@ -844,7 +847,7 @@ int main(int argc, char **argv)
cpu_model_found: continue;
}

else if (string_is_option(argv[i], "-p", "--path"))
else if (string_is_option(option, "p-path"))
{
char **p;
zusize s;
Expand All @@ -866,7 +869,7 @@ int main(int argc, char **argv)
search_paths[search_path_count++] = argv[i];
}

else if (string_is_option(argv[i], "-v", "--verbosity"))
else if (string_is_option(option, "v-verbosity"))
{
if (++i == argc) goto incomplete_option;

Expand Down

0 comments on commit 9e91b15

Please sign in to comment.