8d57ebc5c7
Resolves: RHELMISC-7595 Signed-off-by: Boyang Xue <bxue@redhat.com>
235 lines
5.7 KiB
Bash
Executable File
235 lines
5.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
#
|
|
# Description: Run for fuse-3.x CI gating test
|
|
# Author: Zorro Lang <zlang@redhat.com>
|
|
#
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
#
|
|
# Copyright (c) 2022 Red Hat, Inc. All rights reserved.
|
|
#
|
|
# This copyrighted material is made available to anyone wishing
|
|
# to use, modify, copy, or redistribute it subject to the terms
|
|
# and conditions of the GNU General Public License version 2.
|
|
#
|
|
# This program is distributed in the hope that it will be
|
|
# useful, but WITHOUT ANY WARRANTY; without even the implied
|
|
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
# PURPOSE. See the GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public
|
|
# License along with this program; if not, write to the Free
|
|
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
# Boston, MA 02110-1301, USA.
|
|
#
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# Include Beaker environment
|
|
. /usr/share/beakerlib/beakerlib.sh || exit 1
|
|
|
|
status=1
|
|
trap "cleanup;" 0 1 2 3 9 15
|
|
|
|
# Enable all repos by default, to try our best to get some packages
|
|
YUM_PROG="yum --enablerepo=*"
|
|
WORK_DIR=`pwd`
|
|
|
|
# test exits here
|
|
cleanup()
|
|
{
|
|
if [ $status -eq 0 ];then
|
|
_report "CLEAN" PASS
|
|
else
|
|
_report "CLEAN" FAIL
|
|
fi
|
|
exit $status
|
|
}
|
|
|
|
if [ -z "$RECIPEID" -o -z "$TASKID" ]; then
|
|
OUTPUTFILE=`pwd`/output.log
|
|
fi
|
|
|
|
function echoo()
|
|
{
|
|
echo $@ | tee -a $OUTPUTFILE
|
|
}
|
|
|
|
# Wrapper to log the output of the command
|
|
function xlog()
|
|
{
|
|
echoo "$@"
|
|
$@ 2>&1 | tee -a $OUTPUTFILE
|
|
return $?
|
|
}
|
|
|
|
# Wrapper to report_result, clears $OUTPUTFILE
|
|
function _report()
|
|
{
|
|
local what="$FSTYP:$1"
|
|
local status="$2"
|
|
local score="$3"
|
|
test -z "$score" && score=0
|
|
echoo "---------------------------------------------"
|
|
echoo -e "|Report:\t" "$what\t" "$status\t" "$score|"
|
|
echoo "---------------------------------------------"
|
|
rhts-report-result "$what" "$status" "$OUTPUTFILE" "$score"
|
|
if [ -f "$OUTPUTFILE" ];then
|
|
rm -f $OUTPUTFILE
|
|
touch $OUTPUTFILE
|
|
fi
|
|
}
|
|
|
|
function prepare_test()
|
|
{
|
|
local pkgname
|
|
local specfile
|
|
|
|
echoo "* Get building and running dependences"
|
|
$YUM_PROG install -y --nogpgcheck fuse3 fuse3-libs fuse3-devel rpm-build gcc \
|
|
autoconf automake gettext-devel libselinux-devel libtool yum-utils \
|
|
python3 gcc-c++ python3-pip meson ninja-build
|
|
|
|
echoo "* Get fuse3 srpm"
|
|
rm -rf downloaddir
|
|
mkdir downloaddir
|
|
pushd downloaddir
|
|
rlFetchSrcForInstalled fuse3
|
|
if [ $? -ne 0 ];then
|
|
_report prepare_test:download FAIL
|
|
exit 1
|
|
fi
|
|
|
|
echoo "* Install fuse3 srpm"
|
|
pkgname=$(ls *.src.rpm 2>/dev/null | head -1)
|
|
echoo "Install $pkgname ..."
|
|
rpm -ivh $pkgname
|
|
specfile=`rpm -ql $pkgname 2>/dev/null | grep .spec`
|
|
specfile="$(ls ~/rpmbuild/SPECS/$specfile 2>/dev/null)"
|
|
popd
|
|
if [ ! -f "$specfile" ];then
|
|
_report prepare_test:specfile FAIL
|
|
exit 1
|
|
fi
|
|
|
|
echoo "* Unpack and patch fuse3 source"
|
|
|
|
FUSE3_BUILD_DIR=`rpmbuild --eval %{_builddir}`
|
|
# Remove all old build directory, to avoid they affect later testing.
|
|
rm -rf $FUSE3_BUILD_DIR/*fuse*
|
|
rpmbuild -bp $specfile
|
|
if [ $? -eq 0 ];then
|
|
FUSE3_BUILD_DIR=`realpath $FUSE3_BUILD_DIR/* | head -n 1`
|
|
else
|
|
# unset FUSE3_BUILD_DIR to stop later testing, if rpmbuild fails
|
|
unset FUSE3_BUILD_DIR
|
|
fi
|
|
echoo "FUSE3_BUILD_DIR = $FUSE3_BUILD_DIR"
|
|
if [ ! -d "$FUSE3_BUILD_DIR" ];then
|
|
_report prepare_test:fuse3_unpack FAIL
|
|
exit 1
|
|
fi
|
|
|
|
echoo "* Build fuse3 source locally"
|
|
pushd $FUSE3_BUILD_DIR
|
|
rm -rf build
|
|
mkdir build
|
|
pushd build
|
|
meson .. && ninja
|
|
if [ $? -ne 0 ];then
|
|
echoo "build fuse3 failed!"
|
|
_report prepare_test:fuse3_build FAIL
|
|
exit 1
|
|
fi
|
|
popd
|
|
popd
|
|
|
|
echoo "* Get pytest and looseversion"
|
|
which pip3 && which python3
|
|
if [ $? -ne 0 ];then
|
|
echoo "missing pip3 or python3"
|
|
_report prepare_test:python FAIL
|
|
exit 1
|
|
fi
|
|
if ! pip3 install pytest;then
|
|
echoo "install pytest failed!"
|
|
_report prepare_test:pytest FAIL
|
|
exit 1
|
|
fi
|
|
|
|
if ! pip3 install looseversion;then
|
|
echoo "install looseversion failed!"
|
|
_report prepare_test:looseversion FAIL
|
|
exit 1
|
|
fi
|
|
|
|
|
|
_report prepare_test PASS
|
|
}
|
|
|
|
function do_test()
|
|
{
|
|
local rc=0
|
|
local ver="DEFAULT"
|
|
local expression
|
|
local logfile="$WORK_DIR/pytest.log"
|
|
local nfail=0
|
|
local npass=0
|
|
|
|
pushd $FUSE3_BUILD_DIR/build
|
|
if [ -f ./util/fusermount3 ];then
|
|
chown root:root util/fusermount3
|
|
chmod 4755 util/fusermount3
|
|
ver=`./util/fusermount3 -V|awk '{print $3}'`
|
|
fi
|
|
if [ ! -f "$WORK_DIR/config/$ver" ];then
|
|
ver="DEFAULT"
|
|
fi
|
|
expression=`cat $WORK_DIR/config/$ver|grep -v ^#`
|
|
|
|
# remove -x option of pytest, avoid the test exits instantly on first
|
|
# error
|
|
sed -i /addopts/s/-x// test/pytest.ini
|
|
|
|
if [ -n "$expression" ];then
|
|
echoo "python3 -m pytest -k \"$expression\" test"
|
|
python3 -m pytest -k "$expression" test 2>&1 | tee $logfile
|
|
else
|
|
echoo "python3 -m pytest test"
|
|
python3 -m pytest test 2>&1 | tee $logfile
|
|
fi
|
|
rc=$?
|
|
popd
|
|
|
|
tail -1 $logfile
|
|
if [ $rc -eq 0 ];then
|
|
if ( tail -1 $logfile | grep -q failed);then
|
|
nfail=`tail -1 $logfile | sed -n 's/.* \([0-9]\+\) failed.*/\1/p'`
|
|
fi
|
|
if ( tail -1 $logfile | grep -q passed);then
|
|
npass=`tail -1 $logfile | sed -n 's/.* \([0-9]\+\) passed.*/\1/p'`
|
|
fi
|
|
else
|
|
echoo "pytest failed, please check the log file"
|
|
_report do_test:pytest FAIL
|
|
exit 1
|
|
fi
|
|
|
|
if [ "$nfail" != "0" ];then
|
|
_report do_test:$npass:$nfail FAIL
|
|
exit 1
|
|
elif [ "$npass" == "0" ];then
|
|
echoo "If there's not PASSED test, must be something wrong"
|
|
_report do_test:nopass FAIL
|
|
exit 1
|
|
else
|
|
_report do_test:$npass:$nfail PASS
|
|
fi
|
|
return 0
|
|
}
|
|
|
|
prepare_test
|
|
do_test
|
|
status=0
|
|
exit 0
|