Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / net / wireless / intel / iwlwifi / tests / devinfo.c
blob7361b6d0cdb8e5541a6f055a485a4026dfd79c12
1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /*
3 * KUnit tests for the iwlwifi device info table
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"
12 MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING);
14 static void iwl_pci_print_dev_info(const char *pfx, const struct iwl_dev_info *di)
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);
22 static void devinfo_table_order(struct kunit *test)
24 int idx;
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;
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));
45 static void devinfo_pci_ids(struct kunit *test)
47 struct pci_dev *dev;
49 dev = kunit_kmalloc(test, sizeof(*dev), GFP_KERNEL);
50 KUNIT_ASSERT_NOT_NULL(test, dev);
52 for (int i = 0; iwl_hw_card_ids[i].vendor; i++) {
53 const struct pci_device_id *s, *t;
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;
62 t = pci_match_id(iwl_hw_card_ids, dev);
63 KUNIT_EXPECT_PTR_EQ(test, t, s);
67 static struct kunit_case devinfo_test_cases[] = {
68 KUNIT_CASE(devinfo_table_order),
69 KUNIT_CASE(devinfo_pci_ids),
73 static struct kunit_suite iwlwifi_devinfo = {
74 .name = "iwlwifi-devinfo",
75 .test_cases = devinfo_test_cases,
78 kunit_test_suite(iwlwifi_devinfo);