#!/bin/bash -x
#
# tst_ofdm_mod_check
#
# Setup input and reference data for one of several versions of this test.

# Find the scripts directory
SCRIPTS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"

# Setup common variables
source $SCRIPTS/run_tests_common.sh

# RUN_DIR - Directory where test will be run
RUN_DIR="${UNITTEST_BASE}/test_run/${FULL_TEST_NAME}"

# Call common setup function to make the directory
setup_common "${RUN_DIR}"

# Change to test directory
cd "${RUN_DIR}"


#####################################################################
## Test CHECK actions:

declare -i Fails=0

case "${TEST_OPT}" in

    plain) LDPC="";;
    ldpc) LDPC="--ldpc";;
    esac

echo -e "\nReference check"
if ofdm_demod --in ref_mod_out.raw --out ref_ofdm_demod.raw --testframes ${LDPC}; then
    echo "Passed"
else
    echo "Failed"
    let Fails=($Fails + 1)
fi
#
echo -e "\nTarget check"
if ofdm_demod --in mod.raw --out stm_demod.raw --testframes ${LDPC}; then
    echo "Passed"
else
    echo "Failed"
    let Fails=($Fails + 1)
fi
#
echo -e "\nCompare output binary data"
if compare_ints -s -b2 -t3 ref_mod_out.raw mod.raw; then 
    echo "Passed"
else
    echo "Failed"
    let Fails=($Fails + 1)
fi
#

if (( $Fails == 0 )); then
    echo -e "\nTest PASSED"
else
    echo -e "\nTest FAILED!"
fi

exit $Fails
