Browse Source

A lot of work on general test infrastructure.

master
Ben Kurtovic 9 years ago
parent
commit
2c007c3264
7 changed files with 151 additions and 22 deletions
  1. +1
    -0
      .gitignore
  2. +11
    -4
      README.md
  3. +23
    -17
      makefile
  4. +0
    -0
      tests/cpu/01_basic_math.asm
  5. +0
    -0
      tests/cpu/_header.asm
  6. +18
    -0
      tests/makefile
  7. +98
    -1
      tests/runner.c

+ 1
- 0
.gitignore View File

@@ -3,3 +3,4 @@ roms/*
!roms/README
crater
crater-dev
tests/runner

+ 11
- 4
README.md View File

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


+ 23
- 17
makefile View File

@@ -1,50 +1,59 @@
# Copyright (C) 2014 Ben Kurtovic <ben.kurtovic@gmail.com>
# Copyright (C) 2014-2015 Ben Kurtovic <ben.kurtovic@gmail.com>
# 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-,,$@)

tests/z80/01_basic_math.asm → tests/cpu/01_basic_math.asm View File


tests/z80/_header.asm → tests/cpu/_header.asm View File


+ 18
- 0
tests/makefile View File

@@ -0,0 +1,18 @@
# Copyright (C) 2014-2015 Ben Kurtovic <ben.kurtovic@gmail.com>
# 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) $@

+ 98
- 1
tests/runner.c View File

@@ -1,4 +1,101 @@
/* Copyright (C) 2014-2015 Ben Kurtovic <ben.kurtovic@gmail.com>
Released under the terms of the MIT License. See LICENSE for details. */

// ...
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#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;
}

Loading…
Cancel
Save