#!./common/bats/bin/bats
# -*-sh-*-

load ./common/test_helper_functions || exit 1
source ./common/functions || exit 1

if [ -s ./common/TEST_ENV ];then
    source ./common/TEST_ENV
fi

check_rms
rm=$RESOURCE_MANAGER

tname="libs/GSL"
tx1=test
tx2=test_static

@test "[$tname] run test_gsl_histogram ($LMOD_FAMILY_COMPILER)" {
    pushd test_gsl_histogram
    if [ ! -s ./test_gsl_histogram.sh ];then
        flunk "test_gsl_histogram.sh does not exist"
    fi
    ./test_gsl_histogram.sh
    assert_success
    popd
}

@test "[$tname] run block under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd block
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run bspline under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd bspline
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run cblas under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd cblas
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run cdf under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd cdf
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run cheb under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd cheb
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run combination under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd combination
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run complex under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd complex
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run const under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd const
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run deriv under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd deriv
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run dht under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd dht
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run diff under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd diff
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run eigen under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    # karl.w.schulz@intel.com (6/8/17) - disable test on aarch64 as precision assumptions
    # within GSL are tuned for x86 and 80-bit extended precision
    [[ "$ARCH" == "aarch64" ]] && skip "Skipping eigen test for ARCH=$ARCH"

    pushd eigen
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run err under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd err
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run fft under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd fft
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run fit under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd fit
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run histogram under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd histogram
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run ieee-utils under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd ieee-utils
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run integration under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd integration
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run interpolation under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd interpolation
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run linalg under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd linalg
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run matrix under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd matrix
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    if [ ! -s $tx2 ];then
        flunk "$tx2 binary does not exist"
    fi
    run_serial_binary ./$tx2
    assert_success
    popd
}

@test "[$tname] run min under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd min
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run monte under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd monte
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run multifit under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {

    # karl.w.schulz@intel.com (1/12/17) - disable test on aarch64 as precision assumptions
    # within GSL are tuned for x86 and 80-bit extended precision
    [[ "$ARCH" == "aarch64" ]] && skip "Skipping multifit test for ARCH=$ARCH"

    pushd multifit
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run multilarge under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd multilarge
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi

    run_serial_binary -t "00:03:00" ./$tx1
    assert_success
    popd
}

@test "[$tname] run multimin under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd multimin
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run multiroots under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd multiroots
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run multiset under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd multiset
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run ntuple under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd ntuple
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run ode-initval under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd ode-initval
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run ode-initval2 under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd ode-initval2
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary -t "00:02:00" ./$tx1
    assert_success
    popd
}

@test "[$tname] run permutation under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd permutation
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run poly under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd poly
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run qrng under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd qrng
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run randist under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd randist
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run rng under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd rng
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run roots under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd roots
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run rstat under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd rstat
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary -t "00:02:00" ./$tx1
    assert_success
    popd
}

@test "[$tname] run siman under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd siman
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run sort under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd sort
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run spblas under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd spblas
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run specfunc under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {

    # karl.w.schulz@intel.com (1/12/17) - disable test on aarch64 as precision assumptions
    # within GSL are tuned for x86 and 80-bit extended precision
    [[ "$ARCH" == "aarch64" ]] && skip "Skipping specfun test for ARCH=$ARCH"

    pushd specfunc
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run splinalg under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd splinalg
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run spmatrix under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd spmatrix
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run statistics under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd statistics
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run sum under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd sum
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run sys under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd sys
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

@test "[$tname] run vector under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd vector
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary -t "00:03:00" ./$tx1
    assert_success
    if [ ! -s $tx2 ];then
        flunk "$tx2 binary does not exist"
    fi
    run_serial_binary -t "00:03:00" ./$tx2
    assert_success
    popd
}

@test "[$tname] run wavelet under resource manager ($rm/$LMOD_FAMILY_COMPILER)" {
    pushd wavelet
    if [ ! -s $tx1 ];then
        flunk "$tx1 binary does not exist"
    fi
    run_serial_binary ./$tx1
    assert_success
    popd
}

