From: Johannes Berg Date: Fri, 2 May 2025 12:56:18 +0000 (+0300) Subject: wifi: iwlwifi: tests: check configs are not duplicated X-Git-Tag: v6.16-rc1~132^2~46^2~8^2~131 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=cccb5b266bbe7583ca99967e499940d5d3b32382;p=linux-block.git wifi: iwlwifi: tests: check configs are not duplicated 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 Signed-off-by: Miri Korenblit Link: https://patch.msgid.link/20250502155404.0cfd9fb8322e.I9567b839405be8d1e4be0bfca7a17b5d222b0158@changeid --- 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), {} };