Skip to contentSkip to conversation

Add some more cfg80211 and mac80211 kunit tests

PATCH In review [email protected] 4 participants 19 messages Dec 20, 2023 – Dec 23, 2023

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover Add some more cfg80211 and mac80211 kunit tests

From: Benjamin Berg <[email protected]>

This patchset adds a couple of helpers for kunit as well as tests for cfg80211 and mac80211 that use them.

Benjamin Berg (3):
kunit: add parameter generation macro using description from array
kunit: add a convenience allocation wrapper for SKBs
wifi: cfg80211: tests: add some scanning related tests

Johannes Berg (3):
wifi: mac80211: add kunit tests for public action handling
wifi: mac80211: kunit: generalize public action test
wifi: mac80211: kunit: extend MFP tests

 Documentation/dev-tools/kunit/usage.rst |  12 +-
 include/kunit/skbuff.h                  |  56 +++
 include/kunit/test.h                    |  19 +
 net/mac80211/ieee80211_i.h              |  10 +
 net/mac80211/rx.c                       |   4 +-
 net/mac80211/tests/Makefile             |   2 +-
 net/mac80211/tests/mfp.c                | 286 +++++++++++
 net/wireless/core.h                     |  13 +-
 net/wireless/scan.c                     |   9 +-
 net/wireless/tests/Makefile             |   2 +-
 net/wireless/tests/scan.c               | 625 ++++++++++++++++++++++++
 net/wireless/tests/util.c               |  56 +++
 net/wireless/tests/util.h               |  66 +++
 13 files changed, 1145 insertions(+), 15 deletions(-)
 create mode 100644 include/kunit/skbuff.h
 create mode 100644 net/mac80211/tests/mfp.c
 create mode 100644 net/wireless/tests/scan.c
 create mode 100644 net/wireless/tests/util.c
 create mode 100644 net/wireless/tests/util.h
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/6 kunit: add parameter generation macro using description from array

From: Benjamin Berg <[email protected]>

The existing KUNIT_ARRAY_PARAM macro requires a separate function to get the description. However, in a lot of cases the description can just be copied directly from the array. Add a second macro that avoids having to write a static function just for a single strscpy.

---
 Documentation/dev-tools/kunit/usage.rst | 12 ++++--------
 include/kunit/test.h                    | 19 +++++++++++++++++++
 2 files changed, 23 insertions(+), 8 deletions(-)
Documentation/dev-tools/kunit/usage.rst +4 -8
index c27e1646ecd9..b959e5befcbe 100644
@@ -566,13 +566,9 @@ By reusing the same ``cases`` array from above, we can write the test as a
 		},
 	};
 
-	// Need a helper function to generate a name for each test case.
-	static void case_to_desc(const struct sha1_test_case *t, char *desc)
-	{
-		strcpy(desc, t->str);
-	}
-	// Creates `sha1_gen_params()` to iterate over `cases`.
-	KUNIT_ARRAY_PARAM(sha1, cases, case_to_desc);
+	// Creates `sha1_gen_params()` to iterate over `cases` while using
+	// the struct member `str` for the case description.
+	KUNIT_ARRAY_PARAM_DESC(sha1, cases, str);
 
 	// Looks no different from a normal test.
 	static void sha1_test(struct kunit *test)
@@ -588,7 +584,7 @@ By reusing the same ``cases`` array from above, we can write the test as a
 	}
 
 	// Instead of KUNIT_CASE, we use KUNIT_CASE_PARAM and pass in the
-	// function declared by KUNIT_ARRAY_PARAM.
+	// function declared by KUNIT_ARRAY_PARAM or KUNIT_ARRAY_PARAM_DESC.
 	static struct kunit_case sha1_test_cases[] = {
 		KUNIT_CASE_PARAM(sha1_test, sha1_gen_params),
 		{}
include/kunit/test.h +19 -0
index 20ed9f9275c9..2dfa851e1f88 100644
@@ -1514,6 +1514,25 @@ do {									       \
 		return NULL;									\
 	}
 
+/**
+ * KUNIT_ARRAY_PARAM_DESC() - Define test parameter generator from an array.
+ * @name:  prefix for the test parameter generator function.
+ * @array: array of test parameters.
+ * @desc_member: structure member from array element to use as description
+ *
+ * Define function @name_gen_params which uses @array to generate parameters.
+ */
+#define KUNIT_ARRAY_PARAM_DESC(name, array, desc_member)					\
+	static const void *name##_gen_params(const void *prev, char *desc)			\
+	{											\
+		typeof((array)[0]) *__next = prev ? ((typeof(__next)) prev) + 1 : (array);	\
+		if (__next - (array) < ARRAY_SIZE((array))) {					\
+			strscpy(desc, __next->desc_member, KUNIT_PARAM_DESC_SIZE);		\
+			return __next;								\
+		}										\
+		return NULL;									\
+	}
+
 // TODO([email protected]): consider eventually migrating users to explicitly
 // include resource.h themselves if they need it.
 #include <kunit/resource.h>
Signature · 1 line
2.43.0
Reviewed-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] kunit: add parameter generation macro using description from array

Quoted 10 lines · On Wed, 20 Dec 2023 at 23:20, <[email protected]> wrote:

From: Benjamin Berg <[email protected]>

The existing KUNIT_ARRAY_PARAM macro requires a separate function to get the description. However, in a lot of cases the description can just be copied directly from the array. Add a second macro that avoids having to write a static function just for a single strscpy.

---

I'm generally pretty happy with this, though note the checkpatch warning below.

There was some discussion at plumbers about expanding the parameterised test APIs, so we may need to adjust the implementation of this down the line, but I don't think that'll happen for a while, so don't worry.

With the warnings fixed, this is:

I'm okay with this going in via the wireless tree if that's easier; certainly there are some conflicts with the later patches in this series and the kunit one.

Cheers,
-- David

Quoted 44 lines
 Documentation/dev-tools/kunit/usage.rst | 12 ++++--------
 include/kunit/test.h                    | 19 +++++++++++++++++++
 2 files changed, 23 insertions(+), 8 deletions(-)
Documentation/dev-tools/kunit/usage.rst +4 -8
index c27e1646ecd9..b959e5befcbe 100644
@@ -566,13 +566,9 @@ By reusing the same ``cases`` array from above, we can write the test as a
                },
        };
 
-       // Need a helper function to generate a name for each test case.
-       static void case_to_desc(const struct sha1_test_case *t, char *desc)
-       {
-               strcpy(desc, t->str);
-       }
-       // Creates `sha1_gen_params()` to iterate over `cases`.
-       KUNIT_ARRAY_PARAM(sha1, cases, case_to_desc);
+       // Creates `sha1_gen_params()` to iterate over `cases` while using
+       // the struct member `str` for the case description.
+       KUNIT_ARRAY_PARAM_DESC(sha1, cases, str);
 
        // Looks no different from a normal test.
        static void sha1_test(struct kunit *test)
@@ -588,7 +584,7 @@ By reusing the same ``cases`` array from above, we can write the test as a
        }
 
        // Instead of KUNIT_CASE, we use KUNIT_CASE_PARAM and pass in the
-       // function declared by KUNIT_ARRAY_PARAM.
+       // function declared by KUNIT_ARRAY_PARAM or KUNIT_ARRAY_PARAM_DESC.
        static struct kunit_case sha1_test_cases[] = {
                KUNIT_CASE_PARAM(sha1_test, sha1_gen_params),
                {}
include/kunit/test.h +2 -0
index 20ed9f9275c9..2dfa851e1f88 100644
@@ -1514,6 +1514,25 @@ do {                                                                            \
                return NULL;                                                                    \
        }
 
+/**
+ * KUNIT_ARRAY_PARAM_DESC() - Define test parameter generator from an array.

include/kunit/test.h do { \ · line 1528

Quoted 10 lines
include/kunit/test.h +10 -0
+ * @name:  prefix for the test parameter generator function.
+ * @array: array of test parameters.
+ * @desc_member: structure member from array element to use as description
+ *
+ * Define function @name_gen_params which uses @array to generate parameters.
+ */
+#define KUNIT_ARRAY_PARAM_DESC(name, array, desc_member)                                       \
+       static const void *name##_gen_params(const void *prev, char *desc)                      \
+       {                                                                                       \
+               typeof((array)[0]) *__next = prev ? ((typeof(__next)) prev) + 1 : (array);      \

checkpatch is complaining here:
ERROR: need consistent spacing around '*' (ctx:WxV) #71: FILE: include/kunit/test.h:1528:

+ typeof((array)[0]) *__next = prev ? ((typeof(__next))
prev) + 1 : (array); \

Quoted 17 lines
include/kunit/test.h +7 -1
+               if (__next - (array) < ARRAY_SIZE((array))) {                                   \
+                       strscpy(desc, __next->desc_member, KUNIT_PARAM_DESC_SIZE);              \
+                       return __next;                                                          \
+               }                                                                               \
+               return NULL;                                                                    \
+       }
+
 // TODO([email protected]): consider eventually migrating users to explicitly
 // include resource.h themselves if they need it.
 #include <kunit/resource.h>
--

2.43.0

--
You received this message because you are subscribed to the Google Groups "KUnit Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/20231220151952.415232-2-benjamin%40sipsolutions.net.

#3 lore raw

Re: [PATCH 1/6] kunit: add parameter generation macro using description from array

Quoted 16 lines · David Gow
Quoted 11 lines · On Wed, 20 Dec 2023 at 23:20, <[email protected]> wrote:

From: Benjamin Berg <[email protected]>

The existing KUNIT_ARRAY_PARAM macro requires a separate function to
get the description. However, in a lot of cases the description can just be copied directly from the array. Add a second macro that avoids having to write a static function just for a single strscpy.

---

I'm generally pretty happy with this, though note the checkpatch warning below.

Quoted 6 lines

There was some discussion at plumbers about expanding the parameterised test APIs, so we may need to adjust the implementation of this down the line, but I don't think that'll happen for a while, so don't worry.

With the warnings fixed, this is:

I think the checkpatch warning is a false positive. It seems to confuse the * as a multiplication due to typeof() looking like a function call rather than a variable declaration.

Benjamin

Quoted 120 lines

I'm okay with this going in via the wireless tree if that's easier; certainly there are some conflicts with the later patches in this series and the kunit one.

Cheers,
-- David

Quoted 66 lines

 Documentation/dev-tools/kunit/usage.rst | 12 ++++-------- include/kunit/test.h                    | 19 +++++++++++++++++++

 2 files changed, 23 insertions(+), 8 deletions(-)
Documentation/dev-tools/kunit/usage.rst +0 -0
index c27e1646ecd9..b959e5befcbe 100644
@@ -566,13 +566,9 @@ By reusing the same ``cases`` array from

above, we can write the test as a
                },
        };

-       // Need a helper function to generate a name for each test case.
-       static void case_to_desc(const struct sha1_test_case *t, char *desc)
-       {
-               strcpy(desc, t->str);
-       }
-       // Creates sha1_gen_params() to iterate over cases. -       KUNIT_ARRAY_PARAM(sha1, cases, case_to_desc);
+       // Creates sha1_gen_params() to iterate over cases while using
+       // the struct member str for the case description. +       KUNIT_ARRAY_PARAM_DESC(sha1, cases, str);

        // Looks no different from a normal test.
        static void sha1_test(struct kunit *test)

Documentation/dev-tools/kunit/usage.rst +0 -0
@@ -588,7 +584,7 @@ By reusing the same ``cases`` array from above,

we can write the test as a
        }

        // Instead of KUNIT_CASE, we use KUNIT_CASE_PARAM and pass in the
-       // function declared by KUNIT_ARRAY_PARAM.
+       // function declared by KUNIT_ARRAY_PARAM or KUNIT_ARRAY_PARAM_DESC.
        static struct kunit_case sha1_test_cases[] = { KUNIT_CASE_PARAM(sha1_test, sha1_gen_params), {}

include/kunit/test.h +0 -0
index 20ed9f9275c9..2dfa851e1f88 100644
@@ -1514,6 +1514,25 @@ do
 {                                                                  
           \

                return
NULL;
      \
        }

+/**
+ * KUNIT_ARRAY_PARAM_DESC() - Define test parameter generator from an array.
+ * @name:  prefix for the test parameter generator function.
+ * @array: array of test parameters.
+ * @desc_member: structure member from array element to use as description
+ *
+ * Define function @name_gen_params which uses @array to generate parameters.
+ */
+#define KUNIT_ARRAY_PARAM_DESC(name, array,

Quoted 8 lines

desc_member)                                       \
+       static const void *name##_gen_params(const void *prev, char *desc)                      \
+
{
                     \
+               typeof((array)[0]) *__next = prev ? ((typeof(__next)) prev) + 1 : (array);      \

checkpatch is complaining here:
ERROR: need consistent spacing around '*' (ctx:WxV) #71: FILE: include/kunit/test.h:1528:

+               typeof((array)[0]) *__next = prev ? ((typeof(__next)) prev) + 1 : (array);      \

Quoted 29 lines

+               if (__next - (array) < ARRAY_SIZE((array))) {                                   \
+                       strscpy(desc, __next->desc_member, KUNIT_PARAM_DESC_SIZE);              \
+                       return
__next;                                                          \
+
}
             \
+               return
NULL;
      \
+       }
+
 // TODO([email protected]): consider eventually migrating users to explicitly
 // include resource.h themselves if they need it. #include <kunit/resource.h>
--
2.43.0

--
You received this message because you are subscribed to the Google Groups "KUnit Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit
https://groups.google.com/d/msgid/kunit-dev/20231220151952.415232-2-benjamin%40sipsolutions.net
.

Reviewed-by
#4 lore raw

Re: [PATCH 1/6] kunit: add parameter generation macro using description from array

Quoted 23 lines · Benjamin Berg
Quoted 21 lines · David Gow
Quoted 11 lines · On Wed, 20 Dec 2023 at 23:20, <[email protected]> wrote:

From: Benjamin Berg <[email protected]>

The existing KUNIT_ARRAY_PARAM macro requires a separate function to
get the description. However, in a lot of cases the description can just be copied directly from the array. Add a second macro that avoids having to write a static function just for a single strscpy.

---

I'm generally pretty happy with this, though note the checkpatch warning below.

There was some discussion at plumbers about expanding the parameterised test APIs, so we may need to adjust the implementation of this down the line, but I don't think that'll happen for a while, so don't worry.

Quoted 8 lines
Quoted 1 line

With the warnings fixed, this is:

I think the checkpatch warning is a false positive. It seems to confuse the * as a multiplication due to typeof() looking like a function call rather than a variable declaration.

Benjamin

Ah, yeah: this appears to be due to checkpatch not handling nested () within a typeof().

Cheers,
-- David

#5 lore raw

PATCH 2/6 kunit: add a convenience allocation wrapper for SKBs

In reply to [email protected]

From: Benjamin Berg <[email protected]>

Add a simple convenience helper to allocate and zero fill an SKB for the use by a kunit test. Also provide a way to free it again in case that may be desirable.

This simply mirrors the kunit_kmalloc API.

---
 include/kunit/skbuff.h | 56 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 include/kunit/skbuff.h
include/kunit/skbuff.h new file +56 -0
new file mode 100644
index 000000000000..2144d01e556f
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Base unit test (KUnit) API.
+ *
+ * Copyright (C) 2023 Intel Corporation
+ */
+
+#ifndef _KUNIT_SKBUFF_H
+#define _KUNIT_SKBUFF_H
+
+#include <kunit/resource.h>
+#include <linux/skbuff.h>
+
+static void kunit_action_kfree_skb(void *p)
+{
+	kfree_skb((struct sk_buff *)p);
+}
+
+/**
+ * kunit_zalloc_skb() - Allocate and initialize a resource managed skb.
+ * @test: The test case to which the skb belongs
+ * @len: size to allocate
+ *
+ * Allocate a new struct sk_buff with GFP_KERNEL, zero fill the give length
+ * and add it as a resource to the kunit test for automatic cleanup.
+ *
+ * Returns: newly allocated SKB, or %NULL on error
+ */
+static inline struct sk_buff *kunit_zalloc_skb(struct kunit *test, int len,
+					       gfp_t gfp)
+{
+	struct sk_buff *res = alloc_skb(len, GFP_KERNEL);
+
+	if (!res || skb_pad(res, len))
+		return NULL;
+
+	if (kunit_add_action_or_reset(test, kunit_action_kfree_skb, res))
+		return NULL;
+
+	return res;
+}
+
+/**
+ * kunit_kfree_skb() - Like kfree_skb except for allocations managed by KUnit.
+ * @test: The test case to which the resource belongs.
+ * @skb: The SKB to free.
+ */
+static inline void kunit_kfree_skb(struct kunit *test, struct sk_buff *skb)
+{
+	if (!skb)
+		return;
+
+	kunit_release_action(test, kunit_action_kfree_skb, (void *)skb);
+}
+
+#endif /* _KUNIT_SKBUFF_H */
Signature · 1 line
2.43.0
Reviewed-by on v1 2/6
#6 lore raw

Re: [PATCH 2/6] kunit: add a convenience allocation wrapper for SKBs

Quoted 11 lines · On Wed, 20 Dec 2023 at 23:20, <[email protected]> wrote:

From: Benjamin Berg <[email protected]>

Add a simple convenience helper to allocate and zero fill an SKB for the use by a kunit test. Also provide a way to free it again in case that may be desirable.

This simply mirrors the kunit_kmalloc API.

---

I'm happy with this as-is, but do think there's a discussion to be had about where subsystem-specific KUnit helpers should live. I think, because this is just a header (and it mirrors the normal linux/skbuff.h), that having it in include/kunit works well.

If it needed a source file, I'm not 100% sure whether it should be in net/core/ or lib/kunit.

Regardless, this looks good to me, modulo the small nitpick below.

include/kunit/skbuff.h line 3

Quoted 13 lines
 include/kunit/skbuff.h | 56 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 include/kunit/skbuff.h
include/kunit/skbuff.h new file +3 -0
new file mode 100644
index 000000000000..2144d01e556f
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Base unit test (KUnit) API.

This probably needs a better description which mentions skbuff, and that it's for resource management.

Quoted 60 lines
include/kunit/skbuff.h new file +53 -1
+ *
+ * Copyright (C) 2023 Intel Corporation
+ */
+
+#ifndef _KUNIT_SKBUFF_H
+#define _KUNIT_SKBUFF_H
+
+#include <kunit/resource.h>
+#include <linux/skbuff.h>
+
+static void kunit_action_kfree_skb(void *p)
+{
+       kfree_skb((struct sk_buff *)p);
+}
+
+/**
+ * kunit_zalloc_skb() - Allocate and initialize a resource managed skb.
+ * @test: The test case to which the skb belongs
+ * @len: size to allocate
+ *
+ * Allocate a new struct sk_buff with GFP_KERNEL, zero fill the give length
+ * and add it as a resource to the kunit test for automatic cleanup.
+ *
+ * Returns: newly allocated SKB, or %NULL on error
+ */
+static inline struct sk_buff *kunit_zalloc_skb(struct kunit *test, int len,
+                                              gfp_t gfp)
+{
+       struct sk_buff *res = alloc_skb(len, GFP_KERNEL);
+
+       if (!res || skb_pad(res, len))
+               return NULL;
+
+       if (kunit_add_action_or_reset(test, kunit_action_kfree_skb, res))
+               return NULL;
+
+       return res;
+}
+
+/**
+ * kunit_kfree_skb() - Like kfree_skb except for allocations managed by KUnit.
+ * @test: The test case to which the resource belongs.
+ * @skb: The SKB to free.
+ */
+static inline void kunit_kfree_skb(struct kunit *test, struct sk_buff *skb)
+{
+       if (!skb)
+               return;
+
+       kunit_release_action(test, kunit_action_kfree_skb, (void *)skb);
+}
+
+#endif /* _KUNIT_SKBUFF_H */
--

2.43.0

--
You received this message because you are subscribed to the Google Groups "KUnit Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/20231220151952.415232-3-benjamin%40sipsolutions.net.

#7 lore raw

PATCH 3/6 wifi: mac80211: add kunit tests for public action handling

In reply to [email protected]

From: Johannes Berg <[email protected]>

Check the logic in ieee80211_drop_unencrypted_mgmt() according to a list of test cases derived from the spec.

---
 net/mac80211/ieee80211_i.h  |  10 ++
 net/mac80211/rx.c           |   4 +-
 net/mac80211/tests/Makefile |   2 +-
 net/mac80211/tests/mfp.c    | 184 ++++++++++++++++++++++++++++++++++++
 4 files changed, 198 insertions(+), 2 deletions(-)
 create mode 100644 net/mac80211/tests/mfp.c
net/mac80211/ieee80211_i.h +10 -0
index 29312f6638a1..71fafcd6a36e 100644
@@ -2610,4 +2610,14 @@ void ieee80211_check_wbrf_support(struct ieee80211_local *local);
 void ieee80211_add_wbrf(struct ieee80211_local *local, struct cfg80211_chan_def *chandef);
 void ieee80211_remove_wbrf(struct ieee80211_local *local, struct cfg80211_chan_def *chandef);
 
+#if IS_ENABLED(CONFIG_MAC80211_KUNIT_TEST)
+#define EXPORT_SYMBOL_IF_MAC80211_KUNIT(sym) EXPORT_SYMBOL_IF_KUNIT(sym)
+#define VISIBLE_IF_MAC80211_KUNIT
+ieee80211_rx_result
+ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx);
+#else
+#define EXPORT_SYMBOL_IF_MAC80211_KUNIT(sym)
+#define VISIBLE_IF_MAC80211_KUNIT static
+#endif
+
 #endif /* IEEE80211_I_H */
net/mac80211/rx.c +3 -1
index bbfdcb0ade72..d294787feed0 100644
@@ -19,6 +19,7 @@
 #include <linux/export.h>
 #include <linux/kcov.h>
 #include <linux/bitops.h>
+#include <kunit/visibility.h>
 #include <net/mac80211.h>
 #include <net/ieee80211_radiotap.h>
 #include <asm/unaligned.h>
@@ -2405,7 +2406,7 @@ static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
 	return 0;
 }
 
-static ieee80211_rx_result
+VISIBLE_IF_MAC80211_KUNIT ieee80211_rx_result
 ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
 {
 	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
@@ -2484,6 +2485,7 @@ ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
 
 	return RX_CONTINUE;
 }
+EXPORT_SYMBOL_IF_MAC80211_KUNIT(ieee80211_drop_unencrypted_mgmt);
 
 static ieee80211_rx_result
 __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
net/mac80211/tests/Makefile +1 -1
index 4814584f8a14..4fdaf3feaca3 100644
@@ -1,3 +1,3 @@
-mac80211-tests-y += module.o elems.o
+mac80211-tests-y += module.o elems.o mfp.o
 
 obj-$(CONFIG_MAC80211_KUNIT_TEST) += mac80211-tests.o
net/mac80211/tests/mfp.c new file +184 -0

184 lines not on this page · raw message

Signature · 1 line
2.43.0
#8 lore raw

PATCH 4/6 wifi: mac80211: kunit: generalize public action test

In reply to [email protected]

From: Johannes Berg <[email protected]>

Generalize the test to be able to handle arbitrary action categories and non-action frames, for further test expansion.

---
 net/mac80211/tests/mfp.c | 78 +++++++++++++++++++++++++++++-----------
 1 file changed, 57 insertions(+), 21 deletions(-)
net/mac80211/tests/mfp.c +57 -21
index 629a5801c08f..6ec31386c0df 100644
@@ -13,34 +13,52 @@ MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING);
 
 static const struct mfp_test_case {
 	const char *desc;
-	bool sta, mfp, decrypted, unicast, protected_dual;
+	bool sta, mfp, decrypted, unicast;
+	u8 category;
+	u8 stype;
+	u8 action;
 	ieee80211_rx_result result;
-} accept_public_action_cases[] = {
+} accept_mfp_cases[] = {
 	/* regular public action */
 	{
 		.desc = "public action: accept unicast from unknown peer",
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PUBLIC,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.unicast = true,
 		.result = RX_CONTINUE,
 	},
 	{
 		.desc = "public action: accept multicast from unknown peer",
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PUBLIC,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.unicast = false,
 		.result = RX_CONTINUE,
 	},
 	{
 		.desc = "public action: accept unicast without MFP",
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PUBLIC,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.unicast = true,
 		.sta = true,
 		.result = RX_CONTINUE,
 	},
 	{
 		.desc = "public action: accept multicast without MFP",
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PUBLIC,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.unicast = false,
 		.sta = true,
 		.result = RX_CONTINUE,
 	},
 	{
 		.desc = "public action: drop unicast with MFP",
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PUBLIC,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.unicast = true,
 		.sta = true,
 		.mfp = true,
@@ -48,6 +66,9 @@ static const struct mfp_test_case {
 	},
 	{
 		.desc = "public action: accept multicast with MFP",
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PUBLIC,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.unicast = false,
 		.sta = true,
 		.mfp = true,
@@ -56,33 +77,43 @@ static const struct mfp_test_case {
 	/* protected dual of public action */
 	{
 		.desc = "protected dual: drop unicast from unknown peer",
-		.protected_dual = true,
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.unicast = true,
 		.result = RX_DROP_U_UNPROT_DUAL,
 	},
 	{
 		.desc = "protected dual: drop multicast from unknown peer",
-		.protected_dual = true,
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.unicast = false,
 		.result = RX_DROP_U_UNPROT_DUAL,
 	},
 	{
 		.desc = "protected dual: drop unicast without MFP",
-		.protected_dual = true,
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.unicast = true,
 		.sta = true,
 		.result = RX_DROP_U_UNPROT_DUAL,
 	},
 	{
 		.desc = "protected dual: drop multicast without MFP",
-		.protected_dual = true,
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.unicast = false,
 		.sta = true,
 		.result = RX_DROP_U_UNPROT_DUAL,
 	},
 	{
 		.desc = "protected dual: drop undecrypted unicast with MFP",
-		.protected_dual = true,
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.unicast = true,
 		.sta = true,
 		.mfp = true,
@@ -90,7 +121,9 @@ static const struct mfp_test_case {
 	},
 	{
 		.desc = "protected dual: drop undecrypted multicast with MFP",
-		.protected_dual = true,
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.unicast = false,
 		.sta = true,
 		.mfp = true,
@@ -98,7 +131,9 @@ static const struct mfp_test_case {
 	},
 	{
 		.desc = "protected dual: accept unicast with MFP",
-		.protected_dual = true,
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.decrypted = true,
 		.unicast = true,
 		.sta = true,
@@ -107,7 +142,9 @@ static const struct mfp_test_case {
 	},
 	{
 		.desc = "protected dual: accept multicast with MFP",
-		.protected_dual = true,
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.decrypted = true,
 		.unicast = false,
 		.sta = true,
@@ -116,11 +153,9 @@ static const struct mfp_test_case {
 	},
 };
 
-KUNIT_ARRAY_PARAM_DESC(accept_public_action,
-		       accept_public_action_cases,
-		       desc);
+KUNIT_ARRAY_PARAM_DESC(accept_mfp, accept_mfp_cases, desc);
 
-static void accept_public_action(struct kunit *test)
+static void accept_mfp(struct kunit *test)
 {
 	static struct sta_info sta = {};
 	const struct mfp_test_case *params = test->param_value;
@@ -130,7 +165,7 @@ static void accept_public_action(struct kunit *test)
 	struct ieee80211_rx_status *status;
 	struct ieee80211_hdr_3addr hdr = {
 		.frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
-					     IEEE80211_STYPE_ACTION),
+					     params->stype),
 		.addr1 = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
 		.addr2 = { 0x12, 0x22, 0x33, 0x44, 0x55, 0x66 },
 		/* A3/BSSID doesn't matter here */
@@ -160,11 +195,12 @@ static void accept_public_action(struct kunit *test)
 
 	skb_put_data(rx.skb, &hdr, sizeof(hdr));
 
-	if (params->protected_dual)
-		skb_put_u8(rx.skb, WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION);
-	else
-		skb_put_u8(rx.skb, WLAN_CATEGORY_PUBLIC);
-	skb_put_u8(rx.skb, WLAN_PUB_ACTION_DSE_ENABLEMENT);
+	switch (params->stype) {
+	case IEEE80211_STYPE_ACTION:
+		skb_put_u8(rx.skb, params->category);
+		skb_put_u8(rx.skb, params->action);
+		break;
+	}
 
 	KUNIT_EXPECT_EQ(test,
 			ieee80211_drop_unencrypted_mgmt(&rx),
@@ -172,7 +208,7 @@ static void accept_public_action(struct kunit *test)
 }
 
 static struct kunit_case mfp_test_cases[] = {
-	KUNIT_CASE_PARAM(accept_public_action, accept_public_action_gen_params),
+	KUNIT_CASE_PARAM(accept_mfp, accept_mfp_gen_params),
 	{}
 };
 
Signature · 1 line
2.43.0
#9 lore raw

PATCH 5/6 wifi: mac80211: kunit: extend MFP tests

In reply to [email protected]

From: Johannes Berg <[email protected]>

Extend the MFP tests to handle the case of deauth/disassoc and robust action frames (that are not protected dual of public action frames).

---
 net/mac80211/tests/mfp.c | 74 +++++++++++++++++++++++++++++++++++++---
 1 file changed, 70 insertions(+), 4 deletions(-)
net/mac80211/tests/mfp.c +70 -4
index 6ec31386c0df..a8dc1601da60 100644
@@ -13,7 +13,7 @@ MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING);
 
 static const struct mfp_test_case {
 	const char *desc;
-	bool sta, mfp, decrypted, unicast;
+	bool sta, mfp, decrypted, unicast, assoc;
 	u8 category;
 	u8 stype;
 	u8 action;
@@ -151,13 +151,67 @@ static const struct mfp_test_case {
 		.mfp = true,
 		.result = RX_CONTINUE,
 	},
+	/* deauth/disassoc before keys are set */
+	{
+		.desc = "deauth: accept unicast with MFP but w/o key",
+		.stype = IEEE80211_STYPE_DEAUTH,
+		.sta = true,
+		.mfp = true,
+		.unicast = true,
+		.result = RX_CONTINUE,
+	},
+	{
+		.desc = "disassoc: accept unicast with MFP but w/o key",
+		.stype = IEEE80211_STYPE_DEAUTH,
+		.sta = true,
+		.mfp = true,
+		.unicast = true,
+		.result = RX_CONTINUE,
+	},
+	/* non-public robust action frame ... */
+	{
+		.desc = "BA action: drop unicast before assoc",
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_BACK,
+		.unicast = true,
+		.sta = true,
+		.result = RX_DROP_U_UNPROT_ROBUST_ACTION,
+	},
+	{
+		.desc = "BA action: drop unprotected after assoc",
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_BACK,
+		.unicast = true,
+		.sta = true,
+		.mfp = true,
+		.result = RX_DROP_U_UNPROT_UCAST_MGMT,
+	},
+	{
+		.desc = "BA action: accept unprotected without MFP",
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_BACK,
+		.unicast = true,
+		.sta = true,
+		.assoc = true,
+		.mfp = false,
+		.result = RX_CONTINUE,
+	},
+	{
+		.desc = "BA action: drop unprotected with MFP",
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_BACK,
+		.unicast = true,
+		.sta = true,
+		.mfp = true,
+		.result = RX_DROP_U_UNPROT_UCAST_MGMT,
+	},
 };
 
 KUNIT_ARRAY_PARAM_DESC(accept_mfp, accept_mfp_cases, desc);
 
 static void accept_mfp(struct kunit *test)
 {
-	static struct sta_info sta = {};
+	static struct sta_info sta;
 	const struct mfp_test_case *params = test->param_value;
 	struct ieee80211_rx_data rx = {
 		.sta = params->sta ? &sta : NULL,
@@ -171,6 +225,8 @@ static void accept_mfp(struct kunit *test)
 		/* A3/BSSID doesn't matter here */
 	};
 
+	memset(&sta, 0, sizeof(sta));
+
 	if (!params->sta) {
 		KUNIT_ASSERT_FALSE(test, params->mfp);
 		KUNIT_ASSERT_FALSE(test, params->decrypted);
@@ -179,6 +235,9 @@ static void accept_mfp(struct kunit *test)
 	if (params->mfp)
 		set_sta_flag(&sta, WLAN_STA_MFP);
 
+	if (params->assoc)
+		set_bit(WLAN_STA_ASSOC, &sta._flags);
+
 	rx.skb = kunit_zalloc_skb(test, 128, GFP_KERNEL);
 	KUNIT_ASSERT_NOT_NULL(test, rx.skb);
 	status = IEEE80211_SKB_RXCB(rx.skb);
@@ -200,11 +259,18 @@ static void accept_mfp(struct kunit *test)
 		skb_put_u8(rx.skb, params->category);
 		skb_put_u8(rx.skb, params->action);
 		break;
+	case IEEE80211_STYPE_DEAUTH:
+	case IEEE80211_STYPE_DISASSOC: {
+		__le16 reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
+
+		skb_put_data(rx.skb, &reason, sizeof(reason));
+		}
+		break;
 	}
 
 	KUNIT_EXPECT_EQ(test,
-			ieee80211_drop_unencrypted_mgmt(&rx),
-			params->result);
+			(__force u32)ieee80211_drop_unencrypted_mgmt(&rx),
+			(__force u32)params->result);
 }
 
 static struct kunit_case mfp_test_cases[] = {
Signature · 1 line
2.43.0
#10 lore raw

PATCH 6/6 wifi: cfg80211: tests: add some scanning related tests

In reply to [email protected]

From: Benjamin Berg <[email protected]>

This adds some scanning related tests, mainly exercising the ML element parsing and inheritance.

---
 net/wireless/core.h         |  13 +-
 net/wireless/scan.c         |   9 +-
 net/wireless/tests/Makefile |   2 +-
 net/wireless/tests/scan.c   | 625 ++++++++++++++++++++++++++++++++++++
 net/wireless/tests/util.c   |  56 ++++
 net/wireless/tests/util.h   |  66 ++++
 6 files changed, 766 insertions(+), 5 deletions(-)
 create mode 100644 net/wireless/tests/scan.c
 create mode 100644 net/wireless/tests/util.c
 create mode 100644 net/wireless/tests/util.h
net/wireless/core.h +12 -1
index 1963958263d2..13657a85cf61 100644
@@ -3,7 +3,7 @@
  * Wireless configuration interface internals.
  *
  * Copyright 2006-2010	Johannes Berg <[email protected]>
- * Copyright (C) 2018-2022 Intel Corporation
+ * Copyright (C) 2018-2023 Intel Corporation
  */
 #ifndef __NET_WIRELESS_CORE_H
 #define __NET_WIRELESS_CORE_H
@@ -549,4 +549,15 @@ int cfg80211_remove_virtual_intf(struct cfg80211_registered_device *rdev,
 				 struct wireless_dev *wdev);
 void cfg80211_wdev_release_link_bsses(struct wireless_dev *wdev, u16 link_mask);
 
+#if IS_ENABLED(CONFIG_CFG80211_KUNIT_TEST)
+#define EXPORT_SYMBOL_IF_CFG80211_KUNIT(sym) EXPORT_SYMBOL_IF_KUNIT(sym)
+#define VISIBLE_IF_CFG80211_KUNIT
+size_t cfg80211_gen_new_ie(const u8 *ie, size_t ielen,
+			   const u8 *subie, size_t subie_len,
+			   u8 *new_ie, size_t new_ie_len);
+#else
+#define EXPORT_SYMBOL_IF_CFG80211_KUNIT(sym)
+#define VISIBLE_IF_CFG80211_KUNIT static
+#endif /* IS_ENABLED(CONFIG_CFG80211_KUNIT_TEST) */
+
 #endif /* __NET_WIRELESS_CORE_H */
net/wireless/scan.c +6 -3
index 3d260c99c348..f6c0421f4d77 100644
@@ -20,6 +20,7 @@
 #include <net/cfg80211.h>
 #include <net/cfg80211-wext.h>
 #include <net/iw_handler.h>
+#include <kunit/visibility.h>
 #include "core.h"
 #include "nl80211.h"
 #include "wext-compat.h"
@@ -303,9 +304,10 @@ static size_t cfg80211_copy_elem_with_frags(const struct element *elem,
 	return *pos - buf;
 }
 
-static size_t cfg80211_gen_new_ie(const u8 *ie, size_t ielen,
-				  const u8 *subie, size_t subie_len,
-				  u8 *new_ie, size_t new_ie_len)
+VISIBLE_IF_CFG80211_KUNIT size_t
+cfg80211_gen_new_ie(const u8 *ie, size_t ielen,
+		    const u8 *subie, size_t subie_len,
+		    u8 *new_ie, size_t new_ie_len)
 {
 	const struct element *non_inherit_elem, *parent, *sub;
 	u8 *pos = new_ie;
@@ -413,6 +415,7 @@ static size_t cfg80211_gen_new_ie(const u8 *ie, size_t ielen,
 
 	return pos - new_ie;
 }
+EXPORT_SYMBOL_IF_CFG80211_KUNIT(cfg80211_gen_new_ie);
 
 static bool is_bss(struct cfg80211_bss *a, const u8 *bssid,
 		   const u8 *ssid, size_t ssid_len)
net/wireless/tests/Makefile +1 -1
index fa8e297bbc5e..1f6622fcb758 100644
@@ -1,3 +1,3 @@
-cfg80211-tests-y += module.o fragmentation.o
+cfg80211-tests-y += module.o fragmentation.o scan.o util.o
 
 obj-$(CONFIG_CFG80211_KUNIT_TEST) += cfg80211-tests.o
net/wireless/tests/scan.c new file +625 -0

625 lines not on this page · raw message

net/wireless/tests/util.c new file +56 -0

56 lines not on this page · raw message

net/wireless/tests/util.h new file +66 -0

66 lines not on this page · raw message

Signature · 1 line
2.43.0
maintainer
#11 lore raw
In reply to [email protected]
Quoted 3 lines

This patchset adds a couple of helpers for kunit as well as tests for cfg80211 and mac80211 that use them.

I can take this through the wireless tree, but then I'd like to have ACKs from kunit folks for the kunit patches:

Quoted 3 lines

kunit: add parameter generation macro using description from array
kunit: add a convenience allocation wrapper for SKBs

Thanks,
johannes

maintainer
#12 lore raw
Quoted 7 lines · Johannes Berg
Quoted 3 lines

This patchset adds a couple of helpers for kunit as well as tests for cfg80211 and mac80211 that use them.

I can take this through the wireless tree, but then I'd like to have ACKs from kunit folks for the kunit patches:

We have run into conflicts in the past with the kunit tree. I take the kunit patches through linux-kselftest tree. I do want to make sure there are no conflicts. I don't mind taking these through my tree.

Quoted 4 lines
Quoted 3 lines

kunit: add parameter generation macro using description from array
kunit: add a convenience allocation wrapper for SKBs

Adding David and Brendan to the thread for their review.

thanks,
-- Shuah

maintainer
#13 lore raw
Quoted 5 lines · Shuah Khan
Quoted 4 lines · Johannes Berg
Quoted 3 lines

This patchset adds a couple of helpers for kunit as well as tests for cfg80211 and mac80211 that use them.

Quoted 7 lines
Quoted 3 lines

I can take this through the wireless tree, but then I'd like to have ACKs from kunit folks for the kunit patches:

We have run into conflicts in the past with the kunit tree. I take the kunit patches through linux-kselftest tree. I do want to make sure there are no conflicts. I don't mind taking these through my tree.

OK, fair enough.

If you can still put it into 6.8, then I think you can also take the wireless tests, assuming they pass (I haven't run them in the posted version). I don't think we'll have conflicts there, we don't have much work in wireless that's likely to land for 6.8.

johannes

maintainer
#14 lore raw
Quoted 14 lines · Johannes Berg
Quoted 5 lines · Shuah Khan
Quoted 4 lines · Johannes Berg
Quoted 3 lines

This patchset adds a couple of helpers for kunit as well as tests for cfg80211 and mac80211 that use them.

Quoted 7 lines
Quoted 3 lines

I can take this through the wireless tree, but then I'd like to have ACKs from kunit folks for the kunit patches:

We have run into conflicts in the past with the kunit tree. I take the kunit patches through linux-kselftest tree. I do want to make sure there are no conflicts. I don't mind taking these through my tree.

Quoted 7 lines

OK, fair enough.

If you can still put it into 6.8, then I think you can also take the wireless tests, assuming they pass (I haven't run them in the posted version). I don't think we'll have conflicts there, we don't have much work in wireless that's likely to land for 6.8.

Sounds good.

David, will you be able to look at these patches and let me know if I can apply for Linux 6.8-rc1.

thanks,
-- Shuah

#15 lore raw
Quoted 24 lines · Shuah Khan
Quoted 14 lines · Johannes Berg
Quoted 5 lines · Shuah Khan
Quoted 4 lines · Johannes Berg
Quoted 3 lines

This patchset adds a couple of helpers for kunit as well as tests for cfg80211 and mac80211 that use them.

Quoted 7 lines
Quoted 3 lines

I can take this through the wireless tree, but then I'd like to have ACKs from kunit folks for the kunit patches:

We have run into conflicts in the past with the kunit tree. I take the kunit patches through linux-kselftest tree. I do want to make sure there are no conflicts. I don't mind taking these through my tree.

Quoted 7 lines

OK, fair enough.

If you can still put it into 6.8, then I think you can also take the wireless tests, assuming they pass (I haven't run them in the posted version). I don't think we'll have conflicts there, we don't have much work in wireless that's likely to land for 6.8.

Quoted 4 lines

Sounds good.

David, will you be able to look at these patches and let me know if I can apply for Linux 6.8-rc1.

The two initial KUnit patches look fine, modulo a couple of minor docs issues and checkpatch warnings. They apply cleanly, and I doubt there's much chance of there being a merge conflict for 6.8 -- there are no other changes to the parameterised test macros, and the skb stuff is in its own file.

The remaining patches don't apply on top of the kunit branch as-is. I haven't had a chance to review them properly yet; the initial glance I had didn't show any serious issues (though I think checkpatch suggested some things to 'check').

So (once those small issues are finished), I'm okay with the first two patches going in via either tree. The remaining ones are probably best done via the wireless tree, as they seem to depend on some existing patches there, so maybe it makes sense to push everything via wireless.

Cheers,
-- David

maintainer
#16 lore raw

Hi,

Thanks for taking a look!

Quoted 2 lines · David Gow

The two initial KUnit patches look fine, modulo a couple of minor docs issues and checkpatch warnings.

I can run checkpatch (even if I can't always take it seriously), but do you want to comment more specifically wrt. the docs?

Quoted 4 lines

They apply cleanly, and I doubt
there's much chance of there being a merge conflict for 6.8 -- there are no other changes to the parameterised test macros, and the skb stuff is in its own file.

Right.

Quoted 1 line

The remaining patches don't apply on top of the kunit branch as-is.

Oh, OK. That makes some sense though, we've had a number of changes in the stack this cycle before. I somehow thought the tests were likely standalone, but apparently not.

Quoted 4 lines

I
haven't had a chance to review them properly yet; the initial glance I had didn't show any serious issues (though I think checkpatch suggested some things to 'check').

I can check.

Quoted 5 lines

So (once those small issues are finished), I'm okay with the first two patches going in via either tree. The remaining ones are probably best done via the wireless tree, as they seem to depend on some existing patches there, so maybe it makes sense to push everything via wireless.

If not through wireless I doubt we'll get it synchronized for 6.8, though of course it's also not needed for 6.8 to have the extra unit tests :)

I'll let Shuah decide.

Thanks!

johannes

#17 lore raw
Quoted 12 lines · Johannes Berg

Hi,

Thanks for taking a look!

Quoted 2 lines · David Gow

The two initial KUnit patches look fine, modulo a couple of minor docs issues and checkpatch warnings.

I can run checkpatch (even if I can't always take it seriously), but do you want to comment more specifically wrt. the docs?

Sorry, the 'docs' issue was just the initial comment on the include/linux/skbuff.h file in patch 2, which could have been more specific to skbuff and resource management.
The actual kerneldoc comments seem fine to me.

Quoted 5 lines
Quoted 4 lines

They apply cleanly, and I doubt
there's much chance of there being a merge conflict for 6.8 -- there are no other changes to the parameterised test macros, and the skb stuff is in its own file.

Quoted 8 lines

Right.

Quoted 1 line

The remaining patches don't apply on top of the kunit branch as-is.

Oh, OK. That makes some sense though, we've had a number of changes in the stack this cycle before. I somehow thought the tests were likely standalone, but apparently not.

I managed to get this to apply locally. The only real changes are to net/mac80211/ieee80211_i.h so it may be possible to port this across to the kselftest/kunit branch if you want, but it doesn't apply cleanly as-is.

Also, there are a couple of cfg80211 failures:
---
KTAP version 1
1..1
KTAP version 1
# Subtest: cfg80211-inform-bss
# module: cfg80211_tests
1..2
platform regulatory.0: Direct firmware load for regulatory.db failed with error -2
cfg80211: failed to load regulatory.db
ok 1 test_inform_bss_ssid_only
KTAP version 1
# Subtest: test_inform_bss_ml_sta
# test_inform_bss_ml_sta: EXPECTATION FAILED at net/wireless/tests/scan.c:592 Expected ies->len == 6 + 2 + sizeof(rnr) + 2 + 155 +
mle_basic_common_info.var_len + 5, but

       ies->len == 185 (0xb9)
       6 + 2 + sizeof(rnr) + 2 + 155 + mle_basic_common_info.var_len +

5 == 203 (0xcb)
not ok 1 no_mld_id
# test_inform_bss_ml_sta: EXPECTATION FAILED at net/wireless/tests/scan.c:588 Expected ies->len == 6 + 2 + sizeof(rnr) + 2 + 160 + 2 + 165 +
mle_basic_common_info.var_len + 5, but

       ies->len == 357 (0x165)
       6 + 2 + sizeof(rnr) + 2 + 160 + 2 + 165 +

mle_basic_common_info.var_len + 5 == 376 (0x178)
not ok 2 mld_id_eq_1
# test_inform_bss_ml_sta: pass:0 fail:2 skip:0 total:2 not ok 2 test_inform_bss_ml_sta
# cfg80211-inform-bss: pass:1 fail:1 skip:0 total:2 # Totals: pass:1 fail:2 skip:0 total:3
not ok 1 cfg80211-inform-bss
---

If the failures are because of the missing 'regulatory.db' file, would it make more sense to have that SKIP the tests instead? (And, if you actually want to check that it loads correctly, have that be its own, separate test?)

Quoted 6 lines
Quoted 4 lines

I
haven't had a chance to review them properly yet; the initial glance I had didn't show any serious issues (though I think checkpatch suggested some things to 'check').

I can check.

Yeah, it mostly looks like really minor style 'suggestions' around indenting and putting blank lines in, along with a couple of "you're reusing a value in a macro, double check this" ones.. I'll paste them below (but warning, they're a bit verbose).

CHECK: Please use a blank line after function/struct/union/enum declarations #1142: FILE: net/wireless/tests/scan.c:225:
+};
+KUNIT_ARRAY_PARAM_DESC(gen_new_ie, gen_new_ie_cases, desc)

CHECK: Please use a blank line after function/struct/union/enum declarations #1330: FILE: net/wireless/tests/scan.c:413:
+};
+KUNIT_ARRAY_PARAM_DESC(inform_bss_ml_sta, inform_bss_ml_sta_cases, desc)

CHECK: Alignment should match open parenthesis
#1489: FILE: net/wireless/tests/scan.c:572:
+ KUNIT_EXPECT_EQ(test, link_bss->beacon_interval,
+ le16_to_cpu(sta_prof.beacon_int));

CHECK: Alignment should match open parenthesis
#1491: FILE: net/wireless/tests/scan.c:574:
+ KUNIT_EXPECT_EQ(test, link_bss->capability,
+ le16_to_cpu(sta_prof.capabilities));

CHECK: Macro argument reuse '_freq' - possible side-effects? #1620: FILE: net/wireless/tests/util.h:10:
+#define CHAN2G(_freq) { \

+       .band = NL80211_BAND_2GHZ, \
+       .center_freq = (_freq), \
+       .hw_value = (_freq), \

+}

CHECK: Macro argument reuse 'test' - possible side-effects? #1653: FILE: net/wireless/tests/util.h:43:

+#define T_WIPHY(test, ctx) ({                                          \
+               struct wiphy *__wiphy =                                 \
+                       kunit_alloc_resource(test, t_wiphy_init,        \
+                                            t_wiphy_exit,              \
+                                            GFP_KERNEL, &(ctx));       \
+                                                                       \
+               KUNIT_ASSERT_NOT_NULL(test, __wiphy);                   \
+               __wiphy;                                                \

+ })

Quoted 7 lines
Quoted 6 lines

So (once those small issues are finished), I'm okay with the first two patches going in via either tree. The remaining ones are probably best done via the wireless tree, as they seem to depend on some existing patches there, so maybe it makes sense to push everything via wireless.

Quoted 6 lines

If not through wireless I doubt we'll get it synchronized for 6.8, though of course it's also not needed for 6.8 to have the extra unit tests :)

I'll let Shuah decide.

I think you should be able to rebase on top of the kunit tree if Shuah prefers that -- it's a reasonably straightforward conflict. But I think we'd want to make sure that the various issues above are fixed (and I'd not want the tests to fail out-of-the-box on the kunit.py UML setup, though having them depend on !UML or 'SKIP' should be fine).

Cheers,
-- David

maintainer Acked-by
#18 lore raw
In reply to Johannes Berg
Quoted 37 lines · Johannes Berg

Hi,

Thanks for taking a look!

Quoted 2 lines · David Gow

The two initial KUnit patches look fine, modulo a couple of minor docs issues and checkpatch warnings.

I can run checkpatch (even if I can't always take it seriously), but do you want to comment more specifically wrt. the docs?

Quoted 4 lines

They apply cleanly, and I doubt
there's much chance of there being a merge conflict for 6.8 -- there are no other changes to the parameterised test macros, and the skb stuff is in its own file.

Right.

Quoted 1 line

The remaining patches don't apply on top of the kunit branch as-is.

Oh, OK. That makes some sense though, we've had a number of changes in the stack this cycle before. I somehow thought the tests were likely standalone, but apparently not.

Quoted 4 lines

I
haven't had a chance to review them properly yet; the initial glance I had didn't show any serious issues (though I think checkpatch suggested some things to 'check').

I can check.

Quoted 5 lines

So (once those small issues are finished), I'm okay with the first two patches going in via either tree. The remaining ones are probably best done via the wireless tree, as they seem to depend on some existing patches there, so maybe it makes sense to push everything via wireless.

Quoted 6 lines

If not through wireless I doubt we'll get it synchronized for 6.8, though of course it's also not needed for 6.8 to have the extra unit tests :)

I'll let Shuah decide.

Thank you David for the reviews.

johannes, Please take these through wireless - makes it easier for all of us.

thanks,
-- Shuah