Skip to content

Commit

Permalink
Add Java based test runner
Browse files Browse the repository at this point in the history
This is approximately a 10x speedup on the test suite including
compilation.
  • Loading branch information
TheThirdOne committed Jun 17, 2019
1 parent 07581f9 commit b661ecf
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 15 deletions.
69 changes: 69 additions & 0 deletions Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import rars.AssemblyException;
import rars.SimulationException;
import rars.api.Options;
import rars.api.Program;
import rars.simulator.Simulator;

import java.io.File;

public class Test {
public static void main(String[] args){
Options opt = new Options();
opt.startAtMain = true;
opt.maxSteps = 500;
Program p = new Program(opt);
File[] tests = new File("./test").listFiles(), riscv_tests = new File("./test/riscv-tests").listFiles();
if(tests == null){
System.out.println("./test doesn't exist");
return;
}
StringBuilder total = new StringBuilder("\n");
for(File test : tests){
if(test.isFile() && test.getName().endsWith(".s")){
String errors = run(test.getPath(),p);
if(errors.equals("")) {
System.out.print('.');
}else{
System.out.print('X');
total.append(errors).append('\n');
}
}
}
if(riscv_tests == null){
System.out.println("./test/riscv-tests doesn't exist");
return;
}
for(File test : riscv_tests){
if(test.isFile() && test.getName().endsWith(".s")){
String errors = run(test.getPath(),p);
if(errors.equals("")) {
System.out.print('.');
}else{
System.out.print('X');
total.append(errors).append('\n');
}
}
}
System.out.println(total);
}
public static String run(String path, Program p){
try {
p.assemble(path);
p.setup(null,"");
Simulator.Reason r = p.simulate();
if(r != Simulator.Reason.NORMAL_TERMINATION){
return "Ending abnormally while executing " + path;
}else{
if(p.getExitCode() == 42){
return "";
}else{
return "Final exit code was wrong for " + path;
}
}
} catch (AssemblyException ae){
return "Failed to assemble " + path;
} catch (SimulationException se){
return "Crashed while executing " + path;
}
}
}
18 changes: 3 additions & 15 deletions test.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
#!/bin/bash
RUN="java -jar -ea ./rars.jar"
ERRORS=""
for f in ./test/*.s ./test/riscv-tests/*.s
do
$RUN $f > /dev/null
if [ $? -eq 42 ]
then
printf "."
else
printf "X"
ERRORS="$ERRORS\nFailure on file $f"
fi
done

printf "$ERRORS\n"
javac -cp rars.jar Test.java
java -cp rars.jar Test
rm Test.class

0 comments on commit b661ecf

Please sign in to comment.