Simplified HelloWorld test to detect different types of ragteId (they can have different length)

pull/475/head
Przemek Wirkus 2014-09-02 15:24:51 +01:00
parent b481bc4319
commit 1bdc4b8046
1 changed files with 15 additions and 18 deletions

View File

@ -17,32 +17,29 @@ limitations under the License.
from host_test import DefaultTest from host_test import DefaultTest
from sys import stdout from sys import stdout
import re
class HelloTest(DefaultTest): class HelloTest(DefaultTest):
HELLO_WORLD = "Hello World\n" HELLO_WORLD = "Hello World"
def run(self): def run(self):
c = self.mbed.serial_read(1) c = self.mbed.serial_read(128)
if c is None: if c is None:
self.print_result("ioerr_serial") self.print_result("ioerr_serial")
return return
data_to_read = len(self.HELLO_WORLD) print "Read %d bytes"% len(c)
read_buffer = '' result = True
if c == '$': # target will printout TargetID e.g.: $$$$1040e649d5c09a09a3f6bc568adef61375c6 # Because we can have targetID here let's try to decode
#Read additional 39 bytes of TargetID if len(c) < len(self.HELLO_WORLD):
if self.mbed.serial_read(39) is None: result = False
self.print_result("ioerr_serial") elif c[0] == '$':
return # We are looking for targetID here
res = re.search('^[$]+[0-9a-fA-F]+' + self.HELLO_WORLD, c)
result = res is not None
else: else:
data_to_read -= 1 result = (c == self.HELLO_WORLD)
read_buffer += c
c = self.mbed.serial_read(data_to_read) if result: # Hello World received
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
self.print_result('success') self.print_result('success')
else: else:
self.print_result('failure') self.print_result('failure')