3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-22 06:29:23 +01:00

unit: add simple test for nl80211util

This commit is contained in:
James Prestwood 2024-06-18 09:58:51 -07:00 committed by Denis Kenzior
parent 43d5e89fac
commit 685d105739
2 changed files with 71 additions and 1 deletions

View File

@ -433,7 +433,7 @@ unit_tests += unit/test-cmac-aes \
unit/test-ie unit/test-util unit/test-ssid-security \ unit/test-ie unit/test-util unit/test-ssid-security \
unit/test-arc4 unit/test-wsc unit/test-eap-mschapv2 \ unit/test-arc4 unit/test-wsc unit/test-eap-mschapv2 \
unit/test-eap-sim unit/test-sae unit/test-p2p unit/test-band \ unit/test-eap-sim unit/test-sae unit/test-p2p unit/test-band \
unit/test-dpp unit/test-json unit/test-dpp unit/test-json unit/test-nl80211util
endif endif
if CLIENT if CLIENT
@ -582,6 +582,13 @@ unit_test_dpp_LDADD = $(ell_ldadd)
unit_test_json_SOURCES = unit/test-json.c src/json.h src/json.c shared/jsmn.h unit_test_json_SOURCES = unit/test-json.c src/json.h src/json.c shared/jsmn.h
unit_test_json_LDADD = $(ell_ldadd) unit_test_json_LDADD = $(ell_ldadd)
unit_test_nl80211util_SOURCES = unit/test-nl80211util.c \
src/nl80211util.h src/nl80211util.c \
src/band.h src/band.c \
src/ie.h src/ie.c \
src/util.h src/util.c
unit_test_nl80211util_LDADD = $(ell_ldadd)
endif endif
if CLIENT if CLIENT

63
unit/test-nl80211util.c Normal file
View File

@ -0,0 +1,63 @@
#include <assert.h>
#include <ell/ell.h>
#include "src/nl80211util.h"
#include "linux/nl80211.h"
static void test_parse_attrs(const void *data)
{
struct l_genl_msg *msg = l_genl_msg_new(NL80211_CMD_NEW_INTERFACE);
uint32_t ifindex = 1;
uint32_t freq = 2;
int ret;
l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &ifindex);
l_genl_msg_append_attr(msg, NL80211_ATTR_WIPHY_FREQ, 4, &freq);
ret = nl80211_parse_attrs(msg, NL80211_ATTR_IFINDEX, &ifindex,
NL80211_ATTR_WIPHY_FREQ, &freq,
NL80211_ATTR_UNSPEC);
l_genl_msg_unref(msg);
assert(ret == 0);
}
static void test_parse_nested(const void *data)
{
struct l_genl_msg *msg = l_genl_msg_new(NL80211_CMD_NEW_INTERFACE);
uint32_t ifindex = 1;
uint32_t freq = 2;
uint8_t noise = 3;
uint8_t noise_out;
struct l_genl_attr nested;
int ret;
int ret_nested;
l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &ifindex);
l_genl_msg_append_attr(msg, NL80211_ATTR_WIPHY_FREQ, 4, &freq);
l_genl_msg_enter_nested(msg, NL80211_ATTR_SURVEY_INFO);
l_genl_msg_append_attr(msg, NL80211_SURVEY_INFO_NOISE, 1, &noise);
l_genl_msg_leave_nested(msg);
ret = nl80211_parse_attrs(msg, NL80211_ATTR_IFINDEX, &ifindex,
NL80211_ATTR_WIPHY_FREQ, &freq,
NL80211_ATTR_SURVEY_INFO, &nested,
NL80211_ATTR_UNSPEC);
ret_nested = nl80211_parse_nested(&nested, NL80211_ATTR_SURVEY_INFO,
NL80211_SURVEY_INFO_NOISE, &noise_out,
NL80211_ATTR_UNSPEC);
l_genl_msg_unref(msg);
assert(ret == 0);
assert(ret_nested == 0);
assert(noise_out == noise);
}
int main(int argc, char *argv[])
{
l_test_init(&argc, &argv);
l_test_add("/nl80211util parse attrs", test_parse_attrs, NULL);
l_test_add("/nl80211util parse nested", test_parse_nested, NULL);
return l_test_run();
}