Skip to content

Commit aa882d3

Browse files
authored
Merge pull request #13362 from jamesbeyond/test_update
TESTS: update tests and fixing time drifting tests in rtos folder
2 parents 67e6052 + fe8e51f commit aa882d3

File tree

3 files changed

+149
-5
lines changed

3 files changed

+149
-5
lines changed

TESTS/mbed_hal/common_tickers_freq/main.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@
2929
#include "hal/lp_ticker_api.h"
3030
#include "hal/mbed_lp_ticker_wrapper.h"
3131

32-
#if defined(SKIP_TIME_DRIFT_TESTS) || !DEVICE_USTICKER
33-
#error [NOT_SUPPORTED] test not supported
32+
#if !DEVICE_USTICKER
33+
#error [NOT_SUPPORTED] UsTicker need to be enabled for this test
3434
#else
3535

36+
#if defined(SKIP_TIME_DRIFT_TESTS)
37+
#error [NOT_SUPPORTED] timing accuracy tests skipped
38+
#endif // defined(SKIP_TIME_DRIFT_TESTS)
39+
3640
#define US_PER_S 1000000
3741

3842
using namespace utest::v1;
@@ -208,4 +212,4 @@ int main()
208212
Harness::run(specification);
209213
}
210214

211-
#endif // defined(SKIP_TIME_DRIFT_TESTS) || !DEVICE_USTICKER
215+
#endif // !DEVICE_USTICKER
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
"""
2+
mbed SDK
3+
Copyright (c) 2011-2013 ARM Limited
4+
SPDX-License-Identifier: Apache-2.0
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
"""
18+
19+
from mbed_host_tests import BaseHostTest
20+
import time
21+
22+
23+
class TimingDriftSync(BaseHostTest):
24+
"""
25+
This works as master-slave fashion
26+
1) Device says its booted up and ready to run the test, wait for host to respond
27+
2) Host sends the message to get the device current time i.e base time
28+
29+
#
30+
# *
31+
# * |
32+
#<---* DUT<- base_time | - round_trip_base_time ------
33+
# * | |
34+
# * - |
35+
# - |
36+
# | |
37+
# | |
38+
# | - measurement_stretch | - nominal_time
39+
# | |
40+
# | |
41+
# - |
42+
# * - |
43+
# * | |
44+
#<---* DUT <-final_time | - round_trip_final_time------
45+
# * |
46+
# * -
47+
#
48+
#
49+
# As we increase the measurement_stretch, the error because of transport delay diminishes.
50+
# The values of measurement_stretch is propotional to round_trip_base_time(transport delays)
51+
# by factor time_measurement_multiplier.This multiplier is used is 80 to tolerate 2 sec of
52+
# transport delay and test time ~ 180 secs
53+
#
54+
# Failure in timing can occur if we are ticking too fast or we are ticking too slow, hence we have
55+
# min_range and max_range. if we cross on either side tests would be marked fail. The range is a function of
56+
# tolerance/acceptable drift currently its 5%.
57+
#
58+
59+
"""
60+
__result = None
61+
mega = 1000000.0
62+
max_measurement_time = 180
63+
64+
# this value is obtained for measurements when there is 0 transport delay and we want accurancy of 5%
65+
time_measurement_multiplier = 80
66+
67+
def _callback_timing_drift_check_start(self, key, value, timestamp):
68+
self.round_trip_base_start = timestamp
69+
self.send_kv("base_time", 0)
70+
71+
def _callback_base_time(self, key, value, timestamp):
72+
self.round_trip_base_end = timestamp
73+
self.device_time_base = float(value)
74+
self.round_trip_base_time = self.round_trip_base_end - self.round_trip_base_start
75+
76+
self.log("Device base time {}".format(value))
77+
measurement_stretch = (self.round_trip_base_time * self.time_measurement_multiplier) + 5
78+
79+
if measurement_stretch > self.max_measurement_time:
80+
self.log("Time required {} to determine device timer is too high due to transport delay, skipping".format(measurement_stretch))
81+
else:
82+
self.log("sleeping for {} to measure drift accurately".format(measurement_stretch))
83+
time.sleep(measurement_stretch)
84+
self.round_trip_final_start = time.time()
85+
self.send_kv("final_time", 0)
86+
87+
def _callback_final_time(self, key, value, timestamp):
88+
self.round_trip_final_end = timestamp
89+
self.device_time_final = float(value)
90+
self.round_trip_final_time = self.round_trip_final_end - self.round_trip_final_start
91+
self.log("Device final time {} ".format(value))
92+
93+
# compute the test results and send to device
94+
results = "pass" if self.compute_parameter() else "fail"
95+
self.send_kv(results, "0")
96+
97+
def setup(self):
98+
self.register_callback('timing_drift_check_start', self._callback_timing_drift_check_start)
99+
self.register_callback('base_time', self._callback_base_time)
100+
self.register_callback('final_time', self._callback_final_time)
101+
102+
def compute_parameter(self, failure_criteria=0.05):
103+
t_max = self.round_trip_final_end - self.round_trip_base_start
104+
t_min = self.round_trip_final_start - self.round_trip_base_end
105+
t_max_hi = t_max * (1 + failure_criteria)
106+
t_max_lo = t_max * (1 - failure_criteria)
107+
t_min_hi = t_min * (1 + failure_criteria)
108+
t_min_lo = t_min * (1 - failure_criteria)
109+
device_time = (self.device_time_final - self.device_time_base) / self.mega
110+
111+
self.log("Compute host events")
112+
self.log("Transport delay 0: {}".format(self.round_trip_base_time))
113+
self.log("Transport delay 1: {}".format(self.round_trip_final_time))
114+
self.log("DUT base time : {}".format(self.device_time_base))
115+
self.log("DUT end time : {}".format(self.device_time_final))
116+
117+
self.log("min_pass : {} , max_pass : {} for {}%%".format(t_max_lo, t_min_hi, failure_criteria * 100))
118+
self.log("min_inconclusive : {} , max_inconclusive : {}".format(t_min_lo, t_max_hi))
119+
self.log("Time reported by device: {}".format(device_time))
120+
121+
if t_max_lo <= device_time <= t_min_hi:
122+
self.log("Test passed !!!")
123+
self.__result = True
124+
elif t_min_lo <= device_time <= t_max_hi:
125+
self.log("Test inconclusive due to transport delay, retrying")
126+
self.__result = False
127+
else:
128+
self.log("Time outside of passing range. Timing drift seems to be present !!!")
129+
self.__result = False
130+
return self.__result
131+
132+
def result(self):
133+
return self.__result
134+
135+
def teardown(self):
136+
pass

rtos/tests/TESTS/mbedmicro-rtos-mbed/basic/main.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@
2323
#include "utest/utest.h"
2424
#include "unity/unity.h"
2525

26-
#if defined(SKIP_TIME_DRIFT_TESTS) || !DEVICE_USTICKER
26+
#if !DEVICE_USTICKER
2727
#error [NOT_SUPPORTED] UsTicker need to be enabled for this test.
2828
#else
2929

30+
#if defined(SKIP_TIME_DRIFT_TESTS)
31+
#error [NOT_SUPPORTED] timing accuracy tests skipped
32+
#endif // defined(SKIP_TIME_DRIFT_TESTS
33+
3034
using utest::v1::Case;
3135
using std::milli;
3236
using std::micro;
@@ -122,5 +126,5 @@ int main()
122126
utest::v1::Harness::run(specification);
123127
}
124128

125-
#endif // defined(SKIP_TIME_DRIFT_TESTS) || !DEVICE_USTICKER
129+
#endif // !DEVICE_USTICKER
126130
#endif // defined(MBED_RTOS_SINGLE_THREAD) || !defined(MBED_CONF_RTOS_PRESENT)

0 commit comments

Comments
 (0)