run-tests 2.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
#!/bin/sh
#
# Simple script to run all tests either in-tree or after test RPM
# installation. Output will be nicely formatted if output formatter
# is available. All arguments to this script are passed to formatoutput.

prepareInTreeTestData(){
    # this is a dirty hack to get most of the test data into a place
    # usable for running tests without installation. Currently this
    # causes some duplication
    mkdir -p build/testdata
    TESTDATA=`find tests -name testdata`

    for t in $TESTDATA; do
        test=`echo $t | sed 's,.*tests/,,' | sed 's,/.*,,'`
        mkdir -p build/testdata/$test/
        dirs=`find $t/* -prune -type f`
        if [ -z "$dirs" ]; then
            cp -a $t/* build/testdata/$test/
        else
            mkdir -p build/testdata/$test/configroot/usr/share/ssu/
            mkdir -p build/testdata/$test/configroot/etc/ssu/
            for ini in $t/*.ini; do
                inifile=`echo $ini | sed 's,.*/,,'`
                if [ $inifile = "ssu.ini" ]; then
                    cp $ini build/testdata/$test/configroot/etc/ssu/
                elif [ $inifile = "board-mappings.ini" ]; then
                    mkdir -p build/testdata/$test/configroot/usr/share/ssu/board-mappings.d
                    cp $ini build/testdata/$test/configroot/usr/share/ssu/board-mappings.d/
                else
                    cp $ini build/testdata/$test/configroot/usr/share/ssu/
                fi
            done
            cp $t/* build/testdata/$test/configroot/
            for key in $t/*.{key,crt}; do
                cp $key build/testdata/$test/
            done
        fi
    done
}

if [ -d "build" ]; then
    BASE_DIR="`pwd`/build"
    export LD_LIBRARY_PATH="$BASE_DIR/lib:${LD_LIBRARY_PATH}"
    export SSU_SANDBOX_PATH="$BASE_DIR/lib/libsandboxhook.so"
    prepareInTreeTestData
    TESTS=`ls $BASE_DIR/bin/ut_*`
    if [ -f "$BASE_DIR/bin/formatoutput" ]; then
        FORMATOUTPUT="$BASE_DIR/bin/formatoutput"
    fi
elif [ -d "/opt/tests/ssu" ]; then
    BASE_DIR="/opt/tests/ssu"
    export LD_LIBRARY_PATH="$BASE_DIR:${LD_LIBRARY_PATH}"
    TESTS=`ls $BASE_DIR/ut_*`
    if [ -f "$BASE_DIR/formatoutput" ]; then
        FORMATOUTPUT="$BASE_DIR/formatoutput"
    fi
else
    echo "Neither ./build nor /opt/tests/ssu exist, exiting"
    exit 1
fi

for test in $TESTS; do
    if [ -d "./build/testdata/`basename $test`" ]; then
        export SSU_TESTS_DATA_PATH="`pwd`/build/testdata/`basename $test`"
    else
        unset SSU_TESTS_DATA_PATH
    fi

    if [ -z "$FORMATOUTPUT" ]; then
        $test | grep -v "^PASS"
    else
        $test | $FORMATOUTPUT $@
    fi
done