3 Copyright (c) 2011-2013 ARM Limited
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
20 from sys import stdout
25 TEST_SERIAL_BAUDRATE = 115200
28 def test(self, selftest):
29 """ This host test will use mbed serial port with
30 baudrate 115200 to perform echo test on that port.
32 # Custom initialization for echo test
33 selftest.mbed.init_serial_params(serial_baud=self.TEST_SERIAL_BAUDRATE)
34 selftest.mbed.init_serial()
36 # Test function, return True or False to get standard test notification on stdout
38 selftest.notify("HOST: Starting the ECHO test")
41 """ This ensures that there are no parasites left in the serial buffer.
44 selftest.mbed.serial_write("\n")
45 c = selftest.mbed.serial_readline()
47 for i in range(0, self.TEST_LOOP_COUNT):
48 TEST_STRING = str(uuid.uuid4()) + "\n"
49 selftest.mbed.serial_write(TEST_STRING)
50 c = selftest.mbed.serial_readline()
52 return selftest.RESULT_IO_SERIAL
53 if c.strip() != TEST_STRING.strip():
54 selftest.notify('HOST: "%s" != "%s"'% (c, TEST_STRING))
59 return selftest.RESULT_SUCCESS if result else selftest.RESULT_FAILURE