![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/TESTS/host_tests/timing_drift_auto.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) 2011-2013 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 | |
kadonotakashi | 0:8fdf9a60065b | 18 | from mbed_host_tests import BaseHostTest |
kadonotakashi | 0:8fdf9a60065b | 19 | import time |
kadonotakashi | 0:8fdf9a60065b | 20 | |
kadonotakashi | 0:8fdf9a60065b | 21 | |
kadonotakashi | 0:8fdf9a60065b | 22 | class TimingDriftSync(BaseHostTest): |
kadonotakashi | 0:8fdf9a60065b | 23 | """ |
kadonotakashi | 0:8fdf9a60065b | 24 | This works as master-slave fashion |
kadonotakashi | 0:8fdf9a60065b | 25 | 1) Device says its booted up and ready to run the test, wait for host to respond |
kadonotakashi | 0:8fdf9a60065b | 26 | 2) Host sends the message to get the device current time i.e base time |
kadonotakashi | 0:8fdf9a60065b | 27 | |
kadonotakashi | 0:8fdf9a60065b | 28 | # |
kadonotakashi | 0:8fdf9a60065b | 29 | # * |
kadonotakashi | 0:8fdf9a60065b | 30 | # * | |
kadonotakashi | 0:8fdf9a60065b | 31 | #<---* DUT<- base_time | - round_trip_base_time ------ |
kadonotakashi | 0:8fdf9a60065b | 32 | # * | | |
kadonotakashi | 0:8fdf9a60065b | 33 | # * - | |
kadonotakashi | 0:8fdf9a60065b | 34 | # - | |
kadonotakashi | 0:8fdf9a60065b | 35 | # | | |
kadonotakashi | 0:8fdf9a60065b | 36 | # | | |
kadonotakashi | 0:8fdf9a60065b | 37 | # | - measurement_stretch | - nominal_time |
kadonotakashi | 0:8fdf9a60065b | 38 | # | | |
kadonotakashi | 0:8fdf9a60065b | 39 | # | | |
kadonotakashi | 0:8fdf9a60065b | 40 | # - | |
kadonotakashi | 0:8fdf9a60065b | 41 | # * - | |
kadonotakashi | 0:8fdf9a60065b | 42 | # * | | |
kadonotakashi | 0:8fdf9a60065b | 43 | #<---* DUT <-final_time | - round_trip_final_time------ |
kadonotakashi | 0:8fdf9a60065b | 44 | # * | |
kadonotakashi | 0:8fdf9a60065b | 45 | # * - |
kadonotakashi | 0:8fdf9a60065b | 46 | # |
kadonotakashi | 0:8fdf9a60065b | 47 | # |
kadonotakashi | 0:8fdf9a60065b | 48 | # As we increase the measurement_stretch, the error because of transport delay diminishes. |
kadonotakashi | 0:8fdf9a60065b | 49 | # The values of measurement_stretch is propotional to round_trip_base_time(transport delays) |
kadonotakashi | 0:8fdf9a60065b | 50 | # by factor time_measurement_multiplier.This multiplier is used is 80 to tolerate 2 sec of |
kadonotakashi | 0:8fdf9a60065b | 51 | # transport delay and test time ~ 180 secs |
kadonotakashi | 0:8fdf9a60065b | 52 | # |
kadonotakashi | 0:8fdf9a60065b | 53 | # Failure in timing can occur if we are ticking too fast or we are ticking too slow, hence we have |
kadonotakashi | 0:8fdf9a60065b | 54 | # min_range and max_range. if we cross on either side tests would be marked fail. The range is a function of |
kadonotakashi | 0:8fdf9a60065b | 55 | # tolerance/acceptable drift currently its 5%. |
kadonotakashi | 0:8fdf9a60065b | 56 | # |
kadonotakashi | 0:8fdf9a60065b | 57 | |
kadonotakashi | 0:8fdf9a60065b | 58 | """ |
kadonotakashi | 0:8fdf9a60065b | 59 | __result = None |
kadonotakashi | 0:8fdf9a60065b | 60 | mega = 1000000.0 |
kadonotakashi | 0:8fdf9a60065b | 61 | max_measurement_time = 180 |
kadonotakashi | 0:8fdf9a60065b | 62 | |
kadonotakashi | 0:8fdf9a60065b | 63 | # this value is obtained for measurements when there is 0 transport delay and we want accurancy of 5% |
kadonotakashi | 0:8fdf9a60065b | 64 | time_measurement_multiplier = 80 |
kadonotakashi | 0:8fdf9a60065b | 65 | |
kadonotakashi | 0:8fdf9a60065b | 66 | def _callback_timing_drift_check_start(self, key, value, timestamp): |
kadonotakashi | 0:8fdf9a60065b | 67 | self.round_trip_base_start = timestamp |
kadonotakashi | 0:8fdf9a60065b | 68 | self.send_kv("base_time", 0) |
kadonotakashi | 0:8fdf9a60065b | 69 | |
kadonotakashi | 0:8fdf9a60065b | 70 | def _callback_base_time(self, key, value, timestamp): |
kadonotakashi | 0:8fdf9a60065b | 71 | self.round_trip_base_end = timestamp |
kadonotakashi | 0:8fdf9a60065b | 72 | self.device_time_base = float(value) |
kadonotakashi | 0:8fdf9a60065b | 73 | self.round_trip_base_time = self.round_trip_base_end - self.round_trip_base_start |
kadonotakashi | 0:8fdf9a60065b | 74 | |
kadonotakashi | 0:8fdf9a60065b | 75 | self.log("Device base time {}".format(value)) |
kadonotakashi | 0:8fdf9a60065b | 76 | measurement_stretch = (self.round_trip_base_time * self.time_measurement_multiplier) + 5 |
kadonotakashi | 0:8fdf9a60065b | 77 | |
kadonotakashi | 0:8fdf9a60065b | 78 | if measurement_stretch > self.max_measurement_time: |
kadonotakashi | 0:8fdf9a60065b | 79 | self.log("Time required {} to determine device timer is too high due to transport delay, skipping".format(measurement_stretch)) |
kadonotakashi | 0:8fdf9a60065b | 80 | else: |
kadonotakashi | 0:8fdf9a60065b | 81 | self.log("sleeping for {} to measure drift accurately".format(measurement_stretch)) |
kadonotakashi | 0:8fdf9a60065b | 82 | time.sleep(measurement_stretch) |
kadonotakashi | 0:8fdf9a60065b | 83 | self.round_trip_final_start = time.time() |
kadonotakashi | 0:8fdf9a60065b | 84 | self.send_kv("final_time", 0) |
kadonotakashi | 0:8fdf9a60065b | 85 | |
kadonotakashi | 0:8fdf9a60065b | 86 | def _callback_final_time(self, key, value, timestamp): |
kadonotakashi | 0:8fdf9a60065b | 87 | self.round_trip_final_end = timestamp |
kadonotakashi | 0:8fdf9a60065b | 88 | self.device_time_final = float(value) |
kadonotakashi | 0:8fdf9a60065b | 89 | self.round_trip_final_time = self.round_trip_final_end - self.round_trip_final_start |
kadonotakashi | 0:8fdf9a60065b | 90 | self.log("Device final time {} ".format(value)) |
kadonotakashi | 0:8fdf9a60065b | 91 | |
kadonotakashi | 0:8fdf9a60065b | 92 | # compute the test results and send to device |
kadonotakashi | 0:8fdf9a60065b | 93 | results = "pass" if self.compute_parameter() else "fail" |
kadonotakashi | 0:8fdf9a60065b | 94 | self.send_kv(results, "0") |
kadonotakashi | 0:8fdf9a60065b | 95 | |
kadonotakashi | 0:8fdf9a60065b | 96 | def setup(self): |
kadonotakashi | 0:8fdf9a60065b | 97 | self.register_callback('timing_drift_check_start', self._callback_timing_drift_check_start) |
kadonotakashi | 0:8fdf9a60065b | 98 | self.register_callback('base_time', self._callback_base_time) |
kadonotakashi | 0:8fdf9a60065b | 99 | self.register_callback('final_time', self._callback_final_time) |
kadonotakashi | 0:8fdf9a60065b | 100 | |
kadonotakashi | 0:8fdf9a60065b | 101 | def compute_parameter(self, failure_criteria=0.05): |
kadonotakashi | 0:8fdf9a60065b | 102 | t_max = self.round_trip_final_end - self.round_trip_base_start |
kadonotakashi | 0:8fdf9a60065b | 103 | t_min = self.round_trip_final_start - self.round_trip_base_end |
kadonotakashi | 0:8fdf9a60065b | 104 | t_max_hi = t_max * (1 + failure_criteria) |
kadonotakashi | 0:8fdf9a60065b | 105 | t_max_lo = t_max * (1 - failure_criteria) |
kadonotakashi | 0:8fdf9a60065b | 106 | t_min_hi = t_min * (1 + failure_criteria) |
kadonotakashi | 0:8fdf9a60065b | 107 | t_min_lo = t_min * (1 - failure_criteria) |
kadonotakashi | 0:8fdf9a60065b | 108 | device_time = (self.device_time_final - self.device_time_base) / self.mega |
kadonotakashi | 0:8fdf9a60065b | 109 | |
kadonotakashi | 0:8fdf9a60065b | 110 | self.log("Compute host events") |
kadonotakashi | 0:8fdf9a60065b | 111 | self.log("Transport delay 0: {}".format(self.round_trip_base_time)) |
kadonotakashi | 0:8fdf9a60065b | 112 | self.log("Transport delay 1: {}".format(self.round_trip_final_time)) |
kadonotakashi | 0:8fdf9a60065b | 113 | self.log("DUT base time : {}".format(self.device_time_base)) |
kadonotakashi | 0:8fdf9a60065b | 114 | self.log("DUT end time : {}".format(self.device_time_final)) |
kadonotakashi | 0:8fdf9a60065b | 115 | |
kadonotakashi | 0:8fdf9a60065b | 116 | self.log("min_pass : {} , max_pass : {} for {}%%".format(t_max_lo, t_min_hi, failure_criteria * 100)) |
kadonotakashi | 0:8fdf9a60065b | 117 | self.log("min_inconclusive : {} , max_inconclusive : {}".format(t_min_lo, t_max_hi)) |
kadonotakashi | 0:8fdf9a60065b | 118 | self.log("Time reported by device: {}".format(device_time)) |
kadonotakashi | 0:8fdf9a60065b | 119 | |
kadonotakashi | 0:8fdf9a60065b | 120 | if t_max_lo <= device_time <= t_min_hi: |
kadonotakashi | 0:8fdf9a60065b | 121 | self.log("Test passed !!!") |
kadonotakashi | 0:8fdf9a60065b | 122 | self.__result = True |
kadonotakashi | 0:8fdf9a60065b | 123 | elif t_min_lo <= device_time <= t_max_hi: |
kadonotakashi | 0:8fdf9a60065b | 124 | self.log("Test inconclusive due to transport delay, retrying") |
kadonotakashi | 0:8fdf9a60065b | 125 | self.__result = False |
kadonotakashi | 0:8fdf9a60065b | 126 | else: |
kadonotakashi | 0:8fdf9a60065b | 127 | self.log("Time outside of passing range. Timing drift seems to be present !!!") |
kadonotakashi | 0:8fdf9a60065b | 128 | self.__result = False |
kadonotakashi | 0:8fdf9a60065b | 129 | return self.__result |
kadonotakashi | 0:8fdf9a60065b | 130 | |
kadonotakashi | 0:8fdf9a60065b | 131 | def result(self): |
kadonotakashi | 0:8fdf9a60065b | 132 | return self.__result |
kadonotakashi | 0:8fdf9a60065b | 133 | |
kadonotakashi | 0:8fdf9a60065b | 134 | def teardown(self): |
kadonotakashi | 0:8fdf9a60065b | 135 | pass |