Skip to content

Commit f56d64f

Browse files
authored
Merge pull request #4369 from bridadan/networking_test_update
Increase DHCP timeout, and rework networking tests logic
2 parents 1333410 + d0d7c6f commit f56d64f

File tree

21 files changed

+697
-130
lines changed

21 files changed

+697
-130
lines changed

features/FEATURE_LWIP/TESTS/mbedmicro-net/connectivity/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ void test_bring_up_down() {
5151

5252
// Test setup
5353
utest::v1::status_t test_setup(const size_t number_of_cases) {
54-
GREENTEA_SETUP(60, "default_auto");
54+
GREENTEA_SETUP(120, "default_auto");
5555
return verbose_test_setup_handler(number_of_cases);
5656
}
5757

5858
Case cases[] = {
59-
Case("Testing bringing the network up and down", test_bring_up_down<1>),
60-
Case("Testing bringing the network up and down twice", test_bring_up_down<2>),
59+
Case("Bringing the network up and down", test_bring_up_down<1>),
60+
Case("Bringing the network up and down twice", test_bring_up_down<2>),
6161
};
6262

6363
Specification specification(test_setup, cases);

features/FEATURE_LWIP/TESTS/mbedmicro-net/gethostbyname/main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,16 @@ void test_dns_literal_pref() {
9191

9292
// Test setup
9393
utest::v1::status_t test_setup(const size_t number_of_cases) {
94-
GREENTEA_SETUP(60, "default_auto");
94+
GREENTEA_SETUP(120, "default_auto");
9595
net_bringup();
9696
return verbose_test_setup_handler(number_of_cases);
9797
}
9898

9999
Case cases[] = {
100-
Case("Testing DNS query", test_dns_query),
101-
Case("Testing DNS preference query", test_dns_query_pref),
102-
Case("Testing DNS literal", test_dns_literal),
103-
Case("Testing DNS preference literal", test_dns_literal_pref),
100+
Case("DNS query", test_dns_query),
101+
Case("DNS preference query", test_dns_query_pref),
102+
Case("DNS literal", test_dns_literal),
103+
Case("DNS preference literal", test_dns_literal_pref),
104104
};
105105

106106
Specification specification(test_setup, cases);

features/FEATURE_LWIP/TESTS/mbedmicro-net/tcp_echo/main.cpp

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include "TCPSocket.h"
1111
#include "greentea-client/test_env.h"
1212
#include "unity/unity.h"
13+
#include "utest.h"
14+
15+
using namespace utest::v1;
1316

1417

1518
#ifndef MBED_CFG_TCP_CLIENT_ECHO_BUFFER_SIZE
@@ -28,11 +31,14 @@ void prep_buffer(char *tx_buffer, size_t tx_size) {
2831
}
2932
}
3033

31-
int main() {
32-
GREENTEA_SETUP(60, "tcp_echo");
33-
34+
void test_tcp_echo() {
3435
EthernetInterface eth;
35-
eth.connect();
36+
int err = eth.connect();
37+
38+
if (err) {
39+
printf("MBED: failed to connect with an error of %d\r\n", err);
40+
TEST_ASSERT_EQUAL(0, err);
41+
}
3642

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

6571
prep_buffer(tx_buffer, sizeof(tx_buffer));
6672
sock.send(tx_buffer, sizeof(tx_buffer));
67-
73+
printf("MBED: Finished sending\r\n");
6874
// Server will respond with HTTP GET's success code
6975
const int ret = sock.recv(rx_buffer, sizeof(rx_buffer));
70-
76+
printf("MBED: Finished receiving\r\n");
77+
7178
result = !memcmp(tx_buffer, rx_buffer, sizeof(tx_buffer));
72-
7379
TEST_ASSERT_EQUAL(ret, sizeof(rx_buffer));
74-
TEST_ASSERT_EQUAL(true, result);
80+
TEST_ASSERT(result);
7581
}
7682

7783
sock.close();
7884
eth.disconnect();
79-
GREENTEA_TESTSUITE_RESULT(result);
85+
TEST_ASSERT(result);
86+
}
87+
88+
89+
// Test setup
90+
utest::v1::status_t test_setup(const size_t number_of_cases) {
91+
GREENTEA_SETUP(120, "tcp_echo");
92+
return verbose_test_setup_handler(number_of_cases);
93+
}
94+
95+
Case cases[] = {
96+
Case("TCP echo", test_tcp_echo),
97+
};
98+
99+
Specification specification(test_setup, cases);
100+
101+
int main() {
102+
return !Harness::run(specification);
80103
}

features/FEATURE_LWIP/TESTS/mbedmicro-net/tcp_echo_parallel/main.cpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include "TCPSocket.h"
1111
#include "greentea-client/test_env.h"
1212
#include "unity/unity.h"
13+
#include "utest.h"
14+
15+
using namespace utest::v1;
1316

1417

1518
#ifndef MBED_CFG_TCP_CLIENT_ECHO_BUFFER_SIZE
@@ -64,7 +67,7 @@ class Echo {
6467
TEST_ASSERT_EQUAL(0, err);
6568

6669
iomutex.lock();
67-
printf("HTTP: Connected to %s:%d\r\n",
70+
printf("HTTP: Connected to %s:%d\r\n",
6871
tcp_addr.get_ip_address(), tcp_addr.get_port());
6972
printf("tx_buffer buffer size: %u\r\n", sizeof(tx_buffer));
7073
printf("rx_buffer buffer size: %u\r\n", sizeof(rx_buffer));
@@ -77,18 +80,16 @@ class Echo {
7780
const int ret = sock.recv(rx_buffer, sizeof(rx_buffer));
7881
bool result = !memcmp(tx_buffer, rx_buffer, sizeof(tx_buffer));
7982
TEST_ASSERT_EQUAL(ret, sizeof(rx_buffer));
80-
TEST_ASSERT_EQUAL(true, result);
83+
TEST_ASSERT(result);
8184

8285
err = sock.close();
8386
TEST_ASSERT_EQUAL(0, err);
8487
}
8588
};
8689

87-
int main() {
88-
GREENTEA_SETUP(60, "tcp_echo");
89-
90-
Echo echoers[MBED_CFG_TCP_CLIENT_ECHO_THREADS];
90+
Echo *echoers[MBED_CFG_TCP_CLIENT_ECHO_THREADS];
9191

92+
void test_tcp_echo_parallel() {
9293
int err = net.connect();
9394
TEST_ASSERT_EQUAL(0, err);
9495

@@ -115,13 +116,30 @@ int main() {
115116

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

121123
for (int i = 0; i < MBED_CFG_TCP_CLIENT_ECHO_THREADS; i++) {
122-
echoers[i].join();
124+
echoers[i]->join();
125+
delete echoers[i];
123126
}
124127

125128
net.disconnect();
126-
GREENTEA_TESTSUITE_RESULT(true);
129+
}
130+
131+
// Test setup
132+
utest::v1::status_t test_setup(const size_t number_of_cases) {
133+
GREENTEA_SETUP(120, "tcp_echo");
134+
return verbose_test_setup_handler(number_of_cases);
135+
}
136+
137+
Case cases[] = {
138+
Case("TCP echo parallel", test_tcp_echo_parallel),
139+
};
140+
141+
Specification specification(test_setup, cases);
142+
143+
int main() {
144+
return !Harness::run(specification);
127145
}

features/FEATURE_LWIP/TESTS/mbedmicro-net/tcp_hello_world/main.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
#include "TCPSocket.h"
1212
#include "greentea-client/test_env.h"
1313
#include "unity/unity.h"
14+
#include "utest.h"
15+
16+
using namespace utest::v1;
17+
1418

1519
namespace {
1620
// Test connection information
@@ -35,9 +39,7 @@ bool find_substring(const char *first, const char *last, const char *s_first, co
3539
return (f != last);
3640
}
3741

38-
int main() {
39-
GREENTEA_SETUP(60, "default_auto");
40-
42+
void test_tcp_hello_world() {
4143
bool result = false;
4244
EthernetInterface eth;
4345
//eth.init(); //Use DHCP
@@ -67,8 +69,8 @@ int main() {
6769
// Find "Hello World!" string in reply
6870
bool found_hello = find_substring(buffer, buffer + ret, HTTP_HELLO_STR, HTTP_HELLO_STR + strlen(HTTP_HELLO_STR));
6971

70-
TEST_ASSERT_TRUE(found_200_ok);
71-
TEST_ASSERT_TRUE(found_hello);
72+
TEST_ASSERT(found_200_ok);
73+
TEST_ASSERT(found_hello);
7274

7375
if (found_200_ok && found_hello) result = true;
7476

@@ -83,5 +85,22 @@ int main() {
8385
}
8486

8587
eth.disconnect();
86-
GREENTEA_TESTSUITE_RESULT(result);
88+
TEST_ASSERT(result);
89+
}
90+
91+
92+
// Test setup
93+
utest::v1::status_t test_setup(const size_t number_of_cases) {
94+
GREENTEA_SETUP(120, "default_auto");
95+
return verbose_test_setup_handler(number_of_cases);
96+
}
97+
98+
Case cases[] = {
99+
Case("TCP hello world", test_tcp_hello_world),
100+
};
101+
102+
Specification specification(test_setup, cases);
103+
104+
int main() {
105+
return !Harness::run(specification);
87106
}

features/FEATURE_LWIP/TESTS/mbedmicro-net/tcp_packet_pressure/main.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#include "TCPSocket.h"
1414
#include "greentea-client/test_env.h"
1515
#include "unity/unity.h"
16+
#include "utest.h"
17+
18+
using namespace utest::v1;
1619

1720

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

109112

110-
int main() {
111-
GREENTEA_SETUP(60, "tcp_echo");
113+
void test_tcp_packet_pressure() {
112114
generate_buffer(&buffer, &buffer_size,
113115
MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MIN,
114116
MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MAX);
@@ -123,8 +125,6 @@ int main() {
123125

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

126-
bool result = true;
127-
128128
char recv_key[] = "host_port";
129129
char ipbuf[60] = {0};
130130
char portbuf[16] = {0};
@@ -219,9 +219,25 @@ int main() {
219219
timer.stop();
220220
printf("MBED: Time taken: %fs\r\n", timer.read());
221221
printf("MBED: Speed: %.3fkb/s\r\n",
222-
8*(2*MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MAX -
222+
8*(2*MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MAX -
223223
MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MIN) / (1000*timer.read()));
224224

225225
eth.disconnect();
226-
GREENTEA_TESTSUITE_RESULT(result);
226+
}
227+
228+
229+
// Test setup
230+
utest::v1::status_t test_setup(const size_t number_of_cases) {
231+
GREENTEA_SETUP(120, "tcp_echo");
232+
return verbose_test_setup_handler(number_of_cases);
233+
}
234+
235+
Case cases[] = {
236+
Case("TCP packet pressure", test_tcp_packet_pressure),
237+
};
238+
239+
Specification specification(test_setup, cases);
240+
241+
int main() {
242+
return !Harness::run(specification);
227243
}

features/FEATURE_LWIP/TESTS/mbedmicro-net/tcp_packet_pressure_parallel/main.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#include "TCPSocket.h"
1414
#include "greentea-client/test_env.h"
1515
#include "unity/unity.h"
16+
#include "utest.h"
17+
18+
using namespace utest::v1;
1619

1720

1821
#ifndef MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MIN
@@ -224,9 +227,7 @@ class PressureTest {
224227
PressureTest *pressure_tests[MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_THREADS];
225228

226229

227-
int main() {
228-
GREENTEA_SETUP(2*60, "tcp_echo");
229-
230+
void test_tcp_packet_pressure_parallel() {
230231
uint8_t *buffer;
231232
size_t buffer_size;
232233
generate_buffer(&buffer, &buffer_size,
@@ -247,8 +248,6 @@ int main() {
247248

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

250-
bool result = true;
251-
252251
char recv_key[] = "host_port";
253252
char ipbuf[60] = {0};
254253
char portbuf[16] = {0};
@@ -282,9 +281,25 @@ int main() {
282281
printf("MBED: Time taken: %fs\r\n", timer.read());
283282
printf("MBED: Speed: %.3fkb/s\r\n",
284283
MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_THREADS*
285-
8*(2*MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MAX -
284+
8*(2*MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MAX -
286285
MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MIN) / (1000*timer.read()));
287286

288287
net.disconnect();
289-
GREENTEA_TESTSUITE_RESULT(result);
288+
}
289+
290+
291+
// Test setup
292+
utest::v1::status_t test_setup(const size_t number_of_cases) {
293+
GREENTEA_SETUP(120, "tcp_echo");
294+
return verbose_test_setup_handler(number_of_cases);
295+
}
296+
297+
Case cases[] = {
298+
Case("TCP packet pressure parallel", test_tcp_packet_pressure_parallel),
299+
};
300+
301+
Specification specification(test_setup, cases);
302+
303+
int main() {
304+
return !Harness::run(specification);
290305
}

0 commit comments

Comments
 (0)