tests: net: dhcpv4_server: Add test to verify initialization

Add test that verifies that initialization fails if wrong arguments are
provided.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2024-01-29 12:34:18 +01:00 committed by Fabio Baltieri
parent a147ac9a47
commit 5a08fea48e

View file

@ -840,6 +840,25 @@ ZTEST(dhcpv4_server_tests, test_inform)
verify_lease_count(0, 0, 0);
}
/* Verify that the DHCP server can start and validate input properly. */
ZTEST(dhcpv4_server_tests_no_init, test_initialization)
{
struct in_addr base_addr_wrong_subnet = { { { 192, 0, 3, 10 } } };
struct in_addr base_addr_overlap = { { { 192, 0, 2, 1 } } };
int ret;
ret = net_dhcpv4_server_start(test_ctx.iface, &base_addr_wrong_subnet);
zassert_equal(ret, -EINVAL, "Started server for wrong subnet");
ret = net_dhcpv4_server_start(test_ctx.iface, &base_addr_overlap);
zassert_equal(ret, -EINVAL, "Started server for overlapping address");
ret = net_dhcpv4_server_start(test_ctx.iface, &test_base_addr);
zassert_ok(ret, "Failed to start server for valid address range");
net_dhcpv4_server_stop(test_ctx.iface);
}
static void dhcpv4_server_tests_before(void *fixture)
{
ARG_UNUSED(fixture);
@ -865,3 +884,5 @@ static void dhcpv4_server_tests_after(void *fixture)
ZTEST_SUITE(dhcpv4_server_tests, NULL, NULL, dhcpv4_server_tests_before,
dhcpv4_server_tests_after, NULL);
ZTEST_SUITE(dhcpv4_server_tests_no_init, NULL, NULL, NULL, NULL, NULL);