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.

stdio_auto.py 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 re
  15. import random
  16. from time import time
  17. class StdioTest():
  18. PATTERN_INT_VALUE = "Your value was: (-?\d+)"
  19. re_detect_int_value = re.compile(PATTERN_INT_VALUE)
  20. def test(self, selftest):
  21. test_result = True
  22. c = selftest.mbed.serial_readline() # {{start}} preamble
  23. if c is None:
  24. return selftest.RESULT_IO_SERIAL
  25. selftest.notify(c)
  26. for i in range(0, 10):
  27. random_integer = random.randint(-99999, 99999)
  28. selftest.notify("HOST: Generated number: " + str(random_integer))
  29. start = time()
  30. selftest.mbed.serial_write(str(random_integer) + "\n")
  31. serial_stdio_msg = selftest.mbed.serial_readline()
  32. if serial_stdio_msg is None:
  33. return selftest.RESULT_IO_SERIAL
  34. delay_time = time() - start
  35. selftest.notify(serial_stdio_msg.strip())
  36. # Searching for reply with scanned values
  37. m = self.re_detect_int_value.search(serial_stdio_msg)
  38. if m and len(m.groups()):
  39. int_value = m.groups()[0]
  40. int_value_cmp = random_integer == int(int_value)
  41. test_result = test_result and int_value_cmp
  42. selftest.notify("HOST: Number %s read after %.3f sec ... [%s]"% (int_value, delay_time, "OK" if int_value_cmp else "FAIL"))
  43. else:
  44. test_result = False
  45. break
  46. return selftest.RESULT_SUCCESS if test_result else selftest.RESULT_FAILURE