1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-30 16:24:09 +03:00

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.
This commit is contained in:
Ivan Grokhotkov
2018-04-10 16:27:19 +08:00
committed by Ivan Grokhotkov
parent 2315ac20bc
commit 8bd26f2ded
21 changed files with 306 additions and 78 deletions

View File

@ -2,7 +2,6 @@
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <BSTest.h>
#include <test_config.h>
#include <pgmspace.h>
BS_ENV_DECLARE();
@ -12,7 +11,7 @@ void setup()
Serial.begin(115200);
Serial.setDebugOutput(true);
WiFi.persistent(false);
WiFi.begin(STA_SSID, STA_PASS);
WiFi.begin(getenv("STA_SSID"), getenv("STA_PASS"));
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
@ -26,7 +25,7 @@ TEST_CASE("HTTP GET & POST requests", "[HTTPClient]")
{
// small request
HTTPClient http;
http.begin(SERVER_IP, 8088, "/");
http.begin(getenv("SERVER_IP"), 8088, "/");
auto httpCode = http.GET();
REQUIRE(httpCode == HTTP_CODE_OK);
String payload = http.getString();
@ -35,7 +34,7 @@ TEST_CASE("HTTP GET & POST requests", "[HTTPClient]")
{
// request which returns 8000 bytes
HTTPClient http;
http.begin(SERVER_IP, 8088, "/data?size=8000");
http.begin(getenv("SERVER_IP"), 8088, "/data?size=8000");
auto httpCode = http.GET();
REQUIRE(httpCode == HTTP_CODE_OK);
String payload = http.getString();
@ -50,7 +49,7 @@ TEST_CASE("HTTP GET & POST requests", "[HTTPClient]")
{
// can do two POST requests with one HTTPClient object (#1902)
HTTPClient http;
http.begin(SERVER_IP, 8088, "/");
http.begin(getenv("SERVER_IP"), 8088, "/");
http.addHeader("Content-Type", "text/plain");
auto httpCode = http.POST("foo");
Serial.println(httpCode);
@ -69,7 +68,7 @@ TEST_CASE("HTTPS GET request", "[HTTPClient]")
{
// small request
HTTPClient http;
http.begin(SERVER_IP, 8088, "/", fp);
http.begin(getenv("SERVER_IP"), 8088, "/", fp);
auto httpCode = http.GET();
REQUIRE(httpCode == HTTP_CODE_OK);
String payload = http.getString();
@ -78,7 +77,7 @@ TEST_CASE("HTTPS GET request", "[HTTPClient]")
{
// request which returns 8000 bytes
HTTPClient http;
http.begin(SERVER_IP, 8088, "/data?size=4000", fp);
http.begin(getenv("SERVER_IP"), 8088, "/data?size=4000", fp);
auto httpCode = http.GET();
REQUIRE(httpCode == HTTP_CODE_OK);
String payload = http.getString();