diff --git a/Makefile b/Makefile index cedd59c..748b086 100755 --- a/Makefile +++ b/Makefile @@ -1,7 +1,8 @@ -OUT=build +build=OUT COV_DIR=$(OUT)/coverage/ SRC_DIR=src APP_DIR=src/apps/ +OUT=build CC=gcc @@ -36,9 +37,9 @@ LDFLAGS += -lglib-2.0 C_SOURCES = $(shell find $(SRC_DIR) -name "*.c") ALL_OBJS = $(patsubst $(SRC_DIR)/%.c, $(OUT)/%.o, $(C_SOURCES)) APP_OBJS = $(filter $(OUT)/apps/%, $(ALL_OBJS)) -OBJS = $(filter-out $(APP_OBJS), $(ALL_OBJS)) +TEST_OBJS = $(filter $(OUT)%test.o, $(ALL_OBJS)) +OBJS = $(filter-out $(TEST_OBJS) $(APP_OBJS), $(ALL_OBJS)) APPS = $(patsubst %.o, %, $(APP_OBJS)) - .PHONY: all all: gbdb gbasm tests @@ -66,7 +67,7 @@ gbasm: $(OUT)/apps/gbasm .PHONY: gbasm-test sample-test tests -TESTS=$(OUT)/apps/gbasm_test $(OUT)/apps/tri_test $(OUT)/apps/cpu_integ_test +TESTS = $(patsubst %.o, %, $(filter %/test.o, $(ALL_OBJS))) tests: $(TESTS) $(ALL_APPS) $(ALL_OBJS): $(CONFIG) @@ -77,7 +78,7 @@ $(OUT)/%.o: $(SRC_DIR)/%.c @$(CC) -c $(CCFLAGS) -o $@ $< .SECONDEXPANSION: -$(APPS): $(OBJS) $$@.o +$(APPS) $(TESTS): $(OBJS) $$@.o @echo " LD $@" @$(shell mkdir -p $(@D)) @$(CC) $^ $(LDFLAGS) -o $@ @@ -106,13 +107,10 @@ $(COV_BASE): @lcov -q -c -i -d $(OUT) -o $(COV_BASE) $(COV_DIR)/coverage.info coverage: $(TESTS) $(COV_BASE) - @for test in $(TESTS); do \ - echo " TEST $$test"; \ - $$test -q; \ - echo " LCOV $$(basename $$test)"; \ - lcov -q -c -d $(OUT) -o $(COV_DIR)$$(basename $$test).info -t $$(basename $$test); \ - done - @lcov -q $$(for i in $$(ls -1 $(COV_DIR)*.info); do echo "-a $$i"; done) -o $(COV_DIR)coverage.info + $(call run_tests) + @lcov -q -c -d $(OUT) -o $(COV_DIR)results.info -t results + @lcov -q -a $(COV_DIR)results.info -o $(COV_DIR)coverage.info + @lcov --summary $(COV_DIR)coverage.info coverage-report: coverage @mkdir -p $(COV_DIR)/html/ diff --git a/src/apps/gbdb.c b/src/apps/gbdb.c index cabf6ad..de1d397 100644 --- a/src/apps/gbdb.c +++ b/src/apps/gbdb.c @@ -10,11 +10,11 @@ #include #include -#include "common.h" +#include "common/common.h" #include "gb_disas.h" -#include "cpu.h" -#include "video.h" -#include "tri.h" +#include "gbemu/cpu.h" +#include "gbemu/video.h" +#include "common/tri.h" #define INPUT_MAX_LEN 512 #define MAX_BREAKPTS 256 /* Should be plenty for anyone */ diff --git a/src/common.c b/src/common/common.c similarity index 83% rename from src/common.c rename to src/common/common.c index 74144ee..9f95431 100644 --- a/src/common.c +++ b/src/common/common.c @@ -1,4 +1,4 @@ -#include "common.h" +#include "common/common.h" void downcase(char *str) { diff --git a/src/common.h b/src/common/common.h similarity index 100% rename from src/common.h rename to src/common/common.h diff --git a/src/apps/tri_test.c b/src/common/tests/test.c similarity index 98% rename from src/apps/tri_test.c rename to src/common/tests/test.c index 0ac9ffa..1e66e43 100644 --- a/src/apps/tri_test.c +++ b/src/common/tests/test.c @@ -1,5 +1,5 @@ -#include "tri.h" -#include "common.h" +#include "common/tri.h" +#include "common/common.h" #include #include diff --git a/src/tri.c b/src/common/tri.c similarity index 98% rename from src/tri.c rename to src/common/tri.c index bde1921..1f8682b 100644 --- a/src/tri.c +++ b/src/common/tri.c @@ -3,8 +3,8 @@ #include #include -#include "tri.h" -#include "common.h" +#include "common/tri.h" +#include "common/common.h" static size_t char_to_idx(char c) { diff --git a/src/tri.h b/src/common/tri.h similarity index 100% rename from src/tri.h rename to src/common/tri.h diff --git a/src/util.h b/src/common/util.h similarity index 100% rename from src/util.h rename to src/common/util.h diff --git a/src/gbasm/assemble.c b/src/gbasm/assemble.c index 8cc6dd1..b61d2c2 100644 --- a/src/gbasm/assemble.c +++ b/src/gbasm/assemble.c @@ -5,7 +5,7 @@ #include "gbasm/types.h" #include "gbasm/errors.h" #include "gbasm/opcodes.h" -#include "common.h" +#include "common/common.h" #define GBASM_MAX_INSTS 1024 diff --git a/src/gbasm/emit.c b/src/gbasm/emit.c index e93d6e4..f35f729 100644 --- a/src/gbasm/emit.c +++ b/src/gbasm/emit.c @@ -4,7 +4,7 @@ #include #include "gbasm/emitter.h" -#include "common.h" +#include "common/common.h" int emit(struct emitter *emitter, const void *data, size_t size) { diff --git a/src/gbasm/opcodes.c b/src/gbasm/opcodes.c index a1daab4..f6bfdae 100644 --- a/src/gbasm/opcodes.c +++ b/src/gbasm/opcodes.c @@ -2,8 +2,8 @@ #include "gbasm/opcodes.h" #include "gbasm/errors.h" -#include "tri.h" -#include "common.h" +#include "common/tri.h" +#include "common/common.h" #define MAX_OPCODE_LEN 10 /*TODO: Check that's enough */ diff --git a/src/gbasm/operands.c b/src/gbasm/operands.c index 24188cc..8725f99 100644 --- a/src/gbasm/operands.c +++ b/src/gbasm/operands.c @@ -2,8 +2,8 @@ #include "gbasm/opcodes.h" #include "gbasm/errors.h" -#include "tri.h" -#include "common.h" +#include "common/tri.h" +#include "common/common.h" #include diff --git a/src/gbasm/parser.c b/src/gbasm/parser.c index a52a262..d196bec 100644 --- a/src/gbasm/parser.c +++ b/src/gbasm/parser.c @@ -4,7 +4,7 @@ #include #include -#include "common.h" +#include "common/common.h" #include "gbasm/parser.h" #include "gbasm/gb_types.h" #include "gbasm/operands.h" diff --git a/src/tests/gbasm/fixed.c b/src/gbasm/tests/fixed.c similarity index 94% rename from src/tests/gbasm/fixed.c rename to src/gbasm/tests/fixed.c index d20c973..b345712 100644 --- a/src/tests/gbasm/fixed.c +++ b/src/gbasm/tests/fixed.c @@ -1,5 +1,5 @@ -#include "tests/gbasm/test.h" -#include "common.h" +#include "gbasm/tests/test.h" +#include "common/common.h" #define GEN_FIXED_TEST(_opcode, _hex)\ uint8_t _opcode##_output[] = _hex; \ diff --git a/src/tests/gbasm/fixed.h b/src/gbasm/tests/fixed.h similarity index 66% rename from src/tests/gbasm/fixed.h rename to src/gbasm/tests/fixed.h index 00b7a33..3077a20 100644 --- a/src/tests/gbasm/fixed.h +++ b/src/gbasm/tests/fixed.h @@ -1,8 +1,8 @@ #ifndef GBASM_TEST_FIXED_H #define GBASM_TEST_FIXED_H -#include "tests/gbasm/test.h" -#include "common.h" +#include "gbasm/tests/test.h" +#include "common/common.h" extern const struct gbasm_tests gbasm_fixed_tests; diff --git a/src/tests/gbasm/inc.c b/src/gbasm/tests/inc.c similarity index 92% rename from src/tests/gbasm/inc.c rename to src/gbasm/tests/inc.c index 89e82fa..f015128 100644 --- a/src/tests/gbasm/inc.c +++ b/src/gbasm/tests/inc.c @@ -1,5 +1,5 @@ -#include "tests/gbasm/test.h" -#include "common.h" +#include "gbasm/tests/test.h" +#include "common/common.h" /* TODO: There is probably a better way to do this */ static const char all_src[] = diff --git a/src/tests/gbasm/inc.h b/src/gbasm/tests/inc.h similarity index 65% rename from src/tests/gbasm/inc.h rename to src/gbasm/tests/inc.h index c7eedcb..49c8431 100644 --- a/src/tests/gbasm/inc.h +++ b/src/gbasm/tests/inc.h @@ -1,8 +1,8 @@ #ifndef GBASM_TEST_INC_H #define GBASM_TEST_INC_H -#include "tests/gbasm/test.h" -#include "common.h" +#include "gbasm/tests/test.h" +#include "common/common.h" extern const struct gbasm_tests gbasm_inc_tests; diff --git a/src/apps/gbasm_test.c b/src/gbasm/tests/test.c similarity index 93% rename from src/apps/gbasm_test.c rename to src/gbasm/tests/test.c index 41b6fb0..a55cd4a 100644 --- a/src/apps/gbasm_test.c +++ b/src/gbasm/tests/test.c @@ -1,9 +1,9 @@ #include "gbasm/assemble.h" #include "gbasm/emitter.h" -#include "tests/gbasm/test.h" -#include "tests/gbasm/inc.h" -#include "tests/gbasm/fixed.h" -#include "common.h" +#include "gbasm/tests/test.h" +#include "gbasm/tests/inc.h" +#include "gbasm/tests/fixed.h" +#include "common/common.h" #include /* memset */ #include diff --git a/src/tests/gbasm/test.h b/src/gbasm/tests/test.h similarity index 100% rename from src/tests/gbasm/test.h rename to src/gbasm/tests/test.h diff --git a/src/cpu.c b/src/gbemu/cpu.c similarity index 99% rename from src/cpu.c rename to src/gbemu/cpu.c index 48664ff..4058b58 100644 --- a/src/cpu.c +++ b/src/gbemu/cpu.c @@ -6,8 +6,8 @@ #include #include -#include "cpu.h" -#include "common.h" +#include "gbemu/cpu.h" +#include "common/common.h" #define WRITE_BIT(x, idx, bit) \ do {(x) &= (~(1 << (idx)) | ((bit) << (idx)));} while(0) diff --git a/src/cpu.h b/src/gbemu/cpu.h similarity index 100% rename from src/cpu.h rename to src/gbemu/cpu.h diff --git a/src/apps/cpu_integ_test.c b/src/gbemu/tests/test.c similarity index 97% rename from src/apps/cpu_integ_test.c rename to src/gbemu/tests/test.c index 21dcf50..33fca78 100644 --- a/src/apps/cpu_integ_test.c +++ b/src/gbemu/tests/test.c @@ -1,7 +1,7 @@ #include "gbasm/assemble.h" #include "gbasm/emitter.h" -#include "cpu.h" -#include "common.h" +#include "gbemu/cpu.h" +#include "common/common.h" #include /* memset */ #include diff --git a/src/video.c b/src/gbemu/video.c similarity index 98% rename from src/video.c rename to src/gbemu/video.c index e951f15..51fe2aa 100644 --- a/src/video.c +++ b/src/gbemu/video.c @@ -1,4 +1,4 @@ -#include "video.h" +#include "gbemu/video.h" #include diff --git a/src/video.h b/src/gbemu/video.h similarity index 100% rename from src/video.h rename to src/gbemu/video.h