1 | #!/usr/bin/env bash |
---|
2 | |
---|
3 | # Usage: LANGUAGE TEST | -b SOURCE_FILE |
---|
4 | |
---|
5 | readonly ITERATIONS=1000000 # 1 000 000, one million |
---|
6 | readonly STACK_HEIGHT=100 |
---|
7 | |
---|
8 | # Build Test Programs: |
---|
9 | # Mini-Make: TARGET SOURCE COMMAND ARGS... |
---|
10 | mmake() ( |
---|
11 | if [ ! -e "$1" -o "$1" -ot "$2" ]; then |
---|
12 | "${@:3}" |
---|
13 | fi |
---|
14 | ) |
---|
15 | |
---|
16 | build() ( |
---|
17 | case "$1" in |
---|
18 | *.cfa) |
---|
19 | # Requires a symbolic link. |
---|
20 | mmake "${1%.cfa}" "$1" ./cfa "$1" -o "${1%.cfa}" |
---|
21 | ;; |
---|
22 | *.cpp) |
---|
23 | mmake "${1%.cpp}-cpp" "$1" g++ "$1" -o "${1%.cpp}-cpp" |
---|
24 | ;; |
---|
25 | *.java) |
---|
26 | mmake "${1%.java}.class" "$1" javac "$1" |
---|
27 | ;; |
---|
28 | *) |
---|
29 | echo "Don't know how to build:" $1 >&2 |
---|
30 | exit 2 |
---|
31 | ;; |
---|
32 | esac |
---|
33 | ) |
---|
34 | |
---|
35 | if [ "-b" = "$1" ]; then |
---|
36 | for file in "${@:2}"; do |
---|
37 | build $file |
---|
38 | done |
---|
39 | exit 0 |
---|
40 | elif [ 2 == "$#" ]; then |
---|
41 | TEST_LANG="$1" |
---|
42 | TEST_CASE="$2" |
---|
43 | # Just a weird hack to make this work with rmit.py. |
---|
44 | elif [ 4 == "$#" ]; then |
---|
45 | # -l TEST_LANG -t TEST_CASE |
---|
46 | if [ "-l" = "$1" ]; then |
---|
47 | TEST_LANG="$2" |
---|
48 | TEST_CASE="$4" |
---|
49 | # -t TEST_CASE -l TEST_LANG |
---|
50 | else |
---|
51 | TEST_LANG="$4" |
---|
52 | TEST_CASE="$2" |
---|
53 | fi |
---|
54 | else |
---|
55 | echo "Unknown call pattern." >&2 |
---|
56 | exit 2 |
---|
57 | fi |
---|
58 | |
---|
59 | # Run Test Programs: |
---|
60 | # Used in place of unsupported language/test combinations. |
---|
61 | unsupported() { |
---|
62 | echo "Run-Time: NA" |
---|
63 | } |
---|
64 | |
---|
65 | case "$TEST_CASE" in |
---|
66 | cond-match-all) |
---|
67 | CFAT="./cond-catch $ITERATIONS 1" |
---|
68 | CFAR="./cond-fixup $ITERATIONS 1" |
---|
69 | CPP="./cond-catch-cpp $ITERATIONS 1" |
---|
70 | JAVA="java CondCatch $ITERATIONS 1" |
---|
71 | ;; |
---|
72 | cond-match-none) |
---|
73 | CFAT="./cond-catch $ITERATIONS 0" |
---|
74 | CFAR="./cond-fixup $ITERATIONS 0" |
---|
75 | CPP="./cond-catch-cpp $ITERATIONS 0" |
---|
76 | JAVA="java CondCatch $ITERATIONS 0" |
---|
77 | ;; |
---|
78 | cross-catch) |
---|
79 | CFAT="./cross-catch $ITERATIONS" |
---|
80 | CFAR="./cross-resume $ITERATIONS" |
---|
81 | CPP="./cross-catch-cpp $ITERATIONS" |
---|
82 | JAVA="java CrossCatch $ITERATIONS" |
---|
83 | ;; |
---|
84 | cross-finally) |
---|
85 | CFAT="./cross-finally $ITERATIONS" |
---|
86 | CFAR=unsupported |
---|
87 | CPP=unsupported |
---|
88 | JAVA="java CrossFinally $ITERATIONS" |
---|
89 | ;; |
---|
90 | raise-detor) |
---|
91 | CFAT="./throw-detor $ITERATIONS $STACK_HEIGHT" |
---|
92 | CFAR="./resume-detor $ITERATIONS $STACK_HEIGHT" |
---|
93 | CPP="./throw-detor-cpp $ITERATIONS $STACK_HEIGHT" |
---|
94 | JAVA=unsupported |
---|
95 | ;; |
---|
96 | raise-empty) |
---|
97 | CFAT="./throw-empty $ITERATIONS $STACK_HEIGHT" |
---|
98 | CFAR="./resume-empty $ITERATIONS $STACK_HEIGHT" |
---|
99 | CPP="./throw-empty-cpp $ITERATIONS $STACK_HEIGHT" |
---|
100 | JAVA="java ThrowEmpty $ITERATIONS $STACK_HEIGHT" |
---|
101 | ;; |
---|
102 | raise-finally) |
---|
103 | CFAT="./throw-finally $ITERATIONS $STACK_HEIGHT" |
---|
104 | CFAR="./resume-finally $ITERATIONS $STACK_HEIGHT" |
---|
105 | CPP=unsupported |
---|
106 | JAVA="java ThrowFinally $ITERATIONS $STACK_HEIGHT" |
---|
107 | ;; |
---|
108 | raise-other) |
---|
109 | CFAT="./throw-other $ITERATIONS $STACK_HEIGHT" |
---|
110 | CFAR="./resume-other $ITERATIONS $STACK_HEIGHT" |
---|
111 | CPP="./throw-other-cpp $ITERATIONS $STACK_HEIGHT" |
---|
112 | JAVA="java ThrowOther $ITERATIONS $STACK_HEIGHT" |
---|
113 | ;; |
---|
114 | *) |
---|
115 | echo "No such test: $TEST_CASE" >&2 |
---|
116 | exit 2 |
---|
117 | ;; |
---|
118 | esac |
---|
119 | |
---|
120 | case "$TEST_LANG" in |
---|
121 | cfa-t) echo $CFAT; $CFAT;; |
---|
122 | cfa-r) echo $CFAR; $CFAR;; |
---|
123 | cpp) echo $CPP; $CPP;; |
---|
124 | java) echo $JAVA; $JAVA;; |
---|
125 | *) |
---|
126 | echo "No such language: $TEST_LANG" >&2 |
---|
127 | exit 2 |
---|
128 | esac |
---|