module: Convert symbol namespace to string literal
[linux.git] / net / wireless / tests / chan.c
blob7b97b731993ca72bcd4efed7cc6eeb407fcec6dd
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * KUnit tests for channel helper functions
5 * Copyright (C) 2023-2024 Intel Corporation
6 */
7 #include <net/cfg80211.h>
8 #include <kunit/test.h>
10 MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
12 static struct ieee80211_channel chan_6ghz_1 = {
13 .band = NL80211_BAND_6GHZ,
14 .center_freq = 5955,
17 static struct ieee80211_channel chan_6ghz_5 = {
18 .band = NL80211_BAND_6GHZ,
19 .center_freq = 5975,
22 static struct ieee80211_channel chan_6ghz_105 = {
23 .band = NL80211_BAND_6GHZ,
24 .center_freq = 6475,
27 static const struct chandef_compat_case {
28 const char *desc;
29 /* leave c1 empty for tests for identical */
30 struct cfg80211_chan_def c1, c2;
31 /* we test both ways around, so c2 should always be the compat one */
32 bool compat;
33 } chandef_compat_cases[] = {
35 .desc = "identical non-HT",
36 .c2 = {
37 .width = NL80211_CHAN_WIDTH_20_NOHT,
38 .chan = &chan_6ghz_1,
39 .center_freq1 = 5955,
41 .compat = true,
44 .desc = "identical 20 MHz",
45 .c2 = {
46 .width = NL80211_CHAN_WIDTH_20,
47 .chan = &chan_6ghz_1,
48 .center_freq1 = 5955,
50 .compat = true,
53 .desc = "identical 40 MHz",
54 .c2 = {
55 .width = NL80211_CHAN_WIDTH_40,
56 .chan = &chan_6ghz_1,
57 .center_freq1 = 5955 + 10,
59 .compat = true,
62 .desc = "identical 80 MHz",
63 .c2 = {
64 .width = NL80211_CHAN_WIDTH_80,
65 .chan = &chan_6ghz_1,
66 .center_freq1 = 5955 + 10 + 20,
68 .compat = true,
71 .desc = "identical 160 MHz",
72 .c2 = {
73 .width = NL80211_CHAN_WIDTH_160,
74 .chan = &chan_6ghz_1,
75 .center_freq1 = 5955 + 10 + 20 + 40,
77 .compat = true,
80 .desc = "identical 320 MHz",
81 .c2 = {
82 .width = NL80211_CHAN_WIDTH_320,
83 .chan = &chan_6ghz_1,
84 .center_freq1 = 5955 + 10 + 20 + 40 + 80,
86 .compat = true,
89 .desc = "20 MHz in 320 MHz\n",
90 .c1 = {
91 .width = NL80211_CHAN_WIDTH_20,
92 .chan = &chan_6ghz_1,
93 .center_freq1 = 5955,
95 .c2 = {
96 .width = NL80211_CHAN_WIDTH_320,
97 .chan = &chan_6ghz_1,
98 .center_freq1 = 5955 + 10 + 20 + 40 + 80,
100 .compat = true,
103 .desc = "different 20 MHz",
104 .c1 = {
105 .width = NL80211_CHAN_WIDTH_20,
106 .chan = &chan_6ghz_1,
107 .center_freq1 = 5955,
109 .c2 = {
110 .width = NL80211_CHAN_WIDTH_20,
111 .chan = &chan_6ghz_5,
112 .center_freq1 = 5975,
116 .desc = "different primary 320 MHz",
117 .c1 = {
118 .width = NL80211_CHAN_WIDTH_320,
119 .chan = &chan_6ghz_105,
120 .center_freq1 = 6475 + 110,
122 .c2 = {
123 .width = NL80211_CHAN_WIDTH_320,
124 .chan = &chan_6ghz_105,
125 .center_freq1 = 6475 - 50,
129 /* similar to previous test but one has lower BW */
130 .desc = "matching primary 160 MHz",
131 .c1 = {
132 .width = NL80211_CHAN_WIDTH_160,
133 .chan = &chan_6ghz_105,
134 .center_freq1 = 6475 + 30,
136 .c2 = {
137 .width = NL80211_CHAN_WIDTH_320,
138 .chan = &chan_6ghz_105,
139 .center_freq1 = 6475 - 50,
141 .compat = true,
144 .desc = "matching primary 160 MHz & punctured secondary 160 Mhz",
145 .c1 = {
146 .width = NL80211_CHAN_WIDTH_160,
147 .chan = &chan_6ghz_105,
148 .center_freq1 = 6475 + 30,
150 .c2 = {
151 .width = NL80211_CHAN_WIDTH_320,
152 .chan = &chan_6ghz_105,
153 .center_freq1 = 6475 - 50,
154 .punctured = 0xf,
156 .compat = true,
159 .desc = "matching primary 160 MHz & punctured matching",
160 .c1 = {
161 .width = NL80211_CHAN_WIDTH_160,
162 .chan = &chan_6ghz_105,
163 .center_freq1 = 6475 + 30,
164 .punctured = 0xc0,
166 .c2 = {
167 .width = NL80211_CHAN_WIDTH_320,
168 .chan = &chan_6ghz_105,
169 .center_freq1 = 6475 - 50,
170 .punctured = 0xc000,
172 .compat = true,
175 .desc = "matching primary 160 MHz & punctured not matching",
176 .c1 = {
177 .width = NL80211_CHAN_WIDTH_160,
178 .chan = &chan_6ghz_105,
179 .center_freq1 = 6475 + 30,
180 .punctured = 0x80,
182 .c2 = {
183 .width = NL80211_CHAN_WIDTH_320,
184 .chan = &chan_6ghz_105,
185 .center_freq1 = 6475 - 50,
186 .punctured = 0xc000,
191 KUNIT_ARRAY_PARAM_DESC(chandef_compat, chandef_compat_cases, desc)
193 static void test_chandef_compat(struct kunit *test)
195 const struct chandef_compat_case *params = test->param_value;
196 const struct cfg80211_chan_def *ret, *expect;
197 struct cfg80211_chan_def c1 = params->c1;
199 /* tests with identical ones */
200 if (!params->c1.chan)
201 c1 = params->c2;
203 KUNIT_EXPECT_EQ(test, cfg80211_chandef_valid(&c1), true);
204 KUNIT_EXPECT_EQ(test, cfg80211_chandef_valid(&params->c2), true);
206 expect = params->compat ? &params->c2 : NULL;
208 ret = cfg80211_chandef_compatible(&c1, &params->c2);
209 KUNIT_EXPECT_PTR_EQ(test, ret, expect);
211 if (!params->c1.chan)
212 expect = &c1;
214 ret = cfg80211_chandef_compatible(&params->c2, &c1);
215 KUNIT_EXPECT_PTR_EQ(test, ret, expect);
218 static struct kunit_case chandef_compat_test_cases[] = {
219 KUNIT_CASE_PARAM(test_chandef_compat, chandef_compat_gen_params),
223 static struct kunit_suite chandef_compat = {
224 .name = "cfg80211-chandef-compat",
225 .test_cases = chandef_compat_test_cases,
228 kunit_test_suite(chandef_compat);