Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

echo.py 2.0KB

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