Skip to content

Commit 95908fb

Browse files
authored
Merge pull request #31 from ARMmbed/g-testing-cleanup
Add documentation and fix issues in the network tests
2 parents 918caa0 + 6081f72 commit 95908fb

File tree

16 files changed

+86
-132
lines changed

16 files changed

+86
-132
lines changed

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,33 @@ The mbed OS driver for the ESP8266 WiFi module
55
ESP8266 modules come in different shapes and forms, but most important difference is which firmware version it is programmed with. To make sure that your module has mbed-os compatible firmware follow update guide: https://developer.mbed.org/teams/ESP8266/wiki/Firmware-Update
66

77
## Testing
8-
The ESP8266 library contains the core network tests taken from mbed OS. After installing mbed CLI and importing the mbed OS library, the tests can be ran with the `mbed test` command:
8+
The ESP8266 library contains the core network tests taken from mbed OS. To run the tests you will need mbed CLI and mbed OS.
9+
10+
First, setup the the esp8266-driver and mbed-os repositories for testing:
11+
``` bash
12+
# Sets up the ESP8266 for testing
13+
mbed import esp8266-driver
14+
cd esp8266-driver
15+
mbed add mbed-os
16+
```
17+
18+
Now you should be able to run the network tests with `mbed test`:
919
``` bash
1020
# Runs the ESP8266 network tests, requires a wifi access point
11-
mbed test -t <COMPILER HERE> -m <BOARD HERE> -n tests-net* --compile -DMBED_CFG_ESP8266_SSID='"<SSID HERE>"' -DMBED_CFG_ESP8266_PASS='"<PASS HERE>"'
21+
mbed test -t <COMPILER HERE> -m <BOARD HERE> -n tests-net* --compile -DMBED_CFG_ESP8266_SSID='<SSID HERE>' -DMBED_CFG_ESP8266_PASS='<PASS HERE>'
22+
mbed test -t <COMPILER HERE> -m <BOARD HERE> -n tests-net* --run --verbose
23+
```
24+
25+
There are a couple other options that can be used during testing:
26+
- MBED_CFG_ESP8266_SSID - SSID of the wifi access point to connect to
27+
- MBED_CFG_ESP8266_SSID - Passphrase of the wifi access point to connect to
28+
- MBED_CFG_ESP8266_TX - TX pin for the ESP8266 serial connection (defaults to D1)
29+
- MBED_CFG_ESP8266_RX - TX pin for the ESP8266 serial connection (defaults to D0)
30+
- MBED_CFG_ESP8266_DEBUG - Enabled debug output from the ESP8266
31+
32+
For example, here is how to enabled the debug output from the ESP8266:
33+
``` bash
34+
# Run the ESP8266 network tests with debug output, requires a wifi access point
35+
mbed test -t <COMPILER HERE> -m <BOARD HERE> -n tests-net* --compile -DMBED_CFG_ESP8266_SSID='<SSID HERE>' -DMBED_CFG_ESP8266_PASS='<PASS HERE>' -DMBED_CFG_ESP8266_DEBUG=true
1236
mbed test -t <COMPILER HERE> -m <BOARD HERE> -n tests-net* --run --verbose
1337
```

TESTS/net/connectivity/main.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ using namespace utest::v1;
1919
#define MBED_CFG_ESP8266_DEBUG false
2020
#endif
2121

22+
#define STRINGIZE(x) STRINGIZE2(x)
23+
#define STRINGIZE2(x) #x
24+
2225

2326
// Bringing the network up and down
2427
template <int COUNT>
2528
void test_bring_up_down() {
2629
ESP8266Interface net(MBED_CFG_ESP8266_TX, MBED_CFG_ESP8266_RX, MBED_CFG_ESP8266_DEBUG);
27-
net.set_credentials(MBED_CFG_ESP8266_SSID, MBED_CFG_ESP8266_PASS);
30+
net.set_credentials(STRINGIZE(MBED_CFG_ESP8266_SSID), STRINGIZE(MBED_CFG_ESP8266_PASS));
2831

2932
for (int i = 0; i < COUNT; i++) {
3033
int err = net.connect();
@@ -57,16 +60,7 @@ void test_bring_up_down() {
5760

5861
// Test setup
5962
utest::v1::status_t test_setup(const size_t number_of_cases) {
60-
char uuid[48] = {0};
61-
GREENTEA_SETUP_UUID(120, "default_auto", uuid, sizeof(uuid));
62-
63-
// create mac address based on uuid
64-
uint64_t mac = 0;
65-
for (int i = 0; i < sizeof(uuid); i++) {
66-
mac += uuid[i];
67-
}
68-
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);
69-
63+
GREENTEA_SETUP(120, "default_auto");
7064
return verbose_test_setup_handler(number_of_cases);
7165
}
7266

TESTS/net/gethostbyname/main.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ using namespace utest::v1;
2424
#define MBED_CFG_ESP8266_DEBUG false
2525
#endif
2626

27+
#define STRINGIZE(x) STRINGIZE2(x)
28+
#define STRINGIZE2(x) #x
29+
2730
// Address info from stack
2831
const char *ip_literal;
2932
nsapi_version_t ip_pref;
@@ -32,7 +35,7 @@ const char *ip_pref_repr;
3235
// Network setup
3336
ESP8266Interface net(MBED_CFG_ESP8266_TX, MBED_CFG_ESP8266_RX, MBED_CFG_ESP8266_DEBUG);
3437
void net_bringup() {
35-
int err = net.connect(MBED_CFG_ESP8266_SSID, MBED_CFG_ESP8266_PASS);
38+
int err = net.connect(STRINGIZE(MBED_CFG_ESP8266_SSID), STRINGIZE(MBED_CFG_ESP8266_PASS));
3639
TEST_ASSERT_EQUAL(0, err);
3740
printf("MBED: Connected to network\n");
3841
printf("MBED: IP Address: %s\n", net.get_ip_address());
@@ -96,17 +99,8 @@ void test_dns_literal_pref() {
9699

97100
// Test setup
98101
utest::v1::status_t test_setup(const size_t number_of_cases) {
99-
char uuid[48] = {0};
100-
GREENTEA_SETUP_UUID(120, "default_auto", uuid, 48);
101-
102-
// create mac address based on uuid
103-
uint64_t mac = 0;
104-
for (int i = 0; i < sizeof(uuid); i++) {
105-
mac += uuid[i];
106-
}
107-
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);
102+
GREENTEA_SETUP(120, "default_auto");
108103
net_bringup();
109-
110104
return verbose_test_setup_handler(number_of_cases);
111105
}
112106

TESTS/net/host_tests/tcp_echo.pyc

-7.14 KB
Binary file not shown.

TESTS/net/host_tests/udp_echo.pyc

-5.08 KB
Binary file not shown.

TESTS/net/host_tests/udp_shotgun.pyc

-5.7 KB
Binary file not shown.

TESTS/net/tcp_echo/main.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ using namespace utest::v1;
2424
#define MBED_CFG_ESP8266_DEBUG false
2525
#endif
2626

27+
#define STRINGIZE(x) STRINGIZE2(x)
28+
#define STRINGIZE2(x) #x
29+
2730
namespace {
2831
char tx_buffer[MBED_CFG_TCP_CLIENT_ECHO_BUFFER_SIZE] = {0};
2932
char rx_buffer[MBED_CFG_TCP_CLIENT_ECHO_BUFFER_SIZE] = {0};
@@ -38,7 +41,7 @@ void prep_buffer(char *tx_buffer, size_t tx_size) {
3841

3942
void test_tcp_echo() {
4043
ESP8266Interface net(MBED_CFG_ESP8266_TX, MBED_CFG_ESP8266_RX, MBED_CFG_ESP8266_DEBUG);
41-
int err = net.connect(MBED_CFG_ESP8266_SSID, MBED_CFG_ESP8266_PASS);
44+
int err = net.connect(STRINGIZE(MBED_CFG_ESP8266_SSID), STRINGIZE(MBED_CFG_ESP8266_PASS));
4245

4346
if (err) {
4447
printf("MBED: failed to connect with an error of %d\r\n", err);
@@ -93,16 +96,7 @@ void test_tcp_echo() {
9396

9497
// Test setup
9598
utest::v1::status_t test_setup(const size_t number_of_cases) {
96-
char uuid[48] = {0};
97-
GREENTEA_SETUP_UUID(120, "tcp_echo", uuid, 48);
98-
99-
// create mac address based on uuid
100-
uint64_t mac = 0;
101-
for (int i = 0; i < sizeof(uuid); i++) {
102-
mac += uuid[i];
103-
}
104-
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);
105-
99+
GREENTEA_SETUP(120, "tcp_echo");
106100
return verbose_test_setup_handler(number_of_cases);
107101
}
108102

TESTS/net/tcp_echo_parallel/main.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ using namespace utest::v1;
3232
#define MBED_CFG_ESP8266_DEBUG false
3333
#endif
3434

35+
#define STRINGIZE(x) STRINGIZE2(x)
36+
#define STRINGIZE2(x) #x
37+
3538

3639
ESP8266Interface net(MBED_CFG_ESP8266_TX, MBED_CFG_ESP8266_RX, MBED_CFG_ESP8266_DEBUG);
3740
SocketAddress tcp_addr;
@@ -100,7 +103,7 @@ Echo *echoers[MBED_CFG_TCP_CLIENT_ECHO_THREADS];
100103

101104

102105
void test_tcp_echo_parallel() {
103-
int err = net.connect(MBED_CFG_ESP8266_SSID, MBED_CFG_ESP8266_PASS);
106+
int err = net.connect(STRINGIZE(MBED_CFG_ESP8266_SSID), STRINGIZE(MBED_CFG_ESP8266_PASS));
104107
TEST_ASSERT_EQUAL(0, err);
105108

106109
printf("MBED: TCPClient IP address is '%s'\n", net.get_ip_address());
@@ -140,16 +143,7 @@ void test_tcp_echo_parallel() {
140143

141144
// Test setup
142145
utest::v1::status_t test_setup(const size_t number_of_cases) {
143-
char uuid[48] = {0};
144-
GREENTEA_SETUP_UUID(120, "tcp_echo", uuid, 48);
145-
146-
// create mac address based on uuid
147-
uint64_t mac = 0;
148-
for (int i = 0; i < sizeof(uuid); i++) {
149-
mac += uuid[i];
150-
}
151-
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);
152-
146+
GREENTEA_SETUP(120, "tcp_echo");
153147
return verbose_test_setup_handler(number_of_cases);
154148
}
155149

TESTS/net/tcp_hello_world/main.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ using namespace utest::v1;
2020
#define MBED_CFG_ESP8266_DEBUG false
2121
#endif
2222

23+
#define STRINGIZE(x) STRINGIZE2(x)
24+
#define STRINGIZE2(x) #x
25+
2326

2427
namespace {
2528
// Test connection information
@@ -47,7 +50,7 @@ bool find_substring(const char *first, const char *last, const char *s_first, co
4750
void test_tcp_hello_world() {
4851
bool result = false;
4952
ESP8266Interface net(MBED_CFG_ESP8266_TX, MBED_CFG_ESP8266_RX, MBED_CFG_ESP8266_DEBUG);
50-
net.connect(MBED_CFG_ESP8266_SSID, MBED_CFG_ESP8266_PASS);
53+
net.connect(STRINGIZE(MBED_CFG_ESP8266_SSID), STRINGIZE(MBED_CFG_ESP8266_PASS));
5154
printf("TCP client IP Address is %s\r\n", net.get_ip_address());
5255

5356
TCPSocket sock(&net);
@@ -95,16 +98,7 @@ void test_tcp_hello_world() {
9598

9699
// Test setup
97100
utest::v1::status_t test_setup(const size_t number_of_cases) {
98-
char uuid[48] = {0};
99-
GREENTEA_SETUP_UUID(120, "default_auto", uuid, 48);
100-
101-
// create mac address based on uuid
102-
uint64_t mac = 0;
103-
for (int i = 0; i < sizeof(uuid); i++) {
104-
mac += uuid[i];
105-
}
106-
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);
107-
101+
GREENTEA_SETUP(120, "default_auto");
108102
return verbose_test_setup_handler(number_of_cases);
109103
}
110104

TESTS/net/tcp_packet_pressure/main.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ using namespace utest::v1;
4040
#define MBED_CFG_ESP8266_DEBUG false
4141
#endif
4242

43+
#define STRINGIZE(x) STRINGIZE2(x)
44+
#define STRINGIZE2(x) #x
45+
4346

4447
// Simple xorshift pseudorandom number generator
4548
class RandSeq {
@@ -123,7 +126,7 @@ void test_tcp_packet_pressure() {
123126
printf("MBED: Generated buffer %d\r\n", buffer_size);
124127

125128
ESP8266Interface net(MBED_CFG_ESP8266_TX, MBED_CFG_ESP8266_RX, MBED_CFG_ESP8266_DEBUG);
126-
int err = net.connect(MBED_CFG_ESP8266_SSID, MBED_CFG_ESP8266_PASS);
129+
int err = net.connect(STRINGIZE(MBED_CFG_ESP8266_SSID), STRINGIZE(MBED_CFG_ESP8266_PASS));
127130
TEST_ASSERT_EQUAL(0, err);
128131

129132
printf("MBED: TCPClient IP address is '%s'\n", net.get_ip_address());
@@ -234,16 +237,7 @@ void test_tcp_packet_pressure() {
234237

235238
// Test setup
236239
utest::v1::status_t test_setup(const size_t number_of_cases) {
237-
char uuid[48] = {0};
238-
GREENTEA_SETUP_UUID(120, "tcp_echo", uuid, 48);
239-
240-
// create mac address based on uuid
241-
uint64_t mac = 0;
242-
for (int i = 0; i < sizeof(uuid); i++) {
243-
mac += uuid[i];
244-
}
245-
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);
246-
240+
GREENTEA_SETUP(120, "tcp_echo");
247241
return verbose_test_setup_handler(number_of_cases);
248242
}
249243

TESTS/net/tcp_packet_pressure_parallel/main.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ using namespace utest::v1;
4444
#define MBED_CFG_ESP8266_DEBUG false
4545
#endif
4646

47+
#define STRINGIZE(x) STRINGIZE2(x)
48+
#define STRINGIZE2(x) #x
49+
4750

4851
// Simple xorshift pseudorandom number generator
4952
class RandSeq {
@@ -246,7 +249,7 @@ void test_tcp_packet_pressure_parallel() {
246249
MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_THREADS,
247250
buffer_subsize);
248251

249-
int err = net.connect(MBED_CFG_ESP8266_SSID, MBED_CFG_ESP8266_PASS);
252+
int err = net.connect(STRINGIZE(MBED_CFG_ESP8266_SSID), STRINGIZE(MBED_CFG_ESP8266_PASS));
250253
TEST_ASSERT_EQUAL(0, err);
251254

252255
printf("MBED: TCPClient IP address is '%s'\n", net.get_ip_address());
@@ -296,16 +299,7 @@ void test_tcp_packet_pressure_parallel() {
296299

297300
// Test setup
298301
utest::v1::status_t test_setup(const size_t number_of_cases) {
299-
char uuid[48] = {0};
300-
GREENTEA_SETUP_UUID(120, "tcp_echo", uuid, 48);
301-
302-
// create mac address based on uuid
303-
uint64_t mac = 0;
304-
for (int i = 0; i < sizeof(uuid); i++) {
305-
mac += uuid[i];
306-
}
307-
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);
308-
302+
GREENTEA_SETUP(120, "tcp_echo");
309303
return verbose_test_setup_handler(number_of_cases);
310304
}
311305

TESTS/net/udp_dtls_handshake/main.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ using namespace utest::v1;
3636
#define MBED_CFG_ESP8266_DEBUG false
3737
#endif
3838

39+
#define STRINGIZE(x) STRINGIZE2(x)
40+
#define STRINGIZE2(x) #x
41+
3942
uint8_t buffer[MBED_CFG_UDP_DTLS_HANDSHAKE_BUFFER_SIZE] = {0};
4043
int udp_dtls_handshake_pattern[] = {MBED_CFG_UDP_DTLS_HANDSHAKE_PATTERN};
4144
const int udp_dtls_handshake_count = sizeof(udp_dtls_handshake_pattern) / sizeof(int);
4245

4346
void test_udp_dtls_handshake() {
4447
ESP8266Interface net(MBED_CFG_ESP8266_TX, MBED_CFG_ESP8266_RX, MBED_CFG_ESP8266_DEBUG);
45-
int err = net.connect(MBED_CFG_ESP8266_SSID, MBED_CFG_ESP8266_PASS);
48+
int err = net.connect(STRINGIZE(MBED_CFG_ESP8266_SSID), STRINGIZE(MBED_CFG_ESP8266_PASS));
4649
TEST_ASSERT_EQUAL(0, err);
4750

4851
printf("MBED: UDPClient IP address is '%s'\n", net.get_ip_address());
@@ -140,16 +143,7 @@ void test_udp_dtls_handshake() {
140143

141144
// Test setup
142145
utest::v1::status_t test_setup(const size_t number_of_cases) {
143-
char uuid[48] = {0};
144-
GREENTEA_SETUP_UUID(120, "udp_shotgun", uuid, 48);
145-
146-
// create mac address based on uuid
147-
uint64_t mac = 0;
148-
for (int i = 0; i < sizeof(uuid); i++) {
149-
mac += uuid[i];
150-
}
151-
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);
152-
146+
GREENTEA_SETUP(120, "udp_shotgun");
153147
return verbose_test_setup_handler(number_of_cases);
154148
}
155149

TESTS/net/udp_echo/main.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ using namespace utest::v1;
2828
#define MBED_CFG_ESP8266_DEBUG false
2929
#endif
3030

31+
#define STRINGIZE(x) STRINGIZE2(x)
32+
#define STRINGIZE2(x) #x
33+
3134

3235
namespace {
3336
char tx_buffer[MBED_CFG_UDP_CLIENT_ECHO_BUFFER_SIZE] = {0};
@@ -53,7 +56,7 @@ void prep_buffer(char *uuid, char *tx_buffer, size_t tx_size) {
5356
void test_udp_echo() {
5457
ESP8266Interface net(MBED_CFG_ESP8266_TX, MBED_CFG_ESP8266_RX, MBED_CFG_ESP8266_DEBUG);
5558

56-
int err = net.connect(MBED_CFG_ESP8266_SSID, MBED_CFG_ESP8266_PASS);
59+
int err = net.connect(STRINGIZE(MBED_CFG_ESP8266_SSID), STRINGIZE(MBED_CFG_ESP8266_PASS));
5760
TEST_ASSERT_EQUAL(0, err);
5861

5962
if (err) {
@@ -132,15 +135,7 @@ void test_udp_echo() {
132135

133136
// Test setup
134137
utest::v1::status_t test_setup(const size_t number_of_cases) {
135-
GREENTEA_SETUP_UUID(120, "udp_echo", uuid, 48);
136-
137-
// create mac address based on uuid
138-
uint64_t mac = 0;
139-
for (int i = 0; i < sizeof(uuid); i++) {
140-
mac += uuid[i];
141-
}
142-
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);
143-
138+
GREENTEA_SETUP(120, "udp_echo");
144139
return verbose_test_setup_handler(number_of_cases);
145140
}
146141

0 commit comments

Comments
 (0)