diff --git a/TESTS/network/emac/README.md b/TESTS/network/emac/README.md index 2effe38847..ef3144b96a 100644 --- a/TESTS/network/emac/README.md +++ b/TESTS/network/emac/README.md @@ -124,6 +124,12 @@ The test case passes if there are no responses from the echo server, but further 2. Repeats the sending 10 times. 3. Verifies that all are replied. +### EMAC unicast long + +1. Sends CTP unicast messages with random Ethernet message length. +2. Repeats the sending 50000 times. +3. Verifies that all are replied. + ### EMAC multicast filter Tests multicast filtering. Multicast filtering is an optional feature for the EMAC. The test does not fail if filtering is not implemented. diff --git a/TESTS/network/emac/emac_test_unicast_long.cpp b/TESTS/network/emac/emac_test_unicast_long.cpp new file mode 100644 index 0000000000..365ae18ec7 --- /dev/null +++ b/TESTS/network/emac/emac_test_unicast_long.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2018, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" + +#if MBED_CONF_APP_TEST_WIFI || MBED_CONF_APP_TEST_ETHERNET + +#include "emac_tests.h" +#include "emac_util.h" +#include "emac_ctp.h" + +using namespace utest::v1; + +void test_emac_unicast_long_cb(int opt) +{ + static bool send_request = true; + static int no_response_cnt = 0; + static int retries = 0; + static int msg_len = 0; + static int test_step = 0; + + // Timeout + if (opt == TIMEOUT && send_request) { + CTP_MSG_SEND(msg_len, emac_if_get_echo_server_addr(0), emac_if_get_own_addr(), emac_if_get_own_addr(), 0); + send_request = false; + no_response_cnt = 0; + } else if (opt == TIMEOUT) { + if (++no_response_cnt > 350) { + if (++retries > 5) { + printf("too many retries\r\n\r\n"); + SET_ERROR_FLAGS(TEST_FAILED); + END_TEST_LOOP; + } else { + printf("retry count %i\r\n\r\n", retries); + send_request = true; + } + } + } + + // Echo response received + if (opt == INPUT) { + if (++test_step > 50000) { + END_TEST_LOOP; + } + + if (++test_step % 2000 == 0) { + printf("test step %i\r\n\r\n", test_step); + } + + msg_len = rand() % ETH_MAX_LEN; + retries = 0; + send_request = true; + } +} + +void test_emac_unicast_long() +{ + RESET_ALL_ERROR_FLAGS; + SET_TRACE_LEVEL(TRACE_FAILURE); + + if (ECHO_SERVER_ADDRESS_KNOWN) { + START_TEST_LOOP(test_emac_unicast_long_cb, 1); + } + + PRINT_ERROR_FLAGS; + TEST_ASSERT_FALSE(ERROR_FLAGS); + RESET_OUTGOING_MSG_DATA; +} + +#endif diff --git a/TESTS/network/emac/emac_tests.h b/TESTS/network/emac/emac_tests.h index 0487a0206d..6dbcd340a3 100644 --- a/TESTS/network/emac/emac_tests.h +++ b/TESTS/network/emac/emac_tests.h @@ -23,6 +23,7 @@ void test_emac_broadcast(); void test_emac_unicast(); void test_emac_unicast_frame_len(); void test_emac_unicast_burst(); +void test_emac_unicast_long(); void test_emac_multicast_filter(); void test_emac_memory(); diff --git a/TESTS/network/emac/emac_util.cpp b/TESTS/network/emac/emac_util.cpp index 23ece204ce..ede4925e13 100644 --- a/TESTS/network/emac/emac_util.cpp +++ b/TESTS/network/emac/emac_util.cpp @@ -252,7 +252,7 @@ bool emac_if_update_reply_to_outgoing_msg(int receipt_number, int length, int in /* If length of the sent message is smaller than Ethernet minimum frame length, validates against minimum frame length or sent length (in case frame has been converted to be longer than minimum length does not validate length) */ - if (length != ETH_FRAME_MIN_LEN && outgoing_msgs[outgoing_msg_index].length != length && length < ETH_FRAME_MIN_LEN ) { + if (length != ETH_FRAME_MIN_LEN && length != ETH_FRAME_PADD_LEN && outgoing_msgs[outgoing_msg_index].length != length && length < ETH_FRAME_MIN_LEN) { outgoing_msgs[outgoing_msg_index].flags |= INVALID_LENGHT; } } else { diff --git a/TESTS/network/emac/emac_util.h b/TESTS/network/emac/emac_util.h index 08570341a3..26f5b7339d 100644 --- a/TESTS/network/emac/emac_util.h +++ b/TESTS/network/emac/emac_util.h @@ -59,6 +59,7 @@ extern const unsigned char eth_mac_broadcast_addr[]; #define ETH_FRAME_HEADER_LEN 28 #define ETH_FRAME_MIN_LEN 60 + 4 +#define ETH_FRAME_PADD_LEN 60 #define ETH_MAC_ADDR_LEN 6 #define TIMEOUT 1 diff --git a/TESTS/network/emac/main.cpp b/TESTS/network/emac/main.cpp index c0f8aae377..fe05b721ab 100644 --- a/TESTS/network/emac/main.cpp +++ b/TESTS/network/emac/main.cpp @@ -70,6 +70,7 @@ Case cases[] = { Case("EMAC unicast", test_emac_unicast), Case("EMAC unicast frame length", test_emac_unicast_frame_len), Case("EMAC unicast burst", test_emac_unicast_burst), + Case("EMAC unicast long", test_emac_unicast_long), Case("EMAC multicast filter", test_emac_multicast_filter), Case("EMAC memory", test_emac_memory) };