Commit cccb5b26 authored by Johannes Berg's avatar Johannes Berg Committed by Miri Korenblit
Browse files

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: default avatarJohannes Berg <johannes.berg@intel.com>
Signed-off-by: default avatarMiri Korenblit <miriam.rachel.korenblit@intel.com>
Link: https://patch.msgid.link/20250502155404.0cfd9fb8322e.I9567b839405be8d1e4be0bfca7a17b5d222b0158@changeid
parent 7f0d5a32
Loading
Loading
Loading
Loading
+47 −0
Original line number Diff line number Diff line
@@ -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),
	{}
};