forked from esp8266/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_ClientContext.ino
94 lines (78 loc) · 2 KB
/
test_ClientContext.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <Arduino.h>
#include <BSTest.h>
#include <test_config.h>
#include <ESP8266WiFi.h>
extern "C" {
#include "user_interface.h"
}
BS_ENV_DECLARE();
// no need for #include
struct tcp_pcb;
extern struct tcp_pcb* tcp_tw_pcbs;
extern "C" void tcp_abort (struct tcp_pcb* pcb);
void tcpCleanup (void)
{
while (tcp_tw_pcbs)
tcp_abort(tcp_tw_pcbs);
}
void setup()
{
Serial.begin(115200);
Serial.setDebugOutput(true);
WiFi.persistent(false);
WiFi.mode(WIFI_STA);
WiFi.begin(STA_SSID, STA_PASS);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
BS_RUN(Serial);
}
TEST_CASE("WiFi release ClientContext", "[clientcontext]")
{
#define MAXLOOPS 50
#define SUCCESS_GOAL 10
#define srv SERVER_IP
WiFiClient client;
Serial.print(srv);
// look for reachable port on gateway
int port;
for (port = 8266; port <= 8285; port++)
if (client.connect(srv, port))
{
client.stop();
break;
}
if (port > 8285)
port = 0;
Serial.printf(":%d\r\n", port);
int loops = 0;
int success = 0;
if (port)
{
tcpCleanup();
int heapStart = ESP.getFreeHeap();
int minHeap = heapStart / 2;
int heap = heapStart;
Serial.printf("heap: %d\r\n", heap);
while (success < SUCCESS_GOAL && ++loops <= MAXLOOPS && (int)ESP.getFreeHeap() > minHeap)
if (client.connect(srv, port))
{
client.stop();
tcpCleanup();
int newHeap = (int)ESP.getFreeHeap();
Serial.printf("%03d %5d %d\r\n", loops, newHeap, newHeap - heap);
if (newHeap - heap == 0)
success++;
heap = newHeap;
}
Serial.printf("heap: %d\r\n"
"loops: %d\r\nstable-loops: %d\r\n",
ESP.getFreeHeap(),
loops,
success);
}
REQUIRE(success >= SUCCESS_GOAL);
}
void loop()
{
}