From c7a989ad8f45e88439471952ae57db7cde612676 Mon Sep 17 00:00:00 2001 From: Jordan Yates Date: Thu, 19 Dec 2024 09:51:30 +1000 Subject: [PATCH] tests: nrf_modem_lib: lte_net_if: test MTU behaviour Test the behaviour of the network interface under the three conditions: 1. MTU successfully queried 2. Function reports success but MTU not set 3. Function reports error Signed-off-by: Jordan Yates --- tests/lib/nrf_modem_lib/lte_net_if/src/main.c | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/lib/nrf_modem_lib/lte_net_if/src/main.c b/tests/lib/nrf_modem_lib/lte_net_if/src/main.c index 89c90ea1fe55..79a00d465a06 100644 --- a/tests/lib/nrf_modem_lib/lte_net_if/src/main.c +++ b/tests/lib/nrf_modem_lib/lte_net_if/src/main.c @@ -411,6 +411,13 @@ void test_pdn_act_without_cereg_should_not_activate_iface(void) TEST_ASSERT_TRUE(net_if_is_dormant(net_if)); } +static int pdn_mtu_1000(uint8_t cid, struct in_addr *dns4_pri, + struct in_addr *dns4_sec, unsigned int *ipv4_mtu, int num_calls) +{ + *ipv4_mtu = 1000; + return 0; +} + /* Verify that PDN activation activates iface if cereg state is registered */ void test_pdn_act_with_cereg_should_activate_iface(void) { @@ -442,11 +449,17 @@ void test_pdn_act_with_cereg_should_activate_iface(void) "AT+CGPADDR=0", "+CGPADDR: %*d,\"%46[.:0-9A-F]\",\"%46[:0-9A-F]\"", 1); __mock_nrf_modem_at_scanf_ReturnVarg_string("192.9.201.39"); + /* Netowrk MTU is 1000 */ + __cmock_pdn_dynamic_params_get_Stub(&pdn_mtu_1000); + /* Fire PDN active */ pdn_event_handler_callback(0, PDN_EVENT_ACTIVATED, 0); /* Check that iface becomes active */ TEST_ASSERT_FALSE(net_if_is_dormant(net_if)); + + /* MTU should have been set to reported value */ + TEST_ASSERT_EQUAL(1000, net_if_get_mtu(net_if)); } @@ -504,6 +517,9 @@ void test_cereg_registered_home_with_pdn_should_activate_iface(void) "AT+CGPADDR=0", "+CGPADDR: %*d,\"%46[.:0-9A-F]\",\"%46[:0-9A-F]\"", 1); __mock_nrf_modem_at_scanf_ReturnVarg_string("192.9.201.39"); + /* MTU query fails */ + __cmock_pdn_dynamic_params_get_IgnoreAndReturn(-1); + /* Fire PDN active */ pdn_event_handler_callback(0, PDN_EVENT_ACTIVATED, 0); @@ -516,6 +532,9 @@ void test_cereg_registered_home_with_pdn_should_activate_iface(void) /* Check that iface becomes active */ TEST_ASSERT_FALSE(net_if_is_dormant(net_if)); + + /* MTU should have reverted to default minimum */ + TEST_ASSERT_EQUAL(NET_IPV4_MTU, net_if_get_mtu(net_if)); } /* Verify that CEREG registration (roaming) does activate iface if PDN is active */ @@ -542,6 +561,9 @@ void test_cereg_registered_roaming_with_pdn_should_activate_iface(void) "AT+CGPADDR=0", "+CGPADDR: %*d,\"%46[.:0-9A-F]\",\"%46[:0-9A-F]\"", 1); __mock_nrf_modem_at_scanf_ReturnVarg_string("192.9.201.39"); + /* MTU not set by function */ + __cmock_pdn_dynamic_params_get_IgnoreAndReturn(0); + /* Fire PDN active */ pdn_event_handler_callback(0, PDN_EVENT_ACTIVATED, 0); @@ -554,6 +576,9 @@ void test_cereg_registered_roaming_with_pdn_should_activate_iface(void) /* Check that iface becomes active */ TEST_ASSERT_FALSE(net_if_is_dormant(net_if)); + + /* MTU should have reverted to default minimum */ + TEST_ASSERT_EQUAL(NET_IPV4_MTU, net_if_get_mtu(net_if)); } /* Verify that CEREG searching does not affect iface activation (from inactive to active) */ @@ -602,6 +627,7 @@ void test_cereg_searching_should_not_deactivate_iface(void) */ __cmock_nrf_modem_is_initialized_IgnoreAndReturn(1); __cmock_lte_lc_func_mode_set_IgnoreAndReturn(0); + __cmock_pdn_dynamic_params_get_IgnoreAndReturn(0); /* Take the iface admin-up */ net_if_up(net_if); @@ -644,6 +670,7 @@ void test_cereg_unregistered_should_deactivate_iface(void) */ __cmock_nrf_modem_is_initialized_IgnoreAndReturn(1); __cmock_lte_lc_func_mode_set_IgnoreAndReturn(0); + __cmock_pdn_dynamic_params_get_IgnoreAndReturn(0); /* Take the iface admin-up */ net_if_up(net_if); @@ -686,6 +713,7 @@ void test_pdn_deact_should_deactivate_iface(void) */ __cmock_nrf_modem_is_initialized_IgnoreAndReturn(1); __cmock_lte_lc_func_mode_set_IgnoreAndReturn(0); + __cmock_pdn_dynamic_params_get_IgnoreAndReturn(0); /* Take the iface admin-up */ net_if_up(net_if);