[PATCH 2/4] multipath-tools: devt test: avoid failure when run in containers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Martin Wilck <mwilck@xxxxxxxx>

/sys/dev/block is usually unavailable containers, causing libudev
calls to fail. Skip the respective tests.

Signed-off-by: Martin Wilck <mwilck@xxxxxxxx>
---
 tests/devt.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/tests/devt.c b/tests/devt.c
index 2b72851..02f2e8f 100644
--- a/tests/devt.c
+++ b/tests/devt.c
@@ -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");
-- 
2.29.2


--
dm-devel mailing list
dm-devel@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/dm-devel




[Index of Archives]     [DM Crypt]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Packaging]     [Fedora SELinux]     [Yosemite Discussion]     [KDE Users]     [Fedora Docs]

  Powered by Linux