multipath-tools tests: allow control of test verbosity
PATCH 1/4 multipath-tools tests: allow control of test verbosity
From: Martin Wilck <[email protected]>
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.
--- 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(-)
tests/README.md +5 -0
@@ -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
tests/alias.c +1 -1
@@ -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 ();
tests/blacklist.c +1 -1
@@ -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 ; }
tests/devt.c +1 -0
@@ -187,6 +187,7 @@ int main(void) {int ret =0 ; +init_test_verbosity (-1 ); ret +=devt2devname_tests ();return ret; }
tests/directio.c +1 -1
@@ -770,7 +770,7 @@ int main(void) {int ret =0 ; - conf.verbosity =2 ; +init_test_verbosity (2 ); ret +=test_directio ();return ret; }
tests/dmevents.c +1 -0
@@ -925,6 +925,7 @@ int main(void) {int ret =0 ; +init_test_verbosity (-1 ); ret +=test_dmevents ();return ret; }
tests/globals.c +21 -6
@@ -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; + } +}
tests/hwtable.c +2 -0
@@ -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; }
tests/parser.c +1 -0
@@ -511,6 +511,7 @@ int main(void) {int ret =0 ; +init_test_verbosity (-1 ); ret +=test_config_parser ();return ret; }
tests/pgpolicy.c +1 -0
@@ -1031,6 +1031,7 @@ int main(void) {int ret =0 ; +init_test_verbosity (-1 ); ret +=test_pgpolicies ();return ret; }
tests/uevent.c +1 -0
@@ -322,6 +322,7 @@ int main(void) {int ret =0 ; +init_test_verbosity (-1 ); ret +=test_uevent_get_XXX ();return ret; }
tests/unaligned.c +1 -0
@@ -91,6 +91,7 @@ int main(void) {int ret =0 ; +init_test_verbosity (-1 ); ret +=test_unaligned ();return ret; }
tests/util.c +1 -0
@@ -946,6 +946,7 @@ int main(void) {int ret =0 ; +init_test_verbosity (-1 ); ret +=test_basenamecpy (); ret +=test_bitmasks (); ret +=test_strlcpy ();
tests/valid.c +2 -0
@@ -554,6 +554,8 @@ int test_valid(void)int main (void ) {int ret =0 ; + +init_test_verbosity (-1 ); ret +=test_valid ();return ret; }
tests/vpd.c +1 -0
@@ -799,6 +799,7 @@ int main(void) {int ret =0 ; +init_test_verbosity (-1 ); ret +=test_vpd ();return ret; }
Signature · 7 lines
2.29.2 -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
PATCH 2/4 multipath-tools: devt test: avoid failure when run in containers
From: Martin Wilck <[email protected]>
/sys/dev/block is usually unavailable containers, causing libudev calls to fail. Skip the respective tests.
--- tests/devt.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
tests/devt.c +18 -0
@@ -11,11 +11,25 @@#include <cmocka.h> #include <libudev.h> #include <sys/sysmacros.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <unistd.h> #include "util.h" #include "debug.h" #include "globals.c" +static bool sys_dev_block_exists (void ) +{ +int fd; +bool rc; + + fd =open ("/sys/dev/block" ,O_RDONLY |O_DIRECTORY ); + rc = (fd !=-1 ); +close (fd); +return rc; +} +static int get_one_devt (char *devt,size_t len) {struct udev_enumerate *enm;
@@ -71,6 +85,8 @@ static void test_devt2devname_devt_good(void **state) {char dummy[BLK_DEV_SIZE ]; +if (!sys_dev_block_exists ()) +skip ();assert_int_equal (devt2devname (dummy,sizeof (dummy), *state),0 ); }
@@ -137,6 +153,8 @@ static void test_devt2devname_real(void **state)struct udev_list_entry *first, *item;unsigned int i =0 ; +if (!sys_dev_block_exists ()) +skip (); enm =udev_enumerate_new (udev);assert_non_null (enm); r =udev_enumerate_add_match_subsystem (enm,"block" );
Signature · 7 lines
2.29.2 -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
PATCH 3/4 multipath-tools: fix compilation errors on 32-bit musl
In reply to [email protected]From: Martin Wilck <[email protected]>
gcc on alpine Linux/i386 throws errors because the "tv_sec" element of struct timespec is a time_t, which is a "long long" in that environment. In general, time_t is signed. As we only use CLOCK_MONOTONIC, which starts at boot time, a cast to long should be no problem, even in 32bit environments.
--- multipath/main.c | 2 +- multipathd/main.c | 16 ++++++++-------- multipathd/uxlsnr.c | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-)
multipath/main.c +1 -1
@@ -417,7 +417,7 @@ static int print_cmd_valid(int k, const vector pathvec, wait =find_multipaths_check_timeout (pp,0 , &until);if (wait ==FIND_MULTIPATHS_WAITING )printf ("FIND_MULTIPATHS_WAIT_UNTIL=\"%ld.%06ld\"\n" , - until.tv_sec, until.tv_nsec/1000 ); + (long )until.tv_sec, until.tv_nsec/1000 );else if (wait ==FIND_MULTIPATHS_WAIT_DONE )printf ("FIND_MULTIPATHS_WAIT_UNTIL=\"0\"\n" ); printf("DM_MULTIPATH_DEVICE_PATH=\"%d\"\n",
multipathd/main.c +8 -8
@@ -2408,8 +2408,8 @@ checkerloop (void *ap)get_monotonic_time (&start_time);if (start_time.tv_sec && last_time.tv_sec) {timespecsub (&start_time, &last_time, &diff_time); -condlog (4 ,"tick (%lu.%06lu secs)" , - diff_time.tv_sec, diff_time.tv_nsec /1000 ); +condlog (4 ,"tick (%ld.%06lu secs)" , + (long )diff_time.tv_sec, diff_time.tv_nsec /1000 ); last_time = start_time; ticks = diff_time.tv_sec; }else {
@@ -2470,18 +2470,18 @@ checkerloop (void *ap)if (num_paths) {unsigned int max_checkint; -condlog (4 ,"checked %d path%s in %lu.%06lu secs" , +condlog (4 ,"checked %d path%s in %ld.%06lu secs" , num_paths, num_paths >1 ?"s" :"" , - diff_time.tv_sec, + (long )diff_time.tv_sec, diff_time.tv_nsec /1000 ); conf =get_multipath_config (); max_checkint = conf->max_checkint;put_multipath_config (conf);if (diff_time.tv_sec > (time_t )max_checkint)condlog (1 ,"path checkers took longer " -"than %lu seconds, consider " +"than %ld seconds, consider " "increasing max_polling_interval" , - diff_time.tv_sec); + (long )diff_time.tv_sec); } }
@@ -2507,8 +2507,8 @@ checkerloop (void *ap) }else diff_time.tv_sec =1 ; -condlog (3 ,"waiting for %lu.%06lu secs" , - diff_time.tv_sec, +condlog (3 ,"waiting for %ld.%06lu secs" , + (long )diff_time.tv_sec, diff_time.tv_nsec /1000 );if (nanosleep (&diff_time,NULL ) !=0 ) { condlog(3, "nanosleep failed with error %d",
multipathd/uxlsnr.c +2 -2
@@ -154,8 +154,8 @@ static void check_timeout(struct timespec start_time, char *inbuf, diff_time.tv_nsec / (1000 *1000 );if (msecs > timeout)condlog (2 ,"cli cmd '%s' timeout reached " -"after %lu.%06lu secs" , inbuf, - diff_time.tv_sec, diff_time.tv_nsec /1000 ); +"after %ld.%06lu secs" , inbuf, + (long )diff_time.tv_sec, diff_time.tv_nsec /1000 ); } }
Signature · 7 lines
2.29.2 -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
PATCH 4/4 libmultipath: fix compilation error with gcc 10 on i386
In reply to [email protected]From: Martin Wilck <[email protected]>
gcc complained about a possible negative value of "nr" in the memcpy() call. I consider that a false positive, but it's easily fixed.
--- libmultipath/sysfs.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-)
libmultipath/sysfs.c +14 -15
@@ -344,24 +344,23 @@ bool sysfs_is_multipathed(struct path *pp, bool set_wwid)pthread_cleanup_push (close_fd, (void *)fd); nr =read (fd, uuid,sizeof (uuid));if (nr > (int )UUID_PREFIX_LEN && - !memcmp (uuid,UUID_PREFIX ,UUID_PREFIX_LEN )) + !memcmp (uuid,UUID_PREFIX ,UUID_PREFIX_LEN )) { found = true; -else if (nr <0 ) { +if (set_wwid) { + nr -=UUID_PREFIX_LEN ; +memcpy (pp->wwid, uuid +UUID_PREFIX_LEN , nr); +if (nr ==WWID_SIZE ) { +condlog (4 ,"%s: overflow while reading from %s" , + __func__, pathbuf); + pp->wwid[0 ] ='\0' ; + }else { + pp->wwid[nr] ='\0' ; +strchop (pp->wwid); + } + } + }else if (nr <0 )condlog (1 ,"%s: error reading from %s: %m" , __func__, pathbuf); - } -if (found && set_wwid) { - nr -=UUID_PREFIX_LEN ; -memcpy (pp->wwid, uuid +UUID_PREFIX_LEN , nr); -if (nr ==WWID_SIZE ) { -condlog (4 ,"%s: overflow while reading from %s" , - __func__, pathbuf); - pp->wwid[0 ] ='\0' ; - }else { - pp->wwid[nr] ='\0' ; -strchop (pp->wwid); - } - }pthread_cleanup_pop (1 ); }
Signature · 7 lines
2.29.2 -- dm-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/dm-devel
Quoted 10 lines · On Fri, Feb 12, 2021 at 12:46:47AM +0100, [email protected] wrote:
From: Martin Wilck <[email protected]>
Use common code to control verbosity during unit tests runs. The environment variable
MPATHTEST_VERBOSITYis 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.
For the set.
Quoted 241 lines
Signed-off-by Martin Wilck <[email protected]>--- 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(-)tests/README.md +5
-0@@ -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 permissionstests/alias.c +1
-1@@ -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 ();tests/blacklist.c +1
-1@@ -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 ; }tests/devt.c +1
-0@@ -187,6 +187,7 @@ int main(void) {int ret =0 ; +init_test_verbosity (-1 ); ret +=devt2devname_tests ();return ret; }tests/directio.c +1
-1@@ -770,7 +770,7 @@ int main(void) {int ret =0 ; - conf.verbosity =2 ; +init_test_verbosity (2 ); ret +=test_directio ();return ret; }tests/dmevents.c +1
-0@@ -925,6 +925,7 @@ int main(void) {int ret =0 ; +init_test_verbosity (-1 ); ret +=test_dmevents ();return ret; }tests/globals.c +21
-6@@ -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; + } +}tests/hwtable.c +2
-0@@ -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; }tests/parser.c +1
-0@@ -511,6 +511,7 @@ int main(void) {int ret =0 ; +init_test_verbosity (-1 ); ret +=test_config_parser ();return ret; }tests/pgpolicy.c +1
-0@@ -1031,6 +1031,7 @@ int main(void) {int ret =0 ; +init_test_verbosity (-1 ); ret +=test_pgpolicies ();return ret; }tests/uevent.c +1
-0@@ -322,6 +322,7 @@ int main(void) {int ret =0 ; +init_test_verbosity (-1 ); ret +=test_uevent_get_XXX ();return ret; }tests/unaligned.c +1
-0@@ -91,6 +91,7 @@ int main(void) {int ret =0 ; +init_test_verbosity (-1 ); ret +=test_unaligned ();return ret; }tests/util.c +1
-0@@ -946,6 +946,7 @@ int main(void) {int ret =0 ; +init_test_verbosity (-1 ); ret +=test_basenamecpy (); ret +=test_bitmasks (); ret +=test_strlcpy ();tests/valid.c +2
-0@@ -554,6 +554,8 @@ int test_valid(void)int main (void ) {int ret =0 ; + +init_test_verbosity (-1 ); ret +=test_valid ();return ret; }tests/vpd.c +1
-0@@ -799,6 +799,7 @@ int main(void) {int ret =0 ; +init_test_verbosity (-1 ); ret +=test_vpd ();return ret; }Signature · 1 line
2.29.2
--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel