#!/bin/sh
set -eu

: "${PRE15_DUT:?PRE15_DUT is required}"
: "${PRE15_ROOT:?PRE15_ROOT is required}"
: "${PRE15_RUN_DIR:?PRE15_RUN_DIR is required}"
: "${PRE15_LIB_DIR:?PRE15_LIB_DIR is required}"
. "$PRE15_LIB_DIR/runner.sh"

baseline=22965aea267c3fcaafb67c14f9a246a7bc6195b1
fixture_dir=$PRE15_DUT/tests/pre15/fixtures
spec=$fixture_dir/B10-directory-spec.json
oracle=$fixture_dir/B10-directory-oracle.py
artifacts=$PRE15_RUN_DIR/artifacts
report=$artifacts/B10-directory-results.json

for tool in git python3 sha256sum; do
	command -v "$tool" >/dev/null 2>&1 || \
		pre15_infra_blocked "missing B10 host tool: $tool"
done

pre15_record_fixture b10-spec "$spec"
pre15_record_fixture b10-oracle "$oracle"
pre15_record_fixture b10-case "$PRE15_DUT/tests/pre15/cases/B10-directory.sh"
pre15_record_fixture b10-dir "$PRE15_DUT/src/dir.c"
pre15_record_fixture b10-namei "$PRE15_DUT/src/namei.c"
mkdir -p "$artifacts"
pre15_target_reached

if python3 -B "$oracle" --root "$PRE15_ROOT" --dut "$PRE15_DUT" \
	--baseline "$baseline" --spec "$spec" --report "$report"
then
	pre15_record_fixture b10-report "$report"
else
	pre15_dut_fail 'B10 directory trust-boundary oracle failed'
fi
