tests: net: Refactor tests when running in real hw

The network tests were expecting that network interfaces
are in certain order. As we cannot guarantee that, refactor
the tests like this:

* if test is using DUMMY L2 driver, then disable Ethernet L2
  and fetch only DUMMY L2 instead of default interface
* if test is using Ethernet L2 driver, then make sure that the
  test is using the Ethernet interface specified in the test
  instead of the one provided by the DUT

Fixes #34505

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2021-04-28 14:02:35 +03:00 committed by Jukka Rissanen
commit 6e1df0d603
32 changed files with 184 additions and 63 deletions

View file

@ -1,6 +1,7 @@
CONFIG_NETWORKING=y
CONFIG_NET_TEST=y
CONFIG_NET_L2_DUMMY=y
CONFIG_NET_L2_ETHERNET=n
CONFIG_NET_IPV6=y
CONFIG_NET_IPV6_ND=n
CONFIG_NET_IPV6_DAD=n

View file

@ -460,7 +460,8 @@ static struct net_pkt *create_pkt(struct net_6lo_data *data)
uint16_t len;
int remaining;
pkt = net_pkt_alloc_on_iface(net_if_get_default(), K_FOREVER);
pkt = net_pkt_alloc_on_iface(
net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY)), K_FOREVER);
if (!pkt) {
return NULL;
}
@ -1153,8 +1154,10 @@ void test_loop(void)
}
#if defined(CONFIG_NET_6LO_CONTEXT)
net_6lo_set_context(net_if_get_default(), &ctx1);
net_6lo_set_context(net_if_get_default(), &ctx2);
net_6lo_set_context(net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY)),
&ctx1);
net_6lo_set_context(net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY)),
&ctx2);
#endif
for (count = 0; count < ARRAY_SIZE(tests); count++) {

View file

@ -8,6 +8,7 @@ CONFIG_NET_MAX_CONTEXTS=10
CONFIG_NET_CONTEXT_CHECK=y
CONFIG_NET_CONTEXT_SYNC_RECV=y
CONFIG_NET_L2_DUMMY=y
CONFIG_NET_L2_ETHERNET=n
CONFIG_NET_LOG=y
CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y

View file

@ -978,8 +978,9 @@ static void test_init(void)
{
struct net_if_addr *ifaddr;
struct net_if_mcast_addr *maddr;
struct net_if *iface = net_if_get_default();
struct net_if *iface;
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY));
zassert_not_null(iface, "Interface is NULL");
ifaddr = net_if_ipv6_addr_add(iface, &in6addr_my,

View file

@ -431,7 +431,7 @@ void test_dhcp(void)
net_mgmt_add_event_callback(&dhcp_cb);
iface = net_if_get_default();
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY));
if (!iface) {
zassert_true(false, "Interface not available");
}

View file

@ -4,8 +4,10 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define NET_LOG_LEVEL CONFIG_NET_L2_ETHERNET_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(net_test, CONFIG_NET_L2_ETHERNET_LOG_LEVEL);
LOG_MODULE_REGISTER(net_test, NET_LOG_LEVEL);
#include <zephyr.h>
@ -15,6 +17,14 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_L2_ETHERNET_LOG_LEVEL);
#include <ztest.h>
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG
#define DBG(fmt, ...) printk(fmt, ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif
static struct net_if *default_iface;
static const uint8_t mac_addr_init[6] = { 0x01, 0x02, 0x03,
0x04, 0x05, 0x06 };
@ -305,9 +315,49 @@ ETH_NET_DEVICE_INIT(eth_fake, "eth_fake", eth_fake_init, NULL,
&eth_fake_data, NULL, CONFIG_ETH_INIT_PRIORITY,
&eth_fake_api_funcs, NET_ETH_MTU);
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG
static const char *iface2str(struct net_if *iface)
{
#ifdef CONFIG_NET_L2_ETHERNET
if (net_if_l2(iface) == &NET_L2_GET_NAME(ETHERNET)) {
return "Ethernet";
}
#endif
#ifdef CONFIG_NET_L2_DUMMY
if (net_if_l2(iface) == &NET_L2_GET_NAME(DUMMY)) {
return "Dummy";
}
#endif
return "<unknown type>";
}
#endif
static void iface_cb(struct net_if *iface, void *user_data)
{
struct net_if **my_iface = user_data;
DBG("Interface %p (%s) [%d]\n", iface, iface2str(iface),
net_if_get_by_iface(iface));
if (net_if_l2(iface) == &NET_L2_GET_NAME(ETHERNET)) {
if (PART_OF_ARRAY(NET_IF_GET_NAME(eth_fake, 0), iface)) {
*my_iface = iface;
}
}
}
static void test_setup(void)
{
net_if_foreach(iface_cb, &default_iface);
zassert_not_null(default_iface, "Cannot find test interface");
}
static void test_change_mac_when_up(void)
{
struct net_if *iface = net_if_get_default();
struct net_if *iface = default_iface;
struct ethernet_req_params params;
int ret;
@ -322,7 +372,7 @@ static void test_change_mac_when_up(void)
static void test_change_mac_when_down(void)
{
struct net_if *iface = net_if_get_default();
struct net_if *iface = default_iface;
struct ethernet_req_params params;
int ret;
@ -345,7 +395,7 @@ static void test_change_mac_when_down(void)
static void test_change_auto_neg(void)
{
struct net_if *iface = net_if_get_default();
struct net_if *iface = default_iface;
struct ethernet_req_params params;
int ret;
@ -359,7 +409,7 @@ static void test_change_auto_neg(void)
static void test_change_to_same_auto_neg(void)
{
struct net_if *iface = net_if_get_default();
struct net_if *iface = default_iface;
struct ethernet_req_params params;
int ret;
@ -374,7 +424,7 @@ static void test_change_to_same_auto_neg(void)
static void test_change_link(void)
{
struct net_if *iface = net_if_get_default();
struct net_if *iface = default_iface;
struct ethernet_req_params params = { 0 };
int ret;
@ -388,7 +438,7 @@ static void test_change_link(void)
static void test_change_same_link(void)
{
struct net_if *iface = net_if_get_default();
struct net_if *iface = default_iface;
struct ethernet_req_params params = { 0 };
int ret;
@ -402,7 +452,7 @@ static void test_change_same_link(void)
static void test_change_unsupported_link(void)
{
struct net_if *iface = net_if_get_default();
struct net_if *iface = default_iface;
struct ethernet_req_params params = { 0 };
int ret;
@ -416,7 +466,7 @@ static void test_change_unsupported_link(void)
static void test_change_duplex(void)
{
struct net_if *iface = net_if_get_default();
struct net_if *iface = default_iface;
struct ethernet_req_params params;
int ret;
@ -430,7 +480,7 @@ static void test_change_duplex(void)
static void test_change_same_duplex(void)
{
struct net_if *iface = net_if_get_default();
struct net_if *iface = default_iface;
struct ethernet_req_params params;
int ret;
@ -444,7 +494,7 @@ static void test_change_same_duplex(void)
static void test_change_qav_params(void)
{
struct net_if *iface = net_if_get_default();
struct net_if *iface = default_iface;
const struct device *dev = net_if_get_device(iface);
struct eth_fake_context *ctx = dev->data;
struct ethernet_req_params params;
@ -620,7 +670,7 @@ static void test_change_qav_params(void)
static void test_change_promisc_mode(bool mode)
{
struct net_if *iface = net_if_get_default();
struct net_if *iface = default_iface;
struct ethernet_req_params params;
int ret;
@ -644,7 +694,7 @@ static void test_change_promisc_mode_off(void)
static void test_change_to_same_promisc_mode(void)
{
struct net_if *iface = net_if_get_default();
struct net_if *iface = default_iface;
struct ethernet_req_params params;
int ret;
@ -660,6 +710,7 @@ static void test_change_to_same_promisc_mode(void)
void test_main(void)
{
ztest_test_suite(ethernet_mgmt_test,
ztest_unit_test(test_setup),
ztest_unit_test(test_change_mac_when_up),
ztest_unit_test(test_change_mac_when_down),
ztest_unit_test(test_change_auto_neg),

View file

@ -418,7 +418,7 @@ static void test_icmpv4(void)
{
struct net_if_addr *ifaddr;
iface = net_if_get_default();
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY));
if (!iface) {
zassert_true(false, "Interface not available");
}

View file

@ -13,3 +13,4 @@ CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_ZTEST=y
CONFIG_MAIN_STACK_SIZE=1280
CONFIG_NET_L2_ETHERNET=n

View file

@ -2,6 +2,7 @@ CONFIG_ZTEST=y
CONFIG_NETWORKING=y
CONFIG_NET_TEST=y
CONFIG_NET_L2_DUMMY=y
CONFIG_NET_L2_ETHERNET=n
CONFIG_NET_IPV6=y
CONFIG_NET_IPV6_ND=n
CONFIG_NET_IPV6_DAD=n

View file

@ -237,7 +237,8 @@ static struct net_pkt *create_pkt(struct net_fragment_data *data)
uint16_t len;
int remaining;
pkt = net_pkt_alloc_on_iface(net_if_get_default(), K_FOREVER);
pkt = net_pkt_alloc_on_iface(
net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY)), K_FOREVER);
if (!pkt) {
return NULL;
}
@ -294,7 +295,8 @@ static struct net_pkt *create_pkt(struct net_fragment_data *data)
net_pkt_lladdr_dst(pkt)->type = NET_LINK_IEEE802154;
memcpy(net_pkt_lladdr_src(pkt),
net_if_get_link_addr(net_if_get_default()),
net_if_get_link_addr(
net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY))),
sizeof(struct net_linkaddr));
return pkt;

View file

@ -17,4 +17,5 @@ CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3
CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=2
CONFIG_NET_IF_MCAST_IPV4_ADDR_COUNT=3
CONFIG_NET_L2_DUMMY=y
CONFIG_NET_L2_ETHERNET=n
CONFIG_ZTEST=y

View file

@ -34,6 +34,8 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_IPV6_LOG_LEVEL);
#define DBG(fmt, ...)
#endif
static struct net_if *default_iface;
#define TEST_BYTE_1(value, expected) \
do { \
char out[3]; \
@ -234,7 +236,7 @@ static void test_ipv6_addresses(void)
zassert_true(net_ipv6_is_addr_mcast(&mcast),
"IPv6 multicast address check failed.");
ifaddr1 = net_if_ipv6_addr_add(net_if_get_default(),
ifaddr1 = net_if_ipv6_addr_add(default_iface,
&addr6,
NET_ADDR_MANUAL,
0);
@ -272,12 +274,12 @@ static void test_ipv6_addresses(void)
(uint8_t *)&addr6_pref3, 255),
"Too long prefix test failed");
ifmaddr1 = net_if_ipv6_maddr_add(net_if_get_default(), &mcast);
ifmaddr1 = net_if_ipv6_maddr_add(default_iface, &mcast);
/**TESTPOINTS: Check IPv6 addresses*/
zassert_not_null(ifmaddr1, "IPv6 multicast address add failed");
ifmaddr1 = net_if_ipv6_maddr_add(net_if_get_default(), &addr6);
ifmaddr1 = net_if_ipv6_maddr_add(default_iface, &addr6);
zassert_is_null(ifmaddr1,
"IPv6 multicast address could be added failed");
@ -285,7 +287,7 @@ static void test_ipv6_addresses(void)
zassert_false(memcmp(net_ipv6_unspecified_address(), &any, sizeof(any)),
"My IPv6 unspecified address check failed");
ifaddr2 = net_if_ipv6_addr_add(net_if_get_default(),
ifaddr2 = net_if_ipv6_addr_add(default_iface,
&addr6,
NET_ADDR_AUTOCONF,
0);
@ -293,18 +295,18 @@ static void test_ipv6_addresses(void)
ifaddr2->addr_state = NET_ADDR_PREFERRED;
tmp = net_if_ipv6_get_ll(net_if_get_default(), NET_ADDR_PREFERRED);
tmp = net_if_ipv6_get_ll(default_iface, NET_ADDR_PREFERRED);
zassert_false(tmp && memcmp(tmp, &addr6.s6_addr,
sizeof(struct in6_addr)),
"IPv6 ll address fetch failed");
ifaddr2->addr_state = NET_ADDR_DEPRECATED;
tmp = net_if_ipv6_get_ll(net_if_get_default(), NET_ADDR_PREFERRED);
tmp = net_if_ipv6_get_ll(default_iface, NET_ADDR_PREFERRED);
zassert_false(tmp && !memcmp(tmp, &any, sizeof(struct in6_addr)),
"IPv6 preferred ll address fetch failed");
ifaddr1 = net_if_ipv6_addr_add(net_if_get_default(),
ifaddr1 = net_if_ipv6_addr_add(default_iface,
&addr6_pref2,
NET_ADDR_AUTOCONF,
0);
@ -315,7 +317,7 @@ static void test_ipv6_addresses(void)
/* Two tests for IPv6, first with interface given, then when
* iface is NULL
*/
for (i = 0, iface = net_if_get_default(); i < 2; i++, iface = NULL) {
for (i = 0, iface = default_iface; i < 2; i++, iface = NULL) {
ifaddr2->addr_state = NET_ADDR_DEPRECATED;
out = net_if_ipv6_select_src_addr(iface, &addr6_pref1);
@ -360,9 +362,9 @@ static void test_ipv6_addresses(void)
iface);
}
zassert_true(net_if_ipv6_addr_rm(net_if_get_default(), &addr6),
zassert_true(net_if_ipv6_addr_rm(default_iface, &addr6),
"IPv6 removing address failed\n");
zassert_true(net_if_ipv6_addr_rm(net_if_get_default(), &addr6_pref2),
zassert_true(net_if_ipv6_addr_rm(default_iface, &addr6_pref2),
"IPv6 removing address failed\n");
}
@ -391,7 +393,7 @@ static void test_ipv4_addresses(void)
struct net_if *iface, *iface1, *iface2;
int i, ret;
ifaddr1 = net_if_ipv4_addr_add(net_if_get_default(),
ifaddr1 = net_if_ipv4_addr_add(default_iface,
&addr4,
NET_ADDR_MANUAL,
0);
@ -400,7 +402,7 @@ static void test_ipv4_addresses(void)
zassert_true(net_ipv4_is_my_addr(&addr4),
"My IPv4 address check failed");
ifaddr1 = net_if_ipv4_addr_add(net_if_get_default(),
ifaddr1 = net_if_ipv4_addr_add(default_iface,
&lladdr4,
NET_ADDR_MANUAL,
0);
@ -415,7 +417,7 @@ static void test_ipv4_addresses(void)
/* Two tests for IPv4, first with interface given, then when
* iface is NULL
*/
for (i = 0, iface = net_if_get_default(); i < 2; i++, iface = NULL) {
for (i = 0, iface = default_iface; i < 2; i++, iface = NULL) {
out = net_if_ipv4_select_src_addr(iface, &addr4);
zassert_not_null(out, "IPv4 src addr selection failed, "
"iface %p\n", iface);
@ -464,7 +466,7 @@ static void test_ipv4_addresses(void)
iface);
}
iface = net_if_get_default();
iface = default_iface;
net_if_ipv4_set_gw(iface, &gw);
net_if_ipv4_set_netmask(iface, &netmask);
@ -485,10 +487,10 @@ static void test_ipv4_addresses(void)
zassert_false(net_ipv4_is_addr_mcast(&bcast_addr1), "IPv4 broadcast address");
ifmaddr1 = net_if_ipv4_maddr_add(net_if_get_default(), &maddr4a);
ifmaddr1 = net_if_ipv4_maddr_add(default_iface, &maddr4a);
zassert_not_null(ifmaddr1, "IPv4 multicast address add failed");
ifmaddr1 = net_if_ipv4_maddr_add(net_if_get_default(), &maddr4b);
ifmaddr1 = net_if_ipv4_maddr_add(default_iface, &maddr4b);
zassert_not_null(ifmaddr1, "IPv4 multicast address add failed");
iface = NULL;
@ -559,7 +561,7 @@ static void test_ipv6_mesh_addresses(void)
0, 0, 0, 0, 0x1 } } };
struct in6_addr ml_mcast = { { { 0xff, 0x03, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0x1 } } };
struct net_if *iface = net_if_get_default();
struct net_if *iface = default_iface;
ifaddr = net_if_ipv6_addr_add(iface, &lla, NET_ADDR_AUTOCONF, 0);
zassert_not_null(ifaddr, "IPv6 ll address autoconf add failed");
@ -600,6 +602,8 @@ static void test_ipv6_mesh_addresses(void)
void test_main(void)
{
default_iface = net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY));
ztest_test_suite(test_ip_addr_fn,
ztest_unit_test(test_ip_addresses),
ztest_unit_test(test_ipv6_addresses),

View file

@ -6,6 +6,7 @@ CONFIG_NET_TCP=n
CONFIG_NET_IPV4=n
CONFIG_NET_MAX_CONTEXTS=4
CONFIG_NET_L2_DUMMY=y
CONFIG_NET_L2_ETHERNET=n
CONFIG_NET_LOG=y
CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y

View file

@ -3,6 +3,7 @@ CONFIG_NET_TEST=y
CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_NET_L2_DUMMY=y
CONFIG_NET_L2_ETHERNET=n
CONFIG_DNS_RESOLVER=y
CONFIG_DNS_RESOLVER_MAX_SERVERS=2
CONFIG_DNS_NUM_CONCUR_QUERIES=1

View file

@ -4,6 +4,7 @@ CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_NET_L2_DUMMY=y
CONFIG_NET_L2_ETHERNET=n
CONFIG_DNS_RESOLVER=y
CONFIG_DNS_RESOLVER_MAX_SERVERS=2

View file

@ -4,6 +4,7 @@ CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_NET_L2_DUMMY=y
CONFIG_NET_L2_ETHERNET=n
CONFIG_DNS_RESOLVER=y
CONFIG_DNS_RESOLVER_MAX_SERVERS=4

View file

@ -16,4 +16,5 @@ CONFIG_NET_MGMT_EVENT=y
CONFIG_NET_MGMT_EVENT_INFO=y
CONFIG_NET_IPV6=y
CONFIG_NET_L2_DUMMY=y
CONFIG_NET_L2_ETHERNET=n
CONFIG_ZTEST=y

View file

@ -118,12 +118,15 @@ static void thrower_thread(void)
if (with_info) {
net_mgmt_event_notify_with_info(
event2throw, net_if_get_default(),
event2throw,
net_if_get_first_by_type(
&NET_L2_GET_NAME(DUMMY)),
info_data,
TEST_MGMT_EVENT_INFO_SIZE);
} else {
net_mgmt_event_notify(event2throw,
net_if_get_default());
net_if_get_first_by_type(
&NET_L2_GET_NAME(DUMMY)));
}
}
@ -211,9 +214,10 @@ static int test_synchronous_event_listener(uint32_t times, bool on_iface)
k_sem_give(&thrower_lock);
if (on_iface) {
ret = net_mgmt_event_wait_on_iface(net_if_get_default(),
event_mask, NULL, NULL,
NULL, K_SECONDS(1));
ret = net_mgmt_event_wait_on_iface(
net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY)),
event_mask, NULL, NULL,
NULL, K_SECONDS(1));
} else {
ret = net_mgmt_event_wait(event_mask, NULL, NULL, NULL, NULL,
K_SECONDS(1));
@ -285,8 +289,9 @@ static int test_core_event(uint32_t event, bool (*func)(void))
static bool _iface_ip6_add(void)
{
if (net_if_ipv6_addr_add(net_if_get_default(),
&addr6, NET_ADDR_MANUAL, 0)) {
if (net_if_ipv6_addr_add(
net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY)),
&addr6, NET_ADDR_MANUAL, 0)) {
return true;
}
@ -295,7 +300,9 @@ static bool _iface_ip6_add(void)
static bool _iface_ip6_del(void)
{
if (net_if_ipv6_addr_rm(net_if_get_default(), &addr6)) {
if (net_if_ipv6_addr_rm(
net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY)),
&addr6)) {
return true;
}

View file

@ -7,6 +7,7 @@ CONFIG_NET_UDP=y
CONFIG_NET_TCP=n
CONFIG_NET_IPV4=n
CONFIG_NET_L2_DUMMY=y
CONFIG_NET_L2_ETHERNET=n
CONFIG_NET_LOG=y
CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y

View file

@ -206,7 +206,7 @@ static void test_mld_setup(void)
setup_mgmt_events();
iface = net_if_get_default();
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY));
zassert_not_null(iface, "Interface is NULL");
@ -400,9 +400,11 @@ static void send_query(struct net_if *iface)
*/
static void join_mldv2_capable_routers_group(void)
{
struct net_if *iface = net_if_get_default();
struct net_if *iface;
int ret;
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY));
net_ipv6_addr_create(&mcast_addr, 0xff02, 0, 0, 0, 0, 0, 0, 0x0016);
ret = net_ipv6_mld_join(iface, &mcast_addr);
@ -419,9 +421,11 @@ static void join_mldv2_capable_routers_group(void)
static void leave_mldv2_capable_routers_group(void)
{
struct net_if *iface = net_if_get_default();
struct net_if *iface;
int ret;
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY));
net_ipv6_addr_create(&mcast_addr, 0xff02, 0, 0, 0, 0, 0, 0, 0x0016);
ret = net_ipv6_mld_leave(iface, &mcast_addr);
@ -462,7 +466,7 @@ static void test_catch_query(void)
net_icmpv6_register_handler(&mld_query_input_handler);
send_query(net_if_get_default());
send_query(net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY)));
if (IS_ENABLED(CONFIG_NET_TC_THREAD_PREEMPTIVE)) {
/* Let the network stack to proceed */
@ -495,7 +499,7 @@ static void test_verify_send_report(void)
test_join_group();
send_query(net_if_get_default());
send_query(net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY)));
k_yield();

View file

@ -14,3 +14,4 @@ CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=3
CONFIG_NET_IPV6_MAX_NEIGHBORS=4
CONFIG_ZTEST=y
CONFIG_NET_L2_ETHERNET=n

View file

@ -3,6 +3,7 @@ CONFIG_PM_DEVICE=y
CONFIG_NETWORKING=y
CONFIG_NET_TEST=y
CONFIG_NET_L2_DUMMY=y
CONFIG_NET_L2_ETHERNET=n
CONFIG_NET_UDP=y
CONFIG_NET_IPV4=y
CONFIG_NET_SOCKETS=y

View file

@ -108,10 +108,12 @@ NET_DEVICE_INIT(fake_dev, "fake_dev",
void test_setup(void)
{
struct net_if *iface = net_if_get_default();
struct net_if *iface;
struct in_addr in4addr_my = { { { 192, 168, 0, 2 } } };
struct net_if_addr *ifaddr;
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY));
net_if_up(iface);
ifaddr = net_if_ipv4_addr_add(iface, &in4addr_my, NET_ADDR_MANUAL, 0);
@ -120,7 +122,8 @@ void test_setup(void)
void test_pm(void)
{
struct net_if *iface = net_if_get_default();
struct net_if *iface =
net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY));
const struct device *dev = net_if_get_device(iface);
char data[] = "some data";
struct sockaddr_in addr4;

View file

@ -6,6 +6,7 @@ CONFIG_NET_TCP=n
CONFIG_NET_IPV4=n
CONFIG_NET_MAX_CONTEXTS=4
CONFIG_NET_L2_DUMMY=y
CONFIG_NET_L2_ETHERNET=n
CONFIG_NET_LOG=y
CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y

View file

@ -237,8 +237,8 @@ static void test_init(void)
struct net_if_addr *ifaddr;
int i;
my_iface = net_if_get_default();
peer_iface = net_if_get_default() + 1;
my_iface = net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY));
peer_iface = net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY)) + 1;
DBG("Interfaces: [%d] my %p, [%d] peer %p\n",
net_if_get_by_iface(my_iface), my_iface,
@ -341,7 +341,7 @@ static void test_populate_nbr_cache(void)
zassert_true(net_test_send_ns(peer_iface, &peer_addr), NULL);
nbr = net_ipv6_nbr_add(net_if_get_default(),
nbr = net_ipv6_nbr_add(net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY)),
&peer_addr,
&net_route_data_peer.ll_addr,
false,

View file

@ -143,7 +143,7 @@ NET_DEVICE_INIT(net_udp_test, "net_udp_test",
static void test_setup(void)
{
struct net_if *iface = net_if_get_default();
struct net_if *iface;
struct net_if_addr *ifaddr;
struct sockaddr_in6 any_addr6;
@ -166,6 +166,7 @@ static void test_setup(void)
struct sockaddr_in peer_addr4;
struct in_addr in4addr_peer = { { { 192, 0, 2, 9 } } };
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY));
test_failed = false;
net_ipaddr_copy(&any_addr6.sin6_addr, &in6addr_any);

View file

@ -20,6 +20,8 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL);
#define STACK_SIZE 1024
#define THREAD_PRIORITY K_PRIO_COOP(8)
static struct net_if *default_iface;
static ZTEST_BMEM int fd;
static ZTEST_BMEM struct in6_addr addr_v6;
static ZTEST_DMEM struct in_addr addr_v4 = { { { 192, 0, 2, 3 } } };
@ -274,7 +276,7 @@ static void trigger_events(void)
struct net_if *iface;
int ret;
iface = net_if_get_default();
iface = default_iface;
net_ipv6_addr_create(&addr_v6, 0x2001, 0x0db8, 0, 0, 0, 0, 0, 0x0003);
@ -342,11 +344,25 @@ static char *get_ip_addr(char *ipaddr, size_t len, sa_family_t family,
return buf;
}
static void iface_cb(struct net_if *iface, void *user_data)
{
struct net_if **my_iface = user_data;
if (net_if_l2(iface) == &NET_L2_GET_NAME(ETHERNET)) {
if (PART_OF_ARRAY(NET_IF_GET_NAME(eth_fake, 0), iface)) {
*my_iface = iface;
}
}
}
static void test_net_mgmt_setup(void)
{
struct sockaddr_nm sockaddr;
int ret;
net_if_foreach(iface_cb, &default_iface);
zassert_not_null(default_iface, "Cannot find test interface");
fd = socket(AF_NET_MGMT, SOCK_DGRAM, NET_MGMT_EVENT_PROTO);
zassert_false(fd < 0, "Cannot create net_mgmt socket (%d)", errno);
@ -363,7 +379,7 @@ static void test_net_mgmt_setup(void)
memset(&sockaddr, 0, sizeof(sockaddr));
sockaddr.nm_family = AF_NET_MGMT;
sockaddr.nm_ifindex = net_if_get_by_iface(net_if_get_default());
sockaddr.nm_ifindex = net_if_get_by_iface(default_iface);
sockaddr.nm_pid = (uintptr_t)k_current_get();
sockaddr.nm_mask = NET_EVENT_IPV6_DAD_SUCCEED |
NET_EVENT_IPV6_ADDR_ADD |

View file

@ -1019,12 +1019,23 @@ ETH_NET_DEVICE_INIT(eth_fake, "eth_fake", eth_fake_init, NULL,
&eth_fake_data, NULL, CONFIG_ETH_INIT_PRIORITY,
&eth_fake_api_funcs, NET_ETH_MTU);
static void iface_cb(struct net_if *iface, void *user_data)
{
struct net_if **my_iface = user_data;
if (net_if_l2(iface) == &NET_L2_GET_NAME(ETHERNET)) {
if (PART_OF_ARRAY(NET_IF_GET_NAME(eth_fake, 0), iface)) {
*my_iface = iface;
}
}
}
static void test_setup_eth(void)
{
struct net_if_addr *ifaddr;
int ret;
eth_iface = net_if_get_first_by_type(&NET_L2_GET_NAME(ETHERNET));
net_if_foreach(iface_cb, &eth_iface);
zassert_not_null(eth_iface, "No ethernet interface found");
ifaddr = net_if_ipv6_addr_add(eth_iface, &my_addr1,

View file

@ -2,6 +2,7 @@ CONFIG_TEST=y
CONFIG_NETWORKING=y
CONFIG_NET_TEST=y
CONFIG_NET_L2_DUMMY=y
CONFIG_NET_L2_ETHERNET=n
CONFIG_NET_TCP=y
CONFIG_NET_MAX_CONN=64

View file

@ -276,7 +276,7 @@ static void address_setup(void)
struct net_if_addr *ifaddr;
struct net_if *iface1;
iface1 = net_if_get_default();
iface1 = net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY));
zassert_not_null(iface1, "Interface 1");
@ -379,7 +379,7 @@ static void setup_net_context(struct net_context **ctx)
int ret;
struct net_if *iface1;
iface1 = net_if_get_default();
iface1 = net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY));
ret = net_context_get(AF_INET6, SOCK_DGRAM, IPPROTO_UDP, ctx);
zassert_equal(ret, 0, "Create IPv6 UDP context %p failed (%d)\n",

View file

@ -1,6 +1,7 @@
CONFIG_NETWORKING=y
CONFIG_NET_TEST=y
CONFIG_NET_L2_DUMMY=y
CONFIG_NET_L2_ETHERNET=n
CONFIG_NET_UDP=y
CONFIG_NET_TCP=n
CONFIG_NET_MAX_CONN=64

View file

@ -431,7 +431,7 @@ void test_udp(void)
test_failed = false;
struct net_conn_handle *handlers[CONFIG_NET_MAX_CONN];
struct net_if *iface = net_if_get_default();
struct net_if *iface;
struct net_if_addr *ifaddr;
struct ud *ud;
int ret, i = 0;
@ -457,6 +457,8 @@ void test_udp(void)
struct sockaddr_in peer_addr4;
struct in_addr in4addr_peer = { { { 192, 0, 2, 9 } } };
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY));
net_ipaddr_copy(&any_addr6.sin6_addr, &in6addr_any);
any_addr6.sin6_family = AF_INET6;