#!/bin/bash

set -ux

# Exclude some tests
EXCLUDES=" \
        -x apparmor_stacking \
        -x fd01 "
RESULT=0

run_test() {
        ./zdtm.py run --criu-bin=/usr/sbin/criu --crit-bin=/usr/bin/crit ${EXCLUDES} \
                --keep-going \
                -a

        RESULT=$?
}

# Cleanup test/pycriu directory
rm -fv -- test/pycriu

# Change directory to test directory
cd test

echo "Run the actual CRIU test suite"
run_test

if [ "$RESULT" -ne "0" ]; then
        # Run tests a second time to make sure it is a real failure
        echo "Something failed. Run the actual CRIU test suite a second time"
        run_test
        if [ "$RESULT" -ne "0" ]; then
                echo "Still a test suite error. Something seems to be actually broken"
                exit $RESULT
        fi
fi

exit 0
