Skip to content

Commit 5c15819

Browse files
author
Mika Leppänen
committed
Tests for wifi emac interface
1 parent a519b84 commit 5c15819

15 files changed

+1343
-0
lines changed

TESTS/network/emac/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Description
2+
3+
This document describes how to run EMAC tests. The EMAC test cases are made using Ethernet Configuration Testing Protocol (CTP). To run the tests, one device in the Ethernet segment needs to be configured to be a CTP echo server. The devices running the test cases, use the echo server to forward the CTP Ethernet frames back.
4+
5+
# Configuring CTP echo server
6+
7+
A device can be configured to be a CTP echo server by enabling `echo-server` setting in the test environment's application `json` file. When device is configured to be a CTP echo server, it starts to forward CTP messages automatically after power up and will continue forwarding until power down.
8+
9+
# Test cases
10+
11+
## EMAC interface initialise
12+
13+
Initializes EMAC interface driver.
14+
15+
For WLAN installs test case so that it can intercept incoming Ethernet messages from the WLAN driver. Incoming CTP frames are handed by the test case and other frames are forwarded to the LWIP stack.
16+
17+
## EMAC interface broadcast
18+
19+
Sends three 100 byte CTP broadcast messages, waits for three seconds and sends three 50 byte CTP broadcast messages. Listens for the CTP echo server responses and stores the addresses of the echo servers if replies are received. The test case will pass if there are no responses from echo server, but further test cases will be skipped.
20+
21+
## EMAC interface unicast
22+
23+
Sends three CTP unicast messages to the CTP echo server. Verifies that all are replied.
24+
25+
## EMAC interface unicast frame length
26+
27+
Sends CTP unicast messages with Ethernet message length from 100 bytes to maximum. Verifies that all are replied.
28+

TESTS/network/emac/emac_ctp.cpp

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/*
2+
* Copyright (c) 2017, 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 "greentea-client/test_env.h"
19+
#include "unity/unity.h"
20+
#include "utest.h"
21+
22+
#if MBED_CONF_APP_TEST_WIFI || MBED_CONF_APP_TEST_ETHERNET
23+
24+
#include "mbed.h"
25+
26+
#include "lwip/opt.h" /* ETH_PAD_SIZE */
27+
28+
#include "emac_stack_mem.h"
29+
#include "emac_api.h"
30+
31+
#include "emac_tests.h"
32+
#include "emac_ctp.h"
33+
34+
#include "emac_initialize.h"
35+
#include "emac_util.h"
36+
#include "emac_membuf.h"
37+
38+
using namespace utest::v1;
39+
40+
// Unique identifier for message
41+
static int receipt_number = 0;
42+
43+
static int emac_if_ctp_header_build(unsigned char *eth_frame, const unsigned char *dest_addr, const unsigned char *origin_addr, const unsigned char *forward_addr)
44+
{
45+
memcpy(&eth_frame[0], dest_addr, 6);
46+
memcpy(&eth_frame[6], origin_addr, 6);
47+
48+
eth_frame[12] = 0x90; /* loop back */
49+
eth_frame[13] = 0x00;
50+
51+
eth_frame[14] = 0x00; /* skip count */
52+
eth_frame[15] = 0x00;
53+
54+
eth_frame[16] = 0x02; /* function, forward */
55+
eth_frame[17] = 0x00;
56+
57+
memcpy(&eth_frame[18], forward_addr, 6);
58+
59+
eth_frame[24] = 0x01; /* function, reply */
60+
eth_frame[25] = 0x00;
61+
62+
receipt_number++;
63+
64+
eth_frame[26] = receipt_number; /* receipt number */
65+
eth_frame[27] = receipt_number >> 8;
66+
67+
return receipt_number;
68+
}
69+
70+
ctp_function emac_if_ctp_header_handle(unsigned char *eth_input_frame, unsigned char *eth_output_frame, unsigned char *origin_addr, int *receipt_number)
71+
{
72+
if (eth_input_frame[12] != 0x90 || eth_input_frame[13] != 0x00) {
73+
return CTP_NONE;
74+
}
75+
76+
int skip_count = eth_input_frame[15] << 8 | eth_input_frame[14];
77+
unsigned char *ethernet_ptr = &eth_input_frame[16] + skip_count;
78+
79+
int function = ethernet_ptr[1] << 8 | ethernet_ptr[0];
80+
ethernet_ptr += 2;
81+
82+
// Forward
83+
if (function == 0x0002) {
84+
memcpy(eth_output_frame, eth_input_frame, ETH_FRAME_HEADER_LEN);
85+
// Update skip count
86+
skip_count += 8;
87+
eth_output_frame[14] = skip_count;
88+
eth_output_frame[15] = skip_count >> 8;
89+
// Set forward address to destination address
90+
memcpy(&eth_output_frame[0], ethernet_ptr, 6);
91+
// Copy own address to origin
92+
memcpy(&eth_output_frame[6], origin_addr, 6);
93+
return CTP_FORWARD;
94+
// reply
95+
} else if (function == 0x0001) {
96+
*receipt_number = ethernet_ptr[1] << 8 | ethernet_ptr[0];
97+
return CTP_REPLY;
98+
}
99+
100+
return CTP_NONE;
101+
}
102+
103+
void emac_if_ctp_msg_build(int eth_frame_len, const unsigned char *dest_addr, const unsigned char *origin_addr, const unsigned char *forward_addr)
104+
{
105+
if (eth_frame_len < ETH_FRAME_HEADER_LEN) {
106+
eth_frame_len = ETH_FRAME_HEADER_LEN;
107+
}
108+
109+
printf("message sent %x:%x:%x:%x:%x:%x\r\n\r\n", dest_addr[0], dest_addr[1], dest_addr[2], dest_addr[3], dest_addr[4], dest_addr[5]);
110+
111+
int outgoing_msg_index = emac_if_add_outgoing_msg(eth_frame_len);
112+
113+
if (outgoing_msg_index < 0) {
114+
SET_ERROR_FLAGS(OUT_OF_MSG_DATA);
115+
return;
116+
}
117+
118+
emac_stack_mem_chain_t *mem_chain_p = emac_stack_mem_alloc(0, eth_frame_len + ETH_PAD_SIZE, 0);
119+
120+
if (!mem_chain_p) {
121+
SET_ERROR_FLAGS(NO_FREE_MEM_BUF);
122+
emac_if_free_outgoing_msg(outgoing_msg_index);
123+
return;
124+
}
125+
126+
if (memcmp(dest_addr, eth_mac_broadcast_addr, 6) == 0) {
127+
emac_if_set_outgoing_msg_flags(outgoing_msg_index, BROADCAST);
128+
}
129+
130+
unsigned char eth_output_frame_data[ETH_FRAME_HEADER_LEN];
131+
int receipt_number = emac_if_ctp_header_build(eth_output_frame_data, dest_addr, origin_addr, forward_addr);
132+
emac_if_set_outgoing_msg_receipt_num(outgoing_msg_index, receipt_number);
133+
134+
emac_if_memory_buffer_write(mem_chain_p, eth_output_frame_data, true);
135+
136+
//emac_if->ops.link_out(hw_driver, mem_chain_p);
137+
emac_if_get()->ops.link_out(emac_if_get(), mem_chain_p);
138+
139+
emac_stack_mem_free(0, mem_chain_p);
140+
}
141+
142+
#endif
143+

TESTS/network/emac/emac_ctp.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2017, 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+
#ifndef EMAC_CTP_H
19+
#define EMAC_CTP_H
20+
21+
enum ctp_function {
22+
CTP_NONE,
23+
CTP_FORWARD,
24+
CTP_REPLY
25+
};
26+
27+
ctp_function emac_if_ctp_header_handle(unsigned char *eth_input_frame, unsigned char *eth_output_frame, unsigned char *origin_addr, int *receipt_number);
28+
void emac_if_ctp_msg_build(int eth_frame_len, const unsigned char *dest_addr, const unsigned char *origin_addr, const unsigned char *forward_addr);
29+
void emac_if_ctp_reply_handle(int lenght, int invalid_data_index);
30+
31+
#endif /* EMAC_CTP_H */

TESTS/network/emac/emac_initialize.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2017, 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+
#ifndef EMAC_INITIALIZE_H
19+
#define EMAC_INITIALIZE_H
20+
21+
uint8_t *emac_if_get_hw_addr(void);
22+
emac_interface_t *emac_if_get(void);
23+
24+
#endif /* EMAC_INITIALIZE_H */

TESTS/network/emac/emac_membuf.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright (c) 2017, 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 "lwip/opt.h" /* ETH_PAD_SIZE */
26+
27+
#include "emac_api.h"
28+
#include "emac_stack_mem.h"
29+
30+
#include "emac_membuf.h"
31+
#include "emac_util.h"
32+
33+
int emac_if_memory_buffer_read(emac_stack_mem_chain_t *mem_chain_p, unsigned char *eth_frame)
34+
{
35+
int eth_frame_index = 0;
36+
int invalid_data_index = 0;
37+
int index = ETH_PAD_SIZE;
38+
39+
for (emac_stack_mem_t *mem_p = emac_stack_mem_chain_dequeue(0, &mem_chain_p); mem_p != NULL; mem_p = emac_stack_mem_chain_dequeue(0, &mem_chain_p)) {
40+
unsigned char *buf_payload = (unsigned char *) emac_stack_mem_ptr(0, mem_p);
41+
int buf_payload_len = emac_stack_mem_len(0, mem_p);
42+
43+
for (; index < buf_payload_len; index++) {
44+
if (eth_frame_index < ETH_FRAME_HEADER_LEN) {
45+
eth_frame[eth_frame_index] = buf_payload[index];
46+
} else {
47+
if (buf_payload[index] != (uint8_t) eth_frame_index) {
48+
invalid_data_index = eth_frame_index;
49+
break;
50+
}
51+
}
52+
eth_frame_index++;
53+
}
54+
index = 0;
55+
}
56+
57+
return invalid_data_index;
58+
}
59+
60+
void emac_if_memory_buffer_write(emac_stack_mem_chain_t *mem_chain_p, unsigned char *eth_frame, bool write_data)
61+
{
62+
int eth_frame_index = 0;
63+
int index = ETH_PAD_SIZE;
64+
65+
for (emac_stack_mem_t *mem_p = emac_stack_mem_chain_dequeue(0, &mem_chain_p); mem_p != NULL; mem_p = emac_stack_mem_chain_dequeue(0, &mem_chain_p)) {
66+
unsigned char *buf_payload = (unsigned char *) emac_stack_mem_ptr(0, mem_p);
67+
int buf_payload_len = emac_stack_mem_len(0, mem_p);
68+
69+
for (; index < buf_payload_len; index++) {
70+
if (eth_frame_index < ETH_FRAME_HEADER_LEN) {
71+
buf_payload[index] = eth_frame[eth_frame_index];
72+
} else if (write_data) {
73+
buf_payload[index] = (char) eth_frame_index;
74+
} else {
75+
break;
76+
}
77+
eth_frame_index++;
78+
}
79+
index = 0;
80+
}
81+
}
82+
83+
#endif

TESTS/network/emac/emac_membuf.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2017, 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+
#ifndef EMAC_MEMBUF_H
19+
#define EMAC_MEMBUF_H
20+
21+
int emac_if_memory_buffer_read(emac_stack_mem_chain_t *mem_chain_p, unsigned char *eth_frame);
22+
void emac_if_memory_buffer_write(emac_stack_mem_chain_t *mem_chain_p, unsigned char *eth_frame, bool write_data);
23+
24+
#endif /* EMAC_MEMBUF_H */

0 commit comments

Comments
 (0)