| 1 | #!/bin/sh |
| 2 | # Runs the conformance suite, conform/check.sh, with this compiler's |
| 3 | # messages for it in test/msg; then compiles and runs every example |
| 4 | # and this compiler's own tests, and compares what each prints, and its |
| 5 | # exit status, with what is expected: |
| 6 | # X.raz the program |
| 7 | # X.expect its standard output |
| 8 | # X.args its arguments, one per line (optional) |
| 9 | # X.status its exit status (optional; 0 if missing), 128 and the |
| 10 | # signal's number for one stopped by a signal |
| 11 | # X.stderr its standard error (optional; not compared if missing), |
| 12 | # each address in it, 0x and hex digits, written 0x? |
| 13 | # A program without X.expect is compiled, not run. test/libc puts |
| 14 | # lib/Sys.raz, over the C library, before the system call one. |
| 15 | # Programs in test/err must not compile, and must print X.err (with |
| 16 | # the compiler's own version in a library's note written as N); there |
| 17 | # X.args holds the compiler's options. The examples, test/libc, the |
| 18 | # tools and the library's tests are compiled with -Werror, so warnings |
| 19 | # fail them. test/a64/Encode.raz checks arm64's encoder, src/A64.raz, |
| 20 | # against Apple's assembler. Then the version, tools/Doc.raz, the report's examples, |
| 21 | # the tutorial's, tools/Pretty.raz, and the library's own tests. |
| 22 | |
| 23 | raz=./raz |
| 24 | # Fixtures use only their explicit module paths and the standard library. |
| 25 | # library-path.sh sets up its own HOME and RAZ_PATH for user-path checks. |
| 26 | RAZ_PATH= |
| 27 | export RAZ_PATH |
| 28 | out=build/check |
| 29 | mkdir -p $out |
| 30 | ulimit -c 0 # the tests stopped by a signal leave no core |
| 31 | ulimit -s 8192 # Linux's usual stack: StackOverflow's depth depends on it, and CI's runner gives more |
| 32 | pass=0 |
| 33 | fail=0 |
| 34 | skipped=0 |
| 35 | |
| 36 | # Rosetta, which runs x86 programs on an Apple Silicon Mac, differs from |
| 37 | # Linux in these ways; the tests that can't tell so are skipped there, |
| 38 | # each with its reason, until raz runs natively on the Mac. Elsewhere |
| 39 | # nothing is skipped. |
| 40 | rosetta= |
| 41 | grep -q VirtualApple /proc/cpuinfo 2>/dev/null && rosetta=1 |
| 42 | skip() { # skip name: whether to skip it, saying why |
| 43 | [ -n "$rosetta" ] || return 1 |
| 44 | case $1 in |
| 45 | test/run/ExecOpened|test/libc/ExecOpenedC) why='keeps descriptors 3 to 6 open' ;; |
| 46 | test/libc/SysTest|lib/Sys.linux-x86_64.raz) why='takes descriptor 9 in a child' ;; |
| 47 | test/run/StackOverflow|test/run/ThreadOverflow) why='reads a trap local as 0 after a stack fault' ;; |
| 48 | "Thread under a memory limit") why="aborts under ulimit -v" ;; |
| 49 | *) return 1 ;; |
| 50 | esac |
| 51 | echo "SKIP $1: Rosetta $why" |
| 52 | skipped=$((skipped + 1)) |
| 53 | } |
| 54 | |
| 55 | conform/check.sh $raz test/msg > $out/conform.out |
| 56 | grep -v '^[0-9]* passed' $out/conform.out |
| 57 | set -- $(tail -1 $out/conform.out) |
| 58 | pass=$1; fail=$3 |
| 59 | |
| 60 | run() { # run dir name |
| 61 | dir=$1; name=$2 |
| 62 | skip $dir/$name && return |
| 63 | flags= |
| 64 | [ $dir = examples ] || [ $dir = test/libc ] && flags=-Werror |
| 65 | if ! $raz $flags $libc -I $dir/mods -o $out/$name $dir/$name.raz 2>$out/$name.cerr; then |
| 66 | echo "FAIL $dir/$name$libc: doesn't compile: $(cat $out/$name.cerr)" |
| 67 | fail=$((fail + 1)); return |
| 68 | fi |
| 69 | if [ ! -f $dir/$name.expect ]; then pass=$((pass + 1)); return; fi |
| 70 | set -- |
| 71 | if [ -f $dir/$name.args ]; then |
| 72 | while IFS= read -r a; do set -- "$@" "$a"; done < $dir/$name.args |
| 73 | fi |
| 74 | # in $(...), so that what the shell says of a signal goes nowhere; |
| 75 | # in ( ), since dash says it with the command's 2> still in place |
| 76 | status=$( { ( exec $out/$name "$@" ) > $out/$name.out 2>$out/$name.err; echo $?; } 2>/dev/null ) |
| 77 | want=0 |
| 78 | [ -f $dir/$name.status ] && want=$(cat $dir/$name.status) |
| 79 | if ! cmp -s $out/$name.out $dir/$name.expect; then |
| 80 | echo "FAIL $dir/$name$libc: output differs" |
| 81 | diff $out/$name.out $dir/$name.expect | head -5 |
| 82 | fail=$((fail + 1)) |
| 83 | elif [ $status != $want ]; then |
| 84 | echo "FAIL $dir/$name$libc: status $status, not $want" |
| 85 | fail=$((fail + 1)) |
| 86 | elif [ -f $dir/$name.stderr ] && ! sed 's/0x[0-9a-f]*/0x?/g' $out/$name.err | |
| 87 | cmp -s - $dir/$name.stderr; then |
| 88 | echo "FAIL $dir/$name$libc: standard error differs" |
| 89 | diff $out/$name.err $dir/$name.stderr | head -5 |
| 90 | fail=$((fail + 1)) |
| 91 | else |
| 92 | pass=$((pass + 1)) |
| 93 | fi |
| 94 | } |
| 95 | |
| 96 | libc= |
| 97 | for f in examples/*.raz test/run/*.raz test/libc/*.raz test/bench/*.raz; do |
| 98 | run $(dirname $f) $(basename $f .raz) |
| 99 | done |
| 100 | # test/libc again over musl, where its loader is installed |
| 101 | if [ -e /lib/ld-musl-x86_64.so.1 ]; then |
| 102 | libc=' -libc musl' |
| 103 | for f in test/libc/*.raz; do run test/libc $(basename $f .raz); done |
| 104 | libc= |
| 105 | fi |
| 106 | |
| 107 | # A64, arm64's encoder, which no compiler for this target imports: its |
| 108 | # test is compiled with src/ for its modules, and prints what Apple's |
| 109 | # assembler makes of the same instructions (test/a64/expect.sh) |
| 110 | if $raz -Werror -I src -I build/src -o $out/Encode test/a64/Encode.raz 2>$out/Encode.cerr && |
| 111 | $out/Encode > $out/Encode.out 2>&1 && cmp -s $out/Encode.out test/a64/Encode.expect; then |
| 112 | pass=$((pass + 1)) |
| 113 | else |
| 114 | echo "FAIL test/a64/Encode"; cat $out/Encode.cerr; diff $out/Encode.out test/a64/Encode.expect | head -10 |
| 115 | fail=$((fail + 1)) |
| 116 | fi |
| 117 | |
| 118 | # raz run: a static program and one over C, from memory, with their |
| 119 | # arguments, output and status passed through |
| 120 | runs() { # runs file status [arg]... |
| 121 | f=$1; want=$2; shift 2 |
| 122 | $raz run -I $(dirname $f)/mods $f "$@" > $out/run.out 2>/dev/null |
| 123 | status=$? |
| 124 | if cmp -s $out/run.out ${f%.raz}.expect && [ $status = $want ]; then pass=$((pass + 1)) |
| 125 | else echo "FAIL raz run $f: status $status, not $want, or output differs"; fail=$((fail + 1)); fi |
| 126 | } |
| 127 | runs conform/run/Args.raz 4 one 'two words' é |
| 128 | runs test/libc/Through.raz 2 |
| 129 | for f in test/err/*.raz; do |
| 130 | name=$(basename $f .raz) |
| 131 | flags= |
| 132 | [ -f test/err/$name.args ] && flags=$(cat test/err/$name.args) |
| 133 | if $raz $flags -I test/err/mods -I test/run/mods -o $out/$name $f 2>$out/$name.cerr; then |
| 134 | echo "FAIL $f: compiles" |
| 135 | fail=$((fail + 1)) |
| 136 | elif ! sed 's/ this is raz [^)]*)/ this is raz N)/' $out/$name.cerr | cmp -s test/err/$name.err -; then |
| 137 | echo "FAIL $f: says"; diff test/err/$name.err $out/$name.cerr |
| 138 | fail=$((fail + 1)) |
| 139 | else |
| 140 | pass=$((pass + 1)) |
| 141 | fi |
| 142 | done |
| 143 | # RAZ_PROFILE: a profiled run says which procedure took its time |
| 144 | $raz -o $out/Busy test/list/Busy.raz |
| 145 | if RAZ_PROFILE=1 $out/Busy 2>&1 >/dev/null | sed -n 2p | grep -q 'Busy.spin$'; then pass=$((pass + 1)) |
| 146 | else echo "FAIL RAZ_PROFILE: Busy.spin isn't first"; fail=$((fail + 1)); fi |
| 147 | # the manual pages, raz-lib(3) as make made it from lib/, which groff |
| 148 | # and mandoc, where there, must read without a warning |
| 149 | for f in doc/*.[1-9] build/raz-lib.3; do |
| 150 | : > $out/man.out |
| 151 | command -v groff > /dev/null && groff -mdoc -ww -z $f >> $out/man.out 2>&1 |
| 152 | command -v mandoc > /dev/null && mandoc -Tlint -Wwarning $f >> $out/man.out 2>&1 |
| 153 | if [ ! -s $out/man.out ]; then pass=$((pass + 1)) |
| 154 | else echo "FAIL $f"; head -5 $out/man.out; fail=$((fail + 1)); fi |
| 155 | done |
| 156 | # raz -noprofile leaves the profiler out, and raz -s the places too: a |
| 157 | # failed check is told by its address, and the program is smaller |
| 158 | $raz -noprofile -o $out/BusyNo test/list/Busy.raz |
| 159 | if [ -z "$(RAZ_PROFILE=1 $out/BusyNo 2>&1 >/dev/null)" ]; then pass=$((pass + 1)) |
| 160 | else echo "FAIL raz -noprofile: a profile"; fail=$((fail + 1)); fi |
| 161 | $raz -o $out/Index test/strip/Index.raz |
| 162 | $raz -s -o $out/IndexS test/strip/Index.raz |
| 163 | $out/IndexS > $out/IndexS.out 2>&1 |
| 164 | if [ $? = 2 ] && grep -q '^hello$' $out/IndexS.out && grep -q '^at 0x[0-9a-f]*: index 5 is out of range' $out/IndexS.out \ |
| 165 | && [ $(wc -c < $out/IndexS) -lt $(wc -c < $out/Index) ]; then pass=$((pass + 1)) |
| 166 | else echo "FAIL raz -s:"; cat $out/IndexS.out; fail=$((fail + 1)); fi |
| 167 | # raz -base: loaded elsewhere, a program says the same of a failed |
| 168 | # check, the places found as at 400000H; one for the top 2 GB, as a |
| 169 | # higher-half kernel's, is made, though Linux won't run it there |
| 170 | entry() { od -An -tx8 -j24 -N8 $1 | tr -d ' '; } |
| 171 | $raz -base 7FE00000H -o $out/IndexB test/strip/Index.raz |
| 172 | $out/Index > $out/Index.out 2>&1 |
| 173 | $out/IndexB > $out/IndexB.out 2>&1 |
| 174 | $raz -base 0FFFFFFFF80000000H -o $out/IndexK test/strip/Index.raz |
| 175 | if [ $? = 0 ] && cmp -s $out/Index.out $out/IndexB.out && grep -q 'Index.main' $out/IndexB.out \ |
| 176 | && entry $out/IndexB | grep -q '^000000007fe' && entry $out/IndexK | grep -q '^ffffffff800'; then pass=$((pass + 1)) |
| 177 | else echo "FAIL raz -base:"; cat $out/IndexB.out; fail=$((fail + 1)); fi |
| 178 | # raz -bare: no argc read, so ARGC() is 0, and no handlers set, so a nil |
| 179 | # pointer stops the program by SIGSEGV with nothing said; a failed |
| 180 | # check is still told by its place, and nothing is profiled |
| 181 | $raz -bare -o $out/Bare test/bare/Bare.raz |
| 182 | status=$( { ( exec $out/Bare one two ) > $out/Bare.out 2>$out/Bare.err; echo $?; } 2>/dev/null ) |
| 183 | $raz -bare -o $out/IndexBare test/strip/Index.raz |
| 184 | RAZ_PROFILE=1 $out/IndexBare > $out/IndexBare.out 2>&1 |
| 185 | if [ $status = 139 ] && [ "$(cat $out/Bare.out)" = 0 ] && [ ! -s $out/Bare.err ] \ |
| 186 | && cmp -s $out/Index.out $out/IndexBare.out; then pass=$((pass + 1)) |
| 187 | else echo "FAIL raz -bare: status $status"; cat $out/Bare.out $out/Bare.err $out/IndexBare.out; fail=$((fail + 1)); fi |
| 188 | |
| 189 | # a program with its own Rt (doc/compiler.md): raz -lib of nothing but |
| 190 | # test/own/lib/Rt.raz, whose exit and fail make their system calls |
| 191 | # themselves; Own ends with main's 3 after saying hello, OwnFail with 2 |
| 192 | # after Rt.fail's kind 0, an index; built without -s, with Rt having no |
| 193 | # places, so the ELF has its symbols |
| 194 | rm -rf $out/own; mkdir -p $out/own |
| 195 | $raz -lib test/own/lib -Werror -bare -o $out/own/Own test/own/Own.raz |
| 196 | status=$( { ( exec $out/own/Own ) > $out/own/Own.out 2>&1; echo $?; } 2>/dev/null ) |
| 197 | $raz -lib test/own/lib -Werror -bare -o $out/own/OwnFail test/own/OwnFail.raz |
| 198 | statusFail=$( { ( exec $out/own/OwnFail ) > $out/own/OwnFail.out 2>&1; echo $?; } 2>/dev/null ) |
| 199 | if [ $status = 3 ] && [ $statusFail = 2 ] && [ "$(cat $out/own/Own.out)" = hello ] \ |
| 200 | && [ "$(cat $out/own/OwnFail.out)" = 'check failed: 0' ] \ |
| 201 | && readelf -s $out/own/Own | grep -q ' Own.main$' && readelf --debug-dump=decodedline $out/own/Own | grep -q 'Own.raz'; then pass=$((pass + 1)) |
| 202 | else echo "FAIL own Rt: status $status, $statusFail"; cat $out/own/Own.out $out/own/OwnFail.out; fail=$((fail + 1)); fi |
| 203 | |
| 204 | # raz -q, for an editor: check's rows; the names words offers at a |
| 205 | # cursor after a part of a name, after a module's dot, and none in a |
| 206 | # comment or a string; and where def finds a local, another module's |
| 207 | # name, a module, used and imported, and a built-in, which has no |
| 208 | # place. The text is standard input: checking an empty one shows |
| 209 | # that the file on disk isn't read. |
| 210 | for t in "check Check.raz check" "words Words.raz:9:16 prefix" "words Words.raz:10:11 export" \ |
| 211 | "words Words.raz:11:10 none" "words Words.raz:12:15 none" "def Def.raz:10:15 def-local" \ |
| 212 | "def Def.raz:11:9 def-export" "def Def.raz:11:6 def-module" "def Def.raz:2:9 def-module" \ |
| 213 | "def Def.raz:10:24 def-builtin"; do |
| 214 | set -- $t |
| 215 | f=test/query/${2%%:*} |
| 216 | $raz -q $1 test/query/$2 < $f > $out/query.out |
| 217 | if [ "$3" = none ]; then : > $out/query.expect; else cp test/query/$3.expect $out/query.expect; fi |
| 218 | if cmp -s $out/query.out $out/query.expect; then pass=$((pass + 1)) |
| 219 | else echo "FAIL raz -q $1 $2"; diff $out/query.expect $out/query.out | head -5; fail=$((fail + 1)); fi |
| 220 | done |
| 221 | if [ -z "$($raz -q check test/query/Words.raz < /dev/null | grep 'expected "module"')" ]; then |
| 222 | echo "FAIL raz -q check: read the file, not standard input"; fail=$((fail + 1)) |
| 223 | else pass=$((pass + 1)); fi |
| 224 | |
| 225 | # what src/ asks of lib/ is what doc/compiler.md lists (test/asks.sh) |
| 226 | if sh test/asks.sh > $out/asks.out 2>&1; then pass=$((pass + 1)) |
| 227 | else echo "FAIL test/asks.sh:"; cat $out/asks.out; fail=$((fail + 1)); fi |
| 228 | |
| 229 | # raz -S: test/list/X.raz lists as X.expect |
| 230 | for f in test/list/*.raz; do |
| 231 | want=test/list/$(basename $f .raz).expect |
| 232 | [ -f $want ] || continue |
| 233 | if $raz -S $f 2>&1 | cmp -s $want -; then pass=$((pass + 1)) |
| 234 | else echo "FAIL raz -S $f"; $raz -S $f 2>&1 | diff $want - | head; fail=$((fail + 1)); fi |
| 235 | done |
| 236 | # raz -S's form, as raz(1) states it: every line is blank, a procedure's |
| 237 | # name (after a blank line), a source line (number to column 6, two spaces, |
| 238 | # text) or an instruction (offset to column 14, two spaces, text); a jump |
| 239 | # gives its target as a number |
| 240 | if $raz -S test/list/Listing.raz 2>&1 | awk ' |
| 241 | NR == 1 && $0 != "" { bad = "first line not blank" } |
| 242 | $0 == "" { blank = 1; next } |
| 243 | /^[A-Za-z0-9]+\.[A-Za-z0-9.]+:$/ { if (!blank) bad = "name after no blank: " $0; blank = 0; next } |
| 244 | { blank = 0 } |
| 245 | match($0, /^ *[0-9]+/) && (RLENGTH == 6 || RLENGTH == 14) && substr($0, RLENGTH + 1, 2) == " " { |
| 246 | if (RLENGTH == 14 && $0 ~ /^ *[0-9]+ j[a-z]* / && $0 !~ / j[a-z]* [0-9]+$/) bad = "jump with no offset: " $0 |
| 247 | next } |
| 248 | { bad = "no form: " $0 } |
| 249 | END { if (bad != "") { print bad; exit 1 } }'; then pass=$((pass + 1)) |
| 250 | else echo "FAIL raz -S: a line not of raz(1)'s form"; fail=$((fail + 1)); fi |
| 251 | # the report's version is the one the compiler says it follows |
| 252 | # the version the compiler follows: the report's, or one it names while |
| 253 | # the compiler catches up |
| 254 | want=$(sed -n 's/^This is version \([0-9.-]*\) of the report.*/\1/p' doc/raz.md) |
| 255 | lag=$(sed -n 's/^The compiler follows version \([0-9.-]*\) until.*/\1/p' doc/raz.md) |
| 256 | want=${lag:-$want} |
| 257 | if ./raz --version | grep -qF "report $want"; then pass=$((pass + 1)) |
| 258 | else echo "FAIL raz --version: not report $want"; fail=$((fail + 1)); fi |
| 259 | |
| 260 | # tools/Doc.raz: on every library module, and as test/doc expects (X.expect |
| 261 | # for Doc, X.man for Doc man) |
| 262 | if ./raz -Werror -o $out/Doc tools/Doc.raz 2>$out/Doc.cerr; then |
| 263 | for f in lib/*.raz; do |
| 264 | if ! $out/Doc $f > $out/doc.out; then echo "FAIL Doc $f"; fail=$((fail + 1)); fi |
| 265 | done |
| 266 | for f in test/doc/*.expect; do |
| 267 | name=$(basename $f .expect) |
| 268 | m=lib/$name.raz |
| 269 | [ -f $m ] || m=lib/$name.linux-x86_64.raz |
| 270 | [ -f $m ] || m=test/doc/$name.raz |
| 271 | if $out/Doc $m | cmp -s - $f; then pass=$((pass + 1)) |
| 272 | else echo "FAIL Doc $m: output differs"; fail=$((fail + 1)); fi |
| 273 | done |
| 274 | # Doc man, for the modules that have a test/doc/X.man |
| 275 | for f in test/doc/*.man; do |
| 276 | m=test/doc/$(basename $f .man).raz |
| 277 | if $out/Doc man $m | cmp -s - $f; then pass=$((pass + 1)) |
| 278 | else echo "FAIL Doc man $m: output differs"; fail=$((fail + 1)); fi |
| 279 | done |
| 280 | |
| 281 | # the report's examples that are whole modules: each compiles, and |
| 282 | # each with a main runs and ends with status 0 |
| 283 | rm -rf $out/report; mkdir -p $out/report |
| 284 | for name in $($out/Doc examples doc/raz.md $out/report) $($out/Doc examples doc/raz-lib.md $out/report); do |
| 285 | if ! $raz -o $out/report/$name $out/report/$name.raz 2>$out/report/$name.cerr; then |
| 286 | echo "FAIL report example $name: $(cat $out/report/$name.cerr)"; fail=$((fail + 1)) |
| 287 | elif grep -q '^proc main\*' $out/report/$name.raz && ! $out/report/$name > /dev/null 2>&1; then |
| 288 | echo "FAIL report example $name: status $?"; fail=$((fail + 1)) |
| 289 | else pass=$((pass + 1)); fi |
| 290 | done |
| 291 | |
| 292 | # the tutorial's programs: each with a main runs, in the directory |
| 293 | # it was written to, so that a message names it as the page does; |
| 294 | # it ends with test/man/X.status, or 0, and prints, standard output |
| 295 | # then standard error, the block the page shows after it, if any |
| 296 | rm -rf $out/man; mkdir -p $out/man |
| 297 | for name in $($out/Doc examples doc/raz-tutorial.7 $out/man); do |
| 298 | grep -q '^proc main\*' $out/man/$name.raz || continue |
| 299 | want=0 |
| 300 | [ -f test/man/$name.status ] && want=$(cat test/man/$name.status) |
| 301 | if ! (cd $out/man && ../../../$raz -Werror $name.raz 2>$name.cerr); then |
| 302 | echo "FAIL tutorial example $name: $(cat $out/man/$name.cerr)"; fail=$((fail + 1)) |
| 303 | else |
| 304 | status=$( { ( cd $out/man && exec ./$name ) > $out/man/$name.out 2>$out/man/$name.err; echo $?; } 2>/dev/null ) |
| 305 | if [ $status != $want ]; then |
| 306 | echo "FAIL tutorial example $name: status $status, not $want"; fail=$((fail + 1)) |
| 307 | elif [ -f $out/man/$name.shown ] && |
| 308 | ! cat $out/man/$name.out $out/man/$name.err | sed 's/ *$//' | cmp -s - $out/man/$name.shown; then |
| 309 | echo "FAIL tutorial example $name: prints other than the page shows"; fail=$((fail + 1)) |
| 310 | else pass=$((pass + 1)); fi |
| 311 | fi |
| 312 | done |
| 313 | else |
| 314 | echo "FAIL tools/Doc.raz: $(cat $out/Doc.cerr)"; fail=$((fail + 1)) |
| 315 | fi |
| 316 | |
| 317 | # tools/Pretty.raz: each test/pretty/X.raz comes out as X.expect, which |
| 318 | # comes out as it is; so do the library, the examples and the tools |
| 319 | if ./raz -Werror -o $out/Pretty tools/Pretty.raz 2>$out/Pretty.cerr; then |
| 320 | for f in test/pretty/*.raz; do |
| 321 | want=test/pretty/$(basename $f .raz).expect |
| 322 | if $out/Pretty $f | cmp -s - $want && $out/Pretty $want | cmp -s - $want; then |
| 323 | pass=$((pass + 1)) |
| 324 | else echo "FAIL Pretty $f: output differs"; fail=$((fail + 1)); fi |
| 325 | done |
| 326 | for f in lib/*.raz examples/*.raz tools/*.raz; do |
| 327 | if ! $out/Pretty $f | cmp -s - $f; then |
| 328 | echo "FAIL Pretty $f: not formatted"; fail=$((fail + 1)) |
| 329 | fi |
| 330 | done |
| 331 | pass=$((pass + 1)) |
| 332 | else |
| 333 | echo "FAIL tools/Pretty.raz: $(cat $out/Pretty.cerr)"; fail=$((fail + 1)) |
| 334 | fi |
| 335 | |
| 336 | # error recovery: tools/Mutate.raz changes one symbol of each program, |
| 337 | # and the compiler must not crash, must exit with status 0 or 1, must |
| 338 | # say "error:" when it exits with 1, and must not report one place twice. |
| 339 | # Reproduce a failure with: build/Mutate FILE SEED > M.raz |
| 340 | fuzz() { # fuzz file seed |
| 341 | f=$1; seed=$2; dir=$(dirname $f) |
| 342 | mkdir -p $out/fuzz; m=$out/fuzz/$(basename $f) |
| 343 | $out/Mutate $f $seed > $m |
| 344 | $raz -I $dir/mods -o $out/mutant $m 2>$out/mutant.err |
| 345 | status=$? |
| 346 | why= |
| 347 | if [ $status -gt 1 ]; then why="exit status $status" |
| 348 | elif grep -q 'internal error' $out/mutant.err; then why="internal error" |
| 349 | elif [ $status = 1 ] && ! grep -q ': error:' $out/mutant.err; then why="status 1 without an error" |
| 350 | elif [ -n "$(grep ': error:' $out/mutant.err | sed 's/: error:.*//' | sort | uniq -d)" ]; then |
| 351 | why="two errors at one place" |
| 352 | fi |
| 353 | if [ -n "$why" ]; then |
| 354 | echo "FAIL fuzz $f seed $seed: $why"; cat $out/mutant.err |
| 355 | fail=$((fail + 1)) |
| 356 | else pass=$((pass + 1)); fi |
| 357 | } |
| 358 | if ./raz -Werror -o $out/Mutate tools/Mutate.raz 2>$out/Mutate.cerr; then |
| 359 | for f in examples/*.raz conform/run/*.raz test/run/*.raz lib/Opt.raz; do |
| 360 | $raz -I $(dirname $f)/mods -o $out/mutant $f 2>/dev/null || continue |
| 361 | for seed in ${FUZZ_SEEDS:-1 2 3}; do fuzz $f $seed; done |
| 362 | done |
| 363 | else |
| 364 | echo "FAIL tools/Mutate.raz: $(cat $out/Mutate.cerr)"; fail=$((fail + 1)) |
| 365 | fi |
| 366 | |
| 367 | # each library module's main is its test, run by tools/Test.raz, |
| 368 | # raztest, which says what it counted on its last line; Sys over C is |
| 369 | # tested in test/libc |
| 370 | if $raz -Werror -o $out/raztest tools/Test.raz 2>$out/raztest.cerr; then |
| 371 | libtests= |
| 372 | for f in lib/*.raz; do |
| 373 | case $f in # another target's file is tested there (test/mac.sh) |
| 374 | *.darwin-arm64.raz|*.darwin.raz|*.arm64.raz) continue;; |
| 375 | esac |
| 376 | [ $f != lib/Sys.raz ] && grep -q '^proc main\*' $f && ! skip $f && libtests="$libtests $f" |
| 377 | done |
| 378 | RAZ=$raz $out/raztest -j $(nproc 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1) -o $out/lib \ |
| 379 | $libtests \ |
| 380 | > $out/raztest.out 2>&1 |
| 381 | set -- $(tail -1 $out/raztest.out) # N passed, F failed, T timed out, S |
| 382 | if [ "$2" = passed, ] && [ "$6" = timed ]; then |
| 383 | pass=$((pass + $1)); fail=$((fail + $3 + $5)) |
| 384 | [ $(($3 + $5)) = 0 ] || grep -v '^ok ' $out/raztest.out |
| 385 | else |
| 386 | echo "FAIL tools/Test.raz:"; cat $out/raztest.out; fail=$((fail + 1)) |
| 387 | fi |
| 388 | # and again with the debug heap, RAZ_HEAP=debug: guards after blocks, |
| 389 | # freed blocks filled and quarantined |
| 390 | RAZ_HEAP=debug RAZ=$raz $out/raztest -j $(nproc 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1) -o $out/libdebug \ |
| 391 | $libtests \ |
| 392 | > $out/raztest-debug.out 2>&1 |
| 393 | set -- $(tail -1 $out/raztest-debug.out) |
| 394 | if [ "$2" = passed, ] && [ "$6" = timed ]; then |
| 395 | pass=$((pass + $1)); fail=$((fail + $3 + $5)) |
| 396 | [ $(($3 + $5)) = 0 ] || { echo "RAZ_HEAP=debug:"; grep -v '^ok ' $out/raztest-debug.out; } |
| 397 | else |
| 398 | echo "FAIL tools/Test.raz, RAZ_HEAP=debug:"; cat $out/raztest-debug.out; fail=$((fail + 1)) |
| 399 | fi |
| 400 | else |
| 401 | echo "FAIL tools/Test.raz: $(cat $out/raztest.cerr)"; fail=$((fail + 1)) |
| 402 | fi |
| 403 | |
| 404 | # raztest's own three reports, over the fixtures in test/raztest (a pass, |
| 405 | # a failed check, a build that fails, a test that outlasts -t 1): plain, |
| 406 | # --tap and --junit, each against its .expect, every time in them |
| 407 | # written T |
| 408 | rtreport() { # name, then raztest's arguments after the common ones |
| 409 | name=$1; shift |
| 410 | RAZ=$raz $out/raztest -t 1 -o $out/rt "$@" test/raztest 2>&1 </dev/null | |
| 411 | sed -e 's/[0-9][0-9]*\.[0-9][0-9]s/Ts/' -e 's/time="[0-9.]*"/time="T"/' > $out/rt.$name |
| 412 | if cmp -s $out/rt.$name test/raztest/$name.expect; then pass=$((pass + 1)) |
| 413 | else |
| 414 | echo "FAIL raztest $name:"; diff test/raztest/$name.expect $out/rt.$name |
| 415 | fail=$((fail + 1)) |
| 416 | fi |
| 417 | } |
| 418 | if [ -x $out/raztest ]; then |
| 419 | rtreport plain |
| 420 | rtreport tap --tap |
| 421 | RAZ=$raz $out/raztest -t 1 -o $out/rt --junit $out/rt.xml test/raztest >/dev/null 2>&1 |
| 422 | sed -e 's/time="[0-9.]*"/time="T"/' $out/rt.xml > $out/rt.junit |
| 423 | if cmp -s $out/rt.junit test/raztest/junit.expect; then pass=$((pass + 1)) |
| 424 | else |
| 425 | echo "FAIL raztest junit:"; diff test/raztest/junit.expect $out/rt.junit |
| 426 | fail=$((fail + 1)) |
| 427 | fi |
| 428 | fi |
| 429 | |
| 430 | # raztest -w: a passing test, then edited to fail, is run again by the |
| 431 | # watch, which ^C ends with status 130; each wait is bounded to 10 s |
| 432 | waitfor() { # file, text: whether text shows in file within 10 s |
| 433 | for _ in $(seq 100); do |
| 434 | grep -q "$2" $1 && return 0 |
| 435 | sleep 0.1 |
| 436 | done |
| 437 | return 1 |
| 438 | } |
| 439 | if [ -x $out/raztest ]; then |
| 440 | wd=$out/rtw; rm -rf $wd; mkdir -p $wd/t |
| 441 | cp test/raztest/Pass.raz $wd/t/ |
| 442 | RAZ=$raz $out/raztest -w -o $wd/o $wd/t > $wd/log 2>&1 </dev/null & |
| 443 | wpid=$! |
| 444 | if waitfor $wd/log '1 passed'; then |
| 445 | printf 'module Pass;\nimport Rt;\nproc main*;\nbegin\n Rt.exit(1);\nend;\nend Pass.\n' > $wd/t/Pass.raz |
| 446 | waitfor $wd/log '0 passed, 1 failed'; ok=$? |
| 447 | else ok=1; fi |
| 448 | kill -INT $wpid 2>/dev/null; wait $wpid; st=$? |
| 449 | if [ $ok = 0 ] && [ $st = 130 ]; then pass=$((pass + 1)) |
| 450 | else |
| 451 | echo "FAIL raztest -w (status $st):"; cat $wd/log |
| 452 | fail=$((fail + 1)) |
| 453 | fi |
| 454 | fi |
| 455 | |
| 456 | # CAbi is tools/cabi.c's output, from the C library's own headers: |
| 457 | # compiled with cc, and with musl-gcc, each where it is installed, it |
| 458 | # writes lib/'s file again |
| 459 | for cc in cc musl-gcc; do |
| 460 | command -v $cc >/dev/null || continue |
| 461 | if ! $cc -o $out/cabi tools/cabi.c 2>$out/cabi.cerr; then |
| 462 | echo "FAIL tools/cabi.c with $cc: $(cat $out/cabi.cerr)"; fail=$((fail + 1)) |
| 463 | elif ! $out/cabi linux-x86_64 | cmp -s - lib/CAbi.linux-x86_64.raz; then |
| 464 | echo "FAIL tools/cabi.c with $cc: lib/CAbi.linux-x86_64.raz differs"; fail=$((fail + 1)) |
| 465 | else pass=$((pass + 1)); fi |
| 466 | done |
| 467 | |
| 468 | # Thread's test again, with too little memory for all its threads: |
| 469 | # spawn must fail, with Thread.Failed |
| 470 | if skip "Thread under a memory limit"; then : |
| 471 | elif (ulimit -v 60000; $out/lib/Thread.linux-x86_64 fail) > /dev/null 2>&1; then pass=$((pass + 1)) |
| 472 | else echo "FAIL Thread under a memory limit"; fail=$((fail + 1)); fi |
| 473 | |
| 474 | # the compiler's way of going on after an error, in small: a parser |
| 475 | # that reads names, fails on each bad one, and goes on to the next |
| 476 | if $raz -Werror -I src -o $out/recover src/test/Recover.raz 2>$out/recover.cerr; then |
| 477 | printf 'a bad b bad bad c\nd bad\n' >$out/rec.raz |
| 478 | r=$($out/recover $out/rec.raz 2>/dev/null) || true |
| 479 | if [ "$r" = "8 names, 4 failed, 4 errors" ]; then pass=$((pass + 1)) |
| 480 | else echo "FAIL src/test/Recover.raz: $r"; fail=$((fail + 1)); fi |
| 481 | else |
| 482 | echo "FAIL src/test/Recover.raz: $(cat $out/recover.cerr)"; fail=$((fail + 1)) |
| 483 | fi |
| 484 | |
| 485 | # a module imported and never called leaves nothing of its own in the |
| 486 | # program, not even Width's tables: the same program, importing it or |
| 487 | # not, makes a file of the same size (the names the trace shows may |
| 488 | # come in another order). Width's own imports, Str and through it Heap, |
| 489 | # run their bodies, as every module does, so both import Str |
| 490 | mkdir -p $out/shake |
| 491 | printf 'module Shake;\nimport Out, Str, Width;\nproc main*;\nbegin\n Out.int(1); Out.ln;\nend;\nend Shake.\n' >$out/shake/Shake.raz |
| 492 | $raz -o $out/shake/with $out/shake/Shake.raz 2>/dev/null |
| 493 | printf 'module Shake;\nimport Out, Str;\nproc main*;\nbegin\n Out.int(1); Out.ln;\nend;\nend Shake.\n' >$out/shake/Shake.raz |
| 494 | $raz -o $out/shake/without $out/shake/Shake.raz 2>/dev/null |
| 495 | if [ $(wc -c <$out/shake/with) = $(wc -c <$out/shake/without) ]; then pass=$((pass + 1)) |
| 496 | else echo "FAIL an unused import, Width, changes the program"; fail=$((fail + 1)); fi |
| 497 | |
| 498 | # the editors' support, headless, where the editors are installed |
| 499 | if test/editors.sh; then pass=$((pass + 1)); else fail=$((fail + 1)); fi |
| 500 | |
| 501 | # Installed source libraries: default, explicit and isolated lookup. |
| 502 | if test/library-path.sh "$raz"; then pass=$((pass + 1)); else fail=$((fail + 1)); fi |
| 503 | |
| 504 | # The compiler built with another host (test/host/Host.raz). |
| 505 | if test/compiler-host.sh "$raz"; then pass=$((pass + 1)); else fail=$((fail + 1)); fi |
| 506 | |
| 507 | summary="$pass passed, $fail failed" |
| 508 | [ $skipped = 0 ] || summary="$summary, $skipped skipped" |
| 509 | echo "$summary" |
| 510 | [ $fail = 0 ] |