Commit 9d027a35 authored by Benjamin Berg's avatar Benjamin Berg Committed by Johannes Berg

wifi: cfg80211: tests: add some scanning related tests

This adds some scanning related tests, mainly exercising the ML element
parsing and inheritance.
Signed-off-by: default avatarBenjamin Berg <benjamin.berg@intel.com>
Link: https://msgid.link/20231220151952.415232-7-benjamin@sipsolutions.netSigned-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent bbd97bbe
......@@ -3,7 +3,7 @@
* Wireless configuration interface internals.
*
* Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
* 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 */
......@@ -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,7 +304,8 @@ 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,
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)
{
......@@ -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)
......
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
This diff is collapsed.
// SPDX-License-Identifier: GPL-2.0-only
/*
* KUnit fixture to have a (configurable) wiphy
*
* Copyright (C) 2023 Intel Corporation
*/
#include <linux/ieee80211.h>
#include <net/cfg80211.h>
#include <kunit/test.h>
#include <kunit/test-bug.h>
#include "util.h"
int t_wiphy_init(struct kunit_resource *resource, void *ctx)
{
struct kunit *test = kunit_get_current_test();
struct cfg80211_ops *ops;
struct wiphy *wiphy;
struct t_wiphy_priv *priv;
ops = kzalloc(sizeof(*ops), GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, ops);
wiphy = wiphy_new_nm(ops, sizeof(*priv), "kunit");
KUNIT_ASSERT_NOT_NULL(test, wiphy);
priv = wiphy_priv(wiphy);
priv->ctx = ctx;
priv->ops = ops;
/* Initialize channels, feel free to add more here channels/bands */
memcpy(priv->channels_2ghz, channels_2ghz, sizeof(channels_2ghz));
wiphy->bands[NL80211_BAND_2GHZ] = &priv->band_2ghz;
priv->band_2ghz.channels = priv->channels_2ghz;
priv->band_2ghz.n_channels = ARRAY_SIZE(channels_2ghz);
resource->data = wiphy;
resource->name = "wiphy";
return 0;
}
void t_wiphy_exit(struct kunit_resource *resource)
{
struct t_wiphy_priv *priv;
struct cfg80211_ops *ops;
priv = wiphy_priv(resource->data);
ops = priv->ops;
/* Should we ensure anything about the state here?
* e.g. full destruction or no calls to any ops on destruction?
*/
wiphy_free(resource->data);
kfree(ops);
}
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Utilities for cfg80211 unit testing
*
* Copyright (C) 2023 Intel Corporation
*/
#ifndef __CFG80211_UTILS_H
#define __CFG80211_UTILS_H
#define CHAN2G(_freq) { \
.band = NL80211_BAND_2GHZ, \
.center_freq = (_freq), \
.hw_value = (_freq), \
}
static const struct ieee80211_channel channels_2ghz[] = {
CHAN2G(2412), /* Channel 1 */
CHAN2G(2417), /* Channel 2 */
CHAN2G(2422), /* Channel 3 */
CHAN2G(2427), /* Channel 4 */
CHAN2G(2432), /* Channel 5 */
CHAN2G(2437), /* Channel 6 */
CHAN2G(2442), /* Channel 7 */
CHAN2G(2447), /* Channel 8 */
CHAN2G(2452), /* Channel 9 */
CHAN2G(2457), /* Channel 10 */
CHAN2G(2462), /* Channel 11 */
CHAN2G(2467), /* Channel 12 */
CHAN2G(2472), /* Channel 13 */
CHAN2G(2484), /* Channel 14 */
};
struct t_wiphy_priv {
struct kunit *test;
struct cfg80211_ops *ops;
void *ctx;
struct ieee80211_supported_band band_2ghz;
struct ieee80211_channel channels_2ghz[ARRAY_SIZE(channels_2ghz)];
};
#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; \
})
#define t_wiphy_ctx(wiphy) (((struct t_wiphy_priv *)wiphy_priv(wiphy))->ctx)
int t_wiphy_init(struct kunit_resource *resource, void *data);
void t_wiphy_exit(struct kunit_resource *resource);
#define t_skb_remove_member(skb, type, member) do { \
memmove((skb)->data + (skb)->len - sizeof(type) + \
offsetof(type, member), \
(skb)->data + (skb)->len - sizeof(type) + \
offsetofend(type, member), \
offsetofend(type, member)); \
skb_trim(skb, (skb)->len - sizeof_field(type, member)); \
} while (0)
#endif /* __CFG80211_UTILS_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment