mbed-os for GR-LYCHEE
Dependents: mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more
tools/host_tests/echo.py@0:f782d9c66c49, 2018-02-02 (annotated)
- Committer:
- dkato
- Date:
- Fri Feb 02 05:42:23 2018 +0000
- Revision:
- 0:f782d9c66c49
mbed-os for GR-LYCHEE
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dkato | 0:f782d9c66c49 | 1 | """ |
dkato | 0:f782d9c66c49 | 2 | mbed SDK |
dkato | 0:f782d9c66c49 | 3 | Copyright (c) 2011-2013 ARM Limited |
dkato | 0:f782d9c66c49 | 4 | |
dkato | 0:f782d9c66c49 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
dkato | 0:f782d9c66c49 | 6 | you may not use this file except in compliance with the License. |
dkato | 0:f782d9c66c49 | 7 | You may obtain a copy of the License at |
dkato | 0:f782d9c66c49 | 8 | |
dkato | 0:f782d9c66c49 | 9 | http://www.apache.org/licenses/LICENSE-2.0 |
dkato | 0:f782d9c66c49 | 10 | |
dkato | 0:f782d9c66c49 | 11 | Unless required by applicable law or agreed to in writing, software |
dkato | 0:f782d9c66c49 | 12 | distributed under the License is distributed on an "AS IS" BASIS, |
dkato | 0:f782d9c66c49 | 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
dkato | 0:f782d9c66c49 | 14 | See the License for the specific language governing permissions and |
dkato | 0:f782d9c66c49 | 15 | limitations under the License. |
dkato | 0:f782d9c66c49 | 16 | """ |
dkato | 0:f782d9c66c49 | 17 | |
dkato | 0:f782d9c66c49 | 18 | import sys |
dkato | 0:f782d9c66c49 | 19 | import uuid |
dkato | 0:f782d9c66c49 | 20 | from sys import stdout |
dkato | 0:f782d9c66c49 | 21 | |
dkato | 0:f782d9c66c49 | 22 | class EchoTest(): |
dkato | 0:f782d9c66c49 | 23 | |
dkato | 0:f782d9c66c49 | 24 | # Test parameters |
dkato | 0:f782d9c66c49 | 25 | TEST_SERIAL_BAUDRATE = 115200 |
dkato | 0:f782d9c66c49 | 26 | TEST_LOOP_COUNT = 50 |
dkato | 0:f782d9c66c49 | 27 | |
dkato | 0:f782d9c66c49 | 28 | def test(self, selftest): |
dkato | 0:f782d9c66c49 | 29 | """ This host test will use mbed serial port with |
dkato | 0:f782d9c66c49 | 30 | baudrate 115200 to perform echo test on that port. |
dkato | 0:f782d9c66c49 | 31 | """ |
dkato | 0:f782d9c66c49 | 32 | # Custom initialization for echo test |
dkato | 0:f782d9c66c49 | 33 | selftest.mbed.init_serial_params(serial_baud=self.TEST_SERIAL_BAUDRATE) |
dkato | 0:f782d9c66c49 | 34 | selftest.mbed.init_serial() |
dkato | 0:f782d9c66c49 | 35 | |
dkato | 0:f782d9c66c49 | 36 | # Test function, return True or False to get standard test notification on stdout |
dkato | 0:f782d9c66c49 | 37 | selftest.mbed.flush() |
dkato | 0:f782d9c66c49 | 38 | selftest.notify("HOST: Starting the ECHO test") |
dkato | 0:f782d9c66c49 | 39 | result = True |
dkato | 0:f782d9c66c49 | 40 | |
dkato | 0:f782d9c66c49 | 41 | """ This ensures that there are no parasites left in the serial buffer. |
dkato | 0:f782d9c66c49 | 42 | """ |
dkato | 0:f782d9c66c49 | 43 | for i in range(0, 2): |
dkato | 0:f782d9c66c49 | 44 | selftest.mbed.serial_write("\n") |
dkato | 0:f782d9c66c49 | 45 | c = selftest.mbed.serial_readline() |
dkato | 0:f782d9c66c49 | 46 | |
dkato | 0:f782d9c66c49 | 47 | for i in range(0, self.TEST_LOOP_COUNT): |
dkato | 0:f782d9c66c49 | 48 | TEST_STRING = str(uuid.uuid4()) + "\n" |
dkato | 0:f782d9c66c49 | 49 | selftest.mbed.serial_write(TEST_STRING) |
dkato | 0:f782d9c66c49 | 50 | c = selftest.mbed.serial_readline() |
dkato | 0:f782d9c66c49 | 51 | if c is None: |
dkato | 0:f782d9c66c49 | 52 | return selftest.RESULT_IO_SERIAL |
dkato | 0:f782d9c66c49 | 53 | if c.strip() != TEST_STRING.strip(): |
dkato | 0:f782d9c66c49 | 54 | selftest.notify('HOST: "%s" != "%s"'% (c, TEST_STRING)) |
dkato | 0:f782d9c66c49 | 55 | result = False |
dkato | 0:f782d9c66c49 | 56 | else: |
dkato | 0:f782d9c66c49 | 57 | sys.stdout.write('.') |
dkato | 0:f782d9c66c49 | 58 | stdout.flush() |
dkato | 0:f782d9c66c49 | 59 | return selftest.RESULT_SUCCESS if result else selftest.RESULT_FAILURE |