1 // SPDX-License-Identifier: GPL-2.0-only
3 * KUnit tests for TPE element handling
5 * Copyright (C) 2024 Intel Corporation
7 #include <kunit/test.h>
8 #include "../ieee80211_i.h"
10 MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
12 static struct ieee80211_channel chan6g_1
= {
13 .band
= NL80211_BAND_6GHZ
,
17 static struct ieee80211_channel chan6g_33
= {
18 .band
= NL80211_BAND_6GHZ
,
22 static struct ieee80211_channel chan6g_61
= {
23 .band
= NL80211_BAND_6GHZ
,
27 static const struct subchan_test_case
{
29 struct cfg80211_chan_def c
;
32 } subchan_offset_cases
[] = {
34 .desc
= "identical 20 MHz",
35 .c
.width
= NL80211_CHAN_WIDTH_20
,
37 .c
.center_freq1
= 5955,
42 .desc
= "identical 40 MHz",
43 .c
.width
= NL80211_CHAN_WIDTH_40
,
45 .c
.center_freq1
= 5965,
50 .desc
= "identical 80+80 MHz",
51 /* not really is valid? doesn't matter for the test */
52 .c
.width
= NL80211_CHAN_WIDTH_80P80
,
54 .c
.center_freq1
= 5985,
55 .c
.center_freq2
= 6225,
60 .desc
= "identical 320 MHz",
61 .c
.width
= NL80211_CHAN_WIDTH_320
,
63 .c
.center_freq1
= 6105,
68 .desc
= "lower 160 MHz of 320 MHz",
69 .c
.width
= NL80211_CHAN_WIDTH_320
,
71 .c
.center_freq1
= 6105,
76 .desc
= "upper 160 MHz of 320 MHz",
77 .c
.width
= NL80211_CHAN_WIDTH_320
,
79 .c
.center_freq1
= 6105,
84 .desc
= "upper 160 MHz of 320 MHz, go to 40",
85 .c
.width
= NL80211_CHAN_WIDTH_320
,
87 .c
.center_freq1
= 6105,
92 .desc
= "secondary 80 above primary in 80+80 MHz",
93 /* not really is valid? doesn't matter for the test */
94 .c
.width
= NL80211_CHAN_WIDTH_80P80
,
96 .c
.center_freq1
= 5985,
97 .c
.center_freq2
= 6225,
102 .desc
= "secondary 80 below primary in 80+80 MHz",
103 /* not really is valid? doesn't matter for the test */
104 .c
.width
= NL80211_CHAN_WIDTH_80P80
,
105 .c
.chan
= &chan6g_61
,
106 .c
.center_freq1
= 6225,
107 .c
.center_freq2
= 5985,
112 .desc
= "secondary 80 below primary in 80+80 MHz, go to 20",
113 /* not really is valid? doesn't matter for the test */
114 .c
.width
= NL80211_CHAN_WIDTH_80P80
,
115 .c
.chan
= &chan6g_61
,
116 .c
.center_freq1
= 6225,
117 .c
.center_freq2
= 5985,
123 KUNIT_ARRAY_PARAM_DESC(subchan_offset
, subchan_offset_cases
, desc
);
125 static void subchan_offset(struct kunit
*test
)
127 const struct subchan_test_case
*params
= test
->param_value
;
130 KUNIT_ASSERT_EQ(test
, cfg80211_chandef_valid(¶ms
->c
), true);
132 offset
= ieee80211_calc_chandef_subchan_offset(¶ms
->c
, params
->n
);
134 KUNIT_EXPECT_EQ(test
, params
->expect
, offset
);
137 static const struct psd_reorder_test_case
{
139 struct cfg80211_chan_def ap
, used
;
140 struct ieee80211_parsed_tpe_psd psd
, out
;
141 } psd_reorder_cases
[] = {
143 .desc
= "no changes, 320 MHz",
145 .ap
.width
= NL80211_CHAN_WIDTH_320
,
146 .ap
.chan
= &chan6g_1
,
147 .ap
.center_freq1
= 6105,
149 .used
.width
= NL80211_CHAN_WIDTH_320
,
150 .used
.chan
= &chan6g_1
,
151 .used
.center_freq1
= 6105,
156 .psd
.power
= { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
161 .out
.power
= { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
164 .desc
= "no changes, 320 MHz, 160 MHz used, n=0",
166 .ap
.width
= NL80211_CHAN_WIDTH_320
,
167 .ap
.chan
= &chan6g_1
,
168 .ap
.center_freq1
= 6105,
170 .used
.width
= NL80211_CHAN_WIDTH_160
,
171 .used
.chan
= &chan6g_1
,
172 .used
.center_freq1
= 6025,
177 .psd
.power
= { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, },
182 .out
.power
= { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, },
185 .desc
= "320 MHz, HE is 80, used 160, all lower",
187 .ap
.width
= NL80211_CHAN_WIDTH_320
,
188 .ap
.chan
= &chan6g_1
,
189 .ap
.center_freq1
= 6105,
191 .used
.width
= NL80211_CHAN_WIDTH_160
,
192 .used
.chan
= &chan6g_1
,
193 .used
.center_freq1
= 6025,
198 .psd
.power
= { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
203 .out
.power
= { 0, 1, 2, 3, 4, 5, 6, 7, 127, 127, 127, 127, 127, 127, 127, 127},
206 .desc
= "320 MHz, HE is 80, used 160, all upper",
208 * EHT: | | | | | | | | | | | | | | | | |
210 * used: | | | | | | | | |
213 .ap
.width
= NL80211_CHAN_WIDTH_320
,
214 .ap
.chan
= &chan6g_61
,
215 .ap
.center_freq1
= 6105,
217 .used
.width
= NL80211_CHAN_WIDTH_160
,
218 .used
.chan
= &chan6g_61
,
219 .used
.center_freq1
= 6185,
224 .psd
.power
= { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
229 .out
.power
= { 12, 13, 14, 15, 0, 1, 2, 3, 127, 127, 127, 127, 127, 127, 127, 127},
232 .desc
= "320 MHz, HE is 80, used 160, split",
234 * EHT: | | | | | | | | | | | | | | | | |
236 * used: | | | | | | | | |
239 .ap
.width
= NL80211_CHAN_WIDTH_320
,
240 .ap
.chan
= &chan6g_33
,
241 .ap
.center_freq1
= 6105,
243 .used
.width
= NL80211_CHAN_WIDTH_160
,
244 .used
.chan
= &chan6g_33
,
245 .used
.center_freq1
= 6185,
250 .psd
.power
= { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
255 .out
.power
= { 0, 1, 2, 3, 12, 13, 14, 15, 127, 127, 127, 127, 127, 127, 127, 127},
259 KUNIT_ARRAY_PARAM_DESC(psd_reorder
, psd_reorder_cases
, desc
);
261 static void psd_reorder(struct kunit
*test
)
263 const struct psd_reorder_test_case
*params
= test
->param_value
;
264 struct ieee80211_parsed_tpe_psd tmp
= params
->psd
;
266 KUNIT_ASSERT_EQ(test
, cfg80211_chandef_valid(¶ms
->ap
), true);
267 KUNIT_ASSERT_EQ(test
, cfg80211_chandef_valid(¶ms
->used
), true);
269 ieee80211_rearrange_tpe_psd(&tmp
, ¶ms
->ap
, ¶ms
->used
);
270 KUNIT_EXPECT_MEMEQ(test
, &tmp
, ¶ms
->out
, sizeof(tmp
));
273 static struct kunit_case tpe_test_cases
[] = {
274 KUNIT_CASE_PARAM(subchan_offset
, subchan_offset_gen_params
),
275 KUNIT_CASE_PARAM(psd_reorder
, psd_reorder_gen_params
),
279 static struct kunit_suite tpe
= {
280 .name
= "mac80211-tpe",
281 .test_cases
= tpe_test_cases
,
284 kunit_test_suite(tpe
);