| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
/* |
| 3 |
* KUnit tests for utilities |
| 4 |
* |
| 5 |
* Copyright (C) 2024-2025 Intel Corporation |
| 6 |
*/ |
| 7 |
#include "../iwl-utils.h" |
| 8 |
#include <kunit/test.h> |
| 9 |
|
| 10 |
MODULE_IMPORT_NS("IWLWIFI"); |
| 11 |
|
| 12 |
static const struct average_neg_db_case { |
| 13 |
const char *desc; |
| 14 |
u8 neg_dbm[22]; |
| 15 |
s8 result; |
| 16 |
} average_neg_db_cases[] = { |
| 17 |
{ |
| 18 |
.desc = "Smallest possible value, all filled", |
| 19 |
.neg_dbm = { |
| 20 |
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 21 |
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 22 |
128, 128 |
| 23 |
}, |
| 24 |
.result = -128, |
| 25 |
}, |
| 26 |
{ |
| 27 |
.desc = "Biggest possible value, all filled", |
| 28 |
.neg_dbm = { |
| 29 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 30 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 31 |
0, 0, |
| 32 |
}, |
| 33 |
.result = 0, |
| 34 |
}, |
| 35 |
{ |
| 36 |
.desc = "Smallest possible value, partial filled", |
| 37 |
.neg_dbm = { |
| 38 |
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, |
| 39 |
0xff, 0xff, 0xff, 0xff, 0xff, |
| 40 |
0xff, 0xff, 0xff, 0xff, 0xff, |
| 41 |
0xff, 0xff, |
| 42 |
}, |
| 43 |
.result = -128, |
| 44 |
}, |
| 45 |
{ |
| 46 |
.desc = "Biggest possible value, partial filled", |
| 47 |
.neg_dbm = { |
| 48 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 49 |
0xff, 0xff, 0xff, 0xff, 0xff, |
| 50 |
0xff, 0xff, 0xff, 0xff, 0xff, |
| 51 |
0xff, 0xff, |
| 52 |
}, |
| 53 |
.result = 0, |
| 54 |
}, |
| 55 |
{ |
| 56 |
.desc = "Adding -80dBm to -75dBm until it is still rounded to -79dBm", |
| 57 |
.neg_dbm = { |
| 58 |
75, 80, 80, 80, 80, 80, 80, 80, 80, 80, |
| 59 |
80, 80, 80, 80, 80, 80, 80, 0xff, 0xff, 0xff, |
| 60 |
0xff, 0xff, |
| 61 |
}, |
| 62 |
.result = -79, |
| 63 |
}, |
| 64 |
{ |
| 65 |
.desc = "Adding -80dBm to -75dBm until it is just rounded to -80dBm", |
| 66 |
.neg_dbm = { |
| 67 |
75, 80, 80, 80, 80, 80, 80, 80, 80, 80, |
| 68 |
80, 80, 80, 80, 80, 80, 80, 80, 0xff, 0xff, |
| 69 |
0xff, 0xff, |
| 70 |
}, |
| 71 |
.result = -80, |
| 72 |
}, |
| 73 |
}; |
| 74 |
|
| 75 |
KUNIT_ARRAY_PARAM_DESC(average_neg_db, average_neg_db_cases, desc) |
| 76 |
|
| 77 |
static void test_average_neg_db(struct kunit *test) |
| 78 |
{ |
| 79 |
const struct average_neg_db_case *params = test->param_value; |
| 80 |
u8 reversed[ARRAY_SIZE(params->neg_dbm)]; |
| 81 |
int i; |
| 82 |
|
| 83 |
/* Test the values in the given order */ |
| 84 |
KUNIT_ASSERT_EQ(test, |
| 85 |
iwl_average_neg_dbm(params->neg_dbm, |
| 86 |
ARRAY_SIZE(params->neg_dbm)), |
| 87 |
params->result); |
| 88 |
|
| 89 |
/* Test in reverse order */ |
| 90 |
for (i = 0; i < ARRAY_SIZE(params->neg_dbm); i++) |
| 91 |
reversed[ARRAY_SIZE(params->neg_dbm) - i - 1] = |
| 92 |
params->neg_dbm[i]; |
| 93 |
KUNIT_ASSERT_EQ(test, |
| 94 |
iwl_average_neg_dbm(reversed, |
| 95 |
ARRAY_SIZE(params->neg_dbm)), |
| 96 |
params->result); |
| 97 |
} |
| 98 |
|
| 99 |
static struct kunit_case average_db_case[] = { |
| 100 |
KUNIT_CASE_PARAM(test_average_neg_db, average_neg_db_gen_params), |
| 101 |
{} |
| 102 |
}; |
| 103 |
|
| 104 |
static struct kunit_suite average_db = { |
| 105 |
.name = "iwl-average-db", |
| 106 |
.test_cases = average_db_case, |
| 107 |
}; |
| 108 |
|
| 109 |
kunit_test_suite(average_db); |