Skip to content

Commit 8a90249

Browse files
author
Cruz Monrreal
authored
Merge pull request #6718 from bridadan/echo_test_change
Modifying echo test to be driven more from the device.
2 parents 4c973e3 + 631e5eb commit 8a90249

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)