From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Thu, 11 Feb 2021 22:54:58 +0100 Subject: [PATCH] multipath-tools: devt test: avoid failure when run in containers /sys/dev/block is usually unavailable containers, causing libudev calls to fail. Skip the respective tests. Reviewed-by: Benjamin Marzinski Signed-off-by: Benjamin Marzinski --- tests/devt.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/devt.c b/tests/devt.c index 2b728516..02f2e8f3 100644 --- a/tests/devt.c +++ b/tests/devt.c @@ -11,11 +11,25 @@ #include #include #include +#include +#include +#include #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");