Skip to content

Commit

Permalink
Merge pull request #31 from ARMmbed/g-testing-cleanup
Browse files Browse the repository at this point in the history
Add documentation and fix issues in the network tests
  • Loading branch information
geky committed May 18, 2017
2 parents 918caa0 + 6081f72 commit 95908fb
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 132 deletions.
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,33 @@ The mbed OS driver for the ESP8266 WiFi module
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

## Testing
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:
The ESP8266 library contains the core network tests taken from mbed OS. To run the tests you will need mbed CLI and mbed OS.

First, setup the the esp8266-driver and mbed-os repositories for testing:
``` bash
# Sets up the ESP8266 for testing
mbed import esp8266-driver
cd esp8266-driver
mbed add mbed-os
```

Now you should be able to run the network tests with `mbed test`:
``` bash
# Runs the ESP8266 network tests, requires a wifi access point
mbed test -t <COMPILER HERE> -m <BOARD HERE> -n tests-net* --compile -DMBED_CFG_ESP8266_SSID='"<SSID HERE>"' -DMBED_CFG_ESP8266_PASS='"<PASS HERE>"'
mbed test -t <COMPILER HERE> -m <BOARD HERE> -n tests-net* --compile -DMBED_CFG_ESP8266_SSID='<SSID HERE>' -DMBED_CFG_ESP8266_PASS='<PASS HERE>'
mbed test -t <COMPILER HERE> -m <BOARD HERE> -n tests-net* --run --verbose
```

There are a couple other options that can be used during testing:
- MBED_CFG_ESP8266_SSID - SSID of the wifi access point to connect to
- MBED_CFG_ESP8266_SSID - Passphrase of the wifi access point to connect to
- MBED_CFG_ESP8266_TX - TX pin for the ESP8266 serial connection (defaults to D1)
- MBED_CFG_ESP8266_RX - TX pin for the ESP8266 serial connection (defaults to D0)
- MBED_CFG_ESP8266_DEBUG - Enabled debug output from the ESP8266

For example, here is how to enabled the debug output from the ESP8266:
``` bash
# Run the ESP8266 network tests with debug output, requires a wifi access point
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
mbed test -t <COMPILER HERE> -m <BOARD HERE> -n tests-net* --run --verbose
```
16 changes: 5 additions & 11 deletions TESTS/net/connectivity/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ using namespace utest::v1;
#define MBED_CFG_ESP8266_DEBUG false
#endif

#define STRINGIZE(x) STRINGIZE2(x)
#define STRINGIZE2(x) #x


// Bringing the network up and down
template <int COUNT>
void test_bring_up_down() {
ESP8266Interface net(MBED_CFG_ESP8266_TX, MBED_CFG_ESP8266_RX, MBED_CFG_ESP8266_DEBUG);
net.set_credentials(MBED_CFG_ESP8266_SSID, MBED_CFG_ESP8266_PASS);
net.set_credentials(STRINGIZE(MBED_CFG_ESP8266_SSID), STRINGIZE(MBED_CFG_ESP8266_PASS));

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

// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
char uuid[48] = {0};
GREENTEA_SETUP_UUID(120, "default_auto", uuid, sizeof(uuid));

// create mac address based on uuid
uint64_t mac = 0;
for (int i = 0; i < sizeof(uuid); i++) {
mac += uuid[i];
}
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);

GREENTEA_SETUP(120, "default_auto");
return verbose_test_setup_handler(number_of_cases);
}

Expand Down
16 changes: 5 additions & 11 deletions TESTS/net/gethostbyname/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ using namespace utest::v1;
#define MBED_CFG_ESP8266_DEBUG false
#endif

#define STRINGIZE(x) STRINGIZE2(x)
#define STRINGIZE2(x) #x

// Address info from stack
const char *ip_literal;
nsapi_version_t ip_pref;
Expand All @@ -32,7 +35,7 @@ const char *ip_pref_repr;
// Network setup
ESP8266Interface net(MBED_CFG_ESP8266_TX, MBED_CFG_ESP8266_RX, MBED_CFG_ESP8266_DEBUG);
void net_bringup() {
int err = net.connect(MBED_CFG_ESP8266_SSID, MBED_CFG_ESP8266_PASS);
int err = net.connect(STRINGIZE(MBED_CFG_ESP8266_SSID), STRINGIZE(MBED_CFG_ESP8266_PASS));
TEST_ASSERT_EQUAL(0, err);
printf("MBED: Connected to network\n");
printf("MBED: IP Address: %s\n", net.get_ip_address());
Expand Down Expand Up @@ -96,17 +99,8 @@ void test_dns_literal_pref() {

// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
char uuid[48] = {0};
GREENTEA_SETUP_UUID(120, "default_auto", uuid, 48);

// create mac address based on uuid
uint64_t mac = 0;
for (int i = 0; i < sizeof(uuid); i++) {
mac += uuid[i];
}
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);
GREENTEA_SETUP(120, "default_auto");
net_bringup();

return verbose_test_setup_handler(number_of_cases);
}

Expand Down
Binary file removed TESTS/net/host_tests/tcp_echo.pyc
Binary file not shown.
Binary file removed TESTS/net/host_tests/udp_echo.pyc
Binary file not shown.
Binary file removed TESTS/net/host_tests/udp_shotgun.pyc
Binary file not shown.
16 changes: 5 additions & 11 deletions TESTS/net/tcp_echo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ using namespace utest::v1;
#define MBED_CFG_ESP8266_DEBUG false
#endif

#define STRINGIZE(x) STRINGIZE2(x)
#define STRINGIZE2(x) #x

namespace {
char tx_buffer[MBED_CFG_TCP_CLIENT_ECHO_BUFFER_SIZE] = {0};
char rx_buffer[MBED_CFG_TCP_CLIENT_ECHO_BUFFER_SIZE] = {0};
Expand All @@ -38,7 +41,7 @@ void prep_buffer(char *tx_buffer, size_t tx_size) {

void test_tcp_echo() {
ESP8266Interface net(MBED_CFG_ESP8266_TX, MBED_CFG_ESP8266_RX, MBED_CFG_ESP8266_DEBUG);
int err = net.connect(MBED_CFG_ESP8266_SSID, MBED_CFG_ESP8266_PASS);
int err = net.connect(STRINGIZE(MBED_CFG_ESP8266_SSID), STRINGIZE(MBED_CFG_ESP8266_PASS));

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

// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
char uuid[48] = {0};
GREENTEA_SETUP_UUID(120, "tcp_echo", uuid, 48);

// create mac address based on uuid
uint64_t mac = 0;
for (int i = 0; i < sizeof(uuid); i++) {
mac += uuid[i];
}
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);

GREENTEA_SETUP(120, "tcp_echo");
return verbose_test_setup_handler(number_of_cases);
}

Expand Down
16 changes: 5 additions & 11 deletions TESTS/net/tcp_echo_parallel/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ using namespace utest::v1;
#define MBED_CFG_ESP8266_DEBUG false
#endif

#define STRINGIZE(x) STRINGIZE2(x)
#define STRINGIZE2(x) #x


ESP8266Interface net(MBED_CFG_ESP8266_TX, MBED_CFG_ESP8266_RX, MBED_CFG_ESP8266_DEBUG);
SocketAddress tcp_addr;
Expand Down Expand Up @@ -100,7 +103,7 @@ Echo *echoers[MBED_CFG_TCP_CLIENT_ECHO_THREADS];


void test_tcp_echo_parallel() {
int err = net.connect(MBED_CFG_ESP8266_SSID, MBED_CFG_ESP8266_PASS);
int err = net.connect(STRINGIZE(MBED_CFG_ESP8266_SSID), STRINGIZE(MBED_CFG_ESP8266_PASS));
TEST_ASSERT_EQUAL(0, err);

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

// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
char uuid[48] = {0};
GREENTEA_SETUP_UUID(120, "tcp_echo", uuid, 48);

// create mac address based on uuid
uint64_t mac = 0;
for (int i = 0; i < sizeof(uuid); i++) {
mac += uuid[i];
}
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);

GREENTEA_SETUP(120, "tcp_echo");
return verbose_test_setup_handler(number_of_cases);
}

Expand Down
16 changes: 5 additions & 11 deletions TESTS/net/tcp_hello_world/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ using namespace utest::v1;
#define MBED_CFG_ESP8266_DEBUG false
#endif

#define STRINGIZE(x) STRINGIZE2(x)
#define STRINGIZE2(x) #x


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

TCPSocket sock(&net);
Expand Down Expand Up @@ -95,16 +98,7 @@ void test_tcp_hello_world() {

// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
char uuid[48] = {0};
GREENTEA_SETUP_UUID(120, "default_auto", uuid, 48);

// create mac address based on uuid
uint64_t mac = 0;
for (int i = 0; i < sizeof(uuid); i++) {
mac += uuid[i];
}
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);

GREENTEA_SETUP(120, "default_auto");
return verbose_test_setup_handler(number_of_cases);
}

Expand Down
16 changes: 5 additions & 11 deletions TESTS/net/tcp_packet_pressure/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ using namespace utest::v1;
#define MBED_CFG_ESP8266_DEBUG false
#endif

#define STRINGIZE(x) STRINGIZE2(x)
#define STRINGIZE2(x) #x


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

ESP8266Interface net(MBED_CFG_ESP8266_TX, MBED_CFG_ESP8266_RX, MBED_CFG_ESP8266_DEBUG);
int err = net.connect(MBED_CFG_ESP8266_SSID, MBED_CFG_ESP8266_PASS);
int err = net.connect(STRINGIZE(MBED_CFG_ESP8266_SSID), STRINGIZE(MBED_CFG_ESP8266_PASS));
TEST_ASSERT_EQUAL(0, err);

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

// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
char uuid[48] = {0};
GREENTEA_SETUP_UUID(120, "tcp_echo", uuid, 48);

// create mac address based on uuid
uint64_t mac = 0;
for (int i = 0; i < sizeof(uuid); i++) {
mac += uuid[i];
}
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);

GREENTEA_SETUP(120, "tcp_echo");
return verbose_test_setup_handler(number_of_cases);
}

Expand Down
16 changes: 5 additions & 11 deletions TESTS/net/tcp_packet_pressure_parallel/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ using namespace utest::v1;
#define MBED_CFG_ESP8266_DEBUG false
#endif

#define STRINGIZE(x) STRINGIZE2(x)
#define STRINGIZE2(x) #x


// Simple xorshift pseudorandom number generator
class RandSeq {
Expand Down Expand Up @@ -246,7 +249,7 @@ void test_tcp_packet_pressure_parallel() {
MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_THREADS,
buffer_subsize);

int err = net.connect(MBED_CFG_ESP8266_SSID, MBED_CFG_ESP8266_PASS);
int err = net.connect(STRINGIZE(MBED_CFG_ESP8266_SSID), STRINGIZE(MBED_CFG_ESP8266_PASS));
TEST_ASSERT_EQUAL(0, err);

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

// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
char uuid[48] = {0};
GREENTEA_SETUP_UUID(120, "tcp_echo", uuid, 48);

// create mac address based on uuid
uint64_t mac = 0;
for (int i = 0; i < sizeof(uuid); i++) {
mac += uuid[i];
}
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);

GREENTEA_SETUP(120, "tcp_echo");
return verbose_test_setup_handler(number_of_cases);
}

Expand Down
16 changes: 5 additions & 11 deletions TESTS/net/udp_dtls_handshake/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ using namespace utest::v1;
#define MBED_CFG_ESP8266_DEBUG false
#endif

#define STRINGIZE(x) STRINGIZE2(x)
#define STRINGIZE2(x) #x

uint8_t buffer[MBED_CFG_UDP_DTLS_HANDSHAKE_BUFFER_SIZE] = {0};
int udp_dtls_handshake_pattern[] = {MBED_CFG_UDP_DTLS_HANDSHAKE_PATTERN};
const int udp_dtls_handshake_count = sizeof(udp_dtls_handshake_pattern) / sizeof(int);

void test_udp_dtls_handshake() {
ESP8266Interface net(MBED_CFG_ESP8266_TX, MBED_CFG_ESP8266_RX, MBED_CFG_ESP8266_DEBUG);
int err = net.connect(MBED_CFG_ESP8266_SSID, MBED_CFG_ESP8266_PASS);
int err = net.connect(STRINGIZE(MBED_CFG_ESP8266_SSID), STRINGIZE(MBED_CFG_ESP8266_PASS));
TEST_ASSERT_EQUAL(0, err);

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

// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
char uuid[48] = {0};
GREENTEA_SETUP_UUID(120, "udp_shotgun", uuid, 48);

// create mac address based on uuid
uint64_t mac = 0;
for (int i = 0; i < sizeof(uuid); i++) {
mac += uuid[i];
}
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);

GREENTEA_SETUP(120, "udp_shotgun");
return verbose_test_setup_handler(number_of_cases);
}

Expand Down
15 changes: 5 additions & 10 deletions TESTS/net/udp_echo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ using namespace utest::v1;
#define MBED_CFG_ESP8266_DEBUG false
#endif

#define STRINGIZE(x) STRINGIZE2(x)
#define STRINGIZE2(x) #x


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

int err = net.connect(MBED_CFG_ESP8266_SSID, MBED_CFG_ESP8266_PASS);
int err = net.connect(STRINGIZE(MBED_CFG_ESP8266_SSID), STRINGIZE(MBED_CFG_ESP8266_PASS));
TEST_ASSERT_EQUAL(0, err);

if (err) {
Expand Down Expand Up @@ -132,15 +135,7 @@ void test_udp_echo() {

// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
GREENTEA_SETUP_UUID(120, "udp_echo", uuid, 48);

// create mac address based on uuid
uint64_t mac = 0;
for (int i = 0; i < sizeof(uuid); i++) {
mac += uuid[i];
}
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);

GREENTEA_SETUP(120, "udp_echo");
return verbose_test_setup_handler(number_of_cases);
}

Expand Down
Loading

0 comments on commit 95908fb

Please sign in to comment.