#!/usr/bin/bash

set -e

usage() {
    echo "usage: `basename $0` [OPTIONS]"
    echo "  --threads NUM       The number of threads to use for running tests."
}


threads_arg=''

while [ $# -gt 0 ]; do
    case $1 in
        --threads)
            shift
            threads_arg="--threads $1"
            ;;
        --multilib-arch)
            shift
            ARCH=$1
            ;;
        * )
            echo "unknown option: $1"
            echo ""
            usage
            exit 1
            ;;
    esac
    shift
done


set -xe

if [ -z "$ARCH" ]; then
    ARCH=`rpm --eval '%_arch'`
fi

case $ARCH in
    arm)
        ;&
    i686)
        LIB_DIR="/usr/lib/"
        ;;
    *)
        LIB_DIR="/usr/lib64/"
        ;;
esac

BIN_DIR="/usr/bin/"
INCLUDE_DIR="/usr/include/"

lit $threads_arg -v \
    --config-prefix $ARCH \
    -Dlibomp_compiler=clang \
    -Dbindir=$BIN_DIR \
    -Dlibdir=$LIB_DIR \
    -Dincludedir=$INCLUDE_DIR \
    -Dlibomp_test_root=/usr/share/libomp/src/runtime/test \
    /usr/share/libomp/src/runtime/test

exit 0
