Mbed Host Tests
wait_us_auto.py
Go to the documentation of this file.
1
"""
2
mbed SDK
3
Copyright (c) 2011-2013 ARM Limited
4
5
Licensed under the Apache License, Version 2.0 (the "License");
6
you may not use this file except in compliance with the License.
7
You may obtain a copy of the License at
8
9
http://www.apache.org/licenses/LICENSE-2.0
10
11
Unless required by applicable law or agreed to in writing, software
12
distributed under the License is distributed on an "AS IS" BASIS,
13
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
See the License for the specific language governing permissions and
15
limitations under the License.
16
"""
17
18
from
time
import
time
19
from
mbed_host_tests
import
BaseHostTest
20
21
22
class
WaitusTest
(BaseHostTest):
23
""" This test is reading single characters from stdio
24
and measures time between their occurrences.
25
"""
26
__result =
None
27
DEVIATION = 0.10
# +/-10%
28
ticks = []
29
30
def
_callback_exit
(self, key, value, timeout):
31
self.notify_complete()
32
33
def
_callback_tick
(self, key, value, timestamp):
34
""" {{tick;%d}}} """
35
self.log(
"tick! "
+ str(timestamp))
36
self.
ticks
.append((key, value, timestamp))
37
38
def
setup
(self):
39
self.register_callback(
'exit'
, self.
_callback_exit
_callback_exit
)
40
self.register_callback(
'tick'
, self.
_callback_tick
_callback_tick
)
41
42
def
result
(self):
43
def
sub_timestamps(t1, t2):
44
delta = t1 - t2
45
deviation = abs(delta - 1.0)
46
#return True if delta > 0 and deviation <= self.DEVIATION else False
47
return
deviation <= self.
DEVIATION
48
49
# Check if time between ticks was accurate
50
if
self.
ticks
:
51
# If any ticks were recorded
52
timestamps = [timestamp
for
_, _, timestamp
in
self.
ticks
]
53
self.log(str(timestamps))
54
m = map(sub_timestamps, timestamps[1:], timestamps[:-1])
55
self.log(str(m))
56
self.
__result
= all(m)
57
else
:
58
self.
__result
=
False
59
return
self.
__result
60
61
def
teardown
(self):
62
pass
mbed_host_tests.host_tests.wait_us_auto.WaitusTest
Definition
wait_us_auto.py:22
mbed_host_tests.host_tests.wait_us_auto.WaitusTest._callback_tick
_callback_tick
Definition
wait_us_auto.py:40
mbed_host_tests.host_tests.wait_us_auto.WaitusTest.setup
setup(self)
Definition
wait_us_auto.py:38
mbed_host_tests.host_tests.wait_us_auto.WaitusTest.result
result(self)
Definition
wait_us_auto.py:42
mbed_host_tests.host_tests.wait_us_auto.WaitusTest.teardown
teardown(self)
Definition
wait_us_auto.py:61
mbed_host_tests.host_tests.wait_us_auto.WaitusTest._callback_exit
_callback_exit
Definition
wait_us_auto.py:39
mbed_host_tests.host_tests.wait_us_auto.WaitusTest._callback_exit
_callback_exit(self, key, value, timeout)
Definition
wait_us_auto.py:30
mbed_host_tests.host_tests.wait_us_auto.WaitusTest._callback_tick
_callback_tick(self, key, value, timestamp)
Definition
wait_us_auto.py:33
mbed_host_tests.host_tests.wait_us_auto.WaitusTest.ticks
list ticks
Definition
wait_us_auto.py:28
mbed_host_tests.host_tests.wait_us_auto.WaitusTest.DEVIATION
float DEVIATION
Definition
wait_us_auto.py:27
mbed_host_tests.host_tests.wait_us_auto.WaitusTest.__result
__result
Definition
wait_us_auto.py:26
mbed_host_tests
host_tests
wait_us_auto.py
Generated by
1.9.8