Skip to content

Commit

Permalink
Improvements to the EMAC test (#429)
Browse files Browse the repository at this point in the history
* Improvements to the EMAC test

* Make test less verbose & faster

* Initialize mbed-trace in netsocket tests
  • Loading branch information
multiplemonomials authored Feb 20, 2025
1 parent 635eb86 commit ed468ce
Show file tree
Hide file tree
Showing 15 changed files with 227 additions and 177 deletions.
1 change: 1 addition & 0 deletions connectivity/netsocket/tests/TESTS/netsocket/tcp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ int fetch_stats()
utest::v1::status_t greentea_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(tcp_global::TESTS_TIMEOUT.count(), "default_auto");
mbed_trace_init();
_ifup();
tc_bucket.start();
return greentea_test_setup_handler(number_of_cases);
Expand Down
1 change: 1 addition & 0 deletions connectivity/netsocket/tests/TESTS/netsocket/udp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ int fetch_stats()
utest::v1::status_t greentea_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(seconds(udp_global::TESTS_TIMEOUT).count(), "default_auto");
mbed_trace_init();
_ifup();
tc_bucket.start();
return greentea_test_setup_handler(number_of_cases);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ using namespace utest::v1;
void test_emac_memory_cb(int opt)
{
static bool send_request = true;
static bool memory = true;
static bool echo_should_work = true;
static int no_response_cnt = 0;
static int retries = 0;
static int msg_len = 0;
Expand All @@ -46,60 +46,52 @@ void test_emac_memory_cb(int opt)
printf("STEP 0: memory available\r\n\r\n");
emac_if_set_output_memory(true);
emac_if_set_input_memory(true);
memory = true;
echo_should_work = true;
break;

case 1:
printf("STEP 1: no input memory buffer memory available\r\n\r\n");
emac_if_set_output_memory(true);
emac_if_set_input_memory(false);
memory = false;
echo_should_work = false;
break;

case 2:
printf("STEP 2: memory available\r\n\r\n");
emac_if_set_output_memory(true);
emac_if_set_input_memory(true);
memory = true;
echo_should_work = true;
break;

case 3:
printf("STEP 3: no output memory buffer memory available\r\n\r\n");
emac_if_set_output_memory(false);
emac_if_set_input_memory(true);
memory = false;
echo_should_work = false;
break;

case 4:
printf("STEP 4: memory available\r\n\r\n");
emac_if_set_output_memory(true);
emac_if_set_input_memory(true);
memory = true;
echo_should_work = true;
break;

case 5:
printf("STEP 5: no output or input memory buffer memory available\r\n\r\n");
emac_if_set_output_memory(false);
emac_if_set_input_memory(false);
memory = false;
echo_should_work = false;
break;

case 6:
printf("STEP 6: memory available\r\n\r\n");
emac_if_set_output_memory(true);
emac_if_set_input_memory(true);
memory = true;
echo_should_work = true;
break;

case 7:
printf("STEP 7: memory available, alloc from heap\r\n\r\n");
emac_if_set_output_memory(true);
emac_if_set_input_memory(true);
options |= CTP_OPT_HEAP;
memory = true;
break;

case 8:
// Test ended
END_TEST_LOOP;
}
Expand All @@ -113,10 +105,10 @@ void test_emac_memory_cb(int opt)
send_request = false;
no_response_cnt = 0;
} else if (opt == TIMEOUT) {
if (++no_response_cnt > 5) {
if (++retries > 3) {
if (++no_response_cnt > 3) {
if (++retries > 1) {
// If echo replies should be received fails the test case
if (memory) {
if (echo_should_work) {
printf("too many retries\r\n\r\n");
SET_ERROR_FLAGS(TEST_FAILED);
END_TEST_LOOP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void test_emac_multicast_filter_cb(int opt)
break;

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

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

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

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


case 5:
printf("STEP 5: set receive all multicast, verify that input messages are not filtered\r\n\r\n");
printf("STEP 5: Remove last added mcast address, check that it no longer works\r\n\r\n");
{
unsigned char filter[] = {0x01, 0x00, 0x5e, 0xa5, 0xa6, 0xa7};
emac_if_remove_multicast_group(filter);
}
receive = false;
break;

case 6:
printf("STEP 6: Check that second to last added mcast address still works\r\n\r\n");
{
unsigned char filter[] = {0x01, 0x00, 0x5e, 0xa1, 0xa2, 0xa3};
memcpy(forward_addr, filter, 6);
}
receive = true;
break;

case 7:
printf("STEP 7: Check that first added mcast address still works\r\n\r\n");
{
unsigned char filter[] = {0x33, 0x33, 0xaa, 0xbb, 0xcc, 0xdd};
memcpy(forward_addr, filter, 6);
}
receive = true;
break;

case 8:
printf("STEP 8: Remove first added mcast address, check that it does not work now\r\n\r\n");
{
unsigned char filter[] = {0x33, 0x33, 0xaa, 0xbb, 0xcc, 0xdd};
emac_if_remove_multicast_group(filter);
}
receive = false;
break;

case 9:
printf("STEP 9: set receive all multicast, verify that all mcast addresses are passed now\r\n\r\n");
{
emac_if_set_all_multicast(true);
char forw_addr[] = {0x33, 0x33, 0x11, 0x12, 0x33, 0x44};
Expand All @@ -103,10 +140,11 @@ void test_emac_multicast_filter_cb(int opt)
receive = true;
break;

case 6:
case 10:
// Test ended
if (!multicasts_are_filtered) {
printf("multicast filtering was not enabled!!!\r\n\r\n");
SET_ERROR_FLAGS(TEST_FAILED);
}
END_TEST_LOOP;
}
Expand All @@ -119,7 +157,7 @@ void test_emac_multicast_filter_cb(int opt)
no_response_cnt = 0;
} else if (opt == TIMEOUT) {
if (++no_response_cnt > 5) {
if (++retries > 3) {
if (++retries > 1) {
if (receive) {
printf("too many retries\r\n\r\n");
SET_ERROR_FLAGS(TEST_FAILED);
Expand All @@ -137,23 +175,15 @@ void test_emac_multicast_filter_cb(int opt)
// Echo response received
if (opt == INPUT) {
if (receive == false) {
printf("multicast was not filtered\r\n\r\n");
printf("ERROR: multicast was received but should not have been!\r\n\r\n");
multicasts_are_filtered = false;
}
next_step = true;
}

if (next_step) {
RESET_OUTGOING_MSG_DATA;
#if (MBED_CONF_NETWORK_EMAC_NO_SUPPORT_FOR_IPV4_MULTICAST_FILTER == 1)
if (test_step == 2) {
test_step = 5;
} else {
test_step++;
}
#else
test_step++;
#endif
retries = 0;
send_request = true;
}
Expand All @@ -165,7 +195,7 @@ void test_emac_multicast_filter()
SET_TRACE_LEVEL(TRACE_SEND | TRACE_ETH_FRAMES | TRACE_SUCCESS | TRACE_FAILURE);

if (ECHO_SERVER_ADDRESS_KNOWN) {
START_TEST_LOOP(test_emac_multicast_filter_cb, 1s);
START_TEST_LOOP(test_emac_multicast_filter_cb, 250ms);
}

PRINT_ERROR_FLAGS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void test_emac_unicast_burst_cb(int opt)
void test_emac_unicast_burst()
{
RESET_ALL_ERROR_FLAGS;
SET_TRACE_LEVEL(TRACE_SEND | TRACE_SUCCESS | TRACE_FAILURE);
SET_TRACE_LEVEL(TRACE_FAILURE);

if (ECHO_SERVER_ADDRESS_KNOWN) {
START_TEST_LOOP(test_emac_unicast_burst_cb, 100ms);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void test_emac_unicast_long_cb(int opt)

// Echo response received
if (opt == INPUT) {
if (++test_step > 50000) {
if (++test_step > 10000) {
END_TEST_LOOP;
}

Expand Down
2 changes: 1 addition & 1 deletion connectivity/netsocket/tests/TESTS/network/emac/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ utest::v1::status_t test_setup(const size_t number_of_cases)

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

This file was deleted.

This file was deleted.

Loading

0 comments on commit ed468ce

Please sign in to comment.