wifi: iwlwifi: mvm: add command order checks to kunit
authorJohannes Berg <johannes.berg@intel.com>
Fri, 2 May 2025 12:56:30 +0000 (15:56 +0300)
committerMiri Korenblit <miriam.rachel.korenblit@intel.com>
Wed, 7 May 2025 03:07:11 +0000 (06:07 +0300)
We can test this with kunit instead of having the runtime
checks, add a test here to remove the runtime check next.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Reviewed-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
Signed-off-by: Miri Korenblit <miriam.rachel.korenblit@intel.com>
Link: https://patch.msgid.link/20250502155404.581b60b0833f.I624fb3efc3fa0b155a5da69d7efc39207f133331@changeid
drivers/net/wireless/intel/iwlwifi/mvm/mvm.h
drivers/net/wireless/intel/iwlwifi/mvm/ops.c
drivers/net/wireless/intel/iwlwifi/mvm/tests/Makefile
drivers/net/wireless/intel/iwlwifi/mvm/tests/hcmd.c [new file with mode: 0644]

index 4c03fdae43e3c1bfcff03d8d0a6c158fd3006c67..fbcbef13015df505e6c341e18c4c8d84328b0a53 100644 (file)
@@ -2129,6 +2129,10 @@ bool iwl_mvm_mld_valid_link_pair(struct ieee80211_vif *vif,
                                 const struct iwl_mvm_link_sel_data *b);
 
 s8 iwl_mvm_average_dbm_values(const struct iwl_umac_scan_channel_survey_notif *notif);
+
+
+extern const struct iwl_hcmd_arr iwl_mvm_groups[];
+extern const unsigned int iwl_mvm_groups_size;
 #endif
 
 /* AP and IBSS */
index 14932700c6f9e95b2d8f91c734127b004f231b2d..5c7c1d53a28d7db71071d8470a47137284f1795e 100644 (file)
@@ -777,7 +777,8 @@ static const struct iwl_hcmd_names iwl_mvm_bt_coex_names[] = {
        HCMD_NAME(PROFILE_NOTIF),
 };
 
-static const struct iwl_hcmd_arr iwl_mvm_groups[] = {
+VISIBLE_IF_IWLWIFI_KUNIT
+const struct iwl_hcmd_arr iwl_mvm_groups[] = {
        [LEGACY_GROUP] = HCMD_ARR(iwl_mvm_legacy_names),
        [LONG_GROUP] = HCMD_ARR(iwl_mvm_legacy_names),
        [SYSTEM_GROUP] = HCMD_ARR(iwl_mvm_system_names),
@@ -793,6 +794,11 @@ static const struct iwl_hcmd_arr iwl_mvm_groups[] = {
        [DEBUG_GROUP] = HCMD_ARR(iwl_mvm_debug_names),
        [STATISTICS_GROUP] = HCMD_ARR(iwl_mvm_statistics_names),
 };
+EXPORT_SYMBOL_IF_IWLWIFI_KUNIT(iwl_mvm_groups);
+#if IS_ENABLED(CONFIG_IWLWIFI_KUNIT_TESTS)
+const unsigned int iwl_mvm_groups_size = ARRAY_SIZE(iwl_mvm_groups);
+EXPORT_SYMBOL_IF_IWLWIFI_KUNIT(iwl_mvm_groups_size);
+#endif
 
 /* this forward declaration can avoid to export the function */
 static void iwl_mvm_async_handlers_wk(struct work_struct *wk);
index 6bd56a28cffde9bacccef675051f338120ca2b60..895d53f223e91f46ecc20c1f213941708301a2b6 100644 (file)
@@ -1,3 +1,3 @@
-iwlmvm-tests-y += module.o links.o scan.o
+iwlmvm-tests-y += module.o links.o scan.o hcmd.o
 
 obj-$(CONFIG_IWLWIFI_KUNIT_TESTS) += iwlmvm-tests.o
diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/tests/hcmd.c b/drivers/net/wireless/intel/iwlwifi/mvm/tests/hcmd.c
new file mode 100644 (file)
index 0000000..1fee032
--- /dev/null
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
+/*
+ * KUnit tests for channel helper functions
+ *
+ * Copyright (C) 2025 Intel Corporation
+ */
+#include <kunit/test.h>
+
+#include <iwl-trans.h>
+#include "../mvm.h"
+
+MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
+
+static void test_hcmd_names_sorted(struct kunit *test)
+{
+       for (int i = 0; i < iwl_mvm_groups_size; i++) {
+               const struct iwl_hcmd_arr *arr = &iwl_mvm_groups[i];
+
+               if (!arr->arr)
+                       continue;
+
+               for (int j = 0; j < arr->size - 1; j++)
+                       KUNIT_EXPECT_LE(test, arr->arr[j].cmd_id,
+                                       arr->arr[j + 1].cmd_id);
+       }
+}
+
+static struct kunit_case hcmd_names_cases[] = {
+       KUNIT_CASE(test_hcmd_names_sorted),
+       {},
+};
+
+static struct kunit_suite hcmd_names = {
+       .name = "iwlmvm-hcmd-names",
+       .test_cases = hcmd_names_cases,
+};
+
+kunit_test_suite(hcmd_names);