wifi: iwlwifi: tests: check configs are not duplicated
authorJohannes Berg <johannes.berg@intel.com>
Fri, 2 May 2025 12:56:18 +0000 (15:56 +0300)
committerMiri Korenblit <miriam.rachel.korenblit@intel.com>
Tue, 6 May 2025 19:22:12 +0000 (22:22 +0300)
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>
Link: https://patch.msgid.link/20250502155404.0cfd9fb8322e.I9567b839405be8d1e4be0bfca7a17b5d222b0158@changeid
drivers/net/wireless/intel/iwlwifi/tests/devinfo.c

index a64880fd33986bc54f9c2d68d2b57b13a4ce8554..0de3a01001d705c949b583ebe69725c2e285fb53 100644 (file)
@@ -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),
        {}
 };