#!/bin/sh

testsdir="/usr/libexec/migraphx/migraphx-tests"
tmpdir="$AUTOPKGTEST_TMP/migraphx-tests"

target="$1"
gpu_tests="_gpu|test_verify_"
skipped_tests="test_process_test|test_api_gpu|test_verify"

mkdir -p "$tmpdir" && cp -a "$testsdir/"* "$tmpdir/"

cd "$tmpdir"

exitcode=0
for testname in ./*
do
    if [ -f "$testname" ] && [ -x "$testname" ] && ! echo "$testname" | grep -Eq "($skipped_tests)"; then
        if [ "$target" = cpu ] && echo "$testname" | grep -Eq "($gpu_tests)"; then
            continue
        elif [ "$target" = gpu ] && ! echo "$testname" | grep -Eq "($gpu_tests)"; then
            continue
        fi
        "$testname" || exitcode=1
    fi
done

exit $exitcode
