Clone of official tools
host_tests/wait_us_auto.py@47:21ae3e5a7128, 2021-02-04 (annotated)
- Committer:
- Anders Blomdell
- Date:
- Thu Feb 04 17:17:13 2021 +0100
- Revision:
- 47:21ae3e5a7128
- Parent:
- 0:66f3b5499f7f
Add a few normpath calls
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
screamer | 0:66f3b5499f7f | 1 | """ |
screamer | 0:66f3b5499f7f | 2 | mbed SDK |
screamer | 0:66f3b5499f7f | 3 | Copyright (c) 2011-2013 ARM Limited |
screamer | 0:66f3b5499f7f | 4 | |
screamer | 0:66f3b5499f7f | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
screamer | 0:66f3b5499f7f | 6 | you may not use this file except in compliance with the License. |
screamer | 0:66f3b5499f7f | 7 | You may obtain a copy of the License at |
screamer | 0:66f3b5499f7f | 8 | |
screamer | 0:66f3b5499f7f | 9 | http://www.apache.org/licenses/LICENSE-2.0 |
screamer | 0:66f3b5499f7f | 10 | |
screamer | 0:66f3b5499f7f | 11 | Unless required by applicable law or agreed to in writing, software |
screamer | 0:66f3b5499f7f | 12 | distributed under the License is distributed on an "AS IS" BASIS, |
screamer | 0:66f3b5499f7f | 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
screamer | 0:66f3b5499f7f | 14 | See the License for the specific language governing permissions and |
screamer | 0:66f3b5499f7f | 15 | limitations under the License. |
screamer | 0:66f3b5499f7f | 16 | """ |
screamer | 0:66f3b5499f7f | 17 | |
screamer | 0:66f3b5499f7f | 18 | from time import time |
screamer | 0:66f3b5499f7f | 19 | |
screamer | 0:66f3b5499f7f | 20 | class WaitusTest(): |
screamer | 0:66f3b5499f7f | 21 | """ This test is reading single characters from stdio |
screamer | 0:66f3b5499f7f | 22 | and measures time between their occurrences. |
screamer | 0:66f3b5499f7f | 23 | """ |
screamer | 0:66f3b5499f7f | 24 | TICK_LOOP_COUNTER = 13 |
screamer | 0:66f3b5499f7f | 25 | TICK_LOOP_SUCCESSFUL_COUNTS = 10 |
screamer | 0:66f3b5499f7f | 26 | DEVIATION = 0.10 # +/-10% |
screamer | 0:66f3b5499f7f | 27 | |
screamer | 0:66f3b5499f7f | 28 | def test(self, selftest): |
screamer | 0:66f3b5499f7f | 29 | test_result = True |
screamer | 0:66f3b5499f7f | 30 | # First character to start test (to know after reset when test starts) |
screamer | 0:66f3b5499f7f | 31 | if selftest.mbed.set_serial_timeout(None) is None: |
screamer | 0:66f3b5499f7f | 32 | return selftest.RESULT_IO_SERIAL |
screamer | 0:66f3b5499f7f | 33 | c = selftest.mbed.serial_read(1) |
screamer | 0:66f3b5499f7f | 34 | if c is None: |
screamer | 0:66f3b5499f7f | 35 | return selftest.RESULT_IO_SERIAL |
screamer | 0:66f3b5499f7f | 36 | if c == '$': # target will printout TargetID e.g.: $$$$1040e649d5c09a09a3f6bc568adef61375c6 |
screamer | 0:66f3b5499f7f | 37 | #Read additional 39 bytes of TargetID |
screamer | 0:66f3b5499f7f | 38 | if selftest.mbed.serial_read(39) is None: |
screamer | 0:66f3b5499f7f | 39 | return selftest.RESULT_IO_SERIAL |
screamer | 0:66f3b5499f7f | 40 | c = selftest.mbed.serial_read(1) # Re-read first 'tick' |
screamer | 0:66f3b5499f7f | 41 | if c is None: |
screamer | 0:66f3b5499f7f | 42 | return selftest.RESULT_IO_SERIAL |
screamer | 0:66f3b5499f7f | 43 | start_serial_pool = time() |
screamer | 0:66f3b5499f7f | 44 | start = time() |
screamer | 0:66f3b5499f7f | 45 | |
screamer | 0:66f3b5499f7f | 46 | success_counter = 0 |
screamer | 0:66f3b5499f7f | 47 | |
screamer | 0:66f3b5499f7f | 48 | for i in range(0, self.TICK_LOOP_COUNTER): |
screamer | 0:66f3b5499f7f | 49 | c = selftest.mbed.serial_read(1) |
screamer | 0:66f3b5499f7f | 50 | if c is None: |
screamer | 0:66f3b5499f7f | 51 | return selftest.RESULT_IO_SERIAL |
screamer | 0:66f3b5499f7f | 52 | delta = time() - start |
screamer | 0:66f3b5499f7f | 53 | deviation = abs(delta - 1) |
screamer | 0:66f3b5499f7f | 54 | # Round values |
screamer | 0:66f3b5499f7f | 55 | delta = round(delta, 2) |
screamer | 0:66f3b5499f7f | 56 | deviation = round(deviation, 2) |
screamer | 0:66f3b5499f7f | 57 | # Check if time measurements are in given range |
screamer | 0:66f3b5499f7f | 58 | deviation_ok = True if delta > 0 and deviation <= self.DEVIATION else False |
screamer | 0:66f3b5499f7f | 59 | success_counter = success_counter+1 if deviation_ok else 0 |
screamer | 0:66f3b5499f7f | 60 | msg = "OK" if deviation_ok else "FAIL" |
screamer | 0:66f3b5499f7f | 61 | selftest.notify("%s in %.2f sec (%.2f) [%s]"% (c, delta, deviation, msg)) |
screamer | 0:66f3b5499f7f | 62 | start = time() |
screamer | 0:66f3b5499f7f | 63 | if success_counter >= self.TICK_LOOP_SUCCESSFUL_COUNTS: |
screamer | 0:66f3b5499f7f | 64 | break |
screamer | 0:66f3b5499f7f | 65 | measurement_time = time() - start_serial_pool |
screamer | 0:66f3b5499f7f | 66 | selftest.notify("Consecutive OK timer reads: %d"% success_counter) |
screamer | 0:66f3b5499f7f | 67 | selftest.notify("Completed in %.2f sec" % (measurement_time)) |
screamer | 0:66f3b5499f7f | 68 | test_result = True if success_counter >= self.TICK_LOOP_SUCCESSFUL_COUNTS else False |
screamer | 0:66f3b5499f7f | 69 | return selftest.RESULT_SUCCESS if test_result else selftest.RESULT_FAILURE |