2013-08-06 13:38:00 +00:00
|
|
|
"""
|
|
|
|
mbed SDK
|
|
|
|
Copyright (c) 2011-2013 ARM Limited
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
"""
|
2014-10-21 12:53:19 +00:00
|
|
|
|
2014-09-15 16:43:56 +00:00
|
|
|
import sys
|
2014-09-03 12:33:23 +00:00
|
|
|
import uuid
|
2014-09-03 14:01:19 +00:00
|
|
|
from sys import stdout
|
2014-10-17 14:14:53 +00:00
|
|
|
from host_test import TestResults, Test
|
2013-02-18 15:32:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EchoTest(Test):
|
2014-10-21 12:12:32 +00:00
|
|
|
""" This host test will use mbed serial port with
|
|
|
|
baudrate 115200 to perform echo test on that port.
|
|
|
|
"""
|
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
def __init__(self):
|
2014-10-21 12:12:32 +00:00
|
|
|
# Constructors
|
2014-10-17 14:14:53 +00:00
|
|
|
TestResults.__init__(self)
|
2013-02-18 15:32:11 +00:00
|
|
|
Test.__init__(self)
|
2014-10-21 12:12:32 +00:00
|
|
|
|
|
|
|
# Test parameters
|
|
|
|
self.TEST_SERIAL_BAUDRATE = 115200
|
|
|
|
self.TEST_LOOP_COUNT = 50
|
|
|
|
|
|
|
|
# Initializations
|
|
|
|
serial_init_res = self.mbed.init_serial(self.TEST_SERIAL_BAUDRATE)
|
2014-10-14 09:59:42 +00:00
|
|
|
if not serial_init_res:
|
2014-10-17 14:14:53 +00:00
|
|
|
self.print_result(self.RESULT_IO_SERIAL)
|
2013-02-18 15:32:11 +00:00
|
|
|
self.mbed.reset()
|
2014-05-29 13:42:03 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
def test(self):
|
2014-09-15 16:43:56 +00:00
|
|
|
""" Test function, return True or False to get standard test notification on stdout
|
|
|
|
"""
|
|
|
|
c = self.mbed.serial_readline() # '{{start}}'
|
2014-09-03 12:33:23 +00:00
|
|
|
if c is None:
|
2014-10-21 12:12:32 +00:00
|
|
|
return self.RESULT_IO_SERIAL
|
|
|
|
self.notify(c.strip())
|
2014-09-03 14:01:19 +00:00
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
self.mbed.flush()
|
2014-09-15 16:43:56 +00:00
|
|
|
self.notify("HOST: Starting the ECHO test")
|
|
|
|
result = True
|
|
|
|
for i in range(0, self.TEST_LOOP_COUNT):
|
2014-10-21 12:12:32 +00:00
|
|
|
TEST_STRING = str(uuid.uuid4()) + "\n"
|
|
|
|
self.mbed.serial_write(TEST_STRING)
|
2014-09-15 16:43:56 +00:00
|
|
|
c = self.mbed.serial_readline()
|
|
|
|
if c is None:
|
2014-10-21 12:12:32 +00:00
|
|
|
return self.RESULT_IO_SERIAL
|
|
|
|
if c.strip() != TEST_STRING.strip():
|
|
|
|
self.notify('HOST: "%s" != "%s"'% (c, TEST_STRING))
|
2014-09-15 16:43:56 +00:00
|
|
|
result = False
|
2013-02-18 15:32:11 +00:00
|
|
|
else:
|
2014-09-15 16:43:56 +00:00
|
|
|
sys.stdout.write('.')
|
|
|
|
stdout.flush()
|
2014-10-21 12:12:32 +00:00
|
|
|
return self.RESULT_SUCCESS if result else self.RESULT_FAILURE
|
2013-02-18 15:32:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
EchoTest().run()
|