Blame SOURCES/0121-multipath-tests-tests-for-reconcile_features_with_qu.patch

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