1 // SPDX-License-Identifier: GPL-2.0-only
3 * KUnit tests for channel helper functions
5 * Copyright (C) 2023-2024 Intel Corporation
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
,
17 static struct ieee80211_channel chan_6ghz_5
= {
18 .band
= NL80211_BAND_6GHZ
,
22 static struct ieee80211_channel chan_6ghz_105
= {
23 .band
= NL80211_BAND_6GHZ
,
27 static const struct chandef_compat_case
{
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 */
33 } chandef_compat_cases
[] = {
35 .desc
= "identical non-HT",
37 .width
= NL80211_CHAN_WIDTH_20_NOHT
,
44 .desc
= "identical 20 MHz",
46 .width
= NL80211_CHAN_WIDTH_20
,
53 .desc
= "identical 40 MHz",
55 .width
= NL80211_CHAN_WIDTH_40
,
57 .center_freq1
= 5955 + 10,
62 .desc
= "identical 80 MHz",
64 .width
= NL80211_CHAN_WIDTH_80
,
66 .center_freq1
= 5955 + 10 + 20,
71 .desc
= "identical 160 MHz",
73 .width
= NL80211_CHAN_WIDTH_160
,
75 .center_freq1
= 5955 + 10 + 20 + 40,
80 .desc
= "identical 320 MHz",
82 .width
= NL80211_CHAN_WIDTH_320
,
84 .center_freq1
= 5955 + 10 + 20 + 40 + 80,
89 .desc
= "20 MHz in 320 MHz\n",
91 .width
= NL80211_CHAN_WIDTH_20
,
96 .width
= NL80211_CHAN_WIDTH_320
,
98 .center_freq1
= 5955 + 10 + 20 + 40 + 80,
103 .desc
= "different 20 MHz",
105 .width
= NL80211_CHAN_WIDTH_20
,
106 .chan
= &chan_6ghz_1
,
107 .center_freq1
= 5955,
110 .width
= NL80211_CHAN_WIDTH_20
,
111 .chan
= &chan_6ghz_5
,
112 .center_freq1
= 5975,
116 .desc
= "different primary 320 MHz",
118 .width
= NL80211_CHAN_WIDTH_320
,
119 .chan
= &chan_6ghz_105
,
120 .center_freq1
= 6475 + 110,
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",
132 .width
= NL80211_CHAN_WIDTH_160
,
133 .chan
= &chan_6ghz_105
,
134 .center_freq1
= 6475 + 30,
137 .width
= NL80211_CHAN_WIDTH_320
,
138 .chan
= &chan_6ghz_105
,
139 .center_freq1
= 6475 - 50,
144 .desc
= "matching primary 160 MHz & punctured secondary 160 Mhz",
146 .width
= NL80211_CHAN_WIDTH_160
,
147 .chan
= &chan_6ghz_105
,
148 .center_freq1
= 6475 + 30,
151 .width
= NL80211_CHAN_WIDTH_320
,
152 .chan
= &chan_6ghz_105
,
153 .center_freq1
= 6475 - 50,
159 .desc
= "matching primary 160 MHz & punctured matching",
161 .width
= NL80211_CHAN_WIDTH_160
,
162 .chan
= &chan_6ghz_105
,
163 .center_freq1
= 6475 + 30,
167 .width
= NL80211_CHAN_WIDTH_320
,
168 .chan
= &chan_6ghz_105
,
169 .center_freq1
= 6475 - 50,
175 .desc
= "matching primary 160 MHz & punctured not matching",
177 .width
= NL80211_CHAN_WIDTH_160
,
178 .chan
= &chan_6ghz_105
,
179 .center_freq1
= 6475 + 30,
183 .width
= NL80211_CHAN_WIDTH_320
,
184 .chan
= &chan_6ghz_105
,
185 .center_freq1
= 6475 - 50,
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
)
203 KUNIT_EXPECT_EQ(test
, cfg80211_chandef_valid(&c1
), true);
204 KUNIT_EXPECT_EQ(test
, cfg80211_chandef_valid(¶ms
->c2
), true);
206 expect
= params
->compat
? ¶ms
->c2
: NULL
;
208 ret
= cfg80211_chandef_compatible(&c1
, ¶ms
->c2
);
209 KUNIT_EXPECT_PTR_EQ(test
, ret
, expect
);
211 if (!params
->c1
.chan
)
214 ret
= cfg80211_chandef_compatible(¶ms
->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
);