#!/bin/sh
# autopkgtest check: run the QA of the volk_gnsssdr kernels shipped in
# gnss-sdr. Each SIMD implementation available on the test machine is
# checked against the generic (portable C) implementation of the kernel.

set -e

WORKDIR=$(mktemp -d)
trap 'rm -rf "$WORKDIR"' 0 INT QUIT ABRT PIPE TERM
export HOME="$WORKDIR"
cd "$WORKDIR"

echo "Machines available: $(volk_gnsssdr-config-info --avail-machines)"
echo "Machine selected:   $(volk_gnsssdr-config-info --machine)"

# volk_gnsssdr_profile always exits with 0, so failures are detected
# from its output. --dry-run avoids writing a volk_gnsssdr config file.
volk_gnsssdr_profile --dry-run > profile.log 2>&1
cat profile.log

if grep -E ': fail on arch|Caught Exception' profile.log; then
    echo "volk_gnsssdr QA: FAIL"
    exit 1
fi

if ! grep -q 'RUN_VOLK_GNSSSDR_TESTS' profile.log; then
    echo "volk_gnsssdr QA: no kernel was tested"
    exit 1
fi

echo "volk_gnsssdr QA: OK"
