#!/bin/sh
# autopkgtest driver for ROCm upstream binaries

TESTSDIR="/usr/libexec/rocm/libhipcub-tests"

if [ ! -e /dev/kfd ]
then
    echo "/dev/kfd not present, system either lacks AMD GPU or AMDGPU driver is not loaded."
    echo "Skipping tests."
    # Magic number to signal 'skipped'
    exit 77
elif [ "`id -u`" != "0" ] && [ ! -r /dev/kfd ]
then
    echo "/dev/kfd present but no read permission."
    echo "Skipping tests."
    exit 77
elif [ ! -d "$TESTSDIR" ]
then
    echo "The directory $TESTSDIR does not exist." >&2
    echo "Aborting." >&2
    exit 1
fi

if [ -n "$AUTOPKGTEST_TMP" ]; then
    cd "$AUTOPKGTEST_TMP"
fi

# Any individual failure is overall failure
EXITCODE=0
for TESTNAME in $TESTSDIR/test_*
do
    $TESTNAME || EXITCODE=1
done

exit $EXITCODE
