Skip to content

Commit ed468ce

Browse files
author
Jamie Smith
authored
Improvements to the EMAC test (#429)
* Improvements to the EMAC test * Make test less verbose & faster * Initialize mbed-trace in netsocket tests
1 parent 635eb86 commit ed468ce

File tree

15 files changed

+227
-177
lines changed

15 files changed

+227
-177
lines changed

connectivity/netsocket/tests/TESTS/netsocket/tcp/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ int fetch_stats()
159159
utest::v1::status_t greentea_setup(const size_t number_of_cases)
160160
{
161161
GREENTEA_SETUP(tcp_global::TESTS_TIMEOUT.count(), "default_auto");
162+
mbed_trace_init();
162163
_ifup();
163164
tc_bucket.start();
164165
return greentea_test_setup_handler(number_of_cases);

connectivity/netsocket/tests/TESTS/netsocket/udp/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ int fetch_stats()
136136
utest::v1::status_t greentea_setup(const size_t number_of_cases)
137137
{
138138
GREENTEA_SETUP(seconds(udp_global::TESTS_TIMEOUT).count(), "default_auto");
139+
mbed_trace_init();
139140
_ifup();
140141
tc_bucket.start();
141142
return greentea_test_setup_handler(number_of_cases);

connectivity/netsocket/tests/TESTS/network/emac/emac_test_memory.cpp

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ using namespace utest::v1;
3030
void test_emac_memory_cb(int opt)
3131
{
3232
static bool send_request = true;
33-
static bool memory = true;
33+
static bool echo_should_work = true;
3434
static int no_response_cnt = 0;
3535
static int retries = 0;
3636
static int msg_len = 0;
@@ -46,60 +46,52 @@ void test_emac_memory_cb(int opt)
4646
printf("STEP 0: memory available\r\n\r\n");
4747
emac_if_set_output_memory(true);
4848
emac_if_set_input_memory(true);
49-
memory = true;
49+
echo_should_work = true;
5050
break;
5151

5252
case 1:
5353
printf("STEP 1: no input memory buffer memory available\r\n\r\n");
5454
emac_if_set_output_memory(true);
5555
emac_if_set_input_memory(false);
56-
memory = false;
56+
echo_should_work = false;
5757
break;
5858

5959
case 2:
6060
printf("STEP 2: memory available\r\n\r\n");
6161
emac_if_set_output_memory(true);
6262
emac_if_set_input_memory(true);
63-
memory = true;
63+
echo_should_work = true;
6464
break;
6565

6666
case 3:
6767
printf("STEP 3: no output memory buffer memory available\r\n\r\n");
6868
emac_if_set_output_memory(false);
6969
emac_if_set_input_memory(true);
70-
memory = false;
70+
echo_should_work = false;
7171
break;
7272

7373
case 4:
7474
printf("STEP 4: memory available\r\n\r\n");
7575
emac_if_set_output_memory(true);
7676
emac_if_set_input_memory(true);
77-
memory = true;
77+
echo_should_work = true;
7878
break;
7979

8080
case 5:
8181
printf("STEP 5: no output or input memory buffer memory available\r\n\r\n");
8282
emac_if_set_output_memory(false);
8383
emac_if_set_input_memory(false);
84-
memory = false;
84+
echo_should_work = false;
8585
break;
8686

8787
case 6:
8888
printf("STEP 6: memory available\r\n\r\n");
8989
emac_if_set_output_memory(true);
9090
emac_if_set_input_memory(true);
91-
memory = true;
91+
echo_should_work = true;
9292
break;
9393

9494
case 7:
95-
printf("STEP 7: memory available, alloc from heap\r\n\r\n");
96-
emac_if_set_output_memory(true);
97-
emac_if_set_input_memory(true);
98-
options |= CTP_OPT_HEAP;
99-
memory = true;
100-
break;
101-
102-
case 8:
10395
// Test ended
10496
END_TEST_LOOP;
10597
}
@@ -113,10 +105,10 @@ void test_emac_memory_cb(int opt)
113105
send_request = false;
114106
no_response_cnt = 0;
115107
} else if (opt == TIMEOUT) {
116-
if (++no_response_cnt > 5) {
117-
if (++retries > 3) {
108+
if (++no_response_cnt > 3) {
109+
if (++retries > 1) {
118110
// If echo replies should be received fails the test case
119-
if (memory) {
111+
if (echo_should_work) {
120112
printf("too many retries\r\n\r\n");
121113
SET_ERROR_FLAGS(TEST_FAILED);
122114
END_TEST_LOOP;

connectivity/netsocket/tests/TESTS/network/emac/emac_test_multicast_filter.cpp

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void test_emac_multicast_filter_cb(int opt)
5252
break;
5353

5454
case 1:
55-
printf("STEP 1: set ipv6 multicast filter, test if input message is filtered\r\n\r\n");
55+
printf("STEP 1: set ipv6 multicast filter to wrong address, test if input message is correctly filtered out (NOT received)\r\n\r\n");
5656
{
5757
unsigned char filter[] = {0x33, 0x33, 0x1b, 0x1c, 0x1d, 0x1e};
5858
char forw_addr[] = {0x33, 0x33, 0x11, 0x22, 0x33, 0x44};
@@ -63,7 +63,7 @@ void test_emac_multicast_filter_cb(int opt)
6363
break;
6464

6565
case 2:
66-
printf("STEP 2: set ipv6 multicast filter, test that input message is not filtered\r\n\r\n");
66+
printf("STEP 2: set ipv6 multicast filter, test that input message is passed by mcast filter\r\n\r\n");
6767
{
6868
unsigned char filter[] = {0x33, 0x33, 0xaa, 0xbb, 0xcc, 0xdd};
6969
emac_if_add_multicast_group(filter);
@@ -73,7 +73,7 @@ void test_emac_multicast_filter_cb(int opt)
7373
break;
7474

7575
case 3:
76-
printf("STEP 3: set ipv4 multicast filter, test if input message is filtered\r\n\r\n");
76+
printf("STEP 3: set ipv4 multicast filter to wrong address, test if input message is correctly filtered out (NOT received)\r\n\r\n");
7777
{
7878
unsigned char filter[] = {0x01, 0x00, 0x5e, 0xa1, 0xa2, 0xa3};
7979
char forw_addr[] = {0x01, 0x00, 0x5e, 0x11, 0x22, 0x33};
@@ -84,7 +84,7 @@ void test_emac_multicast_filter_cb(int opt)
8484
break;
8585

8686
case 4:
87-
printf("STEP 4: set ipv4 multicast filter, test that input message is not filtered\r\n\r\n");
87+
printf("STEP 4: set ipv4 multicast filter, test that input message is passed by mcast filter\r\n\r\n");
8888
{
8989
unsigned char filter[] = {0x01, 0x00, 0x5e, 0xa5, 0xa6, 0xa7};
9090
emac_if_add_multicast_group(filter);
@@ -93,8 +93,45 @@ void test_emac_multicast_filter_cb(int opt)
9393
receive = true;
9494
break;
9595

96+
9697
case 5:
97-
printf("STEP 5: set receive all multicast, verify that input messages are not filtered\r\n\r\n");
98+
printf("STEP 5: Remove last added mcast address, check that it no longer works\r\n\r\n");
99+
{
100+
unsigned char filter[] = {0x01, 0x00, 0x5e, 0xa5, 0xa6, 0xa7};
101+
emac_if_remove_multicast_group(filter);
102+
}
103+
receive = false;
104+
break;
105+
106+
case 6:
107+
printf("STEP 6: Check that second to last added mcast address still works\r\n\r\n");
108+
{
109+
unsigned char filter[] = {0x01, 0x00, 0x5e, 0xa1, 0xa2, 0xa3};
110+
memcpy(forward_addr, filter, 6);
111+
}
112+
receive = true;
113+
break;
114+
115+
case 7:
116+
printf("STEP 7: Check that first added mcast address still works\r\n\r\n");
117+
{
118+
unsigned char filter[] = {0x33, 0x33, 0xaa, 0xbb, 0xcc, 0xdd};
119+
memcpy(forward_addr, filter, 6);
120+
}
121+
receive = true;
122+
break;
123+
124+
case 8:
125+
printf("STEP 8: Remove first added mcast address, check that it does not work now\r\n\r\n");
126+
{
127+
unsigned char filter[] = {0x33, 0x33, 0xaa, 0xbb, 0xcc, 0xdd};
128+
emac_if_remove_multicast_group(filter);
129+
}
130+
receive = false;
131+
break;
132+
133+
case 9:
134+
printf("STEP 9: set receive all multicast, verify that all mcast addresses are passed now\r\n\r\n");
98135
{
99136
emac_if_set_all_multicast(true);
100137
char forw_addr[] = {0x33, 0x33, 0x11, 0x12, 0x33, 0x44};
@@ -103,10 +140,11 @@ void test_emac_multicast_filter_cb(int opt)
103140
receive = true;
104141
break;
105142

106-
case 6:
143+
case 10:
107144
// Test ended
108145
if (!multicasts_are_filtered) {
109146
printf("multicast filtering was not enabled!!!\r\n\r\n");
147+
SET_ERROR_FLAGS(TEST_FAILED);
110148
}
111149
END_TEST_LOOP;
112150
}
@@ -119,7 +157,7 @@ void test_emac_multicast_filter_cb(int opt)
119157
no_response_cnt = 0;
120158
} else if (opt == TIMEOUT) {
121159
if (++no_response_cnt > 5) {
122-
if (++retries > 3) {
160+
if (++retries > 1) {
123161
if (receive) {
124162
printf("too many retries\r\n\r\n");
125163
SET_ERROR_FLAGS(TEST_FAILED);
@@ -137,23 +175,15 @@ void test_emac_multicast_filter_cb(int opt)
137175
// Echo response received
138176
if (opt == INPUT) {
139177
if (receive == false) {
140-
printf("multicast was not filtered\r\n\r\n");
178+
printf("ERROR: multicast was received but should not have been!\r\n\r\n");
141179
multicasts_are_filtered = false;
142180
}
143181
next_step = true;
144182
}
145183

146184
if (next_step) {
147185
RESET_OUTGOING_MSG_DATA;
148-
#if (MBED_CONF_NETWORK_EMAC_NO_SUPPORT_FOR_IPV4_MULTICAST_FILTER == 1)
149-
if (test_step == 2) {
150-
test_step = 5;
151-
} else {
152-
test_step++;
153-
}
154-
#else
155186
test_step++;
156-
#endif
157187
retries = 0;
158188
send_request = true;
159189
}
@@ -165,7 +195,7 @@ void test_emac_multicast_filter()
165195
SET_TRACE_LEVEL(TRACE_SEND | TRACE_ETH_FRAMES | TRACE_SUCCESS | TRACE_FAILURE);
166196

167197
if (ECHO_SERVER_ADDRESS_KNOWN) {
168-
START_TEST_LOOP(test_emac_multicast_filter_cb, 1s);
198+
START_TEST_LOOP(test_emac_multicast_filter_cb, 250ms);
169199
}
170200

171201
PRINT_ERROR_FLAGS;

connectivity/netsocket/tests/TESTS/network/emac/emac_test_unicast_burst.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void test_emac_unicast_burst_cb(int opt)
7575
void test_emac_unicast_burst()
7676
{
7777
RESET_ALL_ERROR_FLAGS;
78-
SET_TRACE_LEVEL(TRACE_SEND | TRACE_SUCCESS | TRACE_FAILURE);
78+
SET_TRACE_LEVEL(TRACE_FAILURE);
7979

8080
if (ECHO_SERVER_ADDRESS_KNOWN) {
8181
START_TEST_LOOP(test_emac_unicast_burst_cb, 100ms);

connectivity/netsocket/tests/TESTS/network/emac/emac_test_unicast_long.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void test_emac_unicast_long_cb(int opt)
5555

5656
// Echo response received
5757
if (opt == INPUT) {
58-
if (++test_step > 50000) {
58+
if (++test_step > 10000) {
5959
END_TEST_LOOP;
6060
}
6161

connectivity/netsocket/tests/TESTS/network/emac/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ utest::v1::status_t test_setup(const size_t number_of_cases)
4646

4747
Case cases[] = {
4848
Case("EMAC initialize", test_emac_initialize),
49-
Case("EMAC broadcast", test_emac_broadcast),
49+
Case("EMAC broadcast", test_emac_broadcast), // note: this test case has the side effect of finding the CTP server MAC address and saving it
5050
Case("EMAC unicast", test_emac_unicast),
5151
Case("EMAC unicast frame length", test_emac_unicast_frame_len),
5252
Case("EMAC unicast burst", test_emac_unicast_burst),

connectivity/netsocket/tests/TESTS/network/emac/template_mbed_app.txt

Lines changed: 0 additions & 24 deletions
This file was deleted.

connectivity/netsocket/tests/TESTS/network/emac/template_mbed_app_echo_server.txt

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)