[dm-devel] [PATCH 1/4] multipath-tools tests: allow control of test verbosity
Benjamin Marzinski
bmarzins at redhat.com
Mon Feb 15 21:39:19 UTC 2021
On Fri, Feb 12, 2021 at 12:46:47AM +0100, mwilck at suse.com wrote:
> From: Martin Wilck <mwilck at suse.com>
>
> Use common code to control verbosity during unit tests runs.
> The environment variable MPATHTEST_VERBOSITY is honored by most
> tests, except those that need to parse the log messages or have
> other special needs.
>
> Also, get rid of the now obsolete global variables logsink and
> udev, as these are now defined in libmultipath.
>
Reviewed-by: Benjamin Marzinski <bmarzins at redhat.com>
For the set.
> Signed-off-by: Martin Wilck <mwilck at suse.com>
> ---
> tests/README.md | 5 +++++
> tests/alias.c | 2 +-
> tests/blacklist.c | 2 +-
> tests/devt.c | 1 +
> tests/directio.c | 2 +-
> tests/dmevents.c | 1 +
> tests/globals.c | 27 +++++++++++++++++++++------
> tests/hwtable.c | 2 ++
> tests/parser.c | 1 +
> tests/pgpolicy.c | 1 +
> tests/uevent.c | 1 +
> tests/unaligned.c | 1 +
> tests/util.c | 1 +
> tests/valid.c | 2 ++
> tests/vpd.c | 1 +
> 15 files changed, 41 insertions(+), 9 deletions(-)
>
> diff --git a/tests/README.md b/tests/README.md
> index 6e7ad40..47c0f0b 100644
> --- a/tests/README.md
> +++ b/tests/README.md
> @@ -13,6 +13,11 @@ If valgrind detects a bad memory access or leak, the test will fail. The
> output of the test run, including valgrind output, is stored as
> `<testname>.vgr`.
>
> +## Controlling verbosity for unit tests
> +
> +Some test programs use the environment variable `MPATHTEST_VERBOSITY` to
> +control the log level during test execution.
> +
> ## Notes on individual tests
>
> ### Tests that require root permissions
> diff --git a/tests/alias.c b/tests/alias.c
> index 5e0bfea..b363718 100644
> --- a/tests/alias.c
> +++ b/tests/alias.c
> @@ -736,7 +736,7 @@ static int test_allocate_binding(void)
> int main(void)
> {
> int ret = 0;
> - libmp_verbosity = conf.verbosity;
> + init_test_verbosity(3);
>
> ret += test_format_devname();
> ret += test_scan_devname();
> diff --git a/tests/blacklist.c b/tests/blacklist.c
> index 0b42e25..882aa3a 100644
> --- a/tests/blacklist.c
> +++ b/tests/blacklist.c
> @@ -153,7 +153,7 @@ static int setup(void **state)
> store_ble(blist_property_wwn_inv, "!ID_WWN", ORIGIN_CONFIG))
> return -1;
>
> - libmp_verbosity = conf.verbosity = 4;
> + init_test_verbosity(4);
> return 0;
> }
>
> diff --git a/tests/devt.c b/tests/devt.c
> index fd4d74a..2b72851 100644
> --- a/tests/devt.c
> +++ b/tests/devt.c
> @@ -187,6 +187,7 @@ int main(void)
> {
> int ret = 0;
>
> + init_test_verbosity(-1);
> ret += devt2devname_tests();
> return ret;
> }
> diff --git a/tests/directio.c b/tests/directio.c
> index 9895409..9f7d388 100644
> --- a/tests/directio.c
> +++ b/tests/directio.c
> @@ -770,7 +770,7 @@ int main(void)
> {
> int ret = 0;
>
> - conf.verbosity = 2;
> + init_test_verbosity(2);
> ret += test_directio();
> return ret;
> }
> diff --git a/tests/dmevents.c b/tests/dmevents.c
> index 29eaa6d..204cf1d 100644
> --- a/tests/dmevents.c
> +++ b/tests/dmevents.c
> @@ -925,6 +925,7 @@ int main(void)
> {
> int ret = 0;
>
> + init_test_verbosity(-1);
> ret += test_dmevents();
> return ret;
> }
> diff --git a/tests/globals.c b/tests/globals.c
> index fc0c07a..36319ed 100644
> --- a/tests/globals.c
> +++ b/tests/globals.c
> @@ -1,13 +1,12 @@
> +#include <stdlib.h>
> +#include <string.h>
> +
> +#include "defaults.h"
> #include "structs.h"
> #include "config.h"
> #include "debug.h"
>
> -/* Required globals */
> -struct udev *udev;
> -int logsink = LOGSINK_STDERR_WITHOUT_TIME;
> -struct config conf = {
> - .verbosity = 4,
> -};
> +struct config conf;
>
> struct config *get_multipath_config(void)
> {
> @@ -16,3 +15,19 @@ struct config *get_multipath_config(void)
>
> void put_multipath_config(void *arg)
> {}
> +
> +static __attribute__((unused)) void init_test_verbosity(int test_verbosity)
> +{
> + char *verb = getenv("MPATHTEST_VERBOSITY");
> +
> + libmp_verbosity = test_verbosity >= 0 ? test_verbosity :
> + DEFAULT_VERBOSITY;
> + if (verb && *verb) {
> + char *c;
> + int vb;
> +
> + vb = strtoul(verb, &c, 10);
> + if (!*c && vb >= 0 && vb <= 5)
> + libmp_verbosity = vb;
> + }
> +}
> diff --git a/tests/hwtable.c b/tests/hwtable.c
> index 4dd0873..6f5766f 100644
> --- a/tests/hwtable.c
> +++ b/tests/hwtable.c
> @@ -1778,6 +1778,8 @@ int main(void)
> {
> int ret = 0;
>
> + /* We can't use init_test_verbosity in this test */
> + libmp_verbosity = VERBOSITY;
> ret += test_hwtable();
> return ret;
> }
> diff --git a/tests/parser.c b/tests/parser.c
> index 5772391..cf96d81 100644
> --- a/tests/parser.c
> +++ b/tests/parser.c
> @@ -511,6 +511,7 @@ int main(void)
> {
> int ret = 0;
>
> + init_test_verbosity(-1);
> ret += test_config_parser();
> return ret;
> }
> diff --git a/tests/pgpolicy.c b/tests/pgpolicy.c
> index 3f61b12..57ad338 100644
> --- a/tests/pgpolicy.c
> +++ b/tests/pgpolicy.c
> @@ -1031,6 +1031,7 @@ int main(void)
> {
> int ret = 0;
>
> + init_test_verbosity(-1);
> ret += test_pgpolicies();
> return ret;
> }
> diff --git a/tests/uevent.c b/tests/uevent.c
> index 9ffcd2d..648ff26 100644
> --- a/tests/uevent.c
> +++ b/tests/uevent.c
> @@ -322,6 +322,7 @@ int main(void)
> {
> int ret = 0;
>
> + init_test_verbosity(-1);
> ret += test_uevent_get_XXX();
> return ret;
> }
> diff --git a/tests/unaligned.c b/tests/unaligned.c
> index 7ece1de..e43b64d 100644
> --- a/tests/unaligned.c
> +++ b/tests/unaligned.c
> @@ -91,6 +91,7 @@ int main(void)
> {
> int ret = 0;
>
> + init_test_verbosity(-1);
> ret += test_unaligned();
> return ret;
> }
> diff --git a/tests/util.c b/tests/util.c
> index c3c49b6..9affb0e 100644
> --- a/tests/util.c
> +++ b/tests/util.c
> @@ -946,6 +946,7 @@ int main(void)
> {
> int ret = 0;
>
> + init_test_verbosity(-1);
> ret += test_basenamecpy();
> ret += test_bitmasks();
> ret += test_strlcpy();
> diff --git a/tests/valid.c b/tests/valid.c
> index 8ec803e..e7393a1 100644
> --- a/tests/valid.c
> +++ b/tests/valid.c
> @@ -554,6 +554,8 @@ int test_valid(void)
> int main(void)
> {
> int ret = 0;
> +
> + init_test_verbosity(-1);
> ret += test_valid();
> return ret;
> }
> diff --git a/tests/vpd.c b/tests/vpd.c
> index e2ec65e..8e730d3 100644
> --- a/tests/vpd.c
> +++ b/tests/vpd.c
> @@ -799,6 +799,7 @@ int main(void)
> {
> int ret = 0;
>
> + init_test_verbosity(-1);
> ret += test_vpd();
> return ret;
> }
> --
> 2.29.2
More information about the dm-devel
mailing list