Clone of official tools
host_tests/rtc_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 | import re |
screamer | 0:66f3b5499f7f | 19 | from time import time, strftime, gmtime |
screamer | 0:66f3b5499f7f | 20 | |
screamer | 0:66f3b5499f7f | 21 | class RTCTest(): |
screamer | 0:66f3b5499f7f | 22 | PATTERN_RTC_VALUE = "\[(\d+)\] \[(\d+-\d+-\d+ \d+:\d+:\d+ [AaPpMm]{2})\]" |
screamer | 0:66f3b5499f7f | 23 | re_detect_rtc_value = re.compile(PATTERN_RTC_VALUE) |
screamer | 0:66f3b5499f7f | 24 | |
screamer | 0:66f3b5499f7f | 25 | def test(self, selftest): |
screamer | 0:66f3b5499f7f | 26 | test_result = True |
screamer | 0:66f3b5499f7f | 27 | start = time() |
screamer | 0:66f3b5499f7f | 28 | sec_prev = 0 |
screamer | 0:66f3b5499f7f | 29 | for i in range(0, 5): |
screamer | 0:66f3b5499f7f | 30 | # Timeout changed from default: we need to wait longer for some boards to start-up |
screamer | 0:66f3b5499f7f | 31 | c = selftest.mbed.serial_readline(timeout=10) |
screamer | 0:66f3b5499f7f | 32 | if c is None: |
screamer | 0:66f3b5499f7f | 33 | return selftest.RESULT_IO_SERIAL |
screamer | 0:66f3b5499f7f | 34 | selftest.notify(c.strip()) |
screamer | 0:66f3b5499f7f | 35 | delta = time() - start |
screamer | 0:66f3b5499f7f | 36 | m = self.re_detect_rtc_value.search(c) |
screamer | 0:66f3b5499f7f | 37 | if m and len(m.groups()): |
screamer | 0:66f3b5499f7f | 38 | sec = int(m.groups()[0]) |
screamer | 0:66f3b5499f7f | 39 | time_str = m.groups()[1] |
screamer | 0:66f3b5499f7f | 40 | correct_time_str = strftime("%Y-%m-%d %H:%M:%S %p", gmtime(float(sec))) |
screamer | 0:66f3b5499f7f | 41 | single_result = time_str == correct_time_str and sec > 0 and sec > sec_prev |
screamer | 0:66f3b5499f7f | 42 | test_result = test_result and single_result |
screamer | 0:66f3b5499f7f | 43 | result_msg = "OK" if single_result else "FAIL" |
screamer | 0:66f3b5499f7f | 44 | selftest.notify("HOST: [%s] [%s] received time %+d sec after %.2f sec... %s"% (sec, time_str, sec - sec_prev, delta, result_msg)) |
screamer | 0:66f3b5499f7f | 45 | sec_prev = sec |
screamer | 0:66f3b5499f7f | 46 | else: |
screamer | 0:66f3b5499f7f | 47 | test_result = False |
screamer | 0:66f3b5499f7f | 48 | break |
screamer | 0:66f3b5499f7f | 49 | start = time() |
screamer | 0:66f3b5499f7f | 50 | return selftest.RESULT_SUCCESS if test_result else selftest.RESULT_FAILURE |