]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: make compatible with autotools
authorKarel Zak <kzak@redhat.com>
Fri, 3 Aug 2012 19:24:51 +0000 (21:24 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 3 Aug 2012 19:24:51 +0000 (21:24 +0200)
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 <kzak@redhat.com>
Makefile.am
configure.ac
tests/.gitignore
tests/Makemodule.am
tests/commands.sh [moved from tests/commands.sh.in with 97% similarity]
tests/functions.sh
tests/run-nonroot.sh [deleted file]
tests/run.sh

index fe74e6856428da89f47e95d43b20c9352ecbce62..e22dad339143db0a090d1a1a62e1798041f3e7c0 100644 (file)
@@ -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)
index 763ecff9b20b91a17c48c327ceb8ebb3d8c4b8f2..edb2d78517c8ec99d787d5be3165dd2a7c0cca6f 100644 (file)
@@ -1341,7 +1341,6 @@ misc-utils/uuidd.rc
 misc-utils/uuidd.service
 misc-utils/uuidd.socket
 po/Makefile.in
-tests/commands.sh
 ])
 
 
index c22f5081d9ecd94138fda18eb4fcaaca62ce61b2..d937c7fe4259b7e367f16e52dd46e99b3d68186c 100644 (file)
@@ -1,3 +1,2 @@
-commands.sh
 diff
 output
index a5e26bfb1d1aa3fe845846da9d77255b93c28026..00da7d35dcd451e1b64ebfcb8000ca2357324052 100644 (file)
@@ -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
similarity index 97%
rename from tests/commands.sh.in
rename to tests/commands.sh
index 71934d8a6849738d3a850e1ad2b2e56ec0d2a129..8a1577ec97d8303096466b394f3d06d9037ef4c2 100644 (file)
@@ -1,7 +1,3 @@
-
-top_builddir=@abs_top_builddir@
-top_srcdir=@abs_top_srcdir@
-
 # Misc settings
 TS_TESTUSER=${TS_TESTUSER:-"test"}
 
index 9716534a25cff2c58f27acec75097dd71187fee1..8293539d24dfe477627eeb70455724d4eb2cfb6f 100644 (file)
@@ -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 (executable)
index 150a99f..0000000
+++ /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
index 15bce71ed1ffd9cd3664c3971be4c42c95647f1a..6ed05c1fa6bfc372ff70b337423afc208c73c380 100755 (executable)
@@ -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] [<component> ...]"
+               echo "Usage: "
+               echo "  $(basename $0) [options] [<component> ...]"
+               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=<path>   autotools top source directory"
+               echo "  --builddir=<path> 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