mirror of
				https://github.com/esp8266/Arduino.git
				synced 2025-10-30 04:26:50 +03:00 
			
		
		
		
	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.
		
			
				
	
	
		
			56 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| #include <Arduino.h>
 | |
| #include <BSTest.h>
 | |
| #include <ESP8266WiFi.h>
 | |
| #include <Ticker.h>
 | |
| 
 | |
| extern "C" {
 | |
| #include "user_interface.h"
 | |
| }
 | |
| 
 | |
| 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 void stopAll()
 | |
| {
 | |
|     WiFiClient::stopAll();
 | |
| }
 | |
| 
 | |
| static void disconnectWiFI()
 | |
| {
 | |
|     wifi_station_disconnect();
 | |
| }
 | |
| 
 | |
| /* Some IP address that we can try connecting to, and expect a timeout */
 | |
| #define UNREACHABLE_IP "192.168.255.255"
 | |
| 
 | |
| TEST_CASE("WiFiClient::stopAll during WiFiClient::connect", "[wificlient]")
 | |
| {
 | |
|     WiFiClient client;
 | |
|     Ticker t;
 | |
|     t.once_ms(500, &stopAll);
 | |
|     REQUIRE(client.connect(UNREACHABLE_IP, 1024) == 0);
 | |
| }
 | |
| 
 | |
| TEST_CASE("WiFi disconnect during WiFiClient::connect", "[wificlient]")
 | |
| {
 | |
|     WiFiClient client;
 | |
|     Ticker t;
 | |
|     t.once_ms(500, &disconnectWiFI);
 | |
|     REQUIRE(client.connect(UNREACHABLE_IP, 1024) == 0);
 | |
| }
 | |
| 
 | |
| void loop()
 | |
| {
 | |
| } |