Linux Audio

Check our new training course

Loading...
Note: File does not exist in v3.15.
 1// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
 2/*
 3 * KUnit tests for the iwlwifi device info table
 4 *
 5 * Copyright (C) 2023-2024 Intel Corporation
 6 */
 7#include <kunit/test.h>
 8#include <linux/pci.h>
 9#include "iwl-drv.h"
10#include "iwl-config.h"
11
12MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
13
14static void iwl_pci_print_dev_info(const char *pfx, const struct iwl_dev_info *di)
15{
16	printk(KERN_DEBUG "%sdev=%.4x,subdev=%.4x,mac_type=%.4x,mac_step=%.4x,rf_type=%.4x,cdb=%d,jacket=%d,rf_id=%.2x,no_160=%d,cores=%.2x\n",
17	       pfx, di->device, di->subdevice, di->mac_type, di->mac_step,
18	       di->rf_type, di->cdb, di->jacket, di->rf_id, di->no_160,
19	       di->cores);
20}
21
22static void devinfo_table_order(struct kunit *test)
23{
24	int idx;
25
26	for (idx = 0; idx < iwl_dev_info_table_size; idx++) {
27		const struct iwl_dev_info *di = &iwl_dev_info_table[idx];
28		const struct iwl_dev_info *ret;
29
30		ret = iwl_pci_find_dev_info(di->device, di->subdevice,
31					    di->mac_type, di->mac_step,
32					    di->rf_type, di->cdb,
33					    di->jacket, di->rf_id,
34					    di->no_160, di->cores, di->rf_step);
35		if (ret != di) {
36			iwl_pci_print_dev_info("searched: ", di);
37			iwl_pci_print_dev_info("found:    ", ret);
38			KUNIT_FAIL(test,
39				   "unusable entry at index %d (found index %d instead)\n",
40				   idx, (int)(ret - iwl_dev_info_table));
41		}
42	}
43}
44
45static void devinfo_pci_ids(struct kunit *test)
46{
47	struct pci_dev *dev;
48
49	dev = kunit_kmalloc(test, sizeof(*dev), GFP_KERNEL);
50	KUNIT_ASSERT_NOT_NULL(test, dev);
51
52	for (int i = 0; iwl_hw_card_ids[i].vendor; i++) {
53		const struct pci_device_id *s, *t;
54
55		s = &iwl_hw_card_ids[i];
56		dev->vendor = s->vendor;
57		dev->device = s->device;
58		dev->subsystem_vendor = s->subvendor;
59		dev->subsystem_device = s->subdevice;
60		dev->class = s->class;
61
62		t = pci_match_id(iwl_hw_card_ids, dev);
63		KUNIT_EXPECT_PTR_EQ(test, t, s);
64	}
65}
66
67static struct kunit_case devinfo_test_cases[] = {
68	KUNIT_CASE(devinfo_table_order),
69	KUNIT_CASE(devinfo_pci_ids),
70	{}
71};
72
73static struct kunit_suite iwlwifi_devinfo = {
74	.name = "iwlwifi-devinfo",
75	.test_cases = devinfo_test_cases,
76};
77
78kunit_test_suite(iwlwifi_devinfo);