From 1b03e2cd33a059fdd355c52899e151130777c44f Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 3 Aug 2012 21:24:51 +0200 Subject: tests: make compatible with autotools The command 'make check' is called from 'make distcheck' (which is used to generate official util-linux tarballs). It means that tests/ stuff has to be compatible with autotools and differentiate between source and build directories. * remove run-nonroot.sh (merged into run.sh * remove commands.sh.in * all tests and top level run.sh accept --builddir and --srcdir command line options * functions.sh modified to use $top_builddir/tests for output files Signed-off-by: Karel Zak --- Makefile.am | 3 +++ configure.ac | 1 - tests/.gitignore | 1 - tests/Makemodule.am | 11 ++++++--- tests/commands.sh | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/commands.sh.in | 68 ---------------------------------------------------- tests/functions.sh | 30 +++++++++++++++++++---- tests/run-nonroot.sh | 9 ------- tests/run.sh | 58 ++++++++++++++++++++++++++++++++++++-------- 9 files changed, 149 insertions(+), 96 deletions(-) create mode 100644 tests/commands.sh delete mode 100644 tests/commands.sh.in delete mode 100755 tests/run-nonroot.sh diff --git a/Makefile.am b/Makefile.am index fe74e6856..e22dad339 100644 --- a/Makefile.am +++ b/Makefile.am @@ -47,6 +47,7 @@ INSTALL_EXEC_HOOKS = UNINSTALL_HOOKS = INSTALL_DATA_HOOKS = CLEAN_LOCALS = +CHECK_LOCALS = EXTRA_DIST = man/ru/ddate.1 CLEANFILES = @@ -153,3 +154,5 @@ uninstall-hook: $(UNINSTALL_HOOKS) install-data-hook: $(INSTALL_DATA_HOOKS) clean-local: $(CLEAN_LOCALS) + +check-local: $(CHECK_LOCALS) diff --git a/configure.ac b/configure.ac index 763ecff9b..edb2d7851 100644 --- a/configure.ac +++ b/configure.ac @@ -1341,7 +1341,6 @@ misc-utils/uuidd.rc misc-utils/uuidd.service misc-utils/uuidd.socket po/Makefile.in -tests/commands.sh ]) diff --git a/tests/.gitignore b/tests/.gitignore index c22f5081d..d937c7fe4 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -1,3 +1,2 @@ -commands.sh diff output diff --git a/tests/Makemodule.am b/tests/Makemodule.am index a5e26bfb1..00da7d35d 100644 --- a/tests/Makemodule.am +++ b/tests/Makemodule.am @@ -4,12 +4,17 @@ include tests/helpers/Makemodule.am EXTRA_DIST += \ tests/expected \ tests/functions.sh \ + tests/commands.sh \ tests/run.sh \ - tests/run-nonroot.sh \ tests/ts clean-local-tests: - rm -rf output diff + rm -rf $(top_builddir)/tests/output $(top_builddir)/tests/diff -TESTS += tests/run-nonroot.sh CLEAN_LOCALS += clean-local-tests + + +check-local-tests: $(check_PROGRAMS) + $(top_srcdir)/tests/run.sh --srcdir=$(abs_top_srcdir) --builddir=$(abs_top_builddir) --nonroot + +CHECK_LOCALS += check-local-tests diff --git a/tests/commands.sh b/tests/commands.sh new file mode 100644 index 000000000..8a1577ec9 --- /dev/null +++ b/tests/commands.sh @@ -0,0 +1,64 @@ +# Misc settings +TS_TESTUSER=${TS_TESTUSER:-"test"} + +# helpers +TS_HELPER_SYSINFO="$top_builddir/test_sysinfo" +TS_HELPER_PATHS="$top_builddir/test_pathnames" +TS_HELPER_BYTESWAP="$top_builddir/test_byteswap" +TS_HELPER_MD5="$top_builddir/test_md5" + +TS_HELPER_ISMOUNTED="$top_builddir/test_ismounted" +TS_HELPER_STRUTILS="$top_builddir/test_strutils" +TS_HELPER_CPUSET="$top_builddir/test_cpuset" + +# libmount +TS_HELPER_LIBMOUNT_OPTSTR="$top_builddir/test_mount_optstr" +TS_HELPER_LIBMOUNT_TAB="$top_builddir/test_mount_tab" +TS_HELPER_LIBMOUNT_UTILS="$top_builddir/test_mount_utils" +TS_HELPER_LIBMOUNT_LOCK="$top_builddir/test_mount_lock" +TS_HELPER_LIBMOUNT_UPDATE="$top_builddir/test_mount_tab_update" +TS_HELPER_LIBMOUNT_CONTEXT="$top_builddir/test_mount_context" +TS_HELPER_LIBMOUNT_TABDIFF="$top_builddir/test_mount_tab_diff" + +TS_HELPER_ISLOCAL="$top_builddir/test_islocal" +TS_HELPER_LOGINDEFS="$top_builddir/test_logindefs" + +# TODO: use partx +TS_HELPER_PARTITIONS="$top_builddir/sample-partitions" + +# paths to commands +TS_CMD_MOUNT=${TS_CMD_MOUNT:-"$top_builddir/mount"} +TS_CMD_UMOUNT=${TS_CMD_UMOUNT:-"$top_builddir/umount"} + +TS_CMD_SWAPON=${TS_CMD_SWAPON:-"$top_builddir/swapon"} +TS_CMD_SWAPOFF=${TS_CMD_SWAPOFF:-"$top_builddir/swapoff"} +TS_CMD_LOSETUP=${TS_CMD_LOSETUP:-"$top_builddir/losetup"} + +TS_CMD_MKSWAP=${TS_CMD_MKSWAP:-"$top_builddir/mkswap"} +TS_CMD_MKCRAMFS=${TS_CMD_MKCRAMFS:-"$top_builddir/mkfs.cramfs"} +TS_CMD_MKMINIX=${TS_CMD_MKMINIX:-"$top_builddir/mkfs.minix"} +TS_CMD_FSCKCRAMFS=${TS_CMD_FSCKCRAMFS:-"$top_builddir/fsck.cramfs"} +TS_CMD_FSCKMINIX=${TS_CMD_FSCKMINIX:-"$top_builddir/fsck.minix"} + +TS_CMD_IPCS=${TS_CMD_IPCS:-"$top_builddir/ipcs"} + +TS_CMD_COL=${TS_CMD_COL:-"$top_builddir/col"} +TS_CMD_COLUMN=${TS_CMD_COLUMN:-"$top_builddir/column"} +TS_CMD_COLRM=${TS_CMD_COLRM:-"$top_builddir/colrm"} + +TS_CMD_NAMEI=${TS_CMD_NAMEI-"$top_builddir/namei"} +TS_CMD_LOOK=${TS_CMD_LOOK-"$top_builddir/look"} +TS_CMD_CAL=${TS_CMD_CAL-"$top_builddir/cal"} +TS_CMD_SCRIPT=${TS_CMD_SCRIPT-"$top_builddir/script"} +TS_CMD_EJECT=${TS_CMD_EJECT-"$top_builddir/eject"} + + +TS_CMD_HWCLOCK=${TS_CMD_HWCLOCK-"$top_builddir/hwclock"} +TS_CMD_LSCPU=${TS_CMD_LSCPU-"$top_builddir/lscpu"} + +TS_CMD_BLKID=${TS_CMD_BLKID-"$top_builddir/blkid"} +TS_CMD_PARTX=${TS_CMD_PARTX-"$top_builddir/partx"} +TS_CMD_FINDMNT=${TS_CMD_FINDMNT-"$top_builddir/findmnt"} + +TS_CMD_FDISK=${TS_CMD_FDISK-"$top_builddir/fdisk"} + diff --git a/tests/commands.sh.in b/tests/commands.sh.in deleted file mode 100644 index 71934d8a6..000000000 --- a/tests/commands.sh.in +++ /dev/null @@ -1,68 +0,0 @@ - -top_builddir=@abs_top_builddir@ -top_srcdir=@abs_top_srcdir@ - -# Misc settings -TS_TESTUSER=${TS_TESTUSER:-"test"} - -# helpers -TS_HELPER_SYSINFO="$top_builddir/test_sysinfo" -TS_HELPER_PATHS="$top_builddir/test_pathnames" -TS_HELPER_BYTESWAP="$top_builddir/test_byteswap" -TS_HELPER_MD5="$top_builddir/test_md5" - -TS_HELPER_ISMOUNTED="$top_builddir/test_ismounted" -TS_HELPER_STRUTILS="$top_builddir/test_strutils" -TS_HELPER_CPUSET="$top_builddir/test_cpuset" - -# libmount -TS_HELPER_LIBMOUNT_OPTSTR="$top_builddir/test_mount_optstr" -TS_HELPER_LIBMOUNT_TAB="$top_builddir/test_mount_tab" -TS_HELPER_LIBMOUNT_UTILS="$top_builddir/test_mount_utils" -TS_HELPER_LIBMOUNT_LOCK="$top_builddir/test_mount_lock" -TS_HELPER_LIBMOUNT_UPDATE="$top_builddir/test_mount_tab_update" -TS_HELPER_LIBMOUNT_CONTEXT="$top_builddir/test_mount_context" -TS_HELPER_LIBMOUNT_TABDIFF="$top_builddir/test_mount_tab_diff" - -TS_HELPER_ISLOCAL="$top_builddir/test_islocal" -TS_HELPER_LOGINDEFS="$top_builddir/test_logindefs" - -# TODO: use partx -TS_HELPER_PARTITIONS="$top_builddir/sample-partitions" - -# paths to commands -TS_CMD_MOUNT=${TS_CMD_MOUNT:-"$top_builddir/mount"} -TS_CMD_UMOUNT=${TS_CMD_UMOUNT:-"$top_builddir/umount"} - -TS_CMD_SWAPON=${TS_CMD_SWAPON:-"$top_builddir/swapon"} -TS_CMD_SWAPOFF=${TS_CMD_SWAPOFF:-"$top_builddir/swapoff"} -TS_CMD_LOSETUP=${TS_CMD_LOSETUP:-"$top_builddir/losetup"} - -TS_CMD_MKSWAP=${TS_CMD_MKSWAP:-"$top_builddir/mkswap"} -TS_CMD_MKCRAMFS=${TS_CMD_MKCRAMFS:-"$top_builddir/mkfs.cramfs"} -TS_CMD_MKMINIX=${TS_CMD_MKMINIX:-"$top_builddir/mkfs.minix"} -TS_CMD_FSCKCRAMFS=${TS_CMD_FSCKCRAMFS:-"$top_builddir/fsck.cramfs"} -TS_CMD_FSCKMINIX=${TS_CMD_FSCKMINIX:-"$top_builddir/fsck.minix"} - -TS_CMD_IPCS=${TS_CMD_IPCS:-"$top_builddir/ipcs"} - -TS_CMD_COL=${TS_CMD_COL:-"$top_builddir/col"} -TS_CMD_COLUMN=${TS_CMD_COLUMN:-"$top_builddir/column"} -TS_CMD_COLRM=${TS_CMD_COLRM:-"$top_builddir/colrm"} - -TS_CMD_NAMEI=${TS_CMD_NAMEI-"$top_builddir/namei"} -TS_CMD_LOOK=${TS_CMD_LOOK-"$top_builddir/look"} -TS_CMD_CAL=${TS_CMD_CAL-"$top_builddir/cal"} -TS_CMD_SCRIPT=${TS_CMD_SCRIPT-"$top_builddir/script"} -TS_CMD_EJECT=${TS_CMD_EJECT-"$top_builddir/eject"} - - -TS_CMD_HWCLOCK=${TS_CMD_HWCLOCK-"$top_builddir/hwclock"} -TS_CMD_LSCPU=${TS_CMD_LSCPU-"$top_builddir/lscpu"} - -TS_CMD_BLKID=${TS_CMD_BLKID-"$top_builddir/blkid"} -TS_CMD_PARTX=${TS_CMD_PARTX-"$top_builddir/partx"} -TS_CMD_FINDMNT=${TS_CMD_FINDMNT-"$top_builddir/findmnt"} - -TS_CMD_FDISK=${TS_CMD_FDISK-"$top_builddir/fdisk"} - diff --git a/tests/functions.sh b/tests/functions.sh index 9716534a2..8293539d2 100644 --- a/tests/functions.sh +++ b/tests/functions.sh @@ -86,6 +86,12 @@ function ts_has_option { echo -n $ALL | sed 's/ //g' | awk 'BEGIN { FS="="; RS="--" } /('$NAME'$|'$NAME'=)/ { print "yes" }' } +function ts_option_argument { + NAME="$1" + ALL="$2" + echo -n $ALL | sed 's/ //g' | awk 'BEGIN { FS="="; RS="--" } /'$NAME'=/ { print $2 }' +} + function ts_init_core_env { TS_NS="$TS_COMPONENT/$TS_TESTNAME" TS_OUTPUT="$TS_OUTDIR/$TS_TESTNAME" @@ -118,11 +124,28 @@ function ts_init_env { LC_ALL="POSIX" CHARSET="UTF-8" + export LANG LANGUAGE LC_ALL CHARSET + mydir=$(ts_canonicalize "$mydir") - export LANG LANGUAGE LC_ALL CHARSET + # automake directories + top_srcdir=$(ts_option_argument "srcdir" "$*") + top_builddir=$(ts_option_argument "builddir" "$*") + # where is this script TS_TOPDIR=$(ts_abspath $mydir/../../) + + # default + if [ -z "$top_srcdir" ]; then + top_srcdir="$TS_TOPDIR/.." + fi + if [ -z "$top_builddir" ]; then + top_builddir="$TS_TOPDIR/.." + fi + + top_srcdir=$(ts_abspath $top_srcdir) + top_builddir=$(ts_abspath $top_builddir) + TS_SCRIPT="$mydir/$(basename $0)" TS_SUBDIR=$(dirname $TS_SCRIPT) TS_TESTNAME=$(basename $TS_SCRIPT) @@ -133,8 +156,8 @@ function ts_init_env { TS_SELF="$TS_SUBDIR" - TS_OUTDIR="$TS_TOPDIR/output/$TS_COMPONENT" - TS_DIFFDIR="$TS_TOPDIR/diff/$TS_COMPONENT" + TS_OUTDIR="$top_builddir/tests/output/$TS_COMPONENT" + TS_DIFFDIR="$top_builddir/tests/diff/$TS_COMPONENT" ts_init_core_env @@ -142,7 +165,6 @@ function ts_init_env { BLKID_FILE="$TS_OUTDIR/${TS_TESTNAME}.blkidtab" - declare -a TS_SUID_PROGS declare -a TS_SUID_USER declare -a TS_SUID_GROUP diff --git a/tests/run-nonroot.sh b/tests/run-nonroot.sh deleted file mode 100755 index 150a99f3a..000000000 --- a/tests/run-nonroot.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -MYUID=$(id -ru) -if [ $MYUID -eq 0 ]; then - echo "The automatically executed tests suite is allowed for non-root users only." - exit 0 -fi - -exec $(cd $(dirname $0) && pwd)/run.sh diff --git a/tests/run.sh b/tests/run.sh index 15bce71ed..6ed05c1fa 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -20,6 +20,9 @@ TS_TOPDIR=$(cd $(dirname $0) && pwd) SUBTESTS= OPTS= +top_srcdir= +top_builddir= + while [ -n "$1" ]; do case "$1" in --force) @@ -31,9 +34,34 @@ while [ -n "$1" ]; do --memcheck) OPTS="$OPTS --memcheck" ;; + --verbose) + OPTS="$OPTS --verbose" + ;; + --nonroot) + if [ $(id -ru) -eq 0 ]; then + echo "Ignore utils-linux test suite [non-root UID expected]." + exit 0 + fi + ;; + --srcdir=*) + top_srcdir="${1##--srcdir=}" + ;; + --builddir=*) + top_builddir="${1##--builddir=}" + ;; --*) echo "Unknown option $1" - echo "Usage: run [--fake] [--force] [ ...]" + echo "Usage: " + echo " $(basename $0) [options] [ ...]" + echo "Options:" + echo " --force execute demanding tests" + echo " --fake do not run, setup tests only" + echo " --memcheck run with valgrind" + echo " --verbose verbose mode" + echo " --nonroot ignore test suite if user is root" + echo " --srcdir= autotools top source directory" + echo " --builddir= autotools top build directory" + echo exit 1 ;; @@ -44,11 +72,26 @@ while [ -n "$1" ]; do shift done +# 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/.." +fi + +OPTS="$OPTS --srcdir=$top_srcdir --builddir=$top_builddir" + if [ -n "$SUBTESTS" ]; then # selected tests only for s in $SUBTESTS; do - if [ -d "$TS_TOPDIR/ts/$s" ]; then - co=$(find $TS_TOPDIR/ts/$s -type f -perm /a+x -regex ".*/[^\.~]*" | sort) + if [ -d "$top_srcdir/tests/ts/$s" ]; then + co=$(find $top_srcdir/tests/ts/$s -type f -perm /a+x -regex ".*/[^\.~]*" | sort) comps="$comps $co" else echo "Unknown test component '$s'" @@ -56,17 +99,12 @@ if [ -n "$SUBTESTS" ]; then fi done else - # all tests - if [ ! -f "$TS_TOPDIR/../test_tt" ]; then + if [ ! -f "$top_builddir/test_tt" ]; then echo "Tests not compiled! Run 'make check' to fix the problem." exit 1 fi - if [ ! -f "$TS_TOPDIR/commands.sh" ]; then - echo "Not ready to run tests! Run './configure' or './config.status' to fix the problem." - exit 1 - fi - comps=$(find $TS_TOPDIR/ts/ -type f -perm /a+x -regex ".*/[^\.~]*" | sort) + comps=$(find $top_srcdir/tests/ts/ -type f -perm /a+x -regex ".*/[^\.~]*" | sort) fi -- cgit v1.2.3-55-g7522