[acb38ce9] | 1 | #!/usr/bin/env bash |
---|
| 2 | |
---|
[209dfe2] | 3 | # Usage: |
---|
| 4 | # test.sh LANGUAGE TEST |
---|
| 5 | # Run the TEST in LANGUAGE. |
---|
[f79ee0d] | 6 | # test.sh -a |
---|
| 7 | # Build all tests. |
---|
[209dfe2] | 8 | # test.sh -b SOURCE_FILE... |
---|
| 9 | # Build a test from SOURCE_FILE(s). |
---|
[f79ee0d] | 10 | # test.sh -c |
---|
| 11 | # Clean all executables. |
---|
[209dfe2] | 12 | # test.sh -v LANGUAGE TEST FILE |
---|
| 13 | # View the result from TEST in LANGUAGE stored in FILE. |
---|
[acb38ce9] | 14 | |
---|
[812ba3d] | 15 | readonly DIR=$(dirname "$(readlink -f "$0")") |
---|
| 16 | cd $DIR |
---|
| 17 | |
---|
[678f259] | 18 | readonly MIL=000000 |
---|
| 19 | # Various preset values used as arguments. |
---|
| 20 | readonly ITERS_1M=1$MIL |
---|
| 21 | readonly ITERS_10M=10$MIL |
---|
| 22 | readonly ITERS_100M=100$MIL |
---|
| 23 | readonly ITERS_1000M=1000$MIL |
---|
[acb38ce9] | 24 | readonly STACK_HEIGHT=100 |
---|
| 25 | |
---|
| 26 | # Build Test Programs: |
---|
| 27 | # Mini-Make: TARGET SOURCE COMMAND ARGS... |
---|
| 28 | mmake() ( |
---|
| 29 | if [ ! -e "$1" -o "$1" -ot "$2" ]; then |
---|
| 30 | "${@:3}" |
---|
| 31 | fi |
---|
| 32 | ) |
---|
| 33 | |
---|
| 34 | build() ( |
---|
| 35 | case "$1" in |
---|
| 36 | *.cfa) |
---|
[678f259] | 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}" |
---|
[acb38ce9] | 43 | ;; |
---|
| 44 | *.cpp) |
---|
[f79ee0d] | 45 | mmake "${1%.cpp}-cpp" "$1" g++-10 -DNDEBUG -O3 "$1" -o "${1%.cpp}-cpp" |
---|
[acb38ce9] | 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 | |
---|
[8e42847] | 57 | if [ "-a" = "$1" ]; then |
---|
[f79ee0d] | 58 | for file in *.cfa *.cpp *.java; do |
---|
| 59 | build $file |
---|
| 60 | done |
---|
| 61 | exit 0 |
---|
[8e42847] | 62 | elif [ "-b" = "$1" ]; then |
---|
[acb38ce9] | 63 | for file in "${@:2}"; do |
---|
| 64 | build $file |
---|
| 65 | done |
---|
| 66 | exit 0 |
---|
[8e42847] | 67 | elif [ "-c" = "$1" ]; then |
---|
[0be463c] | 68 | rm $(basename -s ".cfa" -a *.cfa) |
---|
| 69 | rm $(basename -s ".cpp" -a *.cpp) |
---|
| 70 | rm *-cpp |
---|
| 71 | rm *.class |
---|
[f79ee0d] | 72 | exit 0 |
---|
[209dfe2] | 73 | elif [ "-v" = "$1" -a 4 = "$#" ]; then |
---|
[f79ee0d] | 74 | TEST_LANG="$2" |
---|
| 75 | TEST_CASE="$3" |
---|
| 76 | VIEW_FILE="$4" |
---|
[6f27b67] | 77 | elif [ 2 -eq "$#" ]; then |
---|
[63e3ed8] | 78 | TEST_LANG="$1" |
---|
| 79 | TEST_CASE="$2" |
---|
[605673f] | 80 | else |
---|
[63e3ed8] | 81 | echo "Unknown call pattern." >&2 |
---|
| 82 | exit 2 |
---|
[acb38ce9] | 83 | fi |
---|
| 84 | |
---|
| 85 | # Run Test Programs: |
---|
| 86 | # Used in place of unsupported language/test combinations. |
---|
| 87 | unsupported() { |
---|
| 88 | echo "Run-Time: NA" |
---|
| 89 | } |
---|
| 90 | |
---|
[605673f] | 91 | case "$TEST_CASE" in |
---|
[f79ee0d] | 92 | raise-empty) |
---|
| 93 | CFAT="./throw-empty $ITERS_1M $STACK_HEIGHT" |
---|
[8e42847] | 94 | CFAR="./resume-empty $ITERS_10M $STACK_HEIGHT" |
---|
[f79ee0d] | 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" |
---|
[acb38ce9] | 98 | ;; |
---|
| 99 | raise-detor) |
---|
[f79ee0d] | 100 | CFAT="./throw-detor $ITERS_1M $STACK_HEIGHT" |
---|
[8e42847] | 101 | CFAR="./resume-detor $ITERS_10M $STACK_HEIGHT" |
---|
[f79ee0d] | 102 | CPP="./throw-detor-cpp $ITERS_1M $STACK_HEIGHT" |
---|
[acb38ce9] | 103 | JAVA=unsupported |
---|
[63e3ed8] | 104 | PYTHON=unsupported |
---|
[acb38ce9] | 105 | ;; |
---|
| 106 | raise-finally) |
---|
[f79ee0d] | 107 | CFAT="./throw-finally $ITERS_1M $STACK_HEIGHT" |
---|
[8e42847] | 108 | CFAR="./resume-finally $ITERS_10M $STACK_HEIGHT" |
---|
[acb38ce9] | 109 | CPP=unsupported |
---|
[f79ee0d] | 110 | JAVA="java ThrowFinally $ITERS_1M $STACK_HEIGHT" |
---|
| 111 | PYTHON="./throw-finally.py $ITERS_1M $STACK_HEIGHT" |
---|
[acb38ce9] | 112 | ;; |
---|
| 113 | raise-other) |
---|
[f79ee0d] | 114 | CFAT="./throw-other $ITERS_1M $STACK_HEIGHT" |
---|
[8e42847] | 115 | CFAR="./resume-other $ITERS_10M $STACK_HEIGHT" |
---|
[f79ee0d] | 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 | ;; |
---|
| 120 | try-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 | ;; |
---|
| 127 | try-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 | ;; |
---|
| 134 | cond-match-all) |
---|
| 135 | CFAT="./cond-catch $ITERS_10M 1" |
---|
[8e42847] | 136 | CFAR="./cond-fixup $ITERS_100M 1" |
---|
[f79ee0d] | 137 | CPP="./cond-catch-cpp $ITERS_10M 1" |
---|
| 138 | JAVA="java CondCatch $ITERS_10M 1" |
---|
| 139 | PYTHON="./cond-catch.py $ITERS_10M 1" |
---|
| 140 | ;; |
---|
| 141 | cond-match-none) |
---|
| 142 | CFAT="./cond-catch $ITERS_10M 0" |
---|
[8e42847] | 143 | CFAR="./cond-fixup $ITERS_100M 0" |
---|
[f79ee0d] | 144 | CPP="./cond-catch-cpp $ITERS_10M 0" |
---|
| 145 | JAVA="java CondCatch $ITERS_10M 0" |
---|
| 146 | PYTHON="./cond-catch.py $ITERS_10M 0" |
---|
| 147 | ;; |
---|
[678f259] | 148 | fixup-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" |
---|
[f79ee0d] | 154 | ;; |
---|
[678f259] | 155 | fixup-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" |
---|
[acb38ce9] | 161 | ;; |
---|
| 162 | *) |
---|
[605673f] | 163 | echo "No such test: $TEST_CASE" >&2 |
---|
[acb38ce9] | 164 | exit 2 |
---|
| 165 | ;; |
---|
| 166 | esac |
---|
| 167 | |
---|
[605673f] | 168 | case "$TEST_LANG" in |
---|
[8e42847] | 169 | cfa-t) CALL="$CFAT";; |
---|
| 170 | cfa-r) CALL="$CFAR";; |
---|
| 171 | cpp) CALL="$CPP";; |
---|
| 172 | java) CALL="$JAVA";; |
---|
| 173 | python) CALL="$PYTHON";; |
---|
| 174 | *) |
---|
| 175 | echo "No such language: $TEST_LANG" >&2 |
---|
| 176 | exit 2 |
---|
[63e3ed8] | 177 | ;; |
---|
[acb38ce9] | 178 | esac |
---|
[209dfe2] | 179 | |
---|
| 180 | echo $CALL |
---|
| 181 | |
---|
| 182 | if [ -n "$VIEW_FILE" ]; then |
---|
[140eb16] | 183 | grep -A 1 -B 0 "$CALL" "$VIEW_FILE" | sed -n -e 's!Run-Time.*: !!;T;p' |
---|
[f79ee0d] | 184 | exit |
---|
[209dfe2] | 185 | fi |
---|
| 186 | |
---|
| 187 | $CALL |
---|