Skip to content

Modify serial nc tests init part #1781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions libraries/tests/mbed/serial_nc_rx/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,37 @@
#include "test_env.h"

int main() {
Serial *pc = new Serial(USBTX, USBRX);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be better to do hosttest macros first, flush the buffer, and then create a new serial?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had some issues with flushing the buffer in the past. The problem is we don't currently have a blocking call for "flush the serial buffer". There's still the issue of not knowing when the buffer has been emptied and transmitted.


MBED_HOSTTEST_TIMEOUT(20);
MBED_HOSTTEST_SELECT(serial_nc_rx_auto);
MBED_HOSTTEST_DESCRIPTION(Serial NC RX);
MBED_HOSTTEST_START("MBED_37");

Serial *pc = new Serial(NC, USBRX);

char c = pc->getc();

delete pc;

// This should be true
if (c == 'E') {
Serial *pc = new Serial(USBTX, NC);

pc->printf("RX OK - Expected\r\n");

c = pc->getc();

// This should be false/not get here
if (c == 'U') {
pc->printf("RX OK - Unexpected\r\n");
}

delete pc;
// This should be true, sync the start of test
if (c == 'S') {
pc->printf("RX OK - Start NC test\r\n");

// disconnect TX and get char
delete pc;
pc = new Serial(NC, USBRX);
c = pc->getc();
if (c == 'E') {
// ok disconnect Rx and answer to host
delete pc;
pc = new Serial(USBTX, NC);
pc->printf("RX OK - Expected\r\n");

c = pc->getc();
// This should be false/not get here
if (c == 'U') {
pc->printf("RX OK - Unexpected\r\n");
}
}
delete pc;
}

while (1) {
Expand Down
3 changes: 2 additions & 1 deletion libraries/tests/mbed/serial_nc_tx/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
#include "test_env.h"

int main() {
Serial *pc = new Serial(USBTX, USBRX);

MBED_HOSTTEST_TIMEOUT(20);
MBED_HOSTTEST_SELECT(serial_nc_tx_auto);
MBED_HOSTTEST_DESCRIPTION(Serial NC TX);
MBED_HOSTTEST_START("MBED_38");

// Wait until we receive start signal from host test
Serial *pc = new Serial(USBTX, USBRX);
char c = pc->getc();
delete pc;

Expand Down
23 changes: 23 additions & 0 deletions workspace_tools/host_tests/serial_nc_rx_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@ class SerialNCRXTest():

def test(self, selftest):
selftest.mbed.flush();
# Wait 0.5 seconds to ensure mbed is listening
time.sleep(0.5)

#handshake with target to sync test start
selftest.mbed.serial_write("S");

strip_chars = string.whitespace + "\0"

out_str = selftest.mbed.serial_readline()

if not out_str:
selftest.notify("HOST: No output detected")
return selftest.RESULT_IO_SERIAL

out_str_stripped = out_str.strip(strip_chars)

if out_str_stripped != "RX OK - Start NC test":
selftest.notify("HOST: Unexpected output. Expected 'RX OK - Expected' but received '%s'" % out_str_stripped)
return selftest.RESULT_FAILURE

# Wait 0.5 seconds to ensure mbed is listening
time.sleep(0.5)

selftest.mbed.serial_write("E");

strip_chars = string.whitespace + "\0"
Expand Down
3 changes: 3 additions & 0 deletions workspace_tools/host_tests/serial_nc_tx_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class SerialNCTXTest():

def test(self, selftest):
selftest.mbed.flush();
# Wait 0.5 seconds to ensure mbed is listening
time.sleep(0.5)

selftest.mbed.serial_write("S");

strip_chars = string.whitespace + "\0"
Expand Down