diff options
author | Benjamin Berg <benjamin.berg@intel.com> | 2025-06-09 21:21:18 +0300 |
---|---|---|
committer | Miri Korenblit <miriam.rachel.korenblit@intel.com> | 2025-06-25 10:57:32 +0300 |
commit | 40840afa53bed05b990b201d749dfee3bd6e7e42 (patch) | |
tree | 249c785370c1d632209498d56abe677fd00dd0bd /drivers/net/wireless/intel/iwlwifi/tests/utils.c | |
parent | 8ecc3928f26a99c4e46d6dfb78c1d229ab8c9578 (diff) |
wifi: iwlwifi: move dBm averaging function into utils
The function really is just a simple math helper. Move it into
iwl-utils.c so that it can also be used by iwlmld.
Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
Signed-off-by: Miri Korenblit <miriam.rachel.korenblit@intel.com>
Link: https://patch.msgid.link/20250609211928.8cc965af6990.I09bb2137863e888efe756c92d8eb0271ec95456c@changeid
Diffstat (limited to 'drivers/net/wireless/intel/iwlwifi/tests/utils.c')
-rw-r--r-- | drivers/net/wireless/intel/iwlwifi/tests/utils.c | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/drivers/net/wireless/intel/iwlwifi/tests/utils.c b/drivers/net/wireless/intel/iwlwifi/tests/utils.c new file mode 100644 index 000000000000..df2c3a891e7e --- /dev/null +++ b/drivers/net/wireless/intel/iwlwifi/tests/utils.c @@ -0,0 +1,109 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * KUnit tests for utilities + * + * Copyright (C) 2024-2025 Intel Corporation + */ +#include "../iwl-utils.h" +#include <kunit/test.h> + +MODULE_IMPORT_NS("IWLWIFI"); + +static const struct average_neg_db_case { + const char *desc; + u8 neg_dbm[22]; + s8 result; +} average_neg_db_cases[] = { + { + .desc = "Smallest possible value, all filled", + .neg_dbm = { + 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128 + }, + .result = -128, + }, + { + .desc = "Biggest possible value, all filled", + .neg_dbm = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, + }, + .result = 0, + }, + { + .desc = "Smallest possible value, partial filled", + .neg_dbm = { + 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, + 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, + }, + .result = -128, + }, + { + .desc = "Biggest possible value, partial filled", + .neg_dbm = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, + }, + .result = 0, + }, + { + .desc = "Adding -80dBm to -75dBm until it is still rounded to -79dBm", + .neg_dbm = { + 75, 80, 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 0xff, 0xff, 0xff, + 0xff, 0xff, + }, + .result = -79, + }, + { + .desc = "Adding -80dBm to -75dBm until it is just rounded to -80dBm", + .neg_dbm = { + 75, 80, 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, 0xff, 0xff, + 0xff, 0xff, + }, + .result = -80, + }, +}; + +KUNIT_ARRAY_PARAM_DESC(average_neg_db, average_neg_db_cases, desc) + +static void test_average_neg_db(struct kunit *test) +{ + const struct average_neg_db_case *params = test->param_value; + u8 reversed[ARRAY_SIZE(params->neg_dbm)]; + int i; + + /* Test the values in the given order */ + KUNIT_ASSERT_EQ(test, + iwl_average_neg_dbm(params->neg_dbm, + ARRAY_SIZE(params->neg_dbm)), + params->result); + + /* Test in reverse order */ + for (i = 0; i < ARRAY_SIZE(params->neg_dbm); i++) + reversed[ARRAY_SIZE(params->neg_dbm) - i - 1] = + params->neg_dbm[i]; + KUNIT_ASSERT_EQ(test, + iwl_average_neg_dbm(reversed, + ARRAY_SIZE(params->neg_dbm)), + params->result); +} + +static struct kunit_case average_db_case[] = { + KUNIT_CASE_PARAM(test_average_neg_db, average_neg_db_gen_params), + {} +}; + +static struct kunit_suite average_db = { + .name = "iwl-average-db", + .test_cases = average_db_case, +}; + +kunit_test_suite(average_db); |