]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
wifi: mac80211: Add KUnit test for ieee80211_mesh_prep_size_ok
authorMasashi Honma <masashi.honma@gmail.com>
Fri, 29 May 2026 23:09:50 +0000 (08:09 +0900)
committerJohannes Berg <johannes.berg@intel.com>
Wed, 3 Jun 2026 12:11:50 +0000 (14:11 +0200)
Add a kunit test for ieee80211_mesh_prep_size_ok(),
checking various success and failure cases.

Signed-off-by: Masashi Honma <masashi.honma@gmail.com>
Link: https://patch.msgid.link/20260529230952.124754-8-masashi.honma@gmail.com
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
net/mac80211/tests/elems.c

index 576ba746a5268a72aea0b60be3eebd1ef3494efe..b96424d5d0259d233d6ed7e1068a82a50166e081 100644 (file)
@@ -97,6 +97,46 @@ static const struct mesh_preq_parse_test_case {
 
 KUNIT_ARRAY_PARAM_DESC(mesh_preq_parse, mesh_preq_parse_cases, desc);
 
+static const struct mesh_prep_parse_test_case {
+       const char *desc;
+       u8 len;
+       bool ae_enabled;
+       bool result;
+} mesh_prep_parse_cases[] = {
+       {
+               .desc = "shorter than header",
+               .len = 12,
+               .ae_enabled = false,
+               .result = false,
+       },
+       {
+               .desc = "non AE short",
+               .len = 30,
+               .ae_enabled = false,
+               .result = false,
+       },
+       {
+               .desc = "non AE",
+               .len = 31,
+               .ae_enabled = false,
+               .result = true,
+       },
+       {
+               .desc = "AE short",
+               .len = 36,
+               .ae_enabled = true,
+               .result = false,
+       },
+       {
+               .desc = "AE",
+               .len = 37,
+               .ae_enabled = true,
+               .result = true,
+       },
+};
+
+KUNIT_ARRAY_PARAM_DESC(mesh_prep_parse, mesh_prep_parse_cases, desc);
+
 static void mle_defrag(struct kunit *test)
 {
        struct ieee80211_elems_parse_params parse_params = {
@@ -195,9 +235,22 @@ static void mesh_preq_parse(struct kunit *test)
                        params->result);
 }
 
+static void mesh_prep_parse(struct kunit *test)
+{
+       const struct mesh_prep_parse_test_case *params = test->param_value;
+       u8 data[64] = {};
+       struct ieee80211_mesh_hwmp_prep_top *top = (void *)data;
+       top->flags = params->ae_enabled ? AE_F : 0;
+
+       KUNIT_EXPECT_EQ(test,
+                       ieee80211_mesh_prep_size_ok(data, params->len),
+                       params->result);
+}
+
 static struct kunit_case element_parsing_test_cases[] = {
        KUNIT_CASE(mle_defrag),
        KUNIT_CASE_PARAM(mesh_preq_parse, mesh_preq_parse_gen_params),
+       KUNIT_CASE_PARAM(mesh_prep_parse, mesh_prep_parse_gen_params),
        {}
 };