unit tests: added fakeroot support
authorBernardo Dal Seno <bdalseno@google.com>
Tue, 13 Dec 2011 16:16:42 +0000 (17:16 +0100)
committerBernardo Dal Seno <bdalseno@google.com>
Thu, 22 Dec 2011 13:12:40 +0000 (14:12 +0100)
Tests ending in "-runasroot" or "-runasroot.py" are run through fakeroot,
so activity that needs root privileges can be tested.

Signed-off-by: Bernardo Dal Seno <bdalseno@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>

.gitignore
Makefile.am
autotools/testrunner.in [moved from autotools/testrunner with 74% similarity]
configure.ac

index 1b82e7c..86e80c2 100644 (file)
@@ -24,6 +24,7 @@
 /autotools/missing
 /autotools/py-compile
 /autotools/replace_vars.sed
+/autotools/testrunner
 /config.log
 /config.status
 /configure
index 89f5bf3..a240dc5 100644 (file)
@@ -137,6 +137,7 @@ CLEANFILES = \
        $(PYTHON_BOOTSTRAP) \
        epydoc.conf \
        autotools/replace_vars.sed \
+       autotools/testrunner \
        daemons/daemon-util \
        daemons/ganeti-cleaner \
        devel/upload \
@@ -430,6 +431,7 @@ docpng = $(patsubst %.dot,%.png,$(docdot))
 # Things to build but not to install (add it to EXTRA_DIST if it should be
 # distributed)
 noinst_DATA = \
+       autotools/testrunner \
        devel/upload \
        doc/html \
        $(BUILT_EXAMPLES) \
@@ -566,7 +568,7 @@ EXTRA_DIST = \
        autotools/convert-constants \
        autotools/docpp \
        autotools/gen-coverage \
-       autotools/testrunner \
+       autotools/testrunner.in \
        $(RUN_IN_TEMPDIR) \
        daemons/daemon-util.in \
        daemons/ganeti-cleaner.in \
@@ -838,6 +840,10 @@ tools/kvm-ifup: tools/kvm-ifup.in $(REPLACE_VARS_SED)
        sed -f $(REPLACE_VARS_SED) < $< > $@
        chmod +x $@
 
+autotools/testrunner: autotools/testrunner.in $(REPLACE_VARS_SED)
+       sed -f $(REPLACE_VARS_SED) < $< > $@
+       chmod u+x $@
+
 devel/upload: devel/upload.in $(REPLACE_VARS_SED)
        sed -f $(REPLACE_VARS_SED) < $< > $@
        chmod u+x $@
@@ -1048,6 +1054,7 @@ $(REPLACE_VARS_SED): Makefile
          echo 's#@GNTMASTERDGROUP@#$(MASTERD_GROUP)#g'; \
          echo 's#@GNTDAEMONSGROUP@#$(DAEMONS_GROUP)#g'; \
          echo 's#@CUSTOM_ENABLE_CONFD@#$(ENABLE_CONFD)#g'; \
+         echo 's#@FAKEROOT@#$(FAKEROOT_PATH)#g'; \
        } > $@
 
 # Using deferred evaluation
similarity index 74%
rename from autotools/testrunner
rename to autotools/testrunner.in
index d933613..879b4c7 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/bash
 #
 
-# Copyright (C) 2010 Google Inc.
+# Copyright (C) 2010, 2011 Google Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 
 set -e
 
+FAKEROOT='@FAKEROOT@'
+
 filename=$1
 
+execasroot() {
+  if [[ -z "$FAKEROOT" ]]; then
+    echo "'fakeroot' not found at configure time" >&2
+    exit 1
+  fi
+  exec "$FAKEROOT" "$@"
+}
+
 case "$filename" in
+  *-runasroot.py) execasroot $PYTHON "$@" ;;
   *.py) exec $PYTHON "$@" ;;
+  *-runasroot) execasroot "$@" ;;
   *) exec "$@" ;;
 esac
index b672d95..63a33d3 100644 (file)
@@ -487,6 +487,15 @@ AM_CONDITIONAL([WANT_HTOOLS], [test x$HTOOLS = xyes])
 AM_CONDITIONAL([WANT_HTOOLSTESTS], [test "x$GHC_PKG_QUICKCHECK" != x])
 AM_CONDITIONAL([WANT_HTOOLSAPIDOC], [test x$HTOOLS_APIDOC = xyes])
 
+# Check for fakeroot
+AC_ARG_VAR(FAKEROOT_PATH, [fakeroot path])
+AC_PATH_PROG(FAKEROOT_PATH, [fakeroot], [])
+if test -z "$FAKEROOT_PATH"; then
+  AC_MSG_WARN(m4_normalize([fakeroot not found, tests that must run as root
+                            will not be executed]))
+fi
+AM_CONDITIONAL([HAS_FAKEROOT], [test "x$FAKEROOT_PATH" != x])
+
 SOCAT_USE_ESCAPE=
 AC_ARG_ENABLE([socat-escape],
   [AS_HELP_STRING([--enable-socat-escape],