]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/workspace_tools/host_tests/echo.py
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / workspace_tools / host_tests / echo.py
1 """
2 mbed SDK
3 Copyright (c) 2011-2013 ARM Limited
4
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
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
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.
16 """
17
18 import sys
19 import uuid
20 from sys import stdout
21
22 class EchoTest():
23
24 # Test parameters
25 TEST_SERIAL_BAUDRATE = 115200
26 TEST_LOOP_COUNT = 50
27
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.
31 """
32 # Custom initialization for echo test
33 selftest.mbed.init_serial_params(serial_baud=self.TEST_SERIAL_BAUDRATE)
34 selftest.mbed.init_serial()
35
36 # Test function, return True or False to get standard test notification on stdout
37 selftest.mbed.flush()
38 selftest.notify("HOST: Starting the ECHO test")
39 result = True
40
41 """ This ensures that there are no parasites left in the serial buffer.
42 """
43 for i in range(0, 2):
44 selftest.mbed.serial_write("\n")
45 c = selftest.mbed.serial_readline()
46
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()
51 if c is None:
52 return selftest.RESULT_IO_SERIAL
53 if c.strip() != TEST_STRING.strip():
54 selftest.notify('HOST: "%s" != "%s"'% (c, TEST_STRING))
55 result = False
56 else:
57 sys.stdout.write('.')
58 stdout.flush()
59 return selftest.RESULT_SUCCESS if result else selftest.RESULT_FAILURE
Imprint / Impressum