From 1a0e7d81d8e4e6ff4d1d4119f1ae7984dd0452ef Mon Sep 17 00:00:00 2001 From: David Cermak Date: Wed, 29 Jul 2020 11:35:28 +0200 Subject: [PATCH] esp_netif tests: Add manual DHCP state transision tests Extended test cases for DHCP server and DHCP client state transitions to include also manual transitions using esp_netif_dhcps_start/stop() esp_netif_dhcpc_start/stop() --- components/esp_netif/test/test_esp_netif.c | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/components/esp_netif/test/test_esp_netif.c b/components/esp_netif/test/test_esp_netif.c index a3d8447099..69f158cd4f 100644 --- a/components/esp_netif/test/test_esp_netif.c +++ b/components/esp_netif/test/test_esp_netif.c @@ -84,8 +84,20 @@ TEST_CASE("esp_netif: test dhcp client state transitions for wifi station", "[es TEST_ASSERT_EQUAL(ESP_NETIF_DHCP_INIT, state); esp_netif_action_connected(sta, NULL, 0, NULL); TEST_ASSERT_EQUAL(ESP_OK, esp_netif_dhcpc_get_status(sta, &state)); - TEST_ASSERT_EQUAL(ESP_NETIF_DHCP_STARTED, state); + + // test manual DHCP state transitions using dhcpc-start/stop API + TEST_ASSERT_EQUAL(ESP_OK, esp_netif_dhcpc_stop(sta)); + TEST_ASSERT_EQUAL(ESP_OK, esp_netif_dhcpc_get_status(sta, &state)); + TEST_ASSERT_EQUAL(ESP_NETIF_DHCP_STOPPED, state); + TEST_ASSERT_EQUAL(ESP_OK, esp_netif_dhcpc_start(sta)); + TEST_ASSERT_EQUAL(ESP_OK, esp_netif_dhcpc_get_status(sta, &state)); + TEST_ASSERT_EQUAL(ESP_NETIF_DHCP_STARTED, state); + TEST_ASSERT_EQUAL(ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED, esp_netif_dhcpc_start(sta)); + TEST_ASSERT_EQUAL(ESP_OK, esp_netif_dhcpc_get_status(sta, &state)); + TEST_ASSERT_EQUAL(ESP_NETIF_DHCP_STARTED, state); + + // stop the netif and test dhcp state update esp_netif_action_stop(sta, NULL, 0, NULL); TEST_ASSERT_EQUAL(ESP_OK, esp_netif_dhcpc_get_status(sta, &state)); @@ -117,6 +129,18 @@ TEST_CASE("esp_netif: test dhcp server state transitions for wifi soft AP", "[es TEST_ASSERT_EQUAL(ESP_OK, esp_netif_dhcps_get_status(ap, &state)); TEST_ASSERT_EQUAL(ESP_NETIF_DHCP_STARTED, state); + // test manual DHCP state transitions using dhcps-start/stop API + TEST_ASSERT_EQUAL(ESP_OK, esp_netif_dhcps_stop(ap)); + TEST_ASSERT_EQUAL(ESP_OK, esp_netif_dhcps_get_status(ap, &state)); + TEST_ASSERT_EQUAL(ESP_NETIF_DHCP_STOPPED, state); + TEST_ASSERT_EQUAL(ESP_OK, esp_netif_dhcps_start(ap)); + TEST_ASSERT_EQUAL(ESP_OK, esp_netif_dhcps_get_status(ap, &state)); + TEST_ASSERT_EQUAL(ESP_NETIF_DHCP_STARTED, state); + TEST_ASSERT_EQUAL(ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED, esp_netif_dhcps_start(ap)); + TEST_ASSERT_EQUAL(ESP_OK, esp_netif_dhcps_get_status(ap, &state)); + TEST_ASSERT_EQUAL(ESP_NETIF_DHCP_STARTED, state); + + // stop the netif and test dhcp state update esp_netif_action_stop(ap, NULL, 0, NULL); TEST_ASSERT_EQUAL(ESP_OK, esp_netif_dhcps_get_status(ap, &state)); TEST_ASSERT_EQUAL(ESP_NETIF_DHCP_INIT, state);