diff mbox series

[iwlwifi-next,02/15] wifi: iwlwifi: tests: check configs are not duplicated

Message ID 20250502155404.0cfd9fb8322e.I9567b839405be8d1e4be0bfca7a17b5d222b0158@changeid
State New
Headers show
Series wifi: iwlwifi: updates - 2025-05-02 | expand

Commit Message

Miri Korenblit May 2, 2025, 12:56 p.m. UTC
From: Johannes Berg <johannes.berg@intel.com>

Add a kunit test to check that all (used) config structs
are not duplicated, ignoring the name since that can be
handled differently via the dev-info list.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Miri Korenblit <miriam.rachel.korenblit@intel.com>
---
 .../wireless/intel/iwlwifi/tests/devinfo.c    | 47 +++++++++++++++++++
 1 file changed, 47 insertions(+)
diff mbox series

Patch

diff --git a/drivers/net/wireless/intel/iwlwifi/tests/devinfo.c b/drivers/net/wireless/intel/iwlwifi/tests/devinfo.c
index a64880fd3398..0de3a01001d7 100644
--- a/drivers/net/wireless/intel/iwlwifi/tests/devinfo.c
+++ b/drivers/net/wireless/intel/iwlwifi/tests/devinfo.c
@@ -58,6 +58,52 @@  static void devinfo_names(struct kunit *test)
 	}
 }
 
+static void devinfo_no_cfg_dups(struct kunit *test)
+{
+	/* allocate iwl_dev_info_table_size as upper bound */
+	const struct iwl_cfg **cfgs = kunit_kcalloc(test,
+						    iwl_dev_info_table_size,
+						    sizeof(*cfgs), GFP_KERNEL);
+	int p = 0;
+
+	KUNIT_ASSERT_NOT_NULL(test, cfgs);
+
+	/* build a list of unique (by pointer) configs first */
+	for (int i = 0; i < iwl_dev_info_table_size; i++) {
+		bool found = false;
+
+		for (int j = 0; j < p; j++) {
+			if (cfgs[j] == iwl_dev_info_table[i].cfg) {
+				found = true;
+				break;
+			}
+		}
+		if (!found) {
+			cfgs[p] = iwl_dev_info_table[i].cfg;
+			p++;
+		}
+	}
+
+	/* check that they're really all different */
+	for (int i = 0; i < p; i++) {
+		struct iwl_cfg cfg_i = *cfgs[i];
+
+		/* null out the names since we can handle them differently */
+		cfg_i.name = NULL;
+
+		for (int j = 0; j < i; j++) {
+			struct iwl_cfg cfg_j = *cfgs[j];
+
+			cfg_j.name = NULL;
+
+			KUNIT_EXPECT_NE_MSG(test, memcmp(&cfg_i, &cfg_j,
+							 sizeof(cfg_i)), 0,
+					    "identical configs: %ps and %ps\n",
+					    cfgs[i], cfgs[j]);
+		}
+	}
+}
+
 static void devinfo_pci_ids(struct kunit *test)
 {
 	struct pci_dev *dev;
@@ -83,6 +129,7 @@  static void devinfo_pci_ids(struct kunit *test)
 static struct kunit_case devinfo_test_cases[] = {
 	KUNIT_CASE(devinfo_table_order),
 	KUNIT_CASE(devinfo_names),
+	KUNIT_CASE(devinfo_no_cfg_dups),
 	KUNIT_CASE(devinfo_pci_ids),
 	{}
 };