Merge tag 'clk-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux.git] / drivers / net / wireless / intel / iwlwifi / mvm / tests / scan.c
blob7a3275199ace2e4c51dbf22c613ba622b7c768c0
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * KUnit tests for channel helper functions
5 * Copyright (C) 2024 Intel Corporation
6 */
7 #include <net/mac80211.h>
8 #include "../mvm.h"
9 #include <kunit/test.h>
11 MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
13 static const struct acs_average_db_case {
14 const char *desc;
15 u8 neg_dbm[22];
16 s8 result;
17 } acs_average_db_cases[] = {
19 .desc = "Smallest possible value, all filled",
20 .neg_dbm = {
21 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
22 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
23 128, 128
25 .result = -128,
28 .desc = "Biggest possible value, all filled",
29 .neg_dbm = {
30 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
31 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
32 0, 0,
34 .result = 0,
37 .desc = "Smallest possible value, partial filled",
38 .neg_dbm = {
39 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
40 0xff, 0xff, 0xff, 0xff, 0xff,
41 0xff, 0xff, 0xff, 0xff, 0xff,
42 0xff, 0xff,
44 .result = -128,
47 .desc = "Biggest possible value, partial filled",
48 .neg_dbm = {
49 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
50 0xff, 0xff, 0xff, 0xff, 0xff,
51 0xff, 0xff, 0xff, 0xff, 0xff,
52 0xff, 0xff,
54 .result = 0,
57 .desc = "Adding -80dBm to -75dBm until it is still rounded to -79dBm",
58 .neg_dbm = {
59 75, 80, 80, 80, 80, 80, 80, 80, 80, 80,
60 80, 80, 80, 80, 80, 80, 80, 0xff, 0xff, 0xff,
61 0xff, 0xff,
63 .result = -79,
66 .desc = "Adding -80dBm to -75dBm until it is just rounded to -80dBm",
67 .neg_dbm = {
68 75, 80, 80, 80, 80, 80, 80, 80, 80, 80,
69 80, 80, 80, 80, 80, 80, 80, 80, 0xff, 0xff,
70 0xff, 0xff,
72 .result = -80,
76 KUNIT_ARRAY_PARAM_DESC(acs_average_db, acs_average_db_cases, desc)
78 static void test_acs_average_db(struct kunit *test)
80 const struct acs_average_db_case *params = test->param_value;
81 struct iwl_umac_scan_channel_survey_notif notif;
82 int i;
84 /* Test the values in the given order */
85 for (i = 0; i < ARRAY_SIZE(params->neg_dbm); i++)
86 notif.noise[i] = params->neg_dbm[i];
87 KUNIT_ASSERT_EQ(test,
88 iwl_mvm_average_dbm_values(&notif),
89 params->result);
91 /* Test in reverse order */
92 for (i = 0; i < ARRAY_SIZE(params->neg_dbm); i++)
93 notif.noise[ARRAY_SIZE(params->neg_dbm) - i - 1] =
94 params->neg_dbm[i];
95 KUNIT_ASSERT_EQ(test,
96 iwl_mvm_average_dbm_values(&notif),
97 params->result);
100 static struct kunit_case acs_average_db_case[] = {
101 KUNIT_CASE_PARAM(test_acs_average_db, acs_average_db_gen_params),
105 static struct kunit_suite acs_average_db = {
106 .name = "iwlmvm-acs-average-db",
107 .test_cases = acs_average_db_case,
110 kunit_test_suite(acs_average_db);