Skip to content

Commit 05baf36

Browse files
committed
Synchronize host and target for nc serial auto test
We're ensuring target and host start-up sync here in 2 ways: 1) adding a delay on host side to make sure the serial initialization can happen before sending a character is sent to target 2) in case of serial_nc_rx_auto.py test, we're sending a first character S which will trigger the move from rx+tx to NC+rx. This should avoid any crossing case due to HSOT being faster than target or vice-versa
1 parent c35a6f6 commit 05baf36

File tree

3 files changed

+47
-15
lines changed

3 files changed

+47
-15
lines changed

libraries/tests/mbed/serial_nc_rx/main.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,28 @@ int main() {
1111

1212
char c = pc->getc();
1313

14-
delete pc;
1514

16-
// This should be true
17-
if (c == 'E') {
18-
Serial *pc = new Serial(USBTX, NC);
19-
20-
pc->printf("RX OK - Expected\r\n");
21-
22-
c = pc->getc();
23-
24-
// This should be false/not get here
25-
if (c == 'U') {
26-
pc->printf("RX OK - Unexpected\r\n");
27-
}
28-
29-
delete pc;
15+
// This should be true, sync the start of test
16+
if (c == 'S') {
17+
pc->printf("RX OK - Start NC test\r\n");
18+
19+
// disconnect TX and get char
20+
delete pc;
21+
pc = new Serial(NC, USBRX);
22+
c = pc->getc();
23+
if (c == 'E') {
24+
// ok disconnect Rx and answer to host
25+
delete pc;
26+
pc = new Serial(USBTX, NC);
27+
pc->printf("RX OK - Expected\r\n");
28+
29+
c = pc->getc();
30+
// This should be false/not get here
31+
if (c == 'U') {
32+
pc->printf("RX OK - Unexpected\r\n");
33+
}
34+
}
35+
delete pc;
3036
}
3137

3238
while (1) {

workspace_tools/host_tests/serial_nc_rx_auto.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,29 @@ class SerialNCRXTest():
2525

2626
def test(self, selftest):
2727
selftest.mbed.flush();
28+
# Wait 0.5 seconds to ensure mbed is listening
29+
time.sleep(0.5)
30+
31+
#handshake with target to sync test start
32+
selftest.mbed.serial_write("S");
33+
34+
strip_chars = string.whitespace + "\0"
35+
36+
out_str = selftest.mbed.serial_readline()
37+
38+
if not out_str:
39+
selftest.notify("HOST: No output detected")
40+
return selftest.RESULT_IO_SERIAL
41+
42+
out_str_stripped = out_str.strip(strip_chars)
43+
44+
if out_str_stripped != "RX OK - Start NC test":
45+
selftest.notify("HOST: Unexpected output. Expected 'RX OK - Expected' but received '%s'" % out_str_stripped)
46+
return selftest.RESULT_FAILURE
47+
48+
# Wait 0.5 seconds to ensure mbed is listening
49+
time.sleep(0.5)
50+
2851
selftest.mbed.serial_write("E");
2952

3053
strip_chars = string.whitespace + "\0"

workspace_tools/host_tests/serial_nc_tx_auto.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class SerialNCTXTest():
2525

2626
def test(self, selftest):
2727
selftest.mbed.flush();
28+
# Wait 0.5 seconds to ensure mbed is listening
29+
time.sleep(0.5)
30+
2831
selftest.mbed.serial_write("S");
2932

3033
strip_chars = string.whitespace + "\0"

0 commit comments

Comments
 (0)