Skip to content

Networking test fixes #4240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions features/FEATURE_LWIP/TESTS/mbedmicro-net/connectivity/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,22 @@ void test_bring_up_down() {

// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
GREENTEA_SETUP(60, "default_auto");
char uuid[48] = {0};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

48 ??? Magic number, should be #defined

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);

return verbose_test_setup_handler(number_of_cases);
}

Case cases[] = {
Case("Testing bringing the network up and down", test_bring_up_down<1>),
Case("Testing bringing the network up and down twice", test_bring_up_down<2>),
Case("Bringing the network up and down", test_bring_up_down<1>),
Case("Bringing the network up and down twice", test_bring_up_down<2>),
};

Specification specification(test_setup, cases);
Expand Down
19 changes: 14 additions & 5 deletions features/FEATURE_LWIP/TESTS/mbedmicro-net/gethostbyname/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,25 @@ void test_dns_literal_pref() {

// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
GREENTEA_SETUP(60, "default_auto");
char uuid[48] = {0};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

48 ?

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment inside function call

net_bringup();

return verbose_test_setup_handler(number_of_cases);
}

Case cases[] = {
Case("Testing DNS query", test_dns_query),
Case("Testing DNS preference query", test_dns_query_pref),
Case("Testing DNS literal", test_dns_literal),
Case("Testing DNS preference literal", test_dns_literal_pref),
Case("DNS query", test_dns_query),
Case("DNS preference query", test_dns_query_pref),
Case("DNS literal", test_dns_literal),
Case("DNS preference literal", test_dns_literal_pref),
};

Specification specification(test_setup, cases);
Expand Down
49 changes: 41 additions & 8 deletions features/FEATURE_LWIP/TESTS/mbedmicro-net/tcp_echo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include "TCPSocket.h"
#include "greentea-client/test_env.h"
#include "unity/unity.h"
#include "utest.h"

using namespace utest::v1;


#ifndef MBED_CFG_TCP_CLIENT_ECHO_BUFFER_SIZE
Expand All @@ -28,11 +31,14 @@ void prep_buffer(char *tx_buffer, size_t tx_size) {
}
}

int main() {
GREENTEA_SETUP(60, "tcp_echo");

void test_tcp_echo() {
EthernetInterface eth;
eth.connect();
int err = eth.connect();

if (err) {
printf("MBED: failed to connect with an error of %d\r\n", err);
TEST_ASSERT_EQUAL(0, err);
}

printf("MBED: TCPClient IP address is '%s'\n", eth.get_ip_address());
printf("MBED: TCPClient waiting for server IP and port...\n");
Expand Down Expand Up @@ -64,17 +70,44 @@ int main() {

prep_buffer(tx_buffer, sizeof(tx_buffer));
sock.send(tx_buffer, sizeof(tx_buffer));

printf("MBED: Finished sending\r\n");
// Server will respond with HTTP GET's success code
const int ret = sock.recv(rx_buffer, sizeof(rx_buffer));

printf("MBED: Finished receiving\r\n");

result = !memcmp(tx_buffer, rx_buffer, sizeof(tx_buffer));

TEST_ASSERT_EQUAL(ret, sizeof(rx_buffer));
TEST_ASSERT_EQUAL(true, result);
}

sock.close();
eth.disconnect();
GREENTEA_TESTSUITE_RESULT(result);
TEST_ASSERT_EQUAL(true, result);
}


// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
char uuid[48] = {0};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magic number

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment in function


return verbose_test_setup_handler(number_of_cases);
}

Case cases[] = {
Case("TCP echo", test_tcp_echo),
};

Specification specification(test_setup, cases);

int main() {
return !Harness::run(specification);
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include "TCPSocket.h"
#include "greentea-client/test_env.h"
#include "unity/unity.h"
#include "utest.h"

using namespace utest::v1;


#ifndef MBED_CFG_TCP_CLIENT_ECHO_BUFFER_SIZE
Expand Down Expand Up @@ -64,7 +67,7 @@ class Echo {
TEST_ASSERT_EQUAL(0, err);

iomutex.lock();
printf("HTTP: Connected to %s:%d\r\n",
printf("HTTP: Connected to %s:%d\r\n",
tcp_addr.get_ip_address(), tcp_addr.get_port());
printf("tx_buffer buffer size: %u\r\n", sizeof(tx_buffer));
printf("rx_buffer buffer size: %u\r\n", sizeof(rx_buffer));
Expand All @@ -84,12 +87,10 @@ class Echo {
}
};

Echo echoers[MBED_CFG_TCP_CLIENT_ECHO_THREADS];

Echo *echoers[MBED_CFG_TCP_CLIENT_ECHO_THREADS];

int main() {
GREENTEA_SETUP(60, "tcp_echo");

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

Expand All @@ -116,13 +117,40 @@ int main() {

// Startup echo threads in parallel
for (int i = 0; i < MBED_CFG_TCP_CLIENT_ECHO_THREADS; i++) {
echoers[i].start();
echoers[i] = new Echo;
echoers[i]->start();
}

for (int i = 0; i < MBED_CFG_TCP_CLIENT_ECHO_THREADS; i++) {
echoers[i].join();
echoers[i]->join();
delete echoers[i];
}

net.disconnect();
GREENTEA_TESTSUITE_RESULT(true);
}

// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
char uuid[48] = {0};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magic number

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment inside function


return verbose_test_setup_handler(number_of_cases);
}

Case cases[] = {
Case("TCP echo parallel", test_tcp_echo_parallel),
};

Specification specification(test_setup, cases);

int main() {
return !Harness::run(specification);
}

38 changes: 33 additions & 5 deletions features/FEATURE_LWIP/TESTS/mbedmicro-net/tcp_hello_world/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#include "TCPSocket.h"
#include "greentea-client/test_env.h"
#include "unity/unity.h"
#include "utest.h"

using namespace utest::v1;


namespace {
// Test connection information
Expand All @@ -35,12 +39,9 @@ bool find_substring(const char *first, const char *last, const char *s_first, co
return (f != last);
}

int main() {
GREENTEA_SETUP(60, "default_auto");

void test_tcp_hello_world() {
bool result = false;
EthernetInterface eth;
//eth.init(); //Use DHCP
eth.connect();
printf("TCP client IP Address is %s\r\n", eth.get_ip_address());

Expand Down Expand Up @@ -83,5 +84,32 @@ int main() {
}

eth.disconnect();
GREENTEA_TESTSUITE_RESULT(result);
TEST_ASSERT_EQUAL(true, result);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be TEST_ASSERT_TRUE(result)

}


// 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);

return verbose_test_setup_handler(number_of_cases);
}

Case cases[] = {
Case("TCP hello world", test_tcp_hello_world),
};

Specification specification(test_setup, cases);

int main() {
return !Harness::run(specification);
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#include "TCPSocket.h"
#include "greentea-client/test_env.h"
#include "unity/unity.h"
#include "utest.h"

using namespace utest::v1;


#ifndef MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MIN
Expand Down Expand Up @@ -107,8 +110,7 @@ void generate_buffer(uint8_t **buffer, size_t *size, size_t min, size_t max) {
}


int main() {
GREENTEA_SETUP(60, "tcp_echo");
void test_tcp_packet_pressure() {
generate_buffer(&buffer, &buffer_size,
MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MIN,
MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MAX);
Expand All @@ -123,8 +125,6 @@ int main() {

greentea_send_kv("target_ip", eth.get_ip_address());

bool result = true;

char recv_key[] = "host_port";
char ipbuf[60] = {0};
char portbuf[16] = {0};
Expand Down Expand Up @@ -223,5 +223,31 @@ int main() {
MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MIN) / (1000*timer.read()));

eth.disconnect();
GREENTEA_TESTSUITE_RESULT(result);
}


// 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);

return verbose_test_setup_handler(number_of_cases);
}

Case cases[] = {
Case("TCP packet pressure", test_tcp_packet_pressure),
};

Specification specification(test_setup, cases);

int main() {
return !Harness::run(specification);
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
#include "TCPSocket.h"
#include "greentea-client/test_env.h"
#include "unity/unity.h"
#include "utest.h"

using namespace utest::v1;


#ifndef MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MIN
Expand Down Expand Up @@ -224,9 +227,7 @@ class PressureTest {
PressureTest *pressure_tests[MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_THREADS];


int main() {
GREENTEA_SETUP(2*60, "tcp_echo");

void test_tcp_packet_pressure_parallel() {
uint8_t *buffer;
size_t buffer_size;
generate_buffer(&buffer, &buffer_size,
Expand All @@ -247,8 +248,6 @@ int main() {

greentea_send_kv("target_ip", net.get_ip_address());

bool result = true;

char recv_key[] = "host_port";
char ipbuf[60] = {0};
char portbuf[16] = {0};
Expand Down Expand Up @@ -286,5 +285,31 @@ int main() {
MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MIN) / (1000*timer.read()));

net.disconnect();
GREENTEA_TESTSUITE_RESULT(result);
}


// 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);

return verbose_test_setup_handler(number_of_cases);
}

Case cases[] = {
Case("TCP packet pressure parallel", test_tcp_packet_pressure_parallel),
};

Specification specification(test_setup, cases);

int main() {
return !Harness::run(specification);
}

Loading