Skip to content

Commit

Permalink
tests: nrf_modem_lib: lte_net_if: test MTU behaviour
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
JordanYates committed Dec 18, 2024
1 parent 94871ce commit c7a989a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/lib/nrf_modem_lib/lte_net_if/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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));
}


Expand Down Expand Up @@ -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);

Expand All @@ -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 */
Expand All @@ -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);

Expand All @@ -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) */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c7a989a

Please sign in to comment.