tests: net: iface: Add unit test for interface name support

Check that we can set and get the network interface name.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This commit is contained in:
Jukka Rissanen 2023-08-25 11:11:16 +03:00 committed by Carles Cufí
parent 05b7eda618
commit bb5885580f

View file

@ -2,6 +2,7 @@
/*
* Copyright (c) 2016 Intel Corporation
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -1131,4 +1132,53 @@ ZTEST(net_iface, test_ipv6_addr_foreach)
zassert_equal(count, 0, "Incorrect number of callback calls");
}
ZTEST(net_iface, test_interface_name)
{
int ret;
#if defined(CONFIG_NET_INTERFACE_NAME)
char buf[CONFIG_NET_INTERFACE_NAME_LEN + 1];
struct net_if *iface;
char *name;
iface = net_if_get_default();
memset(buf, 0, sizeof(buf));
ret = net_if_get_name(NULL, NULL, -1);
zassert_equal(ret, -EINVAL, "Unexpected value returned");
ret = net_if_get_name(iface, NULL, -1);
zassert_equal(ret, -EINVAL, "Unexpected value returned");
ret = net_if_get_name(iface, buf, 0);
zassert_equal(ret, -EINVAL, "Unexpected value returned");
name = "mynetworkiface0";
ret = net_if_set_name(iface, name);
zassert_equal(ret, -ENAMETOOLONG, "Unexpected value (%d) returned", ret);
name = "eth0";
ret = net_if_set_name(iface, name);
zassert_equal(ret, 0, "Unexpected value (%d) returned", ret);
ret = net_if_get_name(iface, buf, 1);
zassert_equal(ret, -ERANGE, "Unexpected value (%d) returned", ret);
ret = net_if_get_name(iface, buf, strlen(name) - 1);
zassert_equal(ret, -ERANGE, "Unexpected value (%d) returned", ret);
ret = net_if_get_name(iface, buf, sizeof(buf) - 1);
zassert_equal(ret, strlen(name), "Unexpected value (%d) returned", ret);
ret = net_if_get_by_name(name);
zassert_equal(ret, net_if_get_by_iface(iface), "Unexpected value (%d) returned", ret);
ret = net_if_get_by_name("ENOENT");
zassert_equal(ret, -ENOENT, "Unexpected value (%d) returned", ret);
#else
ret = net_if_get_name(NULL, NULL, -1);
zassert_equal(ret, -ENOTSUP, "Invalid value returned");
#endif
}
ZTEST_SUITE(net_iface, NULL, iface_setup, NULL, NULL, iface_teardown);