net: conn_mgr: Minor fixes

- Add missing event sleep after taking all ifaces up in
  test_connect_disconnect.
- Add missing event sleep after resetting ifaces in conn_mgr_conn_before
- Fix typo in comment for internal state flags.
- Add missing NET_MGMT_EVENT_BIT to conn_mgr_connectivity event
  definitions.
- Missing net_mgmt.h include in conn_mgr_connectivity.h
- Split conn_mgr_conn iface reset into network and state resets, before
  and after event sleep, so that triggered events do not corrupt the
  state reset.
- Reduce SIMULATED_EVENT_DELAY to 100ms to avoid timeouts on real-time
  targets.
- Use macro for simulated event wait times.

Signed-off-by: Georges Oates_Larsen <georges.larsen@nordicsemi.no>
This commit is contained in:
Georges Oates_Larsen 2023-04-28 14:38:23 -07:00 committed by Carles Cufí
parent 70655721fb
commit 8785a9f424
5 changed files with 41 additions and 13 deletions

View file

@ -16,6 +16,7 @@
#include <zephyr/device.h>
#include <zephyr/net/net_if.h>
#include <zephyr/sys/iterable_sections.h>
#include <zephyr/net/net_mgmt.h>
#ifdef __cplusplus
extern "C" {
@ -34,7 +35,8 @@ extern "C" {
/* Connectivity Events */
#define _NET_MGMT_CONN_LAYER NET_MGMT_LAYER(NET_MGMT_LAYER_L2)
#define _NET_MGMT_CONN_CODE NET_MGMT_LAYER_CODE(0x207)
#define _NET_MGMT_CONN_BASE (_NET_MGMT_CONN_LAYER | _NET_MGMT_CONN_CODE)
#define _NET_MGMT_CONN_BASE (_NET_MGMT_CONN_LAYER | _NET_MGMT_CONN_CODE | \
NET_MGMT_EVENT_BIT)
#define _NET_MGMT_CONN_IF_EVENT (NET_MGMT_IFACE_BIT | _NET_MGMT_CONN_BASE)
enum net_event_ethernet_cmd {

View file

@ -27,7 +27,7 @@
/* Configuration flags */
#define CONN_MGR_IF_IGNORED BIT(7)
/* Internal state flags*/
/* Internal state flags */
#define CONN_MGR_IF_READY BIT(14)
/* Event flags */

View file

@ -29,7 +29,12 @@ static inline struct test_conn_data *conn_mgr_if_get_data(struct net_if *iface)
return binding->ctx;
}
static void reset_test_iface(struct net_if *iface)
/**
* @brief Reset the network state of the provided iface.
*
* @param iface - iface to reset.
*/
static void reset_test_iface_networking(struct net_if *iface)
{
if (net_if_is_admin_up(iface)) {
(void)net_if_down(iface);
@ -37,7 +42,15 @@ static void reset_test_iface(struct net_if *iface)
/* Some tests can leave the iface in a bad state where it is admin-down but not dormant */
net_if_dormant_on(iface);
}
/**
* @brief Reset testing state for the provided iface.
*
* @param iface - iface to reset.
*/
static void reset_test_iface_state(struct net_if *iface)
{
struct conn_mgr_conn_binding *iface_binding = conn_mgr_if_get_binding(iface);
struct test_conn_data *iface_data = conn_mgr_if_get_data(iface);
@ -98,12 +111,22 @@ static void conn_mgr_conn_handler(struct net_mgmt_event_callback *cb,
static void conn_mgr_conn_before(void *data)
{
ARG_UNUSED(data);
reset_test_iface(ifa1);
reset_test_iface(ifa2);
reset_test_iface(ifb);
reset_test_iface(ifni);
reset_test_iface(ifnone);
reset_test_iface(ifnull);
reset_test_iface_networking(ifa1);
reset_test_iface_networking(ifa2);
reset_test_iface_networking(ifb);
reset_test_iface_networking(ifni);
reset_test_iface_networking(ifnone);
reset_test_iface_networking(ifnull);
/* Allow any triggered events to shake out */
k_sleep(SIMULATED_EVENT_WAIT_TIME);
reset_test_iface_state(ifa1);
reset_test_iface_state(ifa2);
reset_test_iface_state(ifb);
reset_test_iface_state(ifni);
reset_test_iface_state(ifnone);
reset_test_iface_state(ifnull);
k_mutex_lock(&event_mutex, K_FOREVER);
@ -171,6 +194,7 @@ ZTEST(conn_mgr_conn, test_connect_disconnect)
zassert_equal(net_if_up(ifa1), 0, "net_if_up should not fail");
zassert_equal(net_if_up(ifa2), 0, "net_if_up should not fail");
zassert_equal(net_if_up(ifb), 0, "net_if_up should not fail");
k_sleep(K_MSEC(1));
/* Verify ifaces are still disconnected */
zassert_false(net_if_is_up(ifa1), "Ifaces must be disconnected before test");
@ -526,7 +550,7 @@ ZTEST(conn_mgr_conn, test_connect_timeout)
zassert_false(net_if_is_up(ifa1), "ifa1 should not be up if instructed to time out");
/* Ensure timeout event is fired */
k_sleep(K_SECONDS(SIMULATED_EVENT_DELAY_SECONDS + 1));
k_sleep(SIMULATED_EVENT_WAIT_TIME);
k_mutex_lock(&event_mutex, K_FOREVER);
stats = test_event_stats;
@ -557,7 +581,7 @@ ZTEST(conn_mgr_conn, test_connect_fatal_error)
zassert_false(net_if_is_up(ifa1), "ifa1 should not be up if instructed to time out");
/* Ensure fatal_error event is fired */
k_sleep(K_SECONDS(SIMULATED_EVENT_DELAY_SECONDS + 1));
k_sleep(SIMULATED_EVENT_WAIT_TIME);
k_mutex_lock(&event_mutex, K_FOREVER);
stats = test_event_stats;

View file

@ -57,7 +57,7 @@ static void simulate_event(struct net_if *target, int event)
simulated_event = event;
simulated_event_iface = target;
k_work_reschedule(&simulate_event_work, K_SECONDS(SIMULATED_EVENT_DELAY_SECONDS));
k_work_reschedule(&simulate_event_work, SIMULATED_EVENT_DELAY_TIME);
k_mutex_unlock(&simulated_event_mutex);
}

View file

@ -76,7 +76,9 @@ CONN_MGR_CONN_DECLARE_PUBLIC(TEST_L2_CONN_IMPL_N);
#define TEST_L2_CONN_IMPL_NI_CTX_TYPE struct test_conn_data
CONN_MGR_CONN_DECLARE_PUBLIC(TEST_L2_CONN_IMPL_NI);
#define SIMULATED_EVENT_DELAY_SECONDS 5
#define SIMULATED_EVENT_DELAY_MS 100
#define SIMULATED_EVENT_DELAY_TIME K_MSEC(SIMULATED_EVENT_DELAY_MS)
#define SIMULATED_EVENT_WAIT_TIME K_MSEC(SIMULATED_EVENT_DELAY_MS + 10)
#ifdef __cplusplus
}