1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /*
3 * KUnit tests for channel helper functions
4 *
5 * Copyright (C) 2024 Intel Corporation
6 */
7 #include <kunit/test.h>
8
9 #include <iwl-trans.h>
10 #include "mld.h"
11
12 MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
13
test_hcmd_names_sorted(struct kunit * test)14 static void test_hcmd_names_sorted(struct kunit *test)
15 {
16 int i;
17
18 for (i = 0; i < global_iwl_mld_goups_size; i++) {
19 const struct iwl_hcmd_arr *arr = &iwl_mld_groups[i];
20 int j;
21
22 if (!arr->arr)
23 continue;
24 for (j = 0; j < arr->size - 1; j++)
25 KUNIT_EXPECT_LE(test, arr->arr[j].cmd_id,
26 arr->arr[j + 1].cmd_id);
27 }
28 }
29
test_hcmd_names_for_rx(struct kunit * test)30 static void test_hcmd_names_for_rx(struct kunit *test)
31 {
32 static struct iwl_trans t = {
33 .command_groups = iwl_mld_groups,
34 };
35
36 t.command_groups_size = global_iwl_mld_goups_size;
37
38 for (unsigned int i = 0; i < iwl_mld_rx_handlers_num; i++) {
39 const struct iwl_rx_handler *rxh;
40 const char *name;
41
42 rxh = &iwl_mld_rx_handlers[i];
43
44 name = iwl_get_cmd_string(&t, rxh->cmd_id);
45 KUNIT_EXPECT_NOT_NULL(test, name);
46 KUNIT_EXPECT_NE_MSG(test, strcmp(name, "UNKNOWN"), 0,
47 "ID 0x%04x is UNKNOWN", rxh->cmd_id);
48 }
49 }
50
51 static struct kunit_case hcmd_names_cases[] = {
52 KUNIT_CASE(test_hcmd_names_sorted),
53 KUNIT_CASE(test_hcmd_names_for_rx),
54 {},
55 };
56
57 static struct kunit_suite hcmd_names = {
58 .name = "iwlmld-hcmd-names",
59 .test_cases = hcmd_names_cases,
60 };
61
62 kunit_test_suite(hcmd_names);
63