Mbed Host Tests
rtc_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 import re
19 from time import time, strftime, gmtime
20 from mbed_host_tests import BaseHostTest
21 
22 class RTCTest(BaseHostTest):
23  PATTERN_RTC_VALUE = "\[(\d+)\] \[(\d+-\d+-\d+ \d+:\d+:\d+ [AaPpMm]{2})\]"
24  re_detect_rtc_value = re.compile(PATTERN_RTC_VALUE)
25 
26  __result = None
27  timestamp = None
28  rtc_reads = []
29 
30  def _callback_timestamp(self, key, value, timestamp):
31  self.timestamptimestamp = int(value)
32 
33  def _callback_rtc(self, key, value, timestamp):
34  self.rtc_readsrtc_reads.append((key, value, timestamp))
35 
36  def _callback_end(self, key, value, timestamp):
37  self.notify_complete()
38 
39  def setup(self):
40  self.register_callback('timestamp', self._callback_timestamp_callback_timestamp)
41  self.register_callback('rtc', self._callback_rtc_callback_rtc)
42  self.register_callback('end', self._callback_end_callback_end)
43 
44  def result(self):
45  def check_strftimes_format(t):
46  m = self.re_detect_rtc_valuere_detect_rtc_value.search(t)
47  if m and len(m.groups()):
48  sec, time_str = int(m.groups()[0]), m.groups()[1]
49  correct_time_str = strftime("%Y-%m-%d %H:%M:%S", gmtime(float(sec)))
50  return time_str == correct_time_str
51  return False
52 
53  ts = [t for _, t, _ in self.rtc_readsrtc_reads]
54  self.__result__result = all(filter(check_strftimes_format, ts))
55  return self.__result__result
56 
57  def teardown(self):
58  pass
def _callback_timestamp(self, key, value, timestamp)
Definition: rtc_auto.py:30
def _callback_end(self, key, value, timestamp)
Definition: rtc_auto.py:36
def _callback_rtc(self, key, value, timestamp)
Definition: rtc_auto.py:33