2007-01-04 07:23:48 -06:00
|
|
|
#!/bin/bash
|
|
|
|
|
2007-07-20 07:43:49 -05:00
|
|
|
#
|
|
|
|
# Copyright (C) 2007 Karel Zak <kzak@redhat.com>
|
|
|
|
#
|
2010-11-30 04:41:59 -06:00
|
|
|
# This file is part of util-linux.
|
2007-07-20 07:43:49 -05:00
|
|
|
#
|
|
|
|
# This file is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This file 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.
|
|
|
|
#
|
2007-01-04 07:23:48 -06:00
|
|
|
|
2014-02-16 17:54:14 -06:00
|
|
|
TS_TOPDIR=$(cd ${0%/*} && pwd)
|
2011-11-03 07:20:24 -05:00
|
|
|
SUBTESTS=
|
2015-03-25 13:32:22 -05:00
|
|
|
EXCLUDETESTS=
|
2011-11-03 07:20:24 -05:00
|
|
|
OPTS=
|
2019-03-04 10:10:04 -06:00
|
|
|
SYSCOMMANDS=
|
2011-11-03 07:20:24 -05:00
|
|
|
|
2012-08-03 14:24:51 -05:00
|
|
|
top_srcdir=
|
|
|
|
top_builddir=
|
2014-02-16 17:54:15 -06:00
|
|
|
paraller_jobs=1
|
2019-04-24 05:24:15 -05:00
|
|
|
has_asan_opt=
|
2020-07-01 14:52:51 -05:00
|
|
|
has_ubsan_opt=
|
2012-08-03 14:24:51 -05:00
|
|
|
|
2014-03-28 09:48:41 -05:00
|
|
|
function num_cpus()
|
|
|
|
{
|
2018-03-07 13:12:02 -06:00
|
|
|
local num
|
|
|
|
|
|
|
|
# coreutils
|
2019-09-24 10:15:33 -05:00
|
|
|
if num=$(nproc 2>/dev/null); then
|
2018-03-07 13:12:02 -06:00
|
|
|
:
|
|
|
|
# BSD, OSX
|
|
|
|
elif num=$(sysctl -n hw.ncpu 2>/dev/null); then
|
|
|
|
:
|
|
|
|
else
|
|
|
|
num=$(grep -c "^processor" /proc/cpuinfo 2>/dev/null)
|
|
|
|
fi
|
|
|
|
|
|
|
|
# translate garbage output to "1"
|
|
|
|
if test "$num" -gt "0" 2>/dev/null ;then
|
|
|
|
echo "$num"
|
2014-03-28 09:48:41 -05:00
|
|
|
else
|
|
|
|
echo 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-02-17 06:03:11 -06:00
|
|
|
function find_test_scripts()
|
|
|
|
{
|
|
|
|
local searchdir="$1"
|
|
|
|
find "$searchdir" -type f -regex ".*/[^\.~]*" \
|
|
|
|
\( -perm -u=x -o -perm -g=x -o -perm -o=x \)
|
|
|
|
}
|
|
|
|
|
2011-11-03 07:20:24 -05:00
|
|
|
while [ -n "$1" ]; do
|
|
|
|
case "$1" in
|
2016-03-05 08:40:57 -06:00
|
|
|
--force |\
|
|
|
|
--fake |\
|
2017-11-23 07:03:23 -06:00
|
|
|
--memcheck-valgrind |\
|
2017-12-06 07:21:38 -06:00
|
|
|
--nolocks |\
|
2017-02-16 07:14:54 -06:00
|
|
|
--show-diff |\
|
2016-03-05 08:40:57 -06:00
|
|
|
--verbose |\
|
|
|
|
--skip-loopdevs |\
|
2019-03-05 04:06:41 -06:00
|
|
|
--noskip-commands |\
|
2016-03-05 08:40:57 -06:00
|
|
|
--parsable)
|
|
|
|
# these options are simply forwarded to the test scripts
|
|
|
|
OPTS="$OPTS $1"
|
2015-03-17 05:34:22 -05:00
|
|
|
;;
|
2019-04-24 05:24:15 -05:00
|
|
|
--memcheck-asan)
|
|
|
|
OPTS="$OPTS $1"
|
|
|
|
has_asan_opt="yes"
|
|
|
|
;;
|
2020-07-01 14:52:51 -05:00
|
|
|
--memcheck-ubsan)
|
|
|
|
OPTS="$OPTS $1"
|
|
|
|
has_ubsan_opt="yes"
|
|
|
|
;;
|
2019-03-04 10:10:04 -06:00
|
|
|
--use-system-commands)
|
|
|
|
OPTS="$OPTS $1"
|
|
|
|
SYSCOMMANDS="yes"
|
|
|
|
;;
|
|
|
|
|
2012-08-03 14:24:51 -05:00
|
|
|
--nonroot)
|
|
|
|
if [ $(id -ru) -eq 0 ]; then
|
2014-11-15 14:41:43 -06:00
|
|
|
echo "Ignore util-linux test suite [non-root UID expected]."
|
2012-08-03 14:24:51 -05:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
--srcdir=*)
|
|
|
|
top_srcdir="${1##--srcdir=}"
|
|
|
|
;;
|
|
|
|
--builddir=*)
|
|
|
|
top_builddir="${1##--builddir=}"
|
|
|
|
;;
|
2014-02-16 17:54:15 -06:00
|
|
|
--parallel=*)
|
|
|
|
paraller_jobs="${1##--parallel=}"
|
2019-10-09 05:57:10 -05:00
|
|
|
if ! [ "$paraller_jobs" -ge 0 ] 2>/dev/null; then
|
2018-03-09 06:04:41 -06:00
|
|
|
echo "invalid argument '$paraller_jobs' for --parallel="
|
|
|
|
exit 1
|
|
|
|
fi
|
2014-02-16 17:54:15 -06:00
|
|
|
;;
|
|
|
|
--parallel)
|
2014-03-28 09:48:41 -05:00
|
|
|
paraller_jobs=$(num_cpus)
|
2014-02-16 17:54:15 -06:00
|
|
|
;;
|
2019-10-09 05:57:10 -05:00
|
|
|
--parsable)
|
|
|
|
OPTS="$OPTS $1"
|
|
|
|
;;
|
2015-03-25 13:32:22 -05:00
|
|
|
--exclude=*)
|
|
|
|
EXCLUDETESTS="${1##--exclude=}"
|
|
|
|
;;
|
2011-11-03 07:20:24 -05:00
|
|
|
--*)
|
|
|
|
echo "Unknown option $1"
|
2012-08-03 14:24:51 -05:00
|
|
|
echo "Usage: "
|
|
|
|
echo " $(basename $0) [options] [<component> ...]"
|
|
|
|
echo "Options:"
|
2019-03-04 10:10:04 -06:00
|
|
|
echo " --force execute demanding tests"
|
|
|
|
echo " --fake do not run, setup tests only"
|
|
|
|
echo " --memcheck-valgrind run with valgrind"
|
|
|
|
echo " --memcheck-asan enable ASAN (requires ./configure --enable-asan)"
|
|
|
|
echo " --nolocks don't use flock to lock resources"
|
|
|
|
echo " --verbose verbose mode"
|
|
|
|
echo " --show-diff show diff from failed tests"
|
|
|
|
echo " --nonroot ignore test suite if user is root"
|
|
|
|
echo " --use-system-commands use PATH rather than builddir"
|
2019-03-05 04:06:41 -06:00
|
|
|
echo " --noskip-commands fail on missing commands"
|
2019-03-04 10:10:04 -06:00
|
|
|
echo " --srcdir=<path> autotools top source directory"
|
|
|
|
echo " --builddir=<path> autotools top build directory"
|
2019-10-09 05:57:10 -05:00
|
|
|
echo " --parallel=<num> number of parallel test jobs, default: num cpus"
|
|
|
|
echo " --parsable use parsable output (default on --parallel)"
|
2019-03-04 10:10:04 -06:00
|
|
|
echo " --exclude=<list> exclude tests by list '<utilname>/<testname> ..'"
|
2012-08-03 14:24:51 -05:00
|
|
|
echo
|
2009-01-19 11:27:15 -06:00
|
|
|
exit 1
|
2011-11-03 07:20:24 -05:00
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
SUBTESTS="$SUBTESTS $1"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2012-08-03 14:24:51 -05:00
|
|
|
# For compatibility with autotools is necessary to differentiate between source
|
|
|
|
# (with test scripts) and build (with temporary files) directories when
|
|
|
|
# executed by our build-system.
|
|
|
|
#
|
|
|
|
# The default is the source tree with this script.
|
|
|
|
#
|
|
|
|
if [ -z "$top_srcdir" ]; then
|
|
|
|
top_srcdir="$TS_TOPDIR/.."
|
|
|
|
fi
|
|
|
|
if [ -z "$top_builddir" ]; then
|
|
|
|
top_builddir="$TS_TOPDIR/.."
|
2021-03-22 09:15:52 -05:00
|
|
|
if [ -e "$top_builddir/build/meson.conf" ]; then
|
|
|
|
top_builddir="$TS_TOPDIR/../build"
|
|
|
|
fi
|
2012-08-03 14:24:51 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
OPTS="$OPTS --srcdir=$top_srcdir --builddir=$top_builddir"
|
|
|
|
|
2019-04-24 05:24:15 -05:00
|
|
|
# Auto-enable ASAN to avoid conflicts between tests and binaries
|
|
|
|
if [ -z "$has_asan_opt" ]; then
|
meson: add second build system
To build: meson build && ninja -C build
To run tests: ninja -C build check
To install for packaging: DESTDIR=/var/tmp/inst ninja -C build install
To install for realz: sudo ninja -C build install
v2:
- Optional items are now based on the 'feature' feature in meson.
Built libraries which are disabled turn into disabler() objects
and also poison any executables which link to them.
What is there:
- building of the binaries and libs and the python module
- installation of binaries, libs, python module, localization files,
man pages, pkgconfig files
- running of tests
- most options to configure build equivalently to the
./configure settings
Partially implemented:
- disabling of stuff when things missing. In the C code, the defines
are all used, so that should be fine. In the build system, some
files should be skipped, but that is probably not always done properly.
Getting this right might require some testing of various build option
combinations to get the details right.
Not implemented:
- static builds of fdisk and other binaries
- things marked with XXX or FIXME
- ???
Differences:
- .la files are not created. They are useless and everybody hates them.
- Requires.private in pkgconfig files are not present in the
autogenerated .pc file. Not sure if they should be there or not. If
necessary, they can be added by hand.
- man pages and systemd units are installed by the install target. Not
sure why 'make install' doesn't do that.
- the split between / and /usr is probably wrong. But it's all pointless
anyway, so maybe we could simplify things but not implementing it at
all under meson?
2020-02-23 12:42:55 -06:00
|
|
|
if [ -e "$top_builddir/Makefile" ]; then
|
|
|
|
asan=$(awk '/^ASAN_LDFLAGS/ { print $3 }' $top_builddir/Makefile)
|
|
|
|
else
|
|
|
|
. "$top_builddir/meson.conf"
|
|
|
|
fi
|
2019-04-24 05:24:15 -05:00
|
|
|
if [ -n "$asan" ]; then
|
|
|
|
OPTS="$OPTS --memcheck-asan"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-07-01 14:52:51 -05:00
|
|
|
if [ -z "$has_ubsan_opt" ]; then
|
2021-03-22 09:15:52 -05:00
|
|
|
if [ -e "$top_builddir/Makefile" ]; then
|
|
|
|
ubsan=$(awk '/^UBSAN_LDFLAGS/ { print $3 }' $top_builddir/Makefile)
|
|
|
|
fi
|
2020-07-01 14:52:51 -05:00
|
|
|
if [ -n "$ubsan" ]; then
|
|
|
|
OPTS="$OPTS --memcheck-ubsan"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2014-02-16 17:54:15 -06:00
|
|
|
declare -a comps
|
2011-11-03 07:20:24 -05:00
|
|
|
if [ -n "$SUBTESTS" ]; then
|
|
|
|
# selected tests only
|
|
|
|
for s in $SUBTESTS; do
|
2016-08-10 15:36:55 -05:00
|
|
|
if [ -e "$top_srcdir/tests/ts/$s" ]; then
|
2016-02-17 06:03:11 -06:00
|
|
|
comps+=( $(find_test_scripts "$top_srcdir/tests/ts/$s") ) || exit 1
|
2011-11-03 07:20:24 -05:00
|
|
|
else
|
|
|
|
echo "Unknown test component '$s'"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
2019-03-04 10:10:04 -06:00
|
|
|
if [ -z "$SYSCOMMANDS" -a ! -f "$top_builddir/test_ttyutils" ]; then
|
2020-12-17 03:57:33 -06:00
|
|
|
echo "Tests not compiled! Run 'make check-programs' to fix the problem."
|
2012-07-30 11:00:33 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-02-17 06:03:11 -06:00
|
|
|
comps=( $(find_test_scripts "$top_srcdir/tests/ts") ) || exit 1
|
2009-01-19 11:27:15 -06:00
|
|
|
fi
|
|
|
|
|
2015-03-25 13:32:22 -05:00
|
|
|
if [ -n "$EXCLUDETESTS" ]; then
|
|
|
|
declare -a xcomps # temporary array
|
|
|
|
for ts in ${comps[@]}; do
|
|
|
|
tsname=${ts##*ts/} # test name
|
|
|
|
|
|
|
|
if [[ "$EXCLUDETESTS" == *${tsname}* ]]; then
|
|
|
|
#echo "Ignore ${tsname}."
|
|
|
|
true
|
|
|
|
else
|
|
|
|
xcomps+=($ts)
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
comps=("${xcomps[@]}") # replace the array
|
|
|
|
fi
|
2012-07-30 11:00:33 -05:00
|
|
|
|
2012-12-10 06:43:11 -06:00
|
|
|
unset LIBMOUNT_DEBUG
|
|
|
|
unset LIBBLKID_DEBUG
|
2013-04-09 05:44:02 -05:00
|
|
|
unset LIBFDISK_DEBUG
|
2015-03-25 13:32:22 -05:00
|
|
|
unset LIBSMARTCOLS_DEBUG
|
2012-12-10 06:43:11 -06:00
|
|
|
|
2007-01-04 07:23:48 -06:00
|
|
|
echo
|
2012-04-18 06:14:43 -05:00
|
|
|
echo "-------------------- util-linux regression tests --------------------"
|
2007-01-04 07:23:48 -06:00
|
|
|
echo
|
2007-08-07 17:42:29 -05:00
|
|
|
echo " For development purpose only. "
|
|
|
|
echo " Don't execute on production system! "
|
|
|
|
echo
|
2007-01-04 07:23:48 -06:00
|
|
|
|
2016-07-11 04:54:31 -05:00
|
|
|
# TODO: add more information about system
|
|
|
|
printf "%13s: %-30s " "kernel" "$(uname -r)"
|
|
|
|
echo
|
|
|
|
echo
|
2019-04-24 05:24:15 -05:00
|
|
|
echo " options: $(echo $OPTS | sed 's/ / \\\n /g')"
|
|
|
|
echo
|
2016-07-11 04:54:31 -05:00
|
|
|
|
2018-03-09 06:04:41 -06:00
|
|
|
if [ "$paraller_jobs" -ne 1 ]; then
|
|
|
|
tmp=$paraller_jobs
|
|
|
|
[ "$paraller_jobs" -eq 0 ] && tmp=infinite
|
|
|
|
echo " Executing the tests in parallel ($tmp jobs) "
|
2014-02-16 17:54:15 -06:00
|
|
|
echo
|
2015-12-15 11:26:04 -06:00
|
|
|
OPTS="$OPTS --parallel"
|
2014-02-16 17:54:15 -06:00
|
|
|
fi
|
2007-01-04 07:23:48 -06:00
|
|
|
|
2014-02-16 17:54:15 -06:00
|
|
|
count=0
|
2020-02-27 05:13:09 -06:00
|
|
|
mkdir -p $top_builddir/tests/
|
2014-03-13 08:35:59 -05:00
|
|
|
>| $top_builddir/tests/failures
|
2014-02-16 17:54:15 -06:00
|
|
|
printf "%s\n" ${comps[*]} |
|
2014-05-21 08:04:55 -05:00
|
|
|
sort |
|
2014-02-16 17:54:15 -06:00
|
|
|
xargs -I '{}' -P $paraller_jobs -n 1 bash -c "'{}' \"$OPTS\" ||
|
2014-03-13 08:35:59 -05:00
|
|
|
echo 1 >> $top_builddir/tests/failures"
|
2018-03-09 06:04:41 -06:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
echo "xargs error" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2014-02-16 17:54:15 -06:00
|
|
|
declare -a fail_file
|
2014-03-13 11:40:16 -05:00
|
|
|
fail_file=( $( < $top_builddir/tests/failures ) ) || exit 1
|
2014-03-13 08:35:59 -05:00
|
|
|
rm -f $top_builddir/tests/failures
|
2007-01-04 07:23:48 -06:00
|
|
|
echo
|
|
|
|
echo "---------------------------------------------------------------------"
|
2014-02-16 17:54:15 -06:00
|
|
|
if [ ${#fail_file[@]} -eq 0 ]; then
|
|
|
|
echo " All ${#comps[@]} tests PASSED"
|
2007-01-27 18:24:15 -06:00
|
|
|
res=0
|
2007-01-04 07:23:48 -06:00
|
|
|
else
|
2014-02-16 17:54:15 -06:00
|
|
|
echo " ${#fail_file[@]} tests of ${#comps[@]} FAILED"
|
2007-01-27 18:24:15 -06:00
|
|
|
res=1
|
2007-01-04 07:23:48 -06:00
|
|
|
fi
|
|
|
|
echo "---------------------------------------------------------------------"
|
2007-01-27 18:24:15 -06:00
|
|
|
exit $res
|