#!/usr/bin/env bash set -euo pipefail root="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)" if [[ "${1:-}" != "--already-built" ]]; then make -C "$root" PROFILE=observe host >/dev/null fi check_output() { local program="$1" expected="$2" actual actual="$($program)" if [[ "$actual" != "$expected" ]]; then printf 'FAIL %s\nexpected: %s\nactual: %s\n' \ "$program" "$expected" "$actual" >&2 return 1 fi printf 'PASS %s: %s\n' "$(basename -- "$(dirname -- "$program")")" "$actual" } check_output "$root/host-build/task01_libc_without_heap/prog" \ 'length=16 pass=1' check_output "$root/host-build/task03_bounded_sbrk/prog" \ 'grow=40 rejected_grow=40 shrink=32 rejected_shrink=32 preserved=1 bounds=1 pass=1' check_output "$root/host-build/task04_smalloc/prog" \ 'header=16 first=32 second=48 delta=32 aligned=1 metadata=1 append=1 reset=1 pass=1' check_output "$root/host-build/task05_picolibc_malloc/prog" \ 'nonnull=1 delta_nonzero=1 checksum=4612 nonoverlap=1 aligned=1 freed=1 pass=1'