From 2c007c3264f43b1e8ddca2c2b9ac1bab90843d2f Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Mon, 25 May 2015 21:32:45 -0400 Subject: [PATCH] A lot of work on general test infrastructure. --- .gitignore | 1 + README.md | 15 ++++-- makefile | 40 ++++++++------- tests/{z80 => cpu}/01_basic_math.asm | 0 tests/{z80 => cpu}/_header.asm | 0 tests/makefile | 18 +++++++ tests/runner.c | 99 +++++++++++++++++++++++++++++++++++- 7 files changed, 151 insertions(+), 22 deletions(-) rename tests/{z80 => cpu}/01_basic_math.asm (100%) rename tests/{z80 => cpu}/_header.asm (100%) create mode 100644 tests/makefile diff --git a/.gitignore b/.gitignore index 18eb94a..f5cc384 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ roms/* !roms/README crater crater-dev +tests/runner diff --git a/README.md b/README.md index 948fb94..fcd8097 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,19 @@ Installing ---------- Only OS X and Linux are tested. You'll need a modern compiler that supports C11 -(clang preferred) and SDL 2. Using Homebrew, you can `brew install sdl2`; using -apt, you can `apt-get install libsdl2-dev`. +([clang][clang] preferred) and [SDL 2][sdl2]. Using Homebrew, you can +`brew install sdl2`; using apt, you can `apt-get install libsdl2-dev`. Run `make` to create `./crater`. To build the development version with debug -symbols (they can exist simultaneously), run `make DEBUG=1`, which creates -`./crater-dev`. This also enables the printing of debugging info to stdout. +symbols and extra diagnostic info (they can exist simultaneously), run +`make DEBUG=1`, which creates `./crater-dev`. + +crater has a number of test cases. Run the entire suite with `make test`; +individual components can be tested by doing `make test-{component}`, where +`{component}` is one of `cpu`, `vdp`, `psg`, `asm`, `dis`, or `integrate`. + +[clang]: http://clang.llvm.org/ +[sdl2]: https://www.libsdl.org/ Usage ----- diff --git a/makefile b/makefile index fdf785b..61ba471 100644 --- a/makefile +++ b/makefile @@ -1,50 +1,59 @@ -# Copyright (C) 2014 Ben Kurtovic +# Copyright (C) 2014-2015 Ben Kurtovic # Released under the terms of the MIT License. See LICENSE for details. PROGRAM = crater SOURCES = src BUILD = build DEVEXT = -dev +TESTS = cpu vdp psg asm dis integrate CC = clang FLAGS = -O2 -Wall -Wextra -pedantic -std=c11 CFLAGS = $(shell sdl2-config --cflags) LIBS = $(shell sdl2-config --libs) +DFLAGS = -g -DDEBUG_MODE MKDIR = mkdir -p RM = rm -rf ASM_UP = scripts/update_asm_instructions.py MODE = release BNRY = $(PROGRAM) +FLGS = $(FLAGS) SDRS = $(shell find $(SOURCES) -type d | xargs echo) SRCS = $(filter-out %.inc.c,$(foreach d,. $(SDRS),$(wildcard $(addprefix $(d)/*,.c)))) OBJS = $(patsubst %.c,%.o,$(addprefix $(BUILD)/$(MODE)/,$(SRCS))) DEPS = $(OBJS:%.o=%.d) DIRS = $(sort $(dir $(OBJS))) +TCPS = $(addprefix test-,$(TESTS)) ifdef DEBUG - BNRY := $(BNRY)$(DEVEXT) - FLAGS += -g -DDEBUG_MODE - MODE = debug + BNRY := $(BNRY)$(DEVEXT) + FLGS += $(DFLAGS) + MODE = debug endif -.PHONY: all clean test test-all test-z80 test-asm test-dasm +export CC +export FLAGS +export RM + +.PHONY: all clean test-prereqs test tests $(TCPS) all: $(BNRY) clean: $(RM) $(BUILD) $(PROGRAM) $(PROGRAM)$(DEVEXT) + $(MAKE) -C tests clean $(DIRS): $(MKDIR) $@ $(BNRY): $(OBJS) - $(CC) $(FLAGS) $(LIBS) $(OBJS) -o $@ + $(CC) $(FLGS) $(LIBS) $(OBJS) -o $@ $(OBJS): | $(DIRS) $(BUILD)/$(MODE)/%.o: %.c - $(CC) $(FLAGS) $(CFLAGS) -MMD -MP -c $< -o $@ + $(CC) $(FLGS) $(CFLAGS) -MMD -MP -c $< -o $@ -include $(DEPS) @@ -52,16 +61,13 @@ ASM_INST = $(SOURCES)/assembler/instructions $(ASM_INST).inc.c: $(ASM_INST).yml $(ASM_UP) python $(ASM_UP) -test: test-all test-z80 test-asm test-dasm - -test-all: - @echo "running all tests" +test-prereqs: + $(MAKE) $(PROGRAM) DEBUG= -test-z80: - @echo "running Z80 CPU tests" +test: test-prereqs + $(MAKE) -C tests all -test-asm: - @echo "running assembler tests" +tests: test -test-dasm: - @echo "running disassembler tests" +$(TCPS): test-prereqs + $(MAKE) -C tests $(subst test-,,$@) diff --git a/tests/z80/01_basic_math.asm b/tests/cpu/01_basic_math.asm similarity index 100% rename from tests/z80/01_basic_math.asm rename to tests/cpu/01_basic_math.asm diff --git a/tests/z80/_header.asm b/tests/cpu/_header.asm similarity index 100% rename from tests/z80/_header.asm rename to tests/cpu/_header.asm diff --git a/tests/makefile b/tests/makefile new file mode 100644 index 0000000..f202e5f --- /dev/null +++ b/tests/makefile @@ -0,0 +1,18 @@ +# Copyright (C) 2014-2015 Ben Kurtovic +# Released under the terms of the MIT License. See LICENSE for details. + +RUNNER = runner +COMPONENTS = cpu vdp psg asm dis integrate + +.PHONY: all clean $(COMPONENTS) + +all: $(COMPONENTS) + +clean: + $(RM) $(RUNNER) + +$(RUNNER): $(RUNNER).c + $(CC) $(FLAGS) $< -o $@ + +$(COMPONENTS): $(RUNNER) + ./$(RUNNER) $@ diff --git a/tests/runner.c b/tests/runner.c index 1763ea4..44a9e4c 100644 --- a/tests/runner.c +++ b/tests/runner.c @@ -1,4 +1,101 @@ /* Copyright (C) 2014-2015 Ben Kurtovic Released under the terms of the MIT License. See LICENSE for details. */ -// ... +#include +#include +#include +#include + +#include "../src/logging.h" + +/* + TODO +*/ +static bool test_cpu() +{ + // TODO + return true; +} + +/* + TODO +*/ +static bool test_vdp() +{ + // TODO + return true; +} + +/* + TODO +*/ +static bool test_psg() +{ + // TODO + return true; +} + +/* + TODO +*/ +static bool test_asm() +{ + // TODO + return true; +} + +/* + TODO +*/ +static bool test_dis() +{ + // TODO + return true; +} + +/* + TODO +*/ +static bool test_integrate() +{ + // TODO + return true; +} + + +/* + Main function. +*/ +int main(int argc, char *argv[]) +{ + if (argc != 2) + FATAL("a component name is required") + + const char *component = argv[1], *name; + bool (*func)(); + + if (!strcmp(component, "cpu")) { + name = "Z80 CPU"; + func = test_cpu; + } else if (!strcmp(component, "vdp")) { + name = "VDP"; + func = test_vdp; + } else if (!strcmp(component, "psg")) { + name = "SN76489 PSG"; + func = test_psg; + } else if (!strcmp(component, "asm")) { + name = "assembler"; + func = test_asm; + } else if (!strcmp(component, "dis")) { + name = "disassembler"; + func = test_dis; + } else if (!strcmp(component, "integrate")) { + name = "integration"; + func = test_integrate; + } else { + FATAL("unknown component: %s", component) + } + + printf("crater: running %s tests\n", name); + return func() ? EXIT_SUCCESS : EXIT_FAILURE; +}