[acb38ce9] | 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 |
---|
[6f27b67] | 40 | elif [ 2 -eq "$#" ]; then |
---|
[605673f] | 41 | TEST_LANG="$1" |
---|
| 42 | TEST_CASE="$2" |
---|
| 43 | else |
---|
| 44 | echo "Unknown call pattern." >&2 |
---|
| 45 | exit 2 |
---|
[acb38ce9] | 46 | fi |
---|
| 47 | |
---|
| 48 | # Run Test Programs: |
---|
| 49 | # Used in place of unsupported language/test combinations. |
---|
| 50 | unsupported() { |
---|
| 51 | echo "Run-Time: NA" |
---|
| 52 | } |
---|
| 53 | |
---|
[605673f] | 54 | case "$TEST_CASE" in |
---|
[acb38ce9] | 55 | cond-match-all) |
---|
| 56 | CFAT="./cond-catch $ITERATIONS 1" |
---|
| 57 | CFAR="./cond-fixup $ITERATIONS 1" |
---|
| 58 | CPP="./cond-catch-cpp $ITERATIONS 1" |
---|
| 59 | JAVA="java CondCatch $ITERATIONS 1" |
---|
| 60 | ;; |
---|
| 61 | cond-match-none) |
---|
| 62 | CFAT="./cond-catch $ITERATIONS 0" |
---|
| 63 | CFAR="./cond-fixup $ITERATIONS 0" |
---|
| 64 | CPP="./cond-catch-cpp $ITERATIONS 0" |
---|
| 65 | JAVA="java CondCatch $ITERATIONS 0" |
---|
| 66 | ;; |
---|
| 67 | cross-catch) |
---|
| 68 | CFAT="./cross-catch $ITERATIONS" |
---|
| 69 | CFAR="./cross-resume $ITERATIONS" |
---|
| 70 | CPP="./cross-catch-cpp $ITERATIONS" |
---|
| 71 | JAVA="java CrossCatch $ITERATIONS" |
---|
| 72 | ;; |
---|
| 73 | cross-finally) |
---|
| 74 | CFAT="./cross-finally $ITERATIONS" |
---|
| 75 | CFAR=unsupported |
---|
| 76 | CPP=unsupported |
---|
| 77 | JAVA="java CrossFinally $ITERATIONS" |
---|
| 78 | ;; |
---|
| 79 | raise-detor) |
---|
| 80 | CFAT="./throw-detor $ITERATIONS $STACK_HEIGHT" |
---|
| 81 | CFAR="./resume-detor $ITERATIONS $STACK_HEIGHT" |
---|
| 82 | CPP="./throw-detor-cpp $ITERATIONS $STACK_HEIGHT" |
---|
| 83 | JAVA=unsupported |
---|
| 84 | ;; |
---|
| 85 | raise-empty) |
---|
| 86 | CFAT="./throw-empty $ITERATIONS $STACK_HEIGHT" |
---|
| 87 | CFAR="./resume-empty $ITERATIONS $STACK_HEIGHT" |
---|
| 88 | CPP="./throw-empty-cpp $ITERATIONS $STACK_HEIGHT" |
---|
| 89 | JAVA="java ThrowEmpty $ITERATIONS $STACK_HEIGHT" |
---|
| 90 | ;; |
---|
| 91 | raise-finally) |
---|
| 92 | CFAT="./throw-finally $ITERATIONS $STACK_HEIGHT" |
---|
| 93 | CFAR="./resume-finally $ITERATIONS $STACK_HEIGHT" |
---|
| 94 | CPP=unsupported |
---|
| 95 | JAVA="java ThrowFinally $ITERATIONS $STACK_HEIGHT" |
---|
| 96 | ;; |
---|
| 97 | raise-other) |
---|
| 98 | CFAT="./throw-other $ITERATIONS $STACK_HEIGHT" |
---|
| 99 | CFAR="./resume-other $ITERATIONS $STACK_HEIGHT" |
---|
| 100 | CPP="./throw-other-cpp $ITERATIONS $STACK_HEIGHT" |
---|
| 101 | JAVA="java ThrowOther $ITERATIONS $STACK_HEIGHT" |
---|
| 102 | ;; |
---|
| 103 | *) |
---|
[605673f] | 104 | echo "No such test: $TEST_CASE" >&2 |
---|
[acb38ce9] | 105 | exit 2 |
---|
| 106 | ;; |
---|
| 107 | esac |
---|
| 108 | |
---|
[605673f] | 109 | case "$TEST_LANG" in |
---|
[acb38ce9] | 110 | cfa-t) echo $CFAT; $CFAT;; |
---|
| 111 | cfa-r) echo $CFAR; $CFAR;; |
---|
| 112 | cpp) echo $CPP; $CPP;; |
---|
| 113 | java) echo $JAVA; $JAVA;; |
---|
[605673f] | 114 | *) |
---|
| 115 | echo "No such language: $TEST_LANG" >&2 |
---|
| 116 | exit 2 |
---|
[acb38ce9] | 117 | esac |
---|