From 0550ccd46bd8b49241b17be0b22123bb8e30edef Mon Sep 17 00:00:00 2001 From: liebman Date: Sat, 8 Dec 2018 16:22:29 -0800 Subject: [PATCH] device test updates (#5455) add test_ping fix test_millis_mm --- .../device/test_millis_mm/test_millis_mm.ino | 1 - tests/device/test_ping/test_ping.ino | 60 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 tests/device/test_ping/test_ping.ino diff --git a/tests/device/test_millis_mm/test_millis_mm.ino b/tests/device/test_millis_mm/test_millis_mm.ino index 4bc4c78e2..e7cb59cea 100644 --- a/tests/device/test_millis_mm/test_millis_mm.ino +++ b/tests/device/test_millis_mm/test_millis_mm.ino @@ -14,7 +14,6 @@ extern "C" { // SDK functions for Arduino IDE access #include "osapi.h" #include "user_interface.h" -#include "espconn.h" } //end, 'extern C' //--------------------------------------------------------------------------- diff --git a/tests/device/test_ping/test_ping.ino b/tests/device/test_ping/test_ping.ino new file mode 100644 index 000000000..29596745a --- /dev/null +++ b/tests/device/test_ping/test_ping.ino @@ -0,0 +1,60 @@ +#include +#include +#include + +#include + +BS_ENV_DECLARE(); + +void setup() +{ + Serial.begin(115200); + Serial.setDebugOutput(true); + WiFi.persistent(false); + WiFi.mode(WIFI_STA); + WiFi.begin(getenv("STA_SSID"), getenv("STA_PASS")); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + } + BS_RUN(Serial); +} + +static struct ping_option po; +static const uint32_t PING_COUNT = 5; +static volatile uint32_t recv_count; +static volatile uint32_t done_count; + +static void ping_recv(void* options, void* resp) +{ + (void)options; + (void)resp; + ++recv_count; +} + +static void ping_done(void* options, void* resp) +{ + (void)options; + (void)resp; + done_count = ((struct ping_resp*)resp)->total_count; +} + +TEST_CASE("pings sent/answered", "[lwip]") +{ + IPAddress address; + if (WiFi.hostByName(getenv("SERVER_IP"), address)) + { + po.ip = address; + po.count = PING_COUNT; + po.coarse_time = 1; + po.sent_function = &ping_done; + po.recv_function = &ping_recv; + ping_start(&po); + delay((PING_COUNT+2)*1000); + } + REQUIRE(recv_count == PING_COUNT); + REQUIRE(done_count == PING_COUNT); +} + +void loop() +{ +}