Skip to contentSkip to conversation

multipath-tools: unit test fixes

PATCH New Martin Wilck 1 participant 3 messages Oct 2, 2018 Device mapper

lore
Share & tools
lore
#0 lore raw

cover multipath-tools: unit test fixes

Martin Wilck (2):
multipath/tests: fix hwtable tests after "hidden" support
multipath-tools: tests/hwtable: test hidden devices

 tests/hwtable.c  | 20 ++++++++++++++++++++
 tests/test-lib.c |  6 ++++++
 tests/test-lib.h |  3 ++-
 3 files changed, 28 insertions(+), 1 deletion(-)
Signature · 1 line
2.19.0
#1 lore raw

PATCH 1/2 multipath/tests: fix hwtable tests after "hidden" support

The previous patch "libmultipath: pathinfo: skip hidden devices" requires a change in the pathinfo mocking code. Otherwise the hwtable tests will fail.

---
 tests/test-lib.c | 6 ++++++
 tests/test-lib.h | 3 ++-
 2 files changed, 8 insertions(+), 1 deletion(-)
tests/test-lib.c +6 -0
index cff7a5d1..59275163 100644
@@ -248,6 +248,12 @@ static void mock_sysfs_pathinfo(const struct mocked_path *mp)
  */
 void mock_pathinfo(int mask, const struct mocked_path *mp)
 {
+	if (mp->flags & DEV_HIDDEN) {
+		will_return(__wrap_udev_device_get_sysattr_value, "1");
+		return;
+	} else
+		will_return(__wrap_udev_device_get_sysattr_value, "0");
+
 	/* filter_property */
 	will_return(__wrap_udev_device_get_sysname, mp->devnode);
 	if (mp->flags & BL_BY_PROPERTY) {
tests/test-lib.h +2 -1
index d2745979..7643ab67 100644
@@ -14,7 +14,8 @@ enum {
 	BL_MASK = BL_BY_DEVNODE|BL_BY_DEVICE|BL_BY_WWID|BL_BY_PROPERTY,
 	NEED_SELECT_PRIO = (1 << 8),
 	NEED_FD		= (1 << 9),
-	USE_GETUID	= (1 << 10)
+	USE_GETUID	= (1 << 10),
+	DEV_HIDDEN	= (1 << 11),
 };
 
 struct mocked_path {
Signature · 1 line
2.19.0
#2 lore raw

PATCH 2/2 multipath-tools: tests/hwtable: test hidden devices

In reply to Martin Wilck

Add a test for skipping "hidden" devices.

---
 tests/hwtable.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
tests/hwtable.c +20 -0
index 42127adf..9146ecc3 100644
@@ -1661,6 +1661,24 @@ static int setup_multipath_config_3(void **state)
 	return 0;
 }
 
+/*
+ * Test for device with "hidden" attribute
+ */
+static void test_hidden(const struct hwt_state *hwt)
+{
+	mock_path_flags("NVME", "NoName", DEV_HIDDEN|BL_MASK);
+}
+
+static int setup_hidden(void **state)
+{
+	struct hwt_state *hwt = CHECK_STATE(state);
+
+	WRITE_EMPTY_CONF(hwt);
+	SET_TEST_FUNC(hwt, test_hidden);
+
+	return 0;
+}
+
 /*
  * Create wrapper functions around test_driver() to avoid that cmocka
  * always uses the same test name. That makes it easier to read test results.
@@ -1703,6 +1721,7 @@ define_test(product_blacklist_matching)
 define_test(multipath_config)
 define_test(multipath_config_2)
 define_test(multipath_config_3)
+define_test(hidden)
 
 #define test_entry(x) \
 	cmocka_unit_test_setup(run_##x, setup_##x)
@@ -1742,6 +1761,7 @@ static int test_hwtable(void)
 		test_entry(multipath_config),
 		test_entry(multipath_config_2),
 		test_entry(multipath_config_3),
+		test_entry(hidden),
 	};
 
 	return cmocka_run_group_tests(tests, setup, teardown);
Signature · 1 line
2.19.0