Skip to content

Commit f54067d

Browse files
author
Cruz Monrreal
authored
Merge pull request #7208 from mikaleppanen/add_long_emac_echo_test
Added long echo sequence test to EMAC tests
2 parents 938b924 + 0334cd1 commit f54067d

File tree

6 files changed

+97
-1
lines changed

6 files changed

+97
-1
lines changed

TESTS/network/emac/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ The test case passes if there are no responses from the echo server, but further
124124
2. Repeats the sending 10 times.
125125
3. Verifies that all are replied.
126126

127+
### EMAC unicast long
128+
129+
1. Sends CTP unicast messages with random Ethernet message length.
130+
2. Repeats the sending 50000 times.
131+
3. Verifies that all are replied.
132+
127133
### EMAC multicast filter
128134

129135
Tests multicast filtering. Multicast filtering is an optional feature for the EMAC. The test does not fail if filtering is not implemented.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright (c) 2018, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "mbed.h"
19+
#include "greentea-client/test_env.h"
20+
#include "unity.h"
21+
#include "utest.h"
22+
23+
#if MBED_CONF_APP_TEST_WIFI || MBED_CONF_APP_TEST_ETHERNET
24+
25+
#include "emac_tests.h"
26+
#include "emac_util.h"
27+
#include "emac_ctp.h"
28+
29+
using namespace utest::v1;
30+
31+
void test_emac_unicast_long_cb(int opt)
32+
{
33+
static bool send_request = true;
34+
static int no_response_cnt = 0;
35+
static int retries = 0;
36+
static int msg_len = 0;
37+
static int test_step = 0;
38+
39+
// Timeout
40+
if (opt == TIMEOUT && send_request) {
41+
CTP_MSG_SEND(msg_len, emac_if_get_echo_server_addr(0), emac_if_get_own_addr(), emac_if_get_own_addr(), 0);
42+
send_request = false;
43+
no_response_cnt = 0;
44+
} else if (opt == TIMEOUT) {
45+
if (++no_response_cnt > 350) {
46+
if (++retries > 5) {
47+
printf("too many retries\r\n\r\n");
48+
SET_ERROR_FLAGS(TEST_FAILED);
49+
END_TEST_LOOP;
50+
} else {
51+
printf("retry count %i\r\n\r\n", retries);
52+
send_request = true;
53+
}
54+
}
55+
}
56+
57+
// Echo response received
58+
if (opt == INPUT) {
59+
if (++test_step > 50000) {
60+
END_TEST_LOOP;
61+
}
62+
63+
if (++test_step % 2000 == 0) {
64+
printf("test step %i\r\n\r\n", test_step);
65+
}
66+
67+
msg_len = rand() % ETH_MAX_LEN;
68+
retries = 0;
69+
send_request = true;
70+
}
71+
}
72+
73+
void test_emac_unicast_long()
74+
{
75+
RESET_ALL_ERROR_FLAGS;
76+
SET_TRACE_LEVEL(TRACE_FAILURE);
77+
78+
if (ECHO_SERVER_ADDRESS_KNOWN) {
79+
START_TEST_LOOP(test_emac_unicast_long_cb, 1);
80+
}
81+
82+
PRINT_ERROR_FLAGS;
83+
TEST_ASSERT_FALSE(ERROR_FLAGS);
84+
RESET_OUTGOING_MSG_DATA;
85+
}
86+
87+
#endif

TESTS/network/emac/emac_tests.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void test_emac_broadcast();
2323
void test_emac_unicast();
2424
void test_emac_unicast_frame_len();
2525
void test_emac_unicast_burst();
26+
void test_emac_unicast_long();
2627
void test_emac_multicast_filter();
2728
void test_emac_memory();
2829

TESTS/network/emac/emac_util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ bool emac_if_update_reply_to_outgoing_msg(int receipt_number, int length, int in
252252
/* If length of the sent message is smaller than Ethernet minimum frame length, validates against
253253
minimum frame length or sent length (in case frame has been converted to be longer than minimum
254254
length does not validate length) */
255-
if (length != ETH_FRAME_MIN_LEN && outgoing_msgs[outgoing_msg_index].length != length && length < ETH_FRAME_MIN_LEN ) {
255+
if (length != ETH_FRAME_MIN_LEN && length != ETH_FRAME_PADD_LEN && outgoing_msgs[outgoing_msg_index].length != length && length < ETH_FRAME_MIN_LEN) {
256256
outgoing_msgs[outgoing_msg_index].flags |= INVALID_LENGHT;
257257
}
258258
} else {

TESTS/network/emac/emac_util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ extern const unsigned char eth_mac_broadcast_addr[];
5959

6060
#define ETH_FRAME_HEADER_LEN 28
6161
#define ETH_FRAME_MIN_LEN 60 + 4
62+
#define ETH_FRAME_PADD_LEN 60
6263
#define ETH_MAC_ADDR_LEN 6
6364

6465
#define TIMEOUT 1

TESTS/network/emac/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Case cases[] = {
7070
Case("EMAC unicast", test_emac_unicast),
7171
Case("EMAC unicast frame length", test_emac_unicast_frame_len),
7272
Case("EMAC unicast burst", test_emac_unicast_burst),
73+
Case("EMAC unicast long", test_emac_unicast_long),
7374
Case("EMAC multicast filter", test_emac_multicast_filter),
7475
Case("EMAC memory", test_emac_memory)
7576
};

0 commit comments

Comments
 (0)