From b40f5864c1baa634cf6033906f7848c770cc3ef9 Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Fri, 8 Apr 2016 16:52:40 +0200 Subject: [PATCH] Batch processing for scripts/torture/ --- scripts/torture/.gitignore | 9 +++- scripts/torture/Makefile | 53 ++++++++++++++++++++-- scripts/torture/riscv-torture-genloop.diff | 40 ++++++++++++++++ 3 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 scripts/torture/riscv-torture-genloop.diff diff --git a/scripts/torture/.gitignore b/scripts/torture/.gitignore index ee8e834..a1de2e4 100644 --- a/scripts/torture/.gitignore +++ b/scripts/torture/.gitignore @@ -1,4 +1,11 @@ +.looplog riscv-fesvr riscv-isa-sim riscv-torture -test.* +tests +test.S +test.elf +test.bin +test.hex +test.ref +test.vvp diff --git a/scripts/torture/Makefile b/scripts/torture/Makefile index 79cc906..42a927e 100644 --- a/scripts/torture/Makefile +++ b/scripts/torture/Makefile @@ -5,7 +5,9 @@ test: riscv-torture/build.ok riscv-isa-sim/build.ok riscv-torture/build.ok: riscv-torture-rv32.diff rm -rf riscv-torture git clone https://github.com/ucb-bar/riscv-torture.git riscv-torture - cd riscv-torture && git checkout 2bc0c42 && patch -p1 < ../riscv-torture-rv32.diff + cd riscv-torture && git checkout 2bc0c42 + cd riscv-torture && patch -p1 < ../riscv-torture-rv32.diff + cd riscv-torture && patch -p1 < ../riscv-torture-genloop.diff cd riscv-torture && ./sbt generator/run && touch build.ok riscv-fesvr/build.ok: @@ -20,9 +22,54 @@ riscv-isa-sim/build.ok: riscv-fesvr/build.ok 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 +batch_list = $(shell bash -c 'for i in {0..999}; do printf "%03d\n" $$i; done') + +batch: $(addprefix tests/test_,$(addsuffix .ok,$(batch_list))) + +tests/testbench.vvp: testbench.v ../../picorv32.v + mkdir -p tests + iverilog -o tests/testbench.vvp testbench.v ../../picorv32.v + +tests/generated.ok: riscv-torture/build.ok + rm -f riscv-torture/output/test_* + cd riscv-torture && ./sbt 'generator/run -n 1000' + touch tests/generated.ok + +define test_template +tests/test_$(1).S: tests/generated.ok + mkdir -p tests + mv riscv-torture/output/test_$(1).S tests/ + +tests/test_$(1).elf: tests/test_$(1).S + riscv32-unknown-elf-gcc -m32 -ffreestanding -nostdlib -Wl,-Bstatic,-T,sections.lds -I. -o tests/test_$(1).elf tests/test_$(1).S + +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 + +tests/test_$(1).ok: tests/testbench.vvp tests/test_$(1).hex tests/test_$(1).ref + vvp tests/testbench.vvp +hex=tests/test_$(1).hex +ref=tests/test_$(1).ref | tee tests/test_$(1).out + 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 \ + rm -rf tests; $(MAKE) batch; \ + date +"%s %Y-%m-%d %H:%M:%S NEXT" >> .looplog; \ + done + clean: - rm -rf riscv-torture riscv-fesvr riscv-isa-sim + rm -rf riscv-torture riscv-fesvr riscv-isa-sim tests rm -f test.S test.elf test.bin test.hex test.ref test.vvp -.PHONY: test clean +.PHONY: test batch loop clean diff --git a/scripts/torture/riscv-torture-genloop.diff b/scripts/torture/riscv-torture-genloop.diff new file mode 100644 index 0000000..a0a2fd1 --- /dev/null +++ b/scripts/torture/riscv-torture-genloop.diff @@ -0,0 +1,40 @@ +diff --git a/generator/src/main/scala/main.scala b/generator/src/main/scala/main.scala +index 7c78982..1572771 100644 +--- a/generator/src/main/scala/main.scala ++++ b/generator/src/main/scala/main.scala +@@ -8,7 +8,7 @@ import java.util.Properties + import scala.collection.JavaConversions._ + + case class Options(var outFileName: String = "test", +- var confFileName: String = "config/default.config") ++ var confFileName: String = "config/default.config", var numOutFiles: Int = 0) + + object Generator extends App + { +@@ -17,15 +17,25 @@ object Generator extends App + val parser = new OptionParser[Options]("generator/run") { + opt[String]('C', "config") valueName("") text("config file") action {(s: String, c) => c.copy(confFileName = s)} + opt[String]('o', "output") valueName("") text("output filename") action {(s: String, c) => c.copy(outFileName = s)} ++ opt[Int]('n', "numfiles") valueName("") text("number of output files") action {(n: Int, c) => c.copy(numOutFiles = n)} + } + parser.parse(args, Options()) match { + case Some(opts) => +- generate(opts.confFileName, opts.outFileName) ++ generate_loop(opts.confFileName, opts.outFileName, opts.numOutFiles) + case None => + System.exit(1) //error message printed by parser + } + } + ++ def generate_loop(confFile: String, outFileName: String, numOutFiles: Int) = { ++ if (numOutFiles > 0) { ++ for (i <- 0 to (numOutFiles-1)) ++ generate(confFile, outFileName + ("_%03d" format (i))) ++ } else { ++ generate(confFile, outFileName) ++ } ++ } ++ + def generate(confFile: String, outFileName: String): String = { + val config = new Properties() + val in = new FileInputStream(confFile)