111 lines · c
1// SPDX-License-Identifier: GPL-2.0-only2/*3 * KUnit tests for channel helper functions4 *5 * Copyright (C) 2024 Intel Corporation6 */7#include <net/mac80211.h>8#include "../mvm.h"9#include <kunit/test.h>10 11MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING);12 13static const struct acs_average_db_case {14 const char *desc;15 u8 neg_dbm[22];16 s8 result;17} acs_average_db_cases[] = {18 {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, 12824 },25 .result = -128,26 },27 {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,33 },34 .result = 0,35 },36 {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,43 },44 .result = -128,45 },46 {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,53 },54 .result = 0,55 },56 {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,62 },63 .result = -79,64 },65 {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,71 },72 .result = -80,73 },74};75 76KUNIT_ARRAY_PARAM_DESC(acs_average_db, acs_average_db_cases, desc)77 78static void test_acs_average_db(struct kunit *test)79{80 const struct acs_average_db_case *params = test->param_value;81 struct iwl_umac_scan_channel_survey_notif notif;82 int i;83 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(¬if),89 params->result);90 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(¬if),97 params->result);98}99 100static struct kunit_case acs_average_db_case[] = {101 KUNIT_CASE_PARAM(test_acs_average_db, acs_average_db_gen_params),102 {}103};104 105static struct kunit_suite acs_average_db = {106 .name = "iwlmvm-acs-average-db",107 .test_cases = acs_average_db_case,108};109 110kunit_test_suite(acs_average_db);111