Skip to content

Increase DHCP timeout, and rework networking tests logic #4369

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

Merged
merged 21 commits into from
Jun 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ void test_bring_up_down() {

// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
GREENTEA_SETUP(60, "default_auto");
GREENTEA_SETUP(120, "default_auto");
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
10 changes: 5 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,16 @@ void test_dns_literal_pref() {

// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
GREENTEA_SETUP(60, "default_auto");
GREENTEA_SETUP(120, "default_auto");
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
41 changes: 32 additions & 9 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,34 @@ 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);
TEST_ASSERT(result);
}

sock.close();
eth.disconnect();
GREENTEA_TESTSUITE_RESULT(result);
TEST_ASSERT(result);
}


// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
GREENTEA_SETUP(120, "tcp_echo");
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 @@ -77,18 +80,16 @@ class Echo {
const int ret = sock.recv(rx_buffer, sizeof(rx_buffer));
bool result = !memcmp(tx_buffer, rx_buffer, sizeof(tx_buffer));
TEST_ASSERT_EQUAL(ret, sizeof(rx_buffer));
TEST_ASSERT_EQUAL(true, result);
TEST_ASSERT(result);

err = sock.close();
TEST_ASSERT_EQUAL(0, err);
}
};

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

Echo echoers[MBED_CFG_TCP_CLIENT_ECHO_THREADS];
Echo *echoers[MBED_CFG_TCP_CLIENT_ECHO_THREADS];

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

Expand All @@ -115,13 +116,30 @@ 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) {
GREENTEA_SETUP(120, "tcp_echo");
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);
}
31 changes: 25 additions & 6 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,9 +39,7 @@ 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
Expand Down Expand Up @@ -67,8 +69,8 @@ int main() {
// Find "Hello World!" string in reply
bool found_hello = find_substring(buffer, buffer + ret, HTTP_HELLO_STR, HTTP_HELLO_STR + strlen(HTTP_HELLO_STR));

TEST_ASSERT_TRUE(found_200_ok);
TEST_ASSERT_TRUE(found_hello);
TEST_ASSERT(found_200_ok);
TEST_ASSERT(found_hello);

if (found_200_ok && found_hello) result = true;

Expand All @@ -83,5 +85,22 @@ int main() {
}

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


// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
GREENTEA_SETUP(120, "default_auto");
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 @@ -219,9 +219,25 @@ int main() {
timer.stop();
printf("MBED: Time taken: %fs\r\n", timer.read());
printf("MBED: Speed: %.3fkb/s\r\n",
8*(2*MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MAX -
8*(2*MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MAX -
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) {
GREENTEA_SETUP(120, "tcp_echo");
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 @@ -282,9 +281,25 @@ int main() {
printf("MBED: Time taken: %fs\r\n", timer.read());
printf("MBED: Speed: %.3fkb/s\r\n",
MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_THREADS*
8*(2*MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MAX -
8*(2*MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MAX -
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) {
GREENTEA_SETUP(120, "tcp_echo");
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