Skip to content

Commit 56ba283

Browse files
committed
lwip: Migrated to utest framework
per @bridadan
1 parent 3c7f2ab commit 56ba283

File tree

12 files changed

+342
-162
lines changed

12 files changed

+342
-162
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ utest::v1::status_t test_setup(const size_t number_of_cases) {
6565
}
6666

6767
Case cases[] = {
68-
Case("Testing bringing the network up and down", test_bring_up_down<1>),
69-
Case("Testing bringing the network up and down twice", test_bring_up_down<2>),
68+
Case("Bringing the network up and down", test_bring_up_down<1>),
69+
Case("Bringing the network up and down twice", test_bring_up_down<2>),
7070
};
7171

7272
Specification specification(test_setup, cases);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ utest::v1::status_t test_setup(const size_t number_of_cases) {
106106
}
107107

108108
Case cases[] = {
109-
Case("Testing DNS query", test_dns_query),
110-
Case("Testing DNS preference query", test_dns_query_pref),
111-
Case("Testing DNS literal", test_dns_literal),
112-
Case("Testing DNS preference literal", test_dns_literal_pref),
109+
Case("DNS query", test_dns_query),
110+
Case("DNS preference query", test_dns_query_pref),
111+
Case("DNS literal", test_dns_literal),
112+
Case("DNS preference literal", test_dns_literal_pref),
113113
};
114114

115115
Specification specification(test_setup, cases);

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

Lines changed: 33 additions & 13 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,23 +31,13 @@ void prep_buffer(char *tx_buffer, size_t tx_size) {
2831
}
2932
}
3033

31-
int main() {
32-
char uuid[48] = {0};
33-
GREENTEA_SETUP_UUID(120, "tcp_echo", uuid, 48);
34-
35-
// create mac address based on uuid
36-
uint64_t mac = 0;
37-
for (int i = 0; i < sizeof(uuid); i++) {
38-
mac += uuid[i];
39-
}
40-
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);
41-
34+
void test_tcp_echo() {
4235
EthernetInterface eth;
4336
int err = eth.connect();
4437

4538
if (err) {
4639
printf("MBED: failed to connect with an error of %d\r\n", err);
47-
GREENTEA_TESTSUITE_RESULT(false);
40+
TEST_ASSERT_EQUAL(0, err);
4841
}
4942

5043
printf("MBED: TCPClient IP address is '%s'\n", eth.get_ip_address());
@@ -89,5 +82,32 @@ int main() {
8982

9083
sock.close();
9184
eth.disconnect();
92-
GREENTEA_TESTSUITE_RESULT(result);
85+
TEST_ASSERT_EQUAL(true, result);
9386
}
87+
88+
89+
// Test setup
90+
utest::v1::status_t test_setup(const size_t number_of_cases) {
91+
char uuid[48] = {0};
92+
GREENTEA_SETUP_UUID(120, "tcp_echo", uuid, 48);
93+
94+
// create mac address based on uuid
95+
uint64_t mac = 0;
96+
for (int i = 0; i < sizeof(uuid); i++) {
97+
mac += uuid[i];
98+
}
99+
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);
100+
101+
return verbose_test_setup_handler(number_of_cases);
102+
}
103+
104+
Case cases[] = {
105+
Case("TCP echo", test_tcp_echo),
106+
};
107+
108+
Specification specification(test_setup, cases);
109+
110+
int main() {
111+
return !Harness::run(specification);
112+
}
113+

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

Lines changed: 30 additions & 12 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
@@ -87,17 +90,7 @@ class Echo {
8790
Echo echoers[MBED_CFG_TCP_CLIENT_ECHO_THREADS];
8891

8992

90-
int main() {
91-
char uuid[48] = {0};
92-
GREENTEA_SETUP_UUID(120, "tcp_echo", uuid, 48);
93-
94-
// create mac address based on uuid
95-
uint64_t mac = 0;
96-
for (int i = 0; i < sizeof(uuid); i++) {
97-
mac += uuid[i];
98-
}
99-
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);
100-
93+
void test_tcp_echo_parallel() {
10194
int err = net.connect();
10295
TEST_ASSERT_EQUAL(0, err);
10396

@@ -132,5 +125,30 @@ int main() {
132125
}
133126

134127
net.disconnect();
135-
GREENTEA_TESTSUITE_RESULT(true);
136128
}
129+
130+
// Test setup
131+
utest::v1::status_t test_setup(const size_t number_of_cases) {
132+
char uuid[48] = {0};
133+
GREENTEA_SETUP_UUID(120, "tcp_echo", uuid, 48);
134+
135+
// create mac address based on uuid
136+
uint64_t mac = 0;
137+
for (int i = 0; i < sizeof(uuid); i++) {
138+
mac += uuid[i];
139+
}
140+
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);
141+
142+
return verbose_test_setup_handler(number_of_cases);
143+
}
144+
145+
Case cases[] = {
146+
Case("TCP echo parallel", test_tcp_echo_parallel),
147+
};
148+
149+
Specification specification(test_setup, cases);
150+
151+
int main() {
152+
return !Harness::run(specification);
153+
}
154+

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

Lines changed: 33 additions & 12 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,17 +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-
char uuid[48] = {0};
40-
GREENTEA_SETUP_UUID(120, "default_auto", uuid, 48);
41-
42-
// create mac address based on uuid
43-
uint64_t mac = 0;
44-
for (int i = 0; i < sizeof(uuid); i++) {
45-
mac += uuid[i];
46-
}
47-
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);
48-
42+
void test_tcp_hello_world() {
4943
bool result = false;
5044
EthernetInterface eth;
5145
eth.connect();
@@ -90,5 +84,32 @@ int main() {
9084
}
9185

9286
eth.disconnect();
93-
GREENTEA_TESTSUITE_RESULT(result);
87+
TEST_ASSERT_EQUAL(true, result);
88+
}
89+
90+
91+
// Test setup
92+
utest::v1::status_t test_setup(const size_t number_of_cases) {
93+
char uuid[48] = {0};
94+
GREENTEA_SETUP_UUID(120, "default_auto", uuid, 48);
95+
96+
// create mac address based on uuid
97+
uint64_t mac = 0;
98+
for (int i = 0; i < sizeof(uuid); i++) {
99+
mac += uuid[i];
100+
}
101+
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);
102+
103+
return verbose_test_setup_handler(number_of_cases);
104+
}
105+
106+
Case cases[] = {
107+
Case("TCP hello world", test_tcp_hello_world),
108+
};
109+
110+
Specification specification(test_setup, cases);
111+
112+
int main() {
113+
return !Harness::run(specification);
94114
}
115+

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

Lines changed: 31 additions & 14 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,17 +110,7 @@ void generate_buffer(uint8_t **buffer, size_t *size, size_t min, size_t max) {
107110
}
108111

109112

110-
int main() {
111-
char uuid[48] = {0};
112-
GREENTEA_SETUP_UUID(120, "tcp_echo", uuid, 48);
113-
114-
// create mac address based on uuid
115-
uint64_t mac = 0;
116-
for (int i = 0; i < sizeof(uuid); i++) {
117-
mac += uuid[i];
118-
}
119-
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);
120-
113+
void test_tcp_packet_pressure() {
121114
generate_buffer(&buffer, &buffer_size,
122115
MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MIN,
123116
MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MAX);
@@ -132,8 +125,6 @@ int main() {
132125

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

135-
bool result = true;
136-
137128
char recv_key[] = "host_port";
138129
char ipbuf[60] = {0};
139130
char portbuf[16] = {0};
@@ -232,5 +223,31 @@ int main() {
232223
MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MIN) / (1000*timer.read()));
233224

234225
eth.disconnect();
235-
GREENTEA_TESTSUITE_RESULT(result);
236226
}
227+
228+
229+
// Test setup
230+
utest::v1::status_t test_setup(const size_t number_of_cases) {
231+
char uuid[48] = {0};
232+
GREENTEA_SETUP_UUID(120, "tcp_echo", uuid, 48);
233+
234+
// create mac address based on uuid
235+
uint64_t mac = 0;
236+
for (int i = 0; i < sizeof(uuid); i++) {
237+
mac += uuid[i];
238+
}
239+
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);
240+
241+
return verbose_test_setup_handler(number_of_cases);
242+
}
243+
244+
Case cases[] = {
245+
Case("TCP packet pressure", test_tcp_packet_pressure),
246+
};
247+
248+
Specification specification(test_setup, cases);
249+
250+
int main() {
251+
return !Harness::run(specification);
252+
}
253+

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

Lines changed: 31 additions & 14 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,17 +227,7 @@ class PressureTest {
224227
PressureTest *pressure_tests[MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_THREADS];
225228

226229

227-
int main() {
228-
char uuid[48] = {0};
229-
GREENTEA_SETUP_UUID(120, "tcp_echo", uuid, 48);
230-
231-
// create mac address based on uuid
232-
uint64_t mac = 0;
233-
for (int i = 0; i < sizeof(uuid); i++) {
234-
mac += uuid[i];
235-
}
236-
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);
237-
230+
void test_tcp_packet_pressure_parallel() {
238231
uint8_t *buffer;
239232
size_t buffer_size;
240233
generate_buffer(&buffer, &buffer_size,
@@ -255,8 +248,6 @@ int main() {
255248

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

258-
bool result = true;
259-
260251
char recv_key[] = "host_port";
261252
char ipbuf[60] = {0};
262253
char portbuf[16] = {0};
@@ -294,5 +285,31 @@ int main() {
294285
MBED_CFG_TCP_CLIENT_PACKET_PRESSURE_MIN) / (1000*timer.read()));
295286

296287
net.disconnect();
297-
GREENTEA_TESTSUITE_RESULT(result);
298288
}
289+
290+
291+
// Test setup
292+
utest::v1::status_t test_setup(const size_t number_of_cases) {
293+
char uuid[48] = {0};
294+
GREENTEA_SETUP_UUID(120, "tcp_echo", uuid, 48);
295+
296+
// create mac address based on uuid
297+
uint64_t mac = 0;
298+
for (int i = 0; i < sizeof(uuid); i++) {
299+
mac += uuid[i];
300+
}
301+
mbed_set_mac_address((const char*)mac, /*coerce control bits*/ 1);
302+
303+
return verbose_test_setup_handler(number_of_cases);
304+
}
305+
306+
Case cases[] = {
307+
Case("TCP packet pressure parallel", test_tcp_packet_pressure_parallel),
308+
};
309+
310+
Specification specification(test_setup, cases);
311+
312+
int main() {
313+
return !Harness::run(specification);
314+
}
315+

0 commit comments

Comments
 (0)