105 lines
2.3 KiB
Bash
Executable File
105 lines
2.3 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
cc_bin=${CC_BIN:-cc}
|
|
source_file=${SOURCE_FILE:-tests/system/freebsd-syscall-mapping.c}
|
|
|
|
if ! command -v "$cc_bin" >/dev/null 2>&1; then
|
|
echo "C compiler not found: $cc_bin" >&2
|
|
exit 1
|
|
fi
|
|
if [ ! -f "$source_file" ]; then
|
|
echo "Source file not found: $source_file" >&2
|
|
exit 1
|
|
fi
|
|
|
|
cleanup=0
|
|
if [ -n "${WORKDIR:-}" ]; then
|
|
workdir=$WORKDIR
|
|
mkdir -p "$workdir"
|
|
else
|
|
workdir=$(mktemp -d /tmp/fruix-freebsd-syscall-mapping.XXXXXX)
|
|
cleanup=1
|
|
fi
|
|
|
|
if [ "${KEEP_WORKDIR:-0}" -eq 1 ]; then
|
|
cleanup=0
|
|
fi
|
|
|
|
cleanup_workdir() {
|
|
if [ "$cleanup" -eq 1 ]; then
|
|
rm -rf "$workdir"
|
|
fi
|
|
}
|
|
trap cleanup_workdir EXIT INT TERM
|
|
|
|
binary=$workdir/freebsd-syscall-mapping
|
|
compile_log=$workdir/compile.log
|
|
regular_out=$workdir/regular.out
|
|
regular_err=$workdir/regular.err
|
|
root_out=$workdir/root.out
|
|
root_err=$workdir/root.err
|
|
metadata_file=$workdir/freebsd-syscall-mapping-metadata.txt
|
|
|
|
printf 'Working directory: %s\n' "$workdir"
|
|
printf 'Compiler: %s\n' "$cc_bin"
|
|
|
|
"$cc_bin" -Wall -Wextra -std=c11 -I/usr/local/include "$source_file" -o "$binary" >"$compile_log" 2>&1
|
|
|
|
set +e
|
|
"$binary" >"$regular_out" 2>"$regular_err"
|
|
regular_rc=$?
|
|
set -e
|
|
if [ "$regular_rc" -ne 0 ]; then
|
|
echo "regular syscall mapping checks failed" >&2
|
|
cat "$regular_out" >&2 || true
|
|
cat "$regular_err" >&2 || true
|
|
exit 1
|
|
fi
|
|
|
|
set +e
|
|
sudo "$binary" --root-tests >"$root_out" 2>"$root_err"
|
|
root_rc=$?
|
|
set -e
|
|
if [ "$root_rc" -ne 0 ]; then
|
|
echo "root syscall mapping checks failed" >&2
|
|
cat "$root_out" >&2 || true
|
|
cat "$root_err" >&2 || true
|
|
exit 1
|
|
fi
|
|
|
|
cat >"$metadata_file" <<EOF
|
|
source_file=$source_file
|
|
binary=$binary
|
|
compile_log=$compile_log
|
|
regular_out=$regular_out
|
|
regular_err=$regular_err
|
|
regular_rc=$regular_rc
|
|
root_out=$root_out
|
|
root_err=$root_err
|
|
root_rc=$root_rc
|
|
regular_output_begin
|
|
$(cat "$regular_out")
|
|
regular_output_end
|
|
root_output_begin
|
|
$(cat "$root_out")
|
|
root_output_end
|
|
EOF
|
|
|
|
if [ -n "${METADATA_OUT:-}" ]; then
|
|
mkdir -p "$(dirname "$METADATA_OUT")"
|
|
cp "$metadata_file" "$METADATA_OUT"
|
|
fi
|
|
|
|
printf 'PASS freebsd-syscall-mapping\n'
|
|
printf 'Metadata file: %s\n' "$metadata_file"
|
|
if [ -n "${METADATA_OUT:-}" ]; then
|
|
printf 'Copied metadata to: %s\n' "$METADATA_OUT"
|
|
fi
|
|
printf '%s\n' '--- regular output ---'
|
|
cat "$regular_out"
|
|
printf '%s\n' '--- root output ---'
|
|
cat "$root_out"
|
|
printf '%s\n' '--- metadata ---'
|
|
cat "$metadata_file"
|