1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-22 21:23:07 +03:00
esp8266/tests/device/test_WiFiServer/test_WiFiServer.ino
Ivan Grokhotkov 8bd26f2ded add support for environment variables in device tests
Previously device tests included information such as access point SSID/password at compile time. This made it difficult to compile test binaries once and then send them to multiple test runners for execution.

This change adds a command to the test library to set environment variable on the target device: “setenv key value”. C library setenv/getenv facility is used to store variables.

Test runner, tests, and makefile are updated to use this functionality.
2018-04-11 11:19:21 +08:00

54 lines
1.1 KiB
C++

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiClient.h>
#include <BSTest.h>
BS_ENV_DECLARE();
void setup()
{
Serial.begin(115200);
WiFi.persistent(false);
WiFi.begin(getenv("STA_SSID"), getenv("STA_PASS"));
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
MDNS.begin("esp8266-wfs-test");
BS_RUN(Serial);
}
TEST_CASE("Simple echo server", "[WiFiServer]")
{
const uint32_t timeout = 10000;
const uint16_t port = 5000;
const int maxRequests = 5;
const int minRequestLength = 128;
WiFiServer server(port);
server.begin();
auto start = millis();
int replyCount = 0;
while (millis() - start < timeout) {
delay(50);
WiFiClient client = server.available();
if (!client) {
continue;
}
String request = client.readStringUntil('\n');
CHECK(request.length() >= minRequestLength);
client.print(request);
client.print('\n');
if (++replyCount == maxRequests) {
break;
}
}
CHECK(replyCount == maxRequests);
}
void loop()
{
}