2016-04-06 22:38:57 +08:00
|
|
|
|
2016-04-10 18:35:16 +08:00
|
|
|
# Icarus Verilog
|
|
|
|
#TESTBENCH_EXE = tests/testbench.vvp
|
|
|
|
|
|
|
|
# Verilator
|
|
|
|
TESTBENCH_EXE = obj_dir/Vtestbench
|
|
|
|
|
2016-04-08 22:08:23 +08:00
|
|
|
test: riscv-torture/build.ok riscv-isa-sim/build.ok
|
|
|
|
bash test.sh
|
2016-04-06 22:38:57 +08:00
|
|
|
|
|
|
|
riscv-torture/build.ok: riscv-torture-rv32.diff
|
|
|
|
rm -rf riscv-torture
|
|
|
|
git clone https://github.com/ucb-bar/riscv-torture.git riscv-torture
|
2016-04-08 22:52:40 +08:00
|
|
|
cd riscv-torture && git checkout 2bc0c42
|
|
|
|
cd riscv-torture && patch -p1 < ../riscv-torture-rv32.diff
|
|
|
|
cd riscv-torture && patch -p1 < ../riscv-torture-genloop.diff
|
2016-04-06 22:38:57 +08:00
|
|
|
cd riscv-torture && ./sbt generator/run && touch build.ok
|
|
|
|
|
|
|
|
riscv-fesvr/build.ok:
|
|
|
|
rm -rf riscv-fesvr
|
|
|
|
git clone https://github.com/riscv/riscv-fesvr.git riscv-fesvr
|
|
|
|
+cd riscv-fesvr && git checkout 1c02bd6 && ./configure && make && touch build.ok
|
|
|
|
|
|
|
|
riscv-isa-sim/build.ok: riscv-fesvr/build.ok
|
|
|
|
rm -rf riscv-isa-sim
|
|
|
|
git clone https://github.com/riscv/riscv-isa-sim.git riscv-isa-sim
|
2016-04-09 20:09:22 +08:00
|
|
|
cd riscv-isa-sim && git checkout 10ae74e
|
|
|
|
cd riscv-isa-sim && patch -p1 < ../riscv-isa-sim-sbreak.diff
|
|
|
|
cd riscv-isa-sim && patch -p1 < ../riscv-isa-sim-notrap.diff
|
2016-04-06 22:38:57 +08:00
|
|
|
cd riscv-isa-sim && LDFLAGS="-L../riscv-fesvr" ./configure --with-isa=RV32IMC
|
|
|
|
+cd riscv-isa-sim && ln -s ../riscv-fesvr/fesvr . && make && touch build.ok
|
|
|
|
|
2016-04-13 21:30:27 +08:00
|
|
|
batch_size = 1000
|
|
|
|
batch_list = $(shell bash -c 'for i in {0..$(shell expr $(batch_size) - 1)}; do printf "%03d\n" $$i; done')
|
2016-04-08 22:52:40 +08:00
|
|
|
|
|
|
|
batch: $(addprefix tests/test_,$(addsuffix .ok,$(batch_list)))
|
|
|
|
|
2016-04-13 02:17:36 +08:00
|
|
|
config.vh: config.py riscv-torture/build.ok
|
|
|
|
python3 config.py
|
|
|
|
|
|
|
|
obj_dir/Vtestbench: testbench.v testbench.cc ../../picorv32.v config.vh
|
2016-04-10 18:35:16 +08:00
|
|
|
verilator --exe -Wno-fatal --cc --top-module testbench testbench.v ../../picorv32.v testbench.cc
|
|
|
|
$(MAKE) -C obj_dir -f Vtestbench.mk
|
|
|
|
|
2016-04-08 22:52:40 +08:00
|
|
|
tests/testbench.vvp: testbench.v ../../picorv32.v
|
|
|
|
mkdir -p tests
|
|
|
|
iverilog -o tests/testbench.vvp testbench.v ../../picorv32.v
|
|
|
|
|
2016-04-13 02:17:36 +08:00
|
|
|
tests/generated.ok: config.vh riscv-torture/build.ok
|
2016-04-09 19:25:29 +08:00
|
|
|
mkdir -p tests
|
2016-04-08 22:52:40 +08:00
|
|
|
rm -f riscv-torture/output/test_*
|
2016-04-13 21:30:27 +08:00
|
|
|
cd riscv-torture && ./sbt 'generator/run -C config/test.config -n $(batch_size)'
|
2016-04-08 22:52:40 +08:00
|
|
|
touch tests/generated.ok
|
|
|
|
|
|
|
|
define test_template
|
|
|
|
tests/test_$(1).S: tests/generated.ok
|
|
|
|
mv riscv-torture/output/test_$(1).S tests/
|
2016-04-09 19:25:29 +08:00
|
|
|
touch tests/test_$(1).S
|
2016-04-08 22:52:40 +08:00
|
|
|
|
|
|
|
tests/test_$(1).elf: tests/test_$(1).S
|
2016-04-13 02:17:36 +08:00
|
|
|
riscv32-unknown-elf-gcc -m32 `sed '/march=/ ! d; s,^// ,-,;' config.vh` -ffreestanding -nostdlib \
|
|
|
|
-Wl,-Bstatic,-T,sections.lds -I. -o tests/test_$(1).elf tests/test_$(1).S
|
2016-04-08 22:52:40 +08:00
|
|
|
|
|
|
|
tests/test_$(1).bin: tests/test_$(1).elf
|
|
|
|
riscv32-unknown-elf-objcopy -O binary tests/test_$(1).elf tests/test_$(1).bin
|
|
|
|
|
|
|
|
tests/test_$(1).hex: tests/test_$(1).bin
|
|
|
|
python3 ../../firmware/makehex.py tests/test_$(1).bin 4096 > tests/test_$(1).hex
|
|
|
|
|
|
|
|
tests/test_$(1).ref: tests/test_$(1).elf riscv-isa-sim/build.ok
|
|
|
|
LD_LIBRARY_PATH="./riscv-isa-sim:./riscv-fesvr" ./riscv-isa-sim/spike tests/test_$(1).elf > tests/test_$(1).ref
|
|
|
|
|
2016-04-10 18:35:16 +08:00
|
|
|
tests/test_$(1).ok: $(TESTBENCH_EXE) tests/test_$(1).hex tests/test_$(1).ref
|
|
|
|
$(TESTBENCH_EXE) +hex=tests/test_$(1).hex +ref=tests/test_$(1).ref | tee tests/test_$(1).out
|
2016-04-08 22:52:40 +08:00
|
|
|
grep -q PASSED tests/test_$(1).out
|
|
|
|
mv tests/test_$(1).out tests/test_$(1).ok
|
|
|
|
endef
|
|
|
|
|
|
|
|
$(foreach id,$(batch_list),$(eval $(call test_template,$(id))))
|
|
|
|
|
|
|
|
loop:
|
|
|
|
date +"%s %Y-%m-%d %H:%M:%S START" >> .looplog
|
|
|
|
+set -ex; while true; do \
|
2016-04-13 02:17:36 +08:00
|
|
|
rm -rf tests obj_dir config.vh; $(MAKE) batch; \
|
2016-04-08 22:52:40 +08:00
|
|
|
date +"%s %Y-%m-%d %H:%M:%S NEXT" >> .looplog; \
|
|
|
|
done
|
|
|
|
|
2016-04-06 22:38:57 +08:00
|
|
|
clean:
|
2016-04-11 23:08:14 +08:00
|
|
|
rm -rf tests obj_dir
|
2016-04-13 02:17:36 +08:00
|
|
|
rm -f config.vh test.S test.elf test.bin
|
|
|
|
rm -f test.hex test.ref test.vvp test.vcd
|
2016-04-06 22:38:57 +08:00
|
|
|
|
2016-04-11 23:08:14 +08:00
|
|
|
mrproper: clean
|
|
|
|
rm -rf riscv-torture riscv-fesvr riscv-isa-sim
|
|
|
|
|
|
|
|
.PHONY: test batch loop clean mrproper
|
2016-04-06 22:38:57 +08:00
|
|
|
|