Improve build system and add support for tests

This commit is contained in:
madmaurice 2023-08-28 21:56:54 +02:00
parent 505478b840
commit b64c82ec92
4 changed files with 49 additions and 5 deletions

View file

@ -4,6 +4,6 @@ modules := memory/mem_device \
cpu/cpu \ cpu/cpu \
cpu/decoder cpu/decoder
modules += test tests := test_bus
CXX_FLAGS := -I $(CURDIR) CXX_FLAGS := -I $(CURDIR)

View file

@ -1,10 +1,35 @@
include Makeconf include Makeconf
$(info $(modules)) emu-objs := $(addsuffix .o,$(modules))
objs := $(addsuffix .o,$(modules)) test-targets := $(patsubst %,tests/%.bin, $(tests))
clean-objs := $(emu-objs) $(test-targets) libemu.a vgbc
.PHONY: all test clean
all: vgbc $(test-targets)
clean:
rm -rf $(clean-objs)
test: $(test-targets)
@for test in $(tests); do \
if ./tests/$$test.bin; then \
echo "-- $$test successful"; \
else \
echo "-- $$test failed"; \
exit 1; \
fi \
done
%.o: %.cpp %.o: %.cpp
g++ $(CXX_FLAGS) -c -o $@ $^ g++ $(CXX_FLAGS) -c -o $@ $^
vgbc: $(objs) libemu.a: $(emu-objs)
g++ -o $@ $^ ar -rc $@ $^
tests/%.bin: tests/%.cpp libemu.a
g++ $(CXX_FLAGS) -o $@ $^
vgbc: main.c libemu.a
g++ $(CXX_FLAGS) -o $@ $^

4
main.c Normal file
View file

@ -0,0 +1,4 @@
int main(int argc, char** argv)
{
return 0;
}

15
tests/test_bus.cpp Normal file
View file

@ -0,0 +1,15 @@
#include <iostream>
#include "memory/bus.h"
#include "memory/ram.h"
int main(int argc, char** argv)
{
RAM r(0x1000);
Bus b;
b.map_device(0x0000, 0x0FFF, &r);
b.map_device(0x2000, 0x2FFF, &r);
b.write8(0x60, 42);
return (b.read8(0x2060) == 42) ? 0 : 1;
}