Skip to content

Commit f705b41

Browse files
bridadanadbridge
authored andcommitted
Modifying echo test to be driven more from the device.
Previously, the echo test followed a flow like the following: -STEP- -HOST PC- -DEVICE- 0 send _sync 1 echo back _sync 2 send echo_count 3 echo back echo_count 4 send first echo packet 5 echo back echo packet (repeat echo steps) However, as noted by issue #6659, this test would somtimes fail between steps 4 and 5. To ensure each KV pair makes to the correct destination, we usually write the KV back. Step 4 does not wait for this to happen and starts sending echo packets. So the device is acting as the "echo server". This change makes the host PC the "echo server". The idea being that the device will be slower and the host pc should always be able to keep up with it, not the other way around.
1 parent 0296bba commit f705b41

File tree

2 files changed

+62
-9
lines changed

2 files changed

+62
-9
lines changed

TESTS/host_tests/device_echo.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
mbed SDK
3+
Copyright (c) 2011-2016 ARM Limited
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may 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,
13+
WITHOUT 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+
19+
import uuid
20+
from mbed_host_tests import BaseHostTest
21+
22+
class Device_Echo(BaseHostTest):
23+
24+
def _callback_repeat(self, key, value, _):
25+
self.send_kv(key, value)
26+
27+
def setup(self):
28+
self.register_callback("echo", self._callback_repeat)
29+
self.register_callback("echo_count", self._callback_repeat)
30+
31+
def teardown(self):
32+
pass

TESTS/mbed_drivers/echo/main.cpp

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,49 @@
2121
#include "unity/unity.h"
2222
#include "utest/utest.h"
2323

24+
#define PAYLOAD_LENGTH 36
25+
2426
using namespace utest::v1;
2527

28+
// Fill a buffer with a slice of the ASCII alphabet.
29+
void fill_buffer(char* buffer, unsigned int length, unsigned int index) {
30+
unsigned int start = length * index;
31+
for (int i = 0; i < length - 1; i++) {
32+
buffer[i] = 'a' + ((start + i) % 26);
33+
}
34+
buffer[length - 1] = '\0';
35+
}
36+
2637
// Echo server (echo payload to host)
2738
template<int N>
2839
void test_case_echo_server_x() {
2940
char _key[11] = {};
30-
char _value[128] = {};
41+
char _tx_value[PAYLOAD_LENGTH + 1] = {};
42+
char _rx_value[PAYLOAD_LENGTH + 1] = {};
3143
const int echo_count = N;
32-
const char _key_const[] = "echo_count";
44+
const char _echo_count_key_const[] = "echo_count";
45+
const char _echo_key_const[] = "echo";
3346
int expected_key = 1;
3447

35-
greentea_send_kv(_key_const, echo_count);
48+
// Send up the echo count
49+
greentea_send_kv(_echo_count_key_const, echo_count);
3650
// Handshake with host
3751
do {
38-
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
39-
expected_key = strcmp(_key_const, _key);
52+
greentea_parse_kv(_key, _rx_value, sizeof(_key), sizeof(_rx_value));
53+
// Ensure the key received is "echo_count" and not some old data
54+
expected_key = strcmp(_echo_count_key_const, _key);
4055
} while (expected_key);
41-
TEST_ASSERT_EQUAL_INT(echo_count, atoi(_value));
56+
TEST_ASSERT_EQUAL_INT(echo_count, atoi(_rx_value));
4257

4358
for (int i=0; i < echo_count; ++i) {
44-
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
45-
greentea_send_kv(_key, _value);
59+
fill_buffer(_tx_value, PAYLOAD_LENGTH, i);
60+
greentea_send_kv(_echo_key_const, _tx_value);
61+
do {
62+
greentea_parse_kv(_key, _rx_value, sizeof(_key), sizeof(_rx_value));
63+
// Ensure the key received is "echo" and not some old data
64+
expected_key = strcmp(_echo_key_const, _key);
65+
} while (expected_key);
66+
TEST_ASSERT(strncmp(_tx_value, _rx_value, PAYLOAD_LENGTH) == 0);
4667
}
4768
}
4869

@@ -56,7 +77,7 @@ Case cases[] = {
5677
};
5778

5879
utest::v1::status_t greentea_test_setup(const size_t number_of_cases) {
59-
GREENTEA_SETUP(30, "echo");
80+
GREENTEA_SETUP(30, "device_echo");
6081
return greentea_test_setup_handler(number_of_cases);
6182
}
6283

0 commit comments

Comments
 (0)