Skip to content

Commit a8e35a5

Browse files
Add valgrind mocked test to CI (#7501)
Run valgrind on host mock example runs to catch more bugs in CI. These tests would have caught the problem in #7464 before users did. Add a list of some randomly picked examples to run, and add an option to run the loop exactly once in the host mock routine, so the test will actually exit under valgrind.
1 parent fc1aa55 commit a8e35a5

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

Diff for: libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino

+6-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ void setup() {
4444
}
4545

4646
void loop() {
47+
static bool wait = false;
48+
4749
Serial.print("connecting to ");
4850
Serial.print(host);
4951
Serial.print(':');
@@ -87,5 +89,8 @@ void loop() {
8789
Serial.println("closing connection");
8890
client.stop();
8991

90-
delay(300000); // execute once every 5 minutes, don't flood remote service
92+
if (wait) {
93+
delay(300000); // execute once every 5 minutes, don't flood remote service
94+
}
95+
wait = true;
9196
}

Diff for: tests/ci/host_test.sh

+14-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,18 @@ set -ev
66

77
cd $TRAVIS_BUILD_DIR/tests/host
88

9-
make CI
9+
10+
make -j2 ssl
11+
for i in ../../libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient \
12+
../../libraries/ESP8266WiFi/examples/BearSSL_Validation/BearSSL_Validation \
13+
../../libraries/ESP8266WebServer/examples/HelloServer/HelloServer \
14+
../../libraries/SD/examples/Files/Files \
15+
../../libraries/LittleFS/examples/LittleFS_Timestamp/LittleFS_Timestamp \
16+
../../libraries/LittleFS/examples/SpeedTest/SpeedTest ; do
17+
make -j2 D=1 $i
18+
valgrind --leak-check=full --track-origins=yes --error-limit=no --show-leak-kinds=all --error-exitcode=999 bin/$(basename $i)/$(basename $i) -1
19+
done
20+
21+
make -j2 CI
22+
1023
make clean-objects

Diff for: tests/host/common/ArduinoMain.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#define MOCK_PORT_SHIFTER 9000
4343

4444
bool user_exit = false;
45+
bool run_once = false;
4546
const char* host_interface = nullptr;
4647
size_t spiffs_kb = 1024;
4748
size_t littlefs_kb = 1024;
@@ -137,6 +138,7 @@ void help (const char* argv0, int exitcode)
137138
"\tgeneral:\n"
138139
"\t-c - ignore CTRL-C (send it via Serial)\n"
139140
"\t-f - no throttle (possibly 100%%CPU)\n"
141+
"\t-1 - run loop once then exit (for host testing)\n"
140142
"\t-v - verbose\n"
141143
, argv0, MOCK_PORT_SHIFTER, argv0, spiffs_kb, littlefs_kb);
142144
exit(exitcode);
@@ -152,10 +154,11 @@ static struct option options[] =
152154
{ "verbose", no_argument, NULL, 'v' },
153155
{ "timestamp", no_argument, NULL, 'T' },
154156
{ "interface", required_argument, NULL, 'i' },
155-
{ "fspath", required_argument, NULL, 'P' },
157+
{ "fspath", required_argument, NULL, 'P' },
156158
{ "spiffskb", required_argument, NULL, 'S' },
157159
{ "littlefskb", required_argument, NULL, 'L' },
158160
{ "portshifter", required_argument, NULL, 's' },
161+
{ "once", no_argument, NULL, '1' },
159162
};
160163

161164
void cleanup ()
@@ -209,7 +212,7 @@ int main (int argc, char* const argv [])
209212

210213
for (;;)
211214
{
212-
int n = getopt_long(argc, argv, "hlcfbvTi:S:s:L:P:", options, NULL);
215+
int n = getopt_long(argc, argv, "hlcfbvTi:S:s:L:P:1", options, NULL);
213216
if (n < 0)
214217
break;
215218
switch (n)
@@ -250,6 +253,9 @@ int main (int argc, char* const argv [])
250253
case 'T':
251254
serial_timestamp = true;
252255
break;
256+
case '1':
257+
run_once = true;
258+
break;
253259
default:
254260
help(argv[0], EXIT_FAILURE);
255261
}
@@ -300,6 +306,9 @@ int main (int argc, char* const argv [])
300306
usleep(1000); // not 100% cpu, ~1000 loops per second
301307
loop();
302308
check_incoming_udp();
309+
310+
if (run_once)
311+
user_exit = true;
303312
}
304313
cleanup();
305314

0 commit comments

Comments
 (0)