]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: add helper to determine when to skip expensive tests
authorEric Blake <eblake@redhat.com>
Fri, 2 Aug 2013 21:43:07 +0000 (15:43 -0600)
committerEric Blake <eblake@redhat.com>
Mon, 12 Aug 2013 16:06:41 +0000 (10:06 -0600)
The logic set up in previous patch for exposing VIR_TEST_EXPENSIVE
to individual tests is as follows:

make check VIR_TEST_EXPENSIVE=0   => getenv("VIR_TEST_EXPENSIVE") sees "0"
make check VIR_TEST_EXPENSIVE=1   => getenv("VIR_TEST_EXPENSIVE") sees "1"
make check                        => getenv("VIR_TEST_EXPENSIVE") sees
either "0" or "1", based on configure options
cd tests; ./FOOtest               => getenv("VIR_TEST_EXPENSIVE") sees
whatever is in your environment (usually NULL, but possibly garbage)

Merely checking if VIR_TEST_EXPENSIVE is set in the environment
does the wrong thing; likewise, it is unsafe to assume the
variable will always contain a valid number.

As such, it helps to have helper functions, instead of making each
expensive test repeat the probe of the environment.

* tests/testutils.h (virTestGetExpensive): New prototype.
* tests/testutils.c (virTestGetExpensive): Implement it.
* tests/test-lib.sh (very_expensive_): Rename...
(test_expensive): ...and tweak to use VIR_TEST_EXPENSIVE.

Signed-off-by: Eric Blake <eblake@redhat.com>
tests/test-lib.sh
tests/testutils.c
tests/testutils.h

index 918bf734318a32f4a9248d2428f354ba976d8535..2f79706b690dd1747ba87588427ed1c3d7b2aa17 100644 (file)
@@ -1,4 +1,22 @@
-# source this file; set up for tests
+# test-lib.sh: source this file; set up for tests
+
+# Copyright (C) 2008-2013 Red Hat, Inc.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library.  If not, see
+# <http://www.gnu.org/licenses/>.
+#
+# Based on an idea from GNU coreutils
 
 test -z "$abs_srcdir" && abs_srcdir=$(pwd)
 test -z "$abs_builddir" && abs_builddir=$(pwd)
@@ -158,15 +176,12 @@ require_selinux_()
   esac
 }
 
-very_expensive_()
+test_expensive()
 {
-  if test "$RUN_VERY_EXPENSIVE_TESTS" != yes; then
+  if test "$VIR_TEST_EXPENSIVE" != 1; then
     skip_test_ '
 This test is very expensive, so it is disabled by default.
-To run it anyway, rerun make check with the RUN_VERY_EXPENSIVE_TESTS
-environment variable set to yes.  E.g.,
-
-  env RUN_VERY_EXPENSIVE_TESTS=yes make check
+To run it anyway, rerun: make check VIR_TEST_EXPENSIVE=1
 '
   fi
 }
index 72aa5b3ae291ef43784e0e8bb803d1d92f62fb4e..c5215528b03294b527f6f97e2998dc47c60fa64f 100644 (file)
@@ -66,6 +66,7 @@
 
 static unsigned int testDebug = -1;
 static unsigned int testVerbose = -1;
+static unsigned int testExpensive = -1;
 
 static unsigned int testOOM = 0;
 static size_t testCounter = 0;
@@ -581,6 +582,13 @@ virTestGetVerbose(void) {
     return testVerbose || virTestGetDebug();
 }
 
+unsigned int
+virTestGetExpensive(void) {
+    if (testExpensive == -1)
+        testExpensive = virTestGetFlag("VIR_TEST_EXPENSIVE");
+    return testExpensive;
+}
+
 int virtTestMain(int argc,
                  char **argv,
                  int (*func)(void))
index 8583747bfa749663629ef6f60404f171c221d780..ef0ca3cf58aa2d0a56bd77e21ae3547fb860d1fe 100644 (file)
@@ -65,6 +65,7 @@ int virtTestDifferenceBin(FILE *stream,
 
 unsigned int virTestGetDebug(void);
 unsigned int virTestGetVerbose(void);
+unsigned int virTestGetExpensive(void);
 
 char *virtTestLogContentAndReset(void);