Skip to content

Commit 8cb46bc

Browse files
committed
Add a serial transmission complete test
This automated test makes sure that the serial syncrhonous API ensures a full transmission before the function returns. The complete string sent by printf shall be completely transferred before printf returns and the sleep modes are called. mbed Issue #1849
1 parent bd2159d commit 8cb46bc

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "mbed.h"
2+
#include "test_env.h"
3+
4+
Serial *pc = new Serial(USBTX, USBRX);
5+
6+
int main() {
7+
MBED_HOSTTEST_TIMEOUT(20);
8+
MBED_HOSTTEST_SELECT(serial_complete_auto);
9+
MBED_HOSTTEST_DESCRIPTION(Serial Complete);
10+
MBED_HOSTTEST_START("MBED_39");
11+
12+
pc->printf("123456789");
13+
14+
while (1) {
15+
deepsleep();
16+
}
17+
}

tools/host_tests/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from wfi_auto import WFITest
3434
from serial_nc_rx_auto import SerialNCRXTest
3535
from serial_nc_tx_auto import SerialNCTXTest
36+
from serial_complete_auto import SerialCompleteTest
3637

3738
# Populate registry with supervising objects
3839
HOSTREGISTRY = HostRegistry()
@@ -52,6 +53,7 @@
5253
HOSTREGISTRY.register_host_test("wfi_auto", WFITest())
5354
HOSTREGISTRY.register_host_test("serial_nc_rx_auto", SerialNCRXTest())
5455
HOSTREGISTRY.register_host_test("serial_nc_tx_auto", SerialNCTXTest())
56+
HOSTREGISTRY.register_host_test("serial_complete_auto", SerialCompleteTest())
5557

5658
###############################################################################
5759
# Functional interface for test supervisor registry
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
mbed SDK
3+
Copyright (c) 2011-2013 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+
import sys
19+
import uuid
20+
import time
21+
import string
22+
from sys import stdout
23+
24+
class SerialCompleteTest():
25+
26+
def test(self, selftest):
27+
strip_chars = string.whitespace + "\0"
28+
out_str = selftest.mbed.serial_readline()
29+
selftest.notify("HOST: " + out_str)
30+
31+
if not out_str:
32+
selftest.notify("HOST: No output detected")
33+
return selftest.RESULT_IO_SERIAL
34+
35+
out_str_stripped = out_str.strip(strip_chars)
36+
37+
if out_str_stripped != "123456789":
38+
selftest.notify("HOST: Unexpected output. '123456789' Expected. but received '%s'" % out_str_stripped)
39+
return selftest.RESULT_FAILURE
40+
41+
else:
42+
return selftest.RESULT_SUCCESS
43+

tools/tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,12 @@
653653
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
654654
"automated": True
655655
},
656+
{
657+
"id": "MBED_39", "description": "Serial Complete",
658+
"source_dir": join(TEST_DIR, "mbed", "serial_complete"),
659+
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
660+
"automated": True
661+
},
656662

657663
# CMSIS RTOS tests
658664
{

0 commit comments

Comments
 (0)