raz / test / alpine.sh

32 lines · 1.5 KiB · executable · raw · history · last change 6a6bdf5c

1#!/bin/sh
2# Runs test/libc on Alpine, whose C library is musl, in a docker
3# container: raz, a static program, compiles each program there, so it
4# links it against musl by default, having only musl's loader; then
5# each runs, its output and status compared as test/check.sh compares
6# them. Needs docker, and the network the first time, for the image.
7
8image=${ALPINE:-alpine:3.20}
9exec docker run --rm -v "$PWD":/raz:ro -w /raz "$image" sh -c '
10pass=0; fail=0; out=/tmp/out; mkdir -p $out
11for f in test/libc/*.raz; do
12 name=$(basename $f .raz)
13 if ! ./raz -Werror -I test/libc/mods -o $out/$name $f 2>$out/$name.cerr; then
14 echo "FAIL $f: does not compile: $(cat $out/$name.cerr)"; fail=$((fail + 1)); continue
15 fi
16 if ! grep -q ld-musl $out/$name; then # the loader it names
17 echo "FAIL $f: not linked against musl"; fail=$((fail + 1)); continue
18 fi
19 [ -f test/libc/$name.expect ] || { pass=$((pass + 1)); continue; }
20 status=$( { ( cd /tmp && exec $out/$name ) > $out/$name.out 2>$out/$name.err; echo $?; } 2>/dev/null )
21 want=0; [ -f test/libc/$name.status ] && want=$(cat test/libc/$name.status)
22 if ! cmp -s $out/$name.out test/libc/$name.expect; then
23 echo "FAIL $f: output differs"; diff $out/$name.out test/libc/$name.expect | head -5; fail=$((fail + 1))
24 elif [ $status != $want ]; then
25 echo "FAIL $f: status $status, not $want"; cat $out/$name.err | head -5; fail=$((fail + 1))
26 else
27 pass=$((pass + 1))
28 fi
29done
30cat /etc/alpine-release | sed "s/^/Alpine /"
31echo "$pass passed, $fail failed"
32[ $fail = 0 ]'