| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | |
| 3 | # This script runs the regression tests in src/regression. |
| 4 | # It also compiles the tests in benchmark/tests |
| 5 | |
| 6 | # set -e |
| 7 | |
| 8 | MAKE=${MAKE:-make} |
| 9 | |
| 10 | name=$(basenamescip-shell system . . basename. "$0") |
| 11 | |
| 12 | usagescip-shell shell shell-project 0.0.0 usage(). () { |
| 13 | echoscip-shell system . . echo. >&2 "usage: $name [-fail] [-short] [-test-reg reg] [mlton flags ...]" |
| 14 | exit 1 |
| 15 | } |
| 16 | |
| 17 | fail='false' |
| 18 | short='false' |
| 19 | testReg='false' |
| 20 | exitFail=false |
| 21 | declare -a testRegs |
| 22 | declare -a flags |
| 23 | declare -a extraFlags |
| 24 | flags[${#flags[@]}]="-type-check" |
| 25 | flags[${#flags[@]}]="true" |
| 26 | while [scip-shell system . . `[`. "$#" -gt 0 ]; do |
| 27 | case "$1" in |
| 28 | -fail) |
| 29 | fail='true' |
| 30 | shift |
| 31 | ;; |
| 32 | -short) |
| 33 | short='true' |
| 34 | shift |
| 35 | ;; |
| 36 | -test-reg) |
| 37 | testReg='true' |
| 38 | shift |
| 39 | if [scip-shell system . . `[`. "$#" = 0 ]; then |
| 40 | usagescip-shell shell shell-project 0.0.0 usage(). |
| 41 | fi |
| 42 | testRegs[${#testRegs[@]}]="$1" |
| 43 | shift |
| 44 | ;; |
| 45 | *) |
| 46 | flags[${#flags[@]}]="$1" |
| 47 | shift |
| 48 | ;; |
| 49 | esac |
| 50 | done |
| 51 | |
| 52 | |
| 53 | dir=$(dirnamescip-shell system . . dirname. "$0") |
| 54 | src=$(cd "$dir/.." && pwdscip-shell system . . pwd.) |
| 55 | bin="$src/build/bin" |
| 56 | lib="$src/build/lib/mlton" |
| 57 | mlton="$bin/mlton" |
| 58 | cont='callcc.sml callcc2.sml callcc3.sml once.sml' |
| 59 | flatArray='finalize.sml flat-array.sml flat-array.2.sml' |
| 60 | intInf='conv.sml conv2.sml fixed-integer.sml harmonic.sml int-inf.*.sml slow.sml slower.sml smith-normal-form.sml' |
| 61 | signal='finalize.sml signals.sml signals2.sml signals3.sml signals4.sml suspend.sml weak.sml' |
| 62 | thread='thread0.sml thread1.sml thread2.sml mutex.sml prodcons.sml same-fringe.sml timeout.sml' |
| 63 | world='world1.sml world2.sml world3.sml world4.sml world5.sml world6.sml' |
| 64 | tmp=/tmp/z.regression.$$ |
| 65 | PATH="$bin:$PATH" |
| 66 | |
| 67 | # whitelist tests that are known to fail (will still run but exit cleanly) |
| 68 | if [scip-shell system . . `[`. -f "$src/regression/whitelist" ]; then |
| 69 | while read f; do |
| 70 | whitelist[${#whitelist[@]}]="$f" |
| 71 | done < "$src/regression/whitelist" |
| 72 | fi |
| 73 | |
| 74 | isWhitelistedscip-shell shell shell-project 0.0.0 isWhitelisted(). () { |
| 75 | local f=$1 |
| 76 | for (( i = 0 ; i < ${#whitelist[@]} ; i++ )); do |
| 77 | if [ "$f" = "${whitelist[$i]}" ]; then |
| 78 | return 0 |
| 79 | fi |
| 80 | done |
| 81 | return 1 |
| 82 | } |
| 83 | |
| 84 | compFailscip-shell shell shell-project 0.0.0 compFail(). () { |
| 85 | echoscip-shell system . . echo. "compilation of $f failed with ${flags[*]}" |
| 86 | } |
| 87 | |
| 88 | "$mlton" -verbose 1 || (echoscip-shell system . . echo. 'no mlton present' && exitFail=true) |
| 89 | echoscip-shell system . . echo. "flags = ${flags[*]}" |
| 90 | |
| 91 | TARGET_ARCH=$("$mlton" "${flags[@]}" -show path-map | sedscip-shell system . . sed. -n 's/TARGET_ARCH \(.*\)/\1/p') |
| 92 | TARGET_OS=$("$mlton" "${flags[@]}" -show path-map | sedscip-shell system . . sed. -n 's/TARGET_OS \(.*\)/\1/p') |
| 93 | OBJPTR_REP=$("$mlton" "${flags[@]}" -show path-map | sedscip-shell system . . sed. -n 's/OBJPTR_REP \(.*\)/\1/p') |
| 94 | ALIGN=$(echoscip-shell system . . echo. "${flags[@]}" | sedscip-shell system . . sed. -n 's/.*-align \(.\).*/\1/p') |
| 95 | if [scip-shell system . . `[`. -z "$ALIGN" ]; then |
| 96 | ALIGN=$("$mlton" "${flags[@]}" -z 2>&1 | sedscip-shell system . . sed. -n 's/.*-align {\(.\).*/\1/p') |
| 97 | fi |
| 98 | |
| 99 | cd "$src/regression" |
| 100 | |
| 101 | if $fail; then |
| 102 | for f in fail/*.sml; do |
| 103 | echoscip-shell system . . echo. "testing $f" |
| 104 | ( "$mlton" "${flags[@]}" -stop tc "$f" >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 && |
| 105 | (echoscip-shell system . . echo. "compilation of $f should have failed but did not"; isWhitelistedscip-shell shell shell-project 0.0.0 isWhitelisted(). $f || exitFail=true) ) || |
| 106 | truescip-shell system . . true. |
| 107 | done |
| 108 | |
| 109 | if [scip-shell system . . `[`. "$exitFail" = true ] ; then |
| 110 | exit 1 |
| 111 | else |
| 112 | exit 0 |
| 113 | fi |
| 114 | fi |
| 115 | |
| 116 | forMinGW='false' |
| 117 | if [scip-shell system . . `[`. $TARGET_OS = mingw ]; then |
| 118 | forMinGW='true' |
| 119 | fi |
| 120 | |
| 121 | for f in *.sml; do |
| 122 | f=$(basenamescip-shell system . . basename. "$f" .sml) |
| 123 | if ($testReg); then |
| 124 | skip='true' |
| 125 | for (( i = 0 ; $i < ${#testRegs[@]} ; i++ )); do |
| 126 | if [ "$f" = "${testRegs[$i]}" ]; then |
| 127 | skip='false' |
| 128 | fi |
| 129 | done |
| 130 | if ($skip); then |
| 131 | continue |
| 132 | fi |
| 133 | fi |
| 134 | case $TARGET_OS in |
| 135 | cygwin) |
| 136 | case "$f" in |
| 137 | textio.2) |
| 138 | continue |
| 139 | ;; |
| 140 | esac |
| 141 | ;; |
| 142 | darwin) |
| 143 | case "$f" in |
| 144 | world*) |
| 145 | continue |
| 146 | ;; |
| 147 | esac |
| 148 | ;; |
| 149 | hurd) |
| 150 | # Work-around hurd bug (http://bugs.debian.org/551470) |
| 151 | case "$f" in |
| 152 | mutex|prodcons|signals|signals2|signals3|signals4|suspend|thread2|timeout|world5) |
| 153 | continue |
| 154 | ;; |
| 155 | esac |
| 156 | ;; |
| 157 | mingw) |
| 158 | case "$f" in |
| 159 | cmdline|command-line|date-localOffset|echo|filesys|posix-exit|signals|signals2|signals3|signals4|socket|suspend|textio.2|unixpath|world*) |
| 160 | continue |
| 161 | ;; |
| 162 | esac |
| 163 | ;; |
| 164 | esac |
| 165 | case "$f" in |
| 166 | serialize) |
| 167 | continue |
| 168 | ;; |
| 169 | esac |
| 170 | echoscip-shell system . . echo. "testing $f" |
| 171 | unset extraFlags |
| 172 | case "$f" in |
| 173 | exn-history*) |
| 174 | extraFlags[${#extraFlags[@]}]="-const" |
| 175 | extraFlags[${#extraFlags[@]}]="Exn.keepHistory true" |
| 176 | ;; |
| 177 | gc-collect2) |
| 178 | extraFlags[${#extraFlags[@]}]="-runtime" |
| 179 | extraFlags[${#extraFlags[@]}]="mark-compact-ratio 1.001 copy-ratio 1.001 live-ratio 1.001" |
| 180 | ;; |
| 181 | world*) |
| 182 | case $TARGET_OS in |
| 183 | darwin) |
| 184 | extraFlags[${#extraFlags[@]}]="-link-opt" |
| 185 | extraFlags[${#extraFlags[@]}]="-fno-pie" |
| 186 | extraFlags[${#extraFlags[@]}]="-link-opt" |
| 187 | extraFlags[${#extraFlags[@]}]="-fno-PIE" |
| 188 | ;; |
| 189 | *) |
| 190 | extraFlags[${#extraFlags[@]}]="-link-opt" |
| 191 | extraFlags[${#extraFlags[@]}]="-no-pie" |
| 192 | ;; |
| 193 | esac |
| 194 | ;; |
| 195 | esac |
| 196 | |
| 197 | mlb="$f.mlb" |
| 198 | echoscip-shell system . . echo. "\$(SML_LIB)/basis/basis.mlb |
| 199 | \$(SML_LIB)/basis/mlton.mlb |
| 200 | \$(SML_LIB)/basis/sml-nj.mlb |
| 201 | ann |
| 202 | \"allowFFI true\" |
| 203 | \"allowOverload true\" |
| 204 | \"allowExtendedTextConsts true\" |
| 205 | \"nonexhaustiveBind ignore\" |
| 206 | \"nonexhaustiveMatch ignore\" |
| 207 | \"redundantBind ignore\" |
| 208 | \"redundantMatch ignore\" |
| 209 | in $f.sml |
| 210 | end" >"$mlb" |
| 211 | "$mlton" "${flags[@]}" "${extraFlags[@]}" -output "$f" "$mlb" |
| 212 | if [scip-shell system . . `[`. "$?" -ne '0' ] || [scip-shell system . . `[`. ! -x "$f" ]; then |
| 213 | compFailscip-shell shell shell-project 0.0.0 compFail(). "$f" |
| 214 | exitFail=true |
| 215 | fi |
| 216 | rmscip-shell system . . rm. "$mlb" |
| 217 | |
| 218 | if [scip-shell system . . `[`. ! -r "$f".nonterm -a -x "$f" ]; then |
| 219 | nonZeroMsg='Nonzero exit status.' |
| 220 | if $forMinGW; then |
| 221 | nonZeroMsg="$nonZeroMsg"'\r' |
| 222 | fi |
| 223 | ( "./$f" || echoscip-shell system . . echo. -e "$nonZeroMsg" ) >$tmp 2>&1 |
| 224 | if [scip-shell system . . `[`. -r "$f.ok" ]; then |
| 225 | compare="$f.ok" |
| 226 | for x in "$OBJPTR_REP" "${OBJPTR_REP}a$ALIGN" "$TARGET_OS" "$TARGET_ARCH" "$TARGET_ARCH-$TARGET_OS"; do |
| 227 | if [scip-shell system . . `[`. -r "$f.$x.ok" ]; then |
| 228 | compare="$f.$x.ok" |
| 229 | fi |
| 230 | done |
| 231 | if $forMinGW; then |
| 232 | newcompare="$f.sed.ok" |
| 233 | sedscip-shell system . . sed. $'s/$/\r/' <"$compare" > "$newcompare" |
| 234 | compare="$newcompare" |
| 235 | fi |
| 236 | if ! diffscip-shell system . . diff. "$compare" "$tmp"; then |
| 237 | echoscip-shell system . . echo. "$f: difference with ${flags[*]} ${extraFlags[*]}" |
| 238 | isWhitelistedscip-shell shell shell-project 0.0.0 isWhitelisted(). $f || exitFail=true |
| 239 | fi |
| 240 | if $forMinGW; then |
| 241 | rmscip-shell system . . rm. -f "$newcompare" |
| 242 | fi |
| 243 | fi |
| 244 | fi |
| 245 | done |
| 246 | |
| 247 | if $short || $testReg ; then |
| 248 | if [scip-shell system . . `[`. "$exitFail" = true ] ; then |
| 249 | exit 1 |
| 250 | else |
| 251 | exit 0 |
| 252 | fi |
| 253 | fi |
| 254 | |
| 255 | ${MAKE} clean >/dev/nullscip-shell filesystem . . `/dev/null`. |
| 256 | cd "$src/benchmark/tests" |
| 257 | for f in *.sml; do |
| 258 | f=$(basenamescip-shell system . . basename. "$f" .sml) |
| 259 | tmpf="/tmp/$f.$$" |
| 260 | case "$f" in |
| 261 | fxp) |
| 262 | echoscip-shell system . . echo. "skipping $f" |
| 263 | ;; |
| 264 | *) |
| 265 | echoscip-shell system . . echo. "testing $f" |
| 266 | echoscip-shell system . . echo. "val _ = Main.doit 0" | catscip-shell system . . cat. "$f.sml" - > "$tmpf.sml" |
| 267 | $mlton -output "$tmpf" "${flags[@]}" \ |
| 268 | -default-ann 'nonexhaustiveBind ignore'\ |
| 269 | -default-ann 'nonexhaustiveMatch ignore'\ |
| 270 | -default-ann 'redundantBind ignore' \ |
| 271 | -default-ann 'redundantMatch ignore' \ |
| 272 | "$tmpf.sml" |
| 273 | if [scip-shell system . . `[`. $? -ne 0 ]; then |
| 274 | compFailscip-shell shell shell-project 0.0.0 compFail(). "$f" |
| 275 | exitFail=true |
| 276 | fi |
| 277 | rmscip-shell system . . rm. -f "$tmpf" "$tmpf.sml" |
| 278 | ;; |
| 279 | esac |
| 280 | done |
| 281 | ${MAKE} clean >/dev/nullscip-shell filesystem . . `/dev/null`. |
| 282 | cd "$src" |
| 283 | for f in mllex mlyacc mlprof; do |
| 284 | tmpf="/tmp/$f.$$" |
| 285 | cd "$src/$f" |
| 286 | echoscip-shell system . . echo. "testing $f" |
| 287 | ${MAKE} -W "$f" >/dev/nullscip-shell filesystem . . `/dev/null`. |
| 288 | "$mlton" "${flags[@]}" -output "$tmpf" "$f.mlb" |
| 289 | if [scip-shell system . . `[`. $? -ne 0 ]; then |
| 290 | compFailscip-shell shell shell-project 0.0.0 compFail(). "$f" |
| 291 | exitFail=true |
| 292 | fi |
| 293 | rmscip-shell system . . rm. -f "$tmpf" |
| 294 | done |
| 295 | |
| 296 | rmscip-shell system . . rm. -f "$tmp" |
| 297 | |
| 298 | if [scip-shell system . . `[`. "$exitFail" = true ] ; then |
| 299 | exit 1 |
| 300 | else |
| 301 | exit 0 |
| 302 | fi |