Skip to content

Commit

Permalink
multipath-tools tests: fix mapinfo tests
Browse files Browse the repository at this point in the history
After d043c48 ("libmultipath: check DM UUID earlier in libmp_mapinfo__"),
the tests need to be adapted. Also, add tests for the check for
empty table introduced in 9147a20 ("libmultipath: signal multipath UUID device
with no table").

Signed-off-by: Martin Wilck <[email protected]>
  • Loading branch information
mwilck committed Nov 12, 2024
1 parent 8d546b1 commit 05a6a18
Showing 1 changed file with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions tests/mapinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ static const struct dm_info __attribute__((unused)) MPATH_DMI_01 = {
.minor = 123,
};

static const struct dm_info __attribute__((unused)) MPATH_DMI_02 = {
.exists = 1,
.live_table = 0,
.open_count = 1,
.target_count = 1,
.major = 254,
.minor = 123,
};

static const char MPATH_NAME_01[] = "mpathx";
static const char MPATH_UUID_01[] = "mpath-3600a098038302d414b2b4d4453474f62";
static const char MPATH_TARGET_01[] =
Expand Down Expand Up @@ -928,6 +937,8 @@ static void test_mapinfo_bad_target_type_03(void **state)
mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0);
WRAP_DM_TASK_GET_INFO(1);
WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01);
will_return(__wrap_dm_task_get_name, MPATH_NAME_01);
will_return(__wrap_dm_task_get_uuid, MPATH_UUID_01);
mock_dm_get_next_target(12345, TGT_PART, MPATH_STATUS_01, NULL);
rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY,
(mapid_t) { .str = "foo", },
Expand Down Expand Up @@ -1038,6 +1049,37 @@ static void test_mapinfo_good_target_type_04(void **state)
assert_true(!strcmp(uuid, MPATH_UUID_01));
}

static void test_mapinfo_no_table_01(void **state)
{
int rc;
struct dm_info dmi = { .suspended = 0 };

mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0);
WRAP_DM_TASK_GET_INFO(1);
/* DMI with no live table, MAPINFO_CHECK_UUID not set */
WRAP_DM_TASK_GET_INFO(&MPATH_DMI_02);
rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY,
(mapid_t) { .str = "foo", },
(mapinfo_t) { .dmi = &dmi });
assert_int_equal(rc, DMP_NOT_FOUND);
}

static void test_mapinfo_no_table_02(void **state)
{
int rc;
struct dm_info dmi = { .suspended = 0 };

mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0);
WRAP_DM_TASK_GET_INFO(1);
/* DMI with no live table, MAPINFO_CHECK_UUID set */
WRAP_DM_TASK_GET_INFO(&MPATH_DMI_02);
will_return(__wrap_dm_task_get_uuid, MPATH_UUID_01);
rc = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_CHECK_UUID | MAPINFO_MPATH_ONLY,
(mapid_t) { .str = "foo", },
(mapinfo_t) { .dmi = &dmi });
assert_int_equal(rc, DMP_BAD_DEV);
}

static void test_mapinfo_good_status_01(void **state)
{
int rc;
Expand Down Expand Up @@ -1090,7 +1132,6 @@ static void test_mapinfo_bad_get_name_01(void **state)
mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0);
WRAP_DM_TASK_GET_INFO(1);
WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01);
mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL);
will_return(__wrap_dm_task_get_name, NULL);
rc = libmp_mapinfo(DM_MAP_BY_NAME,
(mapid_t) { .str = "foo", },
Expand All @@ -1112,7 +1153,6 @@ static void test_mapinfo_bad_get_uuid_01(void **state)
mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0);
WRAP_DM_TASK_GET_INFO(1);
WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01);
mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL);
will_return(__wrap_dm_task_get_name, MPATH_NAME_01);
will_return(__wrap_dm_task_get_uuid, NULL);
rc = libmp_mapinfo(DM_MAP_BY_NAME,
Expand Down Expand Up @@ -1162,7 +1202,6 @@ static void test_mapinfo_bad_get_name_02(void **state)
mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0);
WRAP_DM_TASK_GET_INFO(1);
WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01);
mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL);
will_return(__wrap_dm_task_get_name, NULL);

rc = libmp_mapinfo(DM_MAP_BY_NAME,
Expand Down Expand Up @@ -1195,7 +1234,6 @@ static void test_mapinfo_bad_get_uuid_02(void **state)
mock_mapinfo_name_1(DM_DEVICE_STATUS, 1, "foo", 1, 1, 0);
WRAP_DM_TASK_GET_INFO(1);
WRAP_DM_TASK_GET_INFO(&MPATH_DMI_01);
mock_dm_get_next_target(12345, TGT_MPATH, MPATH_STATUS_01, NULL);
will_return(__wrap_dm_task_get_name, MPATH_NAME_01);
will_return(__wrap_dm_task_get_uuid, NULL);

Expand Down Expand Up @@ -1377,6 +1415,8 @@ static int test_mapinfo(void)
cmocka_unit_test(test_mapinfo_good_target_type_02),
cmocka_unit_test(test_mapinfo_good_target_type_03),
cmocka_unit_test(test_mapinfo_good_target_type_04),
cmocka_unit_test(test_mapinfo_no_table_01),
cmocka_unit_test(test_mapinfo_no_table_02),
cmocka_unit_test(test_mapinfo_good_status_01),
cmocka_unit_test(test_mapinfo_bad_get_name_01),
cmocka_unit_test(test_mapinfo_bad_get_uuid_01),
Expand Down

0 comments on commit 05a6a18

Please sign in to comment.