#!/bin/sh -eu
# The tests require access to the /dev/aie0 character device, which is only
# present on physical hardware with the appropriate driver, so the tests
# themselves cannot be run in autopkgtest. However, we can test if the binary
# itself works and there are no runtime errors other than the missing hardware.

# Without hardware, every test fails and run-test-aie exits non-zero
OUTPUT="$(/usr/libexec/xaiefal/tests/run-test-aie 2>&1)" || true

# CppUTest ends with a summary line starting with "Errors (" when test cases
# fail (as expected without /dev/aie0), or "OK (" when they all pass (on
# hardware). If neither is present, the binary did not run to completion, so
# treat that as a failure.
if printf '%s\n' "$OUTPUT" | grep -q -E '^(Errors|OK) \('; then
    exit 0
fi

echo "ERROR: run-test-aie did not print a CppUTest summary line" >&2
exit 1
