From: April John Add tests for iwl_mld_he_get_ppe_val() covering both the single-byte extraction path and the cross-byte path where a 3-bit value spans a byte boundary. Signed-off-by: April John --- drivers/net/wireless/intel/iwlwifi/mld/sta.c | 3 +- drivers/net/wireless/intel/iwlwifi/mld/sta.h | 4 + .../wireless/intel/iwlwifi/mld/tests/Makefile | 2 +- .../wireless/intel/iwlwifi/mld/tests/sta.c | 86 +++++++++++++++++++ 4 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 drivers/net/wireless/intel/iwlwifi/mld/tests/sta.c diff --git a/drivers/net/wireless/intel/iwlwifi/mld/sta.c b/drivers/net/wireless/intel/iwlwifi/mld/sta.c index 7957ac11b0cd..fd0cee9a92b5 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/sta.c +++ b/drivers/net/wireless/intel/iwlwifi/mld/sta.c @@ -121,7 +121,7 @@ static u8 iwl_mld_get_uapsd_acs(struct ieee80211_sta *sta) return uapsd_acs | uapsd_acs << 4; } -static u8 iwl_mld_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit) +VISIBLE_IF_IWLWIFI_KUNIT u8 iwl_mld_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit) { u8 byte_num = ppe_pos_bit / 8; u8 bit_num = ppe_pos_bit % 8; @@ -146,6 +146,7 @@ static u8 iwl_mld_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit) return res; } +EXPORT_SYMBOL_IF_IWLWIFI_KUNIT(iwl_mld_he_get_ppe_val); static void iwl_mld_parse_ppe(struct iwl_mld *mld, struct iwl_he_pkt_ext_v2 *pkt_ext, u8 nss, diff --git a/drivers/net/wireless/intel/iwlwifi/mld/sta.h b/drivers/net/wireless/intel/iwlwifi/mld/sta.h index 98d693235c66..8659bb7bf6cf 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/sta.h +++ b/drivers/net/wireless/intel/iwlwifi/mld/sta.h @@ -300,4 +300,8 @@ void iwl_mld_remove_nan_mgmt_sta(struct iwl_mld *mld, void iwl_mld_remove_nan_mcast_data_sta(struct iwl_mld *mld, struct iwl_mld_int_sta *sta); +#if IS_ENABLED(CONFIG_IWLWIFI_KUNIT_TESTS) +u8 iwl_mld_he_get_ppe_val(u8 *ppe, u8 ppe_pos_bit); +#endif + #endif /* __iwl_mld_sta_h__ */ diff --git a/drivers/net/wireless/intel/iwlwifi/mld/tests/Makefile b/drivers/net/wireless/intel/iwlwifi/mld/tests/Makefile index 2af1fb838520..3201dce9a5b0 100644 --- a/drivers/net/wireless/intel/iwlwifi/mld/tests/Makefile +++ b/drivers/net/wireless/intel/iwlwifi/mld/tests/Makefile @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause iwlmld-tests-y += module.o hcmd.o utils.o link.o rx.o agg.o link-selection.o iwlmld-tests-y += chan_load_thresh.o -iwlmld-tests-y += tlc.o +iwlmld-tests-y += tlc.o sta.o ccflags-y += -I$(src)/../ obj-$(CONFIG_IWLWIFI_KUNIT_TESTS) += iwlmld-tests.o diff --git a/drivers/net/wireless/intel/iwlwifi/mld/tests/sta.c b/drivers/net/wireless/intel/iwlwifi/mld/tests/sta.c new file mode 100644 index 000000000000..675408661af2 --- /dev/null +++ b/drivers/net/wireless/intel/iwlwifi/mld/tests/sta.c @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause +/* + * KUnit tests for STA capability helper functions + * + * Copyright (C) 2026 Intel Corporation + */ +#include + +#include "sta.h" + +MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING"); + +struct ppe_val_case { + const char *desc; + u8 ppe[2]; + u8 ppe_pos_bit; + u8 expected_val; +}; + +static const struct ppe_val_case ppe_val_cases[] = { + { + .desc = "Aligned in byte 0", + .ppe = { 0b111, 0 }, + .ppe_pos_bit = 0, + .expected_val = 7, + }, + { + .desc = "Unaligned in byte 0", + .ppe = { 0b00111000, 0 }, + .ppe_pos_bit = 3, + .expected_val = 7, + }, + { + .desc = "Highest non-crossing position", + .ppe = { 0b11100000, 0 }, + .ppe_pos_bit = 5, + .expected_val = 7, + }, + { + .desc = "Value in byte 1", + .ppe = { 0, 0b00000011 }, + .ppe_pos_bit = 8, + .expected_val = 3, + }, + { + .desc = "Cross-byte at bit 6", + .ppe = { 0b01000000, 0b00000001 }, + .ppe_pos_bit = 6, + .expected_val = 5, + }, + { + .desc = "Cross-byte at bit 7", + .ppe = { 0b10000000, 0b00000011 }, + .ppe_pos_bit = 7, + .expected_val = 7, + }, + { + .desc = "Cross-byte all zeros", + .ppe = { 0, 0 }, + .ppe_pos_bit = 6, + .expected_val = 0, + }, +}; + +KUNIT_ARRAY_PARAM_DESC(ppe_val_cases, ppe_val_cases, desc); + +static void test_he_get_ppe_val(struct kunit *test) +{ + const struct ppe_val_case *tc = test->param_value; + u8 ppe[] = { tc->ppe[0], tc->ppe[1] }; + + KUNIT_EXPECT_EQ(test, tc->expected_val, + iwl_mld_he_get_ppe_val(ppe, tc->ppe_pos_bit)); +} + +static struct kunit_case ppe_val_test_cases[] = { + KUNIT_CASE_PARAM(test_he_get_ppe_val, ppe_val_cases_gen_params), + {}, +}; + +static struct kunit_suite ppe_val_tests = { + .name = "iwl_mld_ppe_val_tests", + .test_cases = ppe_val_test_cases, +}; + +kunit_test_suite(ppe_val_tests); -- 2.53.0