BBR 1 Ebene

Committer:
borlanic
Date:
Mon May 14 11:29:06 2018 +0000
Revision:
0:fbdae7e6d805
BBR

Who changed what in which revision?

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