source: doc/theses/andrew_beach_MMath/code/test.sh @ 562ccf9

Last change on this file since 562ccf9 was 140eb16, checked in by Andrew Beach <ajbeach@…>, 3 years ago

Andrew MMath: Updated the performance numbers for hopefully the last time.

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