Mbed Host Tests
rtc_auto.py
Go to the documentation of this file.
1"""
2mbed SDK
3Copyright (c) 2011-2013 ARM Limited
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16"""
17
18import re
19from time import time, strftime, gmtime
20from mbed_host_tests import BaseHostTest
21
22class 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.timestamp = int(value)
32
33 def _callback_rtc(self, key, value, timestamp):
34 self.rtc_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_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_reads]
54 self.__result = all(filter(check_strftimes_format, ts))
55 return self.__result
56
57 def teardown(self):
58 pass
_callback_timestamp(self, key, value, timestamp)
Definition rtc_auto.py:30
_callback_rtc(self, key, value, timestamp)
Definition rtc_auto.py:33
_callback_end(self, key, value, timestamp)
Definition rtc_auto.py:36