forked from TheThirdOne/rars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.java
69 lines (67 loc) · 2.29 KB
/
Test.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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;
}
}
}