source: doc/theses/andrew_beach_MMath/code/test.sh @ 678f259

jacob/cs343-translation
Last change on this file since 678f259 was 678f259, checked in by Andrew Beach <ajbeach@…>, 3 months ago

Some clean-up in the exception benchmark directory. Mostly just shortening names.

  • Property mode set to 100755
File size: 4.3 KB
Line 
1#!/usr/bin/env bash
2
3# Usage:
4# test.sh LANGUAGE TEST
5#   Run the TEST in LANGUAGE.
6# test.sh -a
7#   Build all tests.
8# test.sh -b SOURCE_FILE...
9#   Build a test from SOURCE_FILE(s).
10# test.sh -c
11#   Clean all executables.
12# test.sh -v LANGUAGE TEST FILE
13#   View the result from TEST in LANGUAGE stored in FILE.
14
15readonly MIL=000000
16# Various preset values used as arguments.
17readonly ITERS_1M=1$MIL
18readonly ITERS_10M=10$MIL
19readonly ITERS_100M=100$MIL
20readonly ITERS_1000M=1000$MIL
21readonly STACK_HEIGHT=100
22
23# Build Test Programs:
24# Mini-Make: TARGET SOURCE COMMAND ARGS...
25mmake() (
26        if [ ! -e "$1" -o "$1" -ot "$2" ]; then
27                "${@:3}"
28        fi
29)
30
31build() (
32        case "$1" in
33        *.cfa)
34                # A symbolic link/local copy can be used as an override.
35                cmd=./cfa
36                if [ ! -x $cmd ]; then
37                        cmd=cfa
38                fi
39                mmake "${1%.cfa}" "$1" $cmd -DNDEBUG -nodebug -O3 "$1" -o "${1%.cfa}"
40                ;;
41        *.cpp)
42                mmake "${1%.cpp}-cpp" "$1" g++-10 -DNDEBUG -O3 "$1" -o "${1%.cpp}-cpp"
43                ;;
44        *.java)
45                mmake "${1%.java}.class" "$1" javac "$1"
46                ;;
47        *)
48                echo "Don't know how to build:" $1 >&2
49                exit 2
50                ;;
51        esac
52)
53
54if [ "-a" = "$1" ]; then                        # build all
55        for file in *.cfa *.cpp *.java; do
56                build $file
57        done
58        exit 0
59elif [ "-b" = "$1" ]; then                      # build given
60        for file in "${@:2}"; do
61                build $file
62        done
63        exit 0
64elif [ "-c" = "$1" ]; then                      # clean all
65        rm $(basename -s ".cfa" -a *.cfa)
66        rm $(basename -s ".cpp" -a *.cpp)
67        rm *-cpp
68        rm *.class
69        exit 0
70elif [ "-v" = "$1" -a 4 = "$#" ]; then
71        TEST_LANG="$2"
72        TEST_CASE="$3"
73        VIEW_FILE="$4"
74elif [ 2 -eq "$#" ]; then
75        TEST_LANG="$1"
76        TEST_CASE="$2"
77else
78        echo "Unknown call pattern." >&2
79        exit 2
80fi
81
82# Run Test Programs:
83# Used in place of unsupported language/test combinations.
84unsupported() {
85        echo "Run-Time: NA"
86}
87
88case "$TEST_CASE" in
89raise-empty)
90        CFAT="./throw-empty $ITERS_1M $STACK_HEIGHT"
91        CFAR="./resume-empty $ITERS_1M $STACK_HEIGHT"
92        CPP="./throw-empty-cpp $ITERS_1M $STACK_HEIGHT"
93        JAVA="java ThrowEmpty $ITERS_1M $STACK_HEIGHT"
94        PYTHON="./throw-empty.py $ITERS_1M $STACK_HEIGHT"
95        ;;
96raise-detor)
97        CFAT="./throw-detor $ITERS_1M $STACK_HEIGHT"
98        CFAR="./resume-detor $ITERS_1M $STACK_HEIGHT"
99        CPP="./throw-detor-cpp $ITERS_1M $STACK_HEIGHT"
100        JAVA=unsupported
101        PYTHON=unsupported
102        ;;
103raise-finally)
104        CFAT="./throw-finally $ITERS_1M $STACK_HEIGHT"
105        CFAR="./resume-finally $ITERS_1M $STACK_HEIGHT"
106        CPP=unsupported
107        JAVA="java ThrowFinally $ITERS_1M $STACK_HEIGHT"
108        PYTHON="./throw-finally.py $ITERS_1M $STACK_HEIGHT"
109        ;;
110raise-other)
111        CFAT="./throw-other $ITERS_1M $STACK_HEIGHT"
112        CFAR="./resume-other $ITERS_1M $STACK_HEIGHT"
113        CPP="./throw-other-cpp $ITERS_1M $STACK_HEIGHT"
114        JAVA="java ThrowOther $ITERS_1M $STACK_HEIGHT"
115        PYTHON="./throw-other.py $ITERS_1M $STACK_HEIGHT"
116        ;;
117try-catch)
118        CFAT="./try-catch $ITERS_1000M"
119        CFAR="./try-resume $ITERS_1000M"
120        CPP="./try-catch-cpp $ITERS_1000M"
121        JAVA="java TryCatch $ITERS_1000M"
122        PYTHON="./try-catch.py $ITERS_1000M"
123        ;;
124try-finally)
125        CFAT="./try-finally $ITERS_1000M"
126        CFAR=unsupported
127        CPP=unsupported
128        JAVA="java TryFinally $ITERS_1000M"
129        PYTHON="./try-finally.py $ITERS_1000M"
130        ;;
131cond-match-all)
132        CFAT="./cond-catch $ITERS_10M 1"
133        CFAR="./cond-fixup $ITERS_10M 1"
134        CPP="./cond-catch-cpp $ITERS_10M 1"
135        JAVA="java CondCatch $ITERS_10M 1"
136        PYTHON="./cond-catch.py $ITERS_10M 1"
137        ;;
138cond-match-none)
139        CFAT="./cond-catch $ITERS_10M 0"
140        CFAR="./cond-fixup $ITERS_10M 0"
141        CPP="./cond-catch-cpp $ITERS_10M 0"
142        JAVA="java CondCatch $ITERS_10M 0"
143        PYTHON="./cond-catch.py $ITERS_10M 0"
144        ;;
145fixup-empty)
146        CFAT="./fixup-empty-f $ITERS_10M $STACK_HEIGHT"
147        CFAR="./fixup-empty-r $ITERS_10M $STACK_HEIGHT"
148        CPP="./fixup-empty-cpp $ITERS_10M $STACK_HEIGHT"
149        JAVA="java FixupEmpty $ITERS_10M $STACK_HEIGHT"
150        PYTHON="./fixup-empty.py $ITERS_10M $STACK_HEIGHT"
151        ;;
152fixup-other)
153        CFAT="./fixup-other-f $ITERS_10M $STACK_HEIGHT"
154        CFAR="./fixup-other-r $ITERS_10M $STACK_HEIGHT"
155        CPP="./fixup-other-cpp $ITERS_10M $STACK_HEIGHT"
156        JAVA="java FixupOther $ITERS_10M $STACK_HEIGHT"
157        PYTHON="./fixup-other.py $ITERS_10M $STACK_HEIGHT"
158        ;;
159*)
160        echo "No such test: $TEST_CASE" >&2
161        exit 2
162        ;;
163esac
164
165case "$TEST_LANG" in
166        cfa-t) CALL="$CFAT";;
167        cfa-r) CALL="$CFAR";;
168        cpp) CALL="$CPP";;
169        java) CALL="$JAVA";;
170        python) CALL="$PYTHON";;
171        *)
172                echo "No such language: $TEST_LANG" >&2
173                exit 2
174        ;;
175esac
176
177echo $CALL
178
179if [ -n "$VIEW_FILE" ]; then
180        grep -A 1 -B 0 "$CALL" "$VIEW_FILE" | sed -n -e 's!Run-Time (ns): !!;T;p'
181        exit
182fi
183
184$CALL
Note: See TracBrowser for help on using the repository browser.