![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/TESTS/host_tests/rtc_reset.py@0:8fdf9a60065b, 2018-10-10 (annotated)
- Committer:
- kadonotakashi
- Date:
- Wed Oct 10 00:33:53 2018 +0000
- Revision:
- 0:8fdf9a60065b
how to make mbed librry
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadonotakashi | 0:8fdf9a60065b | 1 | """ |
kadonotakashi | 0:8fdf9a60065b | 2 | mbed SDK |
kadonotakashi | 0:8fdf9a60065b | 3 | Copyright (c) 2017-2017 ARM Limited |
kadonotakashi | 0:8fdf9a60065b | 4 | |
kadonotakashi | 0:8fdf9a60065b | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
kadonotakashi | 0:8fdf9a60065b | 6 | you may not use this file except in compliance with the License. |
kadonotakashi | 0:8fdf9a60065b | 7 | You may obtain a copy of the License at |
kadonotakashi | 0:8fdf9a60065b | 8 | |
kadonotakashi | 0:8fdf9a60065b | 9 | http://www.apache.org/licenses/LICENSE-2.0 |
kadonotakashi | 0:8fdf9a60065b | 10 | |
kadonotakashi | 0:8fdf9a60065b | 11 | Unless required by applicable law or agreed to in writing, software |
kadonotakashi | 0:8fdf9a60065b | 12 | distributed under the License is distributed on an "AS IS" BASIS, |
kadonotakashi | 0:8fdf9a60065b | 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kadonotakashi | 0:8fdf9a60065b | 14 | See the License for the specific language governing permissions and |
kadonotakashi | 0:8fdf9a60065b | 15 | limitations under the License. |
kadonotakashi | 0:8fdf9a60065b | 16 | """ |
kadonotakashi | 0:8fdf9a60065b | 17 | from __future__ import print_function |
kadonotakashi | 0:8fdf9a60065b | 18 | |
kadonotakashi | 0:8fdf9a60065b | 19 | from mbed_host_tests import BaseHostTest |
kadonotakashi | 0:8fdf9a60065b | 20 | from time import sleep |
kadonotakashi | 0:8fdf9a60065b | 21 | |
kadonotakashi | 0:8fdf9a60065b | 22 | |
kadonotakashi | 0:8fdf9a60065b | 23 | class RtcResetTest(BaseHostTest): |
kadonotakashi | 0:8fdf9a60065b | 24 | """This test checks that a device's RTC keeps count through a reset |
kadonotakashi | 0:8fdf9a60065b | 25 | |
kadonotakashi | 0:8fdf9a60065b | 26 | It does this by setting the RTC's time, triggering a reset, |
kadonotakashi | 0:8fdf9a60065b | 27 | delaying and then reading the RTC's time again to ensure |
kadonotakashi | 0:8fdf9a60065b | 28 | that the RTC is still counting. |
kadonotakashi | 0:8fdf9a60065b | 29 | """ |
kadonotakashi | 0:8fdf9a60065b | 30 | |
kadonotakashi | 0:8fdf9a60065b | 31 | """Start of the RTC""" |
kadonotakashi | 0:8fdf9a60065b | 32 | START_TIME = 50000 |
kadonotakashi | 0:8fdf9a60065b | 33 | START_TIME_TOLERANCE = 10 |
kadonotakashi | 0:8fdf9a60065b | 34 | """Time to delay after sending reset""" |
kadonotakashi | 0:8fdf9a60065b | 35 | DELAY_TIME = 5.0 |
kadonotakashi | 0:8fdf9a60065b | 36 | DELAY_TOLERANCE = 1.0 |
kadonotakashi | 0:8fdf9a60065b | 37 | VALUE_PLACEHOLDER = "0" |
kadonotakashi | 0:8fdf9a60065b | 38 | |
kadonotakashi | 0:8fdf9a60065b | 39 | def setup(self): |
kadonotakashi | 0:8fdf9a60065b | 40 | """Register callbacks required for the test""" |
kadonotakashi | 0:8fdf9a60065b | 41 | self._error = False |
kadonotakashi | 0:8fdf9a60065b | 42 | generator = self.rtc_reset_test() |
kadonotakashi | 0:8fdf9a60065b | 43 | generator.next() |
kadonotakashi | 0:8fdf9a60065b | 44 | |
kadonotakashi | 0:8fdf9a60065b | 45 | def run_gen(key, value, time): |
kadonotakashi | 0:8fdf9a60065b | 46 | """Run the generator, and fail testing if the iterator stops""" |
kadonotakashi | 0:8fdf9a60065b | 47 | if self._error: |
kadonotakashi | 0:8fdf9a60065b | 48 | return |
kadonotakashi | 0:8fdf9a60065b | 49 | try: |
kadonotakashi | 0:8fdf9a60065b | 50 | generator.send((key, value, time)) |
kadonotakashi | 0:8fdf9a60065b | 51 | except StopIteration: |
kadonotakashi | 0:8fdf9a60065b | 52 | self._error = True |
kadonotakashi | 0:8fdf9a60065b | 53 | |
kadonotakashi | 0:8fdf9a60065b | 54 | for resp in ("start", "read", "ack"): |
kadonotakashi | 0:8fdf9a60065b | 55 | self.register_callback(resp, run_gen) |
kadonotakashi | 0:8fdf9a60065b | 56 | |
kadonotakashi | 0:8fdf9a60065b | 57 | def teardown(self): |
kadonotakashi | 0:8fdf9a60065b | 58 | """No work to do here""" |
kadonotakashi | 0:8fdf9a60065b | 59 | pass |
kadonotakashi | 0:8fdf9a60065b | 60 | |
kadonotakashi | 0:8fdf9a60065b | 61 | def rtc_reset_test(self): |
kadonotakashi | 0:8fdf9a60065b | 62 | """Generator for running the reset test |
kadonotakashi | 0:8fdf9a60065b | 63 | |
kadonotakashi | 0:8fdf9a60065b | 64 | This function calls yield to wait for the next event from |
kadonotakashi | 0:8fdf9a60065b | 65 | the device. If the device gives the wrong response, then the |
kadonotakashi | 0:8fdf9a60065b | 66 | generator terminates by returing which raises a StopIteration |
kadonotakashi | 0:8fdf9a60065b | 67 | exception and fails the test. |
kadonotakashi | 0:8fdf9a60065b | 68 | """ |
kadonotakashi | 0:8fdf9a60065b | 69 | |
kadonotakashi | 0:8fdf9a60065b | 70 | # Wait for start token |
kadonotakashi | 0:8fdf9a60065b | 71 | key, value, time = yield |
kadonotakashi | 0:8fdf9a60065b | 72 | if key != "start": |
kadonotakashi | 0:8fdf9a60065b | 73 | return |
kadonotakashi | 0:8fdf9a60065b | 74 | |
kadonotakashi | 0:8fdf9a60065b | 75 | # Initialize, and set the time |
kadonotakashi | 0:8fdf9a60065b | 76 | self.send_kv("init", self.VALUE_PLACEHOLDER) |
kadonotakashi | 0:8fdf9a60065b | 77 | |
kadonotakashi | 0:8fdf9a60065b | 78 | # Wait for ack from the device |
kadonotakashi | 0:8fdf9a60065b | 79 | key, value, time = yield |
kadonotakashi | 0:8fdf9a60065b | 80 | if key != "ack": |
kadonotakashi | 0:8fdf9a60065b | 81 | return |
kadonotakashi | 0:8fdf9a60065b | 82 | |
kadonotakashi | 0:8fdf9a60065b | 83 | self.send_kv("write", str(self.START_TIME)) |
kadonotakashi | 0:8fdf9a60065b | 84 | |
kadonotakashi | 0:8fdf9a60065b | 85 | # Wait for ack from the device |
kadonotakashi | 0:8fdf9a60065b | 86 | key, value, time = yield |
kadonotakashi | 0:8fdf9a60065b | 87 | if key != "ack": |
kadonotakashi | 0:8fdf9a60065b | 88 | return |
kadonotakashi | 0:8fdf9a60065b | 89 | |
kadonotakashi | 0:8fdf9a60065b | 90 | self.send_kv("read", self.VALUE_PLACEHOLDER) |
kadonotakashi | 0:8fdf9a60065b | 91 | key, value, time = yield |
kadonotakashi | 0:8fdf9a60065b | 92 | if key != "read": |
kadonotakashi | 0:8fdf9a60065b | 93 | return |
kadonotakashi | 0:8fdf9a60065b | 94 | dev_time_start = int(value) |
kadonotakashi | 0:8fdf9a60065b | 95 | |
kadonotakashi | 0:8fdf9a60065b | 96 | # Unitialize, and reset |
kadonotakashi | 0:8fdf9a60065b | 97 | self.send_kv("free", self.VALUE_PLACEHOLDER) |
kadonotakashi | 0:8fdf9a60065b | 98 | |
kadonotakashi | 0:8fdf9a60065b | 99 | # Wait for ack from the device |
kadonotakashi | 0:8fdf9a60065b | 100 | key, value, time = yield |
kadonotakashi | 0:8fdf9a60065b | 101 | if key != "ack": |
kadonotakashi | 0:8fdf9a60065b | 102 | return |
kadonotakashi | 0:8fdf9a60065b | 103 | |
kadonotakashi | 0:8fdf9a60065b | 104 | self.send_kv("reset", self.VALUE_PLACEHOLDER) |
kadonotakashi | 0:8fdf9a60065b | 105 | |
kadonotakashi | 0:8fdf9a60065b | 106 | # No ack after reset |
kadonotakashi | 0:8fdf9a60065b | 107 | sleep(self.DELAY_TIME) |
kadonotakashi | 0:8fdf9a60065b | 108 | |
kadonotakashi | 0:8fdf9a60065b | 109 | # Restart the test, and send the sync token |
kadonotakashi | 0:8fdf9a60065b | 110 | self.send_kv("__sync", "00000000-0000-000000000-000000000000") |
kadonotakashi | 0:8fdf9a60065b | 111 | key, value, time = yield |
kadonotakashi | 0:8fdf9a60065b | 112 | if key != "start": |
kadonotakashi | 0:8fdf9a60065b | 113 | return |
kadonotakashi | 0:8fdf9a60065b | 114 | |
kadonotakashi | 0:8fdf9a60065b | 115 | # Initialize, and read the time |
kadonotakashi | 0:8fdf9a60065b | 116 | self.send_kv("init", self.VALUE_PLACEHOLDER) |
kadonotakashi | 0:8fdf9a60065b | 117 | |
kadonotakashi | 0:8fdf9a60065b | 118 | # Wait for ack from the device |
kadonotakashi | 0:8fdf9a60065b | 119 | key, value, time = yield |
kadonotakashi | 0:8fdf9a60065b | 120 | if key != "ack": |
kadonotakashi | 0:8fdf9a60065b | 121 | return |
kadonotakashi | 0:8fdf9a60065b | 122 | |
kadonotakashi | 0:8fdf9a60065b | 123 | self.send_kv("read", self.VALUE_PLACEHOLDER) |
kadonotakashi | 0:8fdf9a60065b | 124 | key, value, time = yield |
kadonotakashi | 0:8fdf9a60065b | 125 | if key != "read": |
kadonotakashi | 0:8fdf9a60065b | 126 | return |
kadonotakashi | 0:8fdf9a60065b | 127 | dev_time_end = int(value) |
kadonotakashi | 0:8fdf9a60065b | 128 | |
kadonotakashi | 0:8fdf9a60065b | 129 | # Check result |
kadonotakashi | 0:8fdf9a60065b | 130 | elapsed = dev_time_end - dev_time_start |
kadonotakashi | 0:8fdf9a60065b | 131 | start_time_valid = (self.START_TIME <= dev_time_start < |
kadonotakashi | 0:8fdf9a60065b | 132 | self.START_TIME + self.START_TIME_TOLERANCE) |
kadonotakashi | 0:8fdf9a60065b | 133 | elapsed_time_valid = elapsed >= self.DELAY_TIME - self.DELAY_TOLERANCE |
kadonotakashi | 0:8fdf9a60065b | 134 | passed = start_time_valid and elapsed_time_valid |
kadonotakashi | 0:8fdf9a60065b | 135 | if not start_time_valid: |
kadonotakashi | 0:8fdf9a60065b | 136 | self.log("FAIL: Expected start time of %i got %i" % |
kadonotakashi | 0:8fdf9a60065b | 137 | (self.START_TIME, dev_time_start)) |
kadonotakashi | 0:8fdf9a60065b | 138 | elif not passed: |
kadonotakashi | 0:8fdf9a60065b | 139 | self.log("FAIL: Delayed for %fs but device " |
kadonotakashi | 0:8fdf9a60065b | 140 | "reported elapsed time of %fs" % |
kadonotakashi | 0:8fdf9a60065b | 141 | (self.DELAY_TIME, elapsed)) |
kadonotakashi | 0:8fdf9a60065b | 142 | self.send_kv("exit", "pass" if passed else "fail") |
kadonotakashi | 0:8fdf9a60065b | 143 | yield # No more events expected |
kadonotakashi | 0:8fdf9a60065b | 144 |