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.ticksticks.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.DEVIATIONDEVIATION
48 
49  # Check if time between ticks was accurate
50  if self.ticksticks:
51  # If any ticks were recorded
52  timestamps = [timestamp for _, _, timestamp in self.ticksticks]
53  self.log(str(timestamps))
54  m = map(sub_timestamps, timestamps[1:], timestamps[:-1])
55  self.log(str(m))
56  self.__result__result = all(m)
57  else:
58  self.__result__result = False
59  return self.__result__result
60 
61  def teardown(self):
62  pass
def _callback_exit(self, key, value, timeout)
Definition: wait_us_auto.py:30
def _callback_tick(self, key, value, timestamp)
Definition: wait_us_auto.py:33