Skip to content

Commit 2aa3d3e

Browse files
author
Me No Dev
committed
Merge remote-tracking branch 'esp8266/master'
2 parents 6b9edd4 + 7a2d246 commit 2aa3d3e

File tree

3 files changed

+101
-2
lines changed

3 files changed

+101
-2
lines changed

tests/device/libraries/BSTest/runner.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,18 @@ def __init__(self, spawn_obj, name, mocks):
4242

4343
def get_test_list(self):
4444
self.sp.sendline('-1')
45-
timeout = 10
45+
self.tests = []
46+
timeout = 100
4647
while timeout > 0:
4748
res = self.sp.expect(['>>>>>bs_test_menu_begin', EOF, TIMEOUT])
4849
if res == 0:
4950
break
5051
timeout-=1
5152
time.sleep(0.1)
53+
if timeout <= 0:
54+
debug_print('begin timeout')
55+
return
5256
debug_print('got begin')
53-
self.tests = []
5457
while True:
5558
res = self.sp.expect(['>>>>>bs_test_item id\=(\d+) name\="([^\"]*?)" desc="([^"]*?)"',
5659
'>>>>>bs_test_menu_end',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <Arduino.h>
2+
#include <ESP8266WiFi.h>
3+
#include <ESP8266mDNS.h>
4+
#include <WiFiClient.h>
5+
#include <BSTest.h>
6+
#include <test_config.h>
7+
8+
9+
BS_ENV_DECLARE();
10+
11+
void setup()
12+
{
13+
Serial.begin(115200);
14+
WiFi.persistent(false);
15+
WiFi.begin(STA_SSID, STA_PASS);
16+
while (WiFi.status() != WL_CONNECTED) {
17+
delay(500);
18+
}
19+
MDNS.begin("esp8266-wfs-test");
20+
BS_RUN(Serial);
21+
}
22+
23+
TEST_CASE("Simple echo server", "[WiFiServer]")
24+
{
25+
const uint32_t timeout = 10000;
26+
const uint16_t port = 5000;
27+
const int maxRequests = 5;
28+
const int minRequestLength = 128;
29+
WiFiServer server(port);
30+
server.begin();
31+
auto start = millis();
32+
33+
int replyCount = 0;
34+
while (millis() - start < timeout) {
35+
delay(50);
36+
WiFiClient client = server.available();
37+
if (!client) {
38+
continue;
39+
}
40+
String request = client.readStringUntil('\n');
41+
CHECK(request.length() >= minRequestLength);
42+
client.print(request);
43+
client.print('\n');
44+
if (++replyCount == maxRequests) {
45+
break;
46+
}
47+
}
48+
CHECK(replyCount == maxRequests);
49+
}
50+
51+
void loop()
52+
{
53+
}
54+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from mock_decorators import setup, teardown
2+
from threading import Thread
3+
import socket
4+
import time
5+
6+
stop_client_thread = False
7+
client_thread = None
8+
9+
@setup('Simple echo server')
10+
def setup_echo_server(e):
11+
global stop_client_thread
12+
global client_thread
13+
def echo_client_thread():
14+
server_address = socket.gethostbyname('esp8266-wfs-test.local')
15+
count = 0
16+
while count < 5 and not stop_client_thread:
17+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
18+
sock.connect((server_address, 5000))
19+
sock.settimeout(1.0)
20+
buf = 'a' * 1023 + '\n'
21+
sock.sendall(buf)
22+
data = ''
23+
retries = 0
24+
while len(data) < 1024 and retries < 3:
25+
data += sock.recv(1024)
26+
retries += 1
27+
print 'Received {} bytes'.format(len(data))
28+
if len(data) != 1024:
29+
raise RuntimeError('client failed to receive response')
30+
count += 1
31+
32+
stop_client_thread = False
33+
client_thread = Thread(target=echo_client_thread)
34+
client_thread.start()
35+
36+
@teardown('Simple echo server')
37+
def teardown_echo_server(e):
38+
global stop_client_thread
39+
stop_client_thread = True
40+
client_thread.join()
41+
42+

0 commit comments

Comments
 (0)