From 1bdc4b8046d5931544815bc01156168b0acd6da8 Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Tue, 2 Sep 2014 15:24:51 +0100 Subject: [PATCH] Simplified HelloWorld test to detect different types of ragteId (they can have different length) --- workspace_tools/host_tests/hello_auto.py | 33 +++++++++++------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/workspace_tools/host_tests/hello_auto.py b/workspace_tools/host_tests/hello_auto.py index e69b740c5d..e1b10a84c3 100644 --- a/workspace_tools/host_tests/hello_auto.py +++ b/workspace_tools/host_tests/hello_auto.py @@ -17,32 +17,29 @@ limitations under the License. from host_test import DefaultTest from sys import stdout +import re class HelloTest(DefaultTest): - HELLO_WORLD = "Hello World\n" + HELLO_WORLD = "Hello World" def run(self): - c = self.mbed.serial_read(1) + c = self.mbed.serial_read(128) if c is None: self.print_result("ioerr_serial") return - data_to_read = len(self.HELLO_WORLD) - read_buffer = '' - if c == '$': # target will printout TargetID e.g.: $$$$1040e649d5c09a09a3f6bc568adef61375c6 - #Read additional 39 bytes of TargetID - if self.mbed.serial_read(39) is None: - self.print_result("ioerr_serial") - return + print "Read %d bytes"% len(c) + result = True + # Because we can have targetID here let's try to decode + if len(c) < len(self.HELLO_WORLD): + result = False + elif c[0] == '$': + # We are looking for targetID here + res = re.search('^[$]+[0-9a-fA-F]+' + self.HELLO_WORLD, c) + result = res is not None else: - data_to_read -= 1 - read_buffer += c - c = self.mbed.serial_read(data_to_read) - read_buffer += c - if c is None: - self.print_result("ioerr_serial") - return - stdout.write(read_buffer) - if read_buffer == self.HELLO_WORLD: # Hello World received + result = (c == self.HELLO_WORLD) + + if result: # Hello World received self.print_result('success') else: self.print_result('failure')