提交 38d4bf49 编写于 作者: E Eric Blake

tests: add helper to determine when to skip expensive tests

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: NEric Blake <eblake@redhat.com>
上级 70363ea9
# 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_srcdir" && abs_srcdir=$(pwd)
test -z "$abs_builddir" && abs_builddir=$(pwd) test -z "$abs_builddir" && abs_builddir=$(pwd)
...@@ -158,15 +176,12 @@ require_selinux_() ...@@ -158,15 +176,12 @@ require_selinux_()
esac esac
} }
very_expensive_() test_expensive()
{ {
if test "$RUN_VERY_EXPENSIVE_TESTS" != yes; then if test "$VIR_TEST_EXPENSIVE" != 1; then
skip_test_ ' skip_test_ '
This test is very expensive, so it is disabled by default. This test is very expensive, so it is disabled by default.
To run it anyway, rerun make check with the RUN_VERY_EXPENSIVE_TESTS To run it anyway, rerun: make check VIR_TEST_EXPENSIVE=1
environment variable set to yes. E.g.,
env RUN_VERY_EXPENSIVE_TESTS=yes make check
' '
fi fi
} }
......
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
static unsigned int testDebug = -1; static unsigned int testDebug = -1;
static unsigned int testVerbose = -1; static unsigned int testVerbose = -1;
static unsigned int testExpensive = -1;
static unsigned int testOOM = 0; static unsigned int testOOM = 0;
static size_t testCounter = 0; static size_t testCounter = 0;
...@@ -581,6 +582,13 @@ virTestGetVerbose(void) { ...@@ -581,6 +582,13 @@ virTestGetVerbose(void) {
return testVerbose || virTestGetDebug(); return testVerbose || virTestGetDebug();
} }
unsigned int
virTestGetExpensive(void) {
if (testExpensive == -1)
testExpensive = virTestGetFlag("VIR_TEST_EXPENSIVE");
return testExpensive;
}
int virtTestMain(int argc, int virtTestMain(int argc,
char **argv, char **argv,
int (*func)(void)) int (*func)(void))
......
...@@ -65,6 +65,7 @@ int virtTestDifferenceBin(FILE *stream, ...@@ -65,6 +65,7 @@ int virtTestDifferenceBin(FILE *stream,
unsigned int virTestGetDebug(void); unsigned int virTestGetDebug(void);
unsigned int virTestGetVerbose(void); unsigned int virTestGetVerbose(void);
unsigned int virTestGetExpensive(void);
char *virtTestLogContentAndReset(void); char *virtTestLogContentAndReset(void);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册