#!/bin/sh
# autopkgtest check: Build and run the upstream test suite.
# (C) 2012 Canonical Ltd.
# Author: Daniel Kessel <d.kessel@gmx.de>

# running the mysql testsuite as described in:
# https://bugs.launchpad.net/ubuntu/+source/mysql-5.5/+bug/959683

echo "running test 'testsuite'"
set -e

ARCH=$(dpkg-architecture -qDEB_BUILD_ARCH)
SKIP_TEST_LST="/tmp/skip-test.lst"
WORKDIR=$(mktemp -d)
trap "rm -rf $WORKDIR $SKIP_TEST_LST" 0 INT QUIT ABRT PIPE TERM
cd $WORKDIR

mkdir var
mkdir tmp

echo "using vardir: $WORKDIR/var"
echo "using tmpdir: $WORKDIR/tmp"

echo "Setting up skip-tests-list"

# Broken on all architectures
cat > $SKIP_TEST_LST << EOF
main.file_contents                 : BUG#000000 - Tests package contents, which differs from upstream
main.loaddata_special              : BUG#96341  - Access blocked by apparmor. https://bugs.mysql.com/bug.php?id=96341
main.mysql_client_test             : BUG#100274 - Unstable test
main.slow_log                      : BUG#000000 - broken
main.log_state                     : BUG#000000 - requires additional resources
main.histograms                    : BUG#000000 - requires additional resources
main.sp-threads                    : BUG#000000 - requires additional resources
EOF

# Broken on specific architectures
case "$ARCH" in
  s390x)
  cat >> $SKIP_TEST_LST << EOF
main.archive                       : BUG#111156 - fails on s390x since 8.4.2
main.func_compress                 : BUG#111156 - fails on s390x since 8.4.2
EOF
    ;;
  ppc64el)
  cat >> $SKIP_TEST_LST << EOF
main.dd_upgrade_error_cs           : BUG#000000 - fails on ppc64el in mysql 8.4
main.explain                       : BUG#000000 - fails on ppc64el in mysql 8.4
main.packet_myisam                 : BUG#000000 - fails on ppc64el in mysql 8.4
main.parser_stack                  : BUG#000000 - fails on ppc64el in mysql 8.4
main.ssl-big-packet                : BUG#000000 - fails on ppc64el in mysql 8.4
EOF
    ;;
esac

cd /usr/lib/mysql-test
echo "starting mysql-test-run.pl..."
# Workaround for change introduced as part of https://www.debian.org/security/2016/dsa-3628
# Pending upstream fix of mtr includes
export PERLLIB=.
./mysql-test-run.pl --suite=main --vardir=$WORKDIR/var --tmpdir=$WORKDIR/tmp \
    --skip-ndbcluster --parallel=auto --skip-rpl --report-features --client-bindir=/usr/lib/mysql-test/bin/ \
    --force --skip-test-list=$SKIP_TEST_LST --report-unstable-tests $@ 2>&1
echo "run: OK"
