|
|
86e138 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
86e138 |
From: Benjamin Marzinski <bmarzins@redhat.com>
|
|
|
86e138 |
Date: Fri, 7 Oct 2022 12:35:41 -0500
|
|
|
86e138 |
Subject: [PATCH] multipath tests: tests for reconcile_features_with_queue_mode
|
|
|
86e138 |
|
|
|
86e138 |
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
|
|
|
86e138 |
Reviewed-by: Martin Wilck <mwilck@suse.com>
|
|
|
86e138 |
---
|
|
|
86e138 |
tests/Makefile | 2 +
|
|
|
86e138 |
tests/features.c | 232 ++++++++++++++++++++++++++++++++++++++++++++++-
|
|
|
86e138 |
2 files changed, 233 insertions(+), 1 deletion(-)
|
|
|
86e138 |
|
|
|
86e138 |
diff --git a/tests/Makefile b/tests/Makefile
|
|
|
86e138 |
index 972a5e04..27e3ffa9 100644
|
|
|
86e138 |
--- a/tests/Makefile
|
|
|
86e138 |
+++ b/tests/Makefile
|
|
|
86e138 |
@@ -33,6 +33,7 @@ ifneq ($(DIO_TEST_DEV),)
|
|
|
86e138 |
directio-test_FLAGS := -DDIO_TEST_DEV=\"$(DIO_TEST_DEV)\"
|
|
|
86e138 |
endif
|
|
|
86e138 |
mpathvalid-test_FLAGS := -I$(mpathvaliddir)
|
|
|
86e138 |
+features-test_FLAGS := -I$(multipathdir)/nvme
|
|
|
86e138 |
|
|
|
86e138 |
# test-specific linker flags
|
|
|
86e138 |
# XYZ-test_TESTDEPS: test libraries containing __wrap_xyz functions
|
|
|
86e138 |
@@ -64,6 +65,7 @@ ifneq ($(DIO_TEST_DEV),)
|
|
|
86e138 |
directio-test_LIBDEPS := -laio
|
|
|
86e138 |
endif
|
|
|
86e138 |
strbuf-test_OBJDEPS := ../libmultipath/strbuf.o
|
|
|
86e138 |
+features-test_LIBDEPS := -ludev -lpthread
|
|
|
86e138 |
|
|
|
86e138 |
%.o: %.c
|
|
|
86e138 |
$(CC) $(CFLAGS) $($*-test_FLAGS) -c -o $@ $<
|
|
|
86e138 |
diff --git a/tests/features.c b/tests/features.c
|
|
|
86e138 |
index 4d8f0860..31f978fd 100644
|
|
|
86e138 |
--- a/tests/features.c
|
|
|
86e138 |
+++ b/tests/features.c
|
|
|
86e138 |
@@ -1,9 +1,10 @@
|
|
|
86e138 |
+#define _GNU_SOURCE
|
|
|
86e138 |
#include <stddef.h>
|
|
|
86e138 |
#include <stdarg.h>
|
|
|
86e138 |
#include <setjmp.h>
|
|
|
86e138 |
#include <cmocka.h>
|
|
|
86e138 |
|
|
|
86e138 |
-#include "structs.h"
|
|
|
86e138 |
+#include "../libmultipath/propsel.c"
|
|
|
86e138 |
#include "globals.c"
|
|
|
86e138 |
|
|
|
86e138 |
static void test_af_null_features_ptr(void **state)
|
|
|
86e138 |
@@ -307,6 +308,234 @@ static int test_remove_features(void)
|
|
|
86e138 |
return cmocka_run_group_tests(tests, NULL, NULL);
|
|
|
86e138 |
}
|
|
|
86e138 |
|
|
|
86e138 |
+static void test_cf_null_features(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ struct multipath mp = {
|
|
|
86e138 |
+ .alias = "test",
|
|
|
86e138 |
+ };
|
|
|
86e138 |
+ reconcile_features_with_queue_mode(&mp);
|
|
|
86e138 |
+ assert_null(mp.features);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void cf_helper(const char *features_start, const char *features_end,
|
|
|
86e138 |
+ int queue_mode_start, int queue_mode_end)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ struct multipath mp = {
|
|
|
86e138 |
+ .alias = "test",
|
|
|
86e138 |
+ .features = strdup(features_start),
|
|
|
86e138 |
+ .queue_mode = queue_mode_start,
|
|
|
86e138 |
+ };
|
|
|
86e138 |
+ char *orig = mp.features;
|
|
|
86e138 |
+
|
|
|
86e138 |
+ assert_non_null(orig);
|
|
|
86e138 |
+ reconcile_features_with_queue_mode(&mp);
|
|
|
86e138 |
+ if (!features_end)
|
|
|
86e138 |
+ assert_ptr_equal(orig, mp.features);
|
|
|
86e138 |
+ else
|
|
|
86e138 |
+ assert_string_equal(mp.features, features_end);
|
|
|
86e138 |
+ free(mp.features);
|
|
|
86e138 |
+ assert_int_equal(mp.queue_mode, queue_mode_end);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_unset_unset1(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("0", NULL, QUEUE_MODE_UNDEF, QUEUE_MODE_UNDEF);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_unset_unset2(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("1 queue_mode", NULL, QUEUE_MODE_UNDEF, QUEUE_MODE_UNDEF);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_unset_unset3(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("queue_mode", NULL, QUEUE_MODE_UNDEF, QUEUE_MODE_UNDEF);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_unset_unset4(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("2 queue_model bio", NULL, QUEUE_MODE_UNDEF,
|
|
|
86e138 |
+ QUEUE_MODE_UNDEF);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_unset_unset5(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("1 queue_if_no_path", NULL, QUEUE_MODE_UNDEF,
|
|
|
86e138 |
+ QUEUE_MODE_UNDEF);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_invalid_unset1(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("2 queue_mode biop", "0", QUEUE_MODE_UNDEF, QUEUE_MODE_UNDEF);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_invalid_unset2(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("3 queue_mode rqs queue_if_no_path", "1 queue_if_no_path",
|
|
|
86e138 |
+ QUEUE_MODE_UNDEF, QUEUE_MODE_UNDEF);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_rq_unset1(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("2 queue_mode rq", NULL, QUEUE_MODE_UNDEF, QUEUE_MODE_RQ);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_rq_unset2(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("2 queue_mode mq", NULL, QUEUE_MODE_UNDEF, QUEUE_MODE_RQ);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_bio_unset(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("2 queue_mode bio", NULL, QUEUE_MODE_UNDEF, QUEUE_MODE_BIO);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_unset_bio1(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("1 queue_if_no_path", "3 queue_if_no_path queue_mode bio",
|
|
|
86e138 |
+ QUEUE_MODE_BIO, QUEUE_MODE_BIO);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_unset_bio2(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("0", "2 queue_mode bio", QUEUE_MODE_BIO, QUEUE_MODE_BIO);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_unset_bio3(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("2 pg_init_retries 50", "4 pg_init_retries 50 queue_mode bio",
|
|
|
86e138 |
+ QUEUE_MODE_BIO, QUEUE_MODE_BIO);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_invalid_bio1(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("2 queue_mode bad", "2 queue_mode bio",
|
|
|
86e138 |
+ QUEUE_MODE_BIO, QUEUE_MODE_BIO);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_invalid_bio2(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("3 queue_if_no_path queue_mode\tbad", "3 queue_if_no_path queue_mode bio",
|
|
|
86e138 |
+ QUEUE_MODE_BIO, QUEUE_MODE_BIO);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_bio_bio1(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("2 queue_mode bio", NULL, QUEUE_MODE_BIO, QUEUE_MODE_BIO);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_bio_bio2(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("3 queue_if_no_path queue_mode bio", NULL, QUEUE_MODE_BIO, QUEUE_MODE_BIO);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_bio_bio3(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("3 queue_mode\nbio queue_if_no_path", NULL, QUEUE_MODE_BIO, QUEUE_MODE_BIO);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_bio_rq1(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("2\nqueue_mode\tbio", "0", QUEUE_MODE_RQ, QUEUE_MODE_RQ);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_bio_rq2(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("3 queue_if_no_path\nqueue_mode bio", "1 queue_if_no_path",
|
|
|
86e138 |
+ QUEUE_MODE_RQ, QUEUE_MODE_RQ);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_bio_rq3(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("4 queue_mode bio pg_init_retries 20", "2 pg_init_retries 20",
|
|
|
86e138 |
+ QUEUE_MODE_RQ, QUEUE_MODE_RQ);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_unset_rq1(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("0", NULL, QUEUE_MODE_RQ, QUEUE_MODE_RQ);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_unset_rq2(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("2 pg_init_retries 15", NULL, QUEUE_MODE_RQ, QUEUE_MODE_RQ);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_invalid_rq1(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("2 queue_mode bionic", "0", QUEUE_MODE_RQ, QUEUE_MODE_RQ);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_invalid_rq2(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("3 queue_mode b\nqueue_if_no_path", "1 queue_if_no_path",
|
|
|
86e138 |
+ QUEUE_MODE_RQ, QUEUE_MODE_RQ);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_rq_rq1(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("2 queue_mode rq", NULL, QUEUE_MODE_RQ, QUEUE_MODE_RQ);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_rq_rq2(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("3 queue_mode\t \trq\nqueue_if_no_path", NULL, QUEUE_MODE_RQ, QUEUE_MODE_RQ);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_rq_bio1(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("2 queue_mode rq", "2 queue_mode bio", QUEUE_MODE_BIO,
|
|
|
86e138 |
+ QUEUE_MODE_BIO);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_rq_bio2(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("3 queue_if_no_path\nqueue_mode rq", "3 queue_if_no_path queue_mode bio", QUEUE_MODE_BIO, QUEUE_MODE_BIO);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static void test_cf_rq_bio3(void **state)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ cf_helper("3 queue_mode rq\nqueue_if_no_path", "3 queue_if_no_path queue_mode bio", QUEUE_MODE_BIO, QUEUE_MODE_BIO);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
+static int test_reconcile_features(void)
|
|
|
86e138 |
+{
|
|
|
86e138 |
+ const struct CMUnitTest tests[] = {
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_null_features),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_unset_unset1),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_unset_unset2),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_unset_unset3),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_unset_unset4),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_unset_unset5),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_invalid_unset1),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_invalid_unset2),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_rq_unset1),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_rq_unset2),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_bio_unset),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_unset_bio1),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_unset_bio2),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_unset_bio3),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_invalid_bio1),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_invalid_bio2),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_bio_bio1),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_bio_bio2),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_bio_bio3),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_bio_rq1),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_bio_rq2),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_bio_rq3),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_unset_rq1),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_unset_rq2),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_invalid_rq1),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_invalid_rq2),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_rq_rq1),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_rq_rq2),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_rq_bio1),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_rq_bio2),
|
|
|
86e138 |
+ cmocka_unit_test(test_cf_rq_bio3),
|
|
|
86e138 |
+ };
|
|
|
86e138 |
+ return cmocka_run_group_tests(tests, NULL, NULL);
|
|
|
86e138 |
+}
|
|
|
86e138 |
+
|
|
|
86e138 |
int main(void)
|
|
|
86e138 |
{
|
|
|
86e138 |
int ret = 0;
|
|
|
86e138 |
@@ -314,6 +543,7 @@ int main(void)
|
|
|
86e138 |
init_test_verbosity(-1);
|
|
|
86e138 |
ret += test_add_features();
|
|
|
86e138 |
ret += test_remove_features();
|
|
|
86e138 |
+ ret += test_reconcile_features();
|
|
|
86e138 |
|
|
|
86e138 |
return ret;
|
|
|
86e138 |
}
|