1 | #!/usr/bin/env bash |
---|
2 | |
---|
3 | # Usage: |
---|
4 | # test.sh LANGUAGE TEST |
---|
5 | # Run the TEST in LANGUAGE. |
---|
6 | # test.sh -b SOURCE_FILE... |
---|
7 | # Build a test from SOURCE_FILE(s). |
---|
8 | # test.sh -v LANGUAGE TEST FILE |
---|
9 | # View the result from TEST in LANGUAGE stored in FILE. |
---|
10 | |
---|
11 | readonly ITERATIONS=1000000 # 1 000 000, one million |
---|
12 | readonly STACK_HEIGHT=100 |
---|
13 | |
---|
14 | # Build Test Programs: |
---|
15 | # Mini-Make: TARGET SOURCE COMMAND ARGS... |
---|
16 | mmake() ( |
---|
17 | if [ ! -e "$1" -o "$1" -ot "$2" ]; then |
---|
18 | "${@:3}" |
---|
19 | fi |
---|
20 | ) |
---|
21 | |
---|
22 | build() ( |
---|
23 | case "$1" in |
---|
24 | *.cfa) |
---|
25 | # Requires a symbolic link. |
---|
26 | mmake "${1%.cfa}" "$1" ./cfa -DNDEBUG -nodebug -O3 "$1" -o "${1%.cfa}" |
---|
27 | ;; |
---|
28 | *.cpp) |
---|
29 | mmake "${1%.cpp}-cpp" "$1" g++ -DNDEBUG -O3 "$1" -o "${1%.cpp}-cpp" |
---|
30 | ;; |
---|
31 | *.java) |
---|
32 | mmake "${1%.java}.class" "$1" javac "$1" |
---|
33 | ;; |
---|
34 | *) |
---|
35 | echo "Don't know how to build:" $1 >&2 |
---|
36 | exit 2 |
---|
37 | ;; |
---|
38 | esac |
---|
39 | ) |
---|
40 | |
---|
41 | if [ "-b" = "$1" ]; then |
---|
42 | for file in "${@:2}"; do |
---|
43 | build $file |
---|
44 | done |
---|
45 | exit 0 |
---|
46 | elif [ "-v" = "$1" -a 4 = "$#" ]; then |
---|
47 | TEST_LANG="$2" |
---|
48 | TEST_CASE="$3" |
---|
49 | VIEW_FILE="$4" |
---|
50 | elif [ 2 -eq "$#" ]; then |
---|
51 | TEST_LANG="$1" |
---|
52 | TEST_CASE="$2" |
---|
53 | else |
---|
54 | echo "Unknown call pattern." >&2 |
---|
55 | exit 2 |
---|
56 | fi |
---|
57 | |
---|
58 | # Run Test Programs: |
---|
59 | # Used in place of unsupported language/test combinations. |
---|
60 | unsupported() { |
---|
61 | echo "Run-Time: NA" |
---|
62 | } |
---|
63 | |
---|
64 | case "$TEST_CASE" in |
---|
65 | cond-match-all) |
---|
66 | CFAT="./cond-catch $ITERATIONS 1" |
---|
67 | CFAR="./cond-fixup $ITERATIONS 1" |
---|
68 | CPP="./cond-catch-cpp $ITERATIONS 1" |
---|
69 | JAVA="java CondCatch $ITERATIONS 1" |
---|
70 | PYTHON="./cond_catch.py $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 | PYTHON="./cond_catch.py $ITERATIONS 0" |
---|
78 | ;; |
---|
79 | cross-catch) |
---|
80 | CFAT="./cross-catch $ITERATIONS" |
---|
81 | CFAR="./cross-resume $ITERATIONS" |
---|
82 | CPP="./cross-catch-cpp $ITERATIONS" |
---|
83 | JAVA="java CrossCatch $ITERATIONS" |
---|
84 | PYTHON="./cross_catch.py $ITERATIONS" |
---|
85 | ;; |
---|
86 | cross-finally) |
---|
87 | CFAT="./cross-finally $ITERATIONS" |
---|
88 | CFAR=unsupported |
---|
89 | CPP=unsupported |
---|
90 | JAVA="java CrossFinally $ITERATIONS" |
---|
91 | PYTHON="./cross_finally.py $ITERATIONS" |
---|
92 | ;; |
---|
93 | raise-detor) |
---|
94 | CFAT="./throw-detor $ITERATIONS $STACK_HEIGHT" |
---|
95 | CFAR="./resume-detor $ITERATIONS $STACK_HEIGHT" |
---|
96 | CPP="./throw-detor-cpp $ITERATIONS $STACK_HEIGHT" |
---|
97 | JAVA=unsupported |
---|
98 | PYTHON=unsupported |
---|
99 | ;; |
---|
100 | raise-empty) |
---|
101 | CFAT="./throw-empty $ITERATIONS $STACK_HEIGHT" |
---|
102 | CFAR="./resume-empty $ITERATIONS $STACK_HEIGHT" |
---|
103 | CPP="./throw-empty-cpp $ITERATIONS $STACK_HEIGHT" |
---|
104 | JAVA="java ThrowEmpty $ITERATIONS $STACK_HEIGHT" |
---|
105 | PYTHON="./throw_empty.py $ITERATIONS $STACK_HEIGHT" |
---|
106 | ;; |
---|
107 | raise-finally) |
---|
108 | CFAT="./throw-finally $ITERATIONS $STACK_HEIGHT" |
---|
109 | CFAR="./resume-finally $ITERATIONS $STACK_HEIGHT" |
---|
110 | CPP=unsupported |
---|
111 | JAVA="java ThrowFinally $ITERATIONS $STACK_HEIGHT" |
---|
112 | PYTHON="./throw_finally.py $ITERATIONS $STACK_HEIGHT" |
---|
113 | ;; |
---|
114 | raise-other) |
---|
115 | CFAT="./throw-other $ITERATIONS $STACK_HEIGHT" |
---|
116 | CFAR="./resume-other $ITERATIONS $STACK_HEIGHT" |
---|
117 | CPP="./throw-other-cpp $ITERATIONS $STACK_HEIGHT" |
---|
118 | JAVA="java ThrowOther $ITERATIONS $STACK_HEIGHT" |
---|
119 | PYTHON="./throw_other.py $ITERATIONS $STACK_HEIGHT" |
---|
120 | ;; |
---|
121 | *) |
---|
122 | echo "No such test: $TEST_CASE" >&2 |
---|
123 | exit 2 |
---|
124 | ;; |
---|
125 | esac |
---|
126 | |
---|
127 | case "$TEST_LANG" in |
---|
128 | cfa-t) CALL="$CFAT";; |
---|
129 | cfa-r) CALL="$CFAR";; |
---|
130 | cpp) CALL="$CPP";; |
---|
131 | java) CALL="$JAVA";; |
---|
132 | python) CALL="$PYTHON";; |
---|
133 | *) |
---|
134 | echo "No such language: $TEST_LANG" >&2 |
---|
135 | exit 2 |
---|
136 | ;; |
---|
137 | esac |
---|
138 | |
---|
139 | echo $CALL |
---|
140 | |
---|
141 | if [ -n "$VIEW_FILE" ]; then |
---|
142 | grep -A 1 -B 0 "$CALL" "$VIEW_FILE" | sed -n -e 's!Run-Time (ns): !!;T;p' |
---|
143 | exit |
---|
144 | fi |
---|
145 | |
---|
146 | $CALL |
---|