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(a)redhat.com>
---
v2: new patch followup, no v1
tests/test-lib.sh | 29 ++++++++++++++++++++++-------
tests/testutils.c | 8 ++++++++
tests/testutils.h | 1 +
3 files changed, 31 insertions(+), 7 deletions(-)
diff --git a/tests/test-lib.sh b/tests/test-lib.sh
index 918bf73..2f79706 100644
--- a/tests/test-lib.sh
+++ b/tests/test-lib.sh
@@ -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
}
diff --git a/tests/testutils.c b/tests/testutils.c
index 72aa5b3..c521552 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -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))
diff --git a/tests/testutils.h b/tests/testutils.h
index 8583747..ef0ca3c 100644
--- a/tests/testutils.h
+++ b/tests/testutils.h
@@ -65,6 +65,7 @@ int virtTestDifferenceBin(FILE *stream,
unsigned int virTestGetDebug(void);
unsigned int virTestGetVerbose(void);
+unsigned int virTestGetExpensive(void);
char *virtTestLogContentAndReset(void);
--
1.8.3.1