2014-03-20 15:52:37 +00:00
|
|
|
"""
|
|
|
|
mbed SDK
|
|
|
|
Copyright (c) 2011-2013 ARM Limited
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import re
|
2014-07-09 10:07:56 +00:00
|
|
|
from host_test import DefaultTest
|
2014-09-22 09:04:24 +00:00
|
|
|
from time import time, strftime, gmtime
|
2014-03-20 15:52:37 +00:00
|
|
|
from sys import stdout
|
|
|
|
|
|
|
|
class RTCTest(DefaultTest):
|
2014-09-15 10:08:05 +00:00
|
|
|
PATTERN_RTC_VALUE = "\[(\d+)\] \[(\d+-\d+-\d+ \d+:\d+:\d+ [AaPpMm]{2})\]"
|
2014-07-09 10:07:56 +00:00
|
|
|
re_detect_rtc_value = re.compile(PATTERN_RTC_VALUE)
|
2014-03-20 15:52:37 +00:00
|
|
|
|
|
|
|
def run(self):
|
|
|
|
test_result = True
|
2014-09-22 09:04:24 +00:00
|
|
|
start = time()
|
|
|
|
sec_prev = 0
|
2014-03-20 15:52:37 +00:00
|
|
|
for i in range(0, 5):
|
2014-10-15 16:19:36 +00:00
|
|
|
# Timeout changed from default: we need to wait longer for some boards to start-up
|
|
|
|
c = self.mbed.serial_readline(timeout=10)
|
2014-07-10 13:54:05 +00:00
|
|
|
if c is None:
|
2014-10-17 14:14:53 +00:00
|
|
|
self.print_result(self.RESULT_IO_SERIAL)
|
2014-07-10 13:54:05 +00:00
|
|
|
return
|
2014-10-17 14:14:53 +00:00
|
|
|
self.notify(c.strip())
|
2014-09-22 09:04:24 +00:00
|
|
|
delta = time() - start
|
2014-03-20 15:52:37 +00:00
|
|
|
m = self.re_detect_rtc_value.search(c)
|
|
|
|
if m and len(m.groups()):
|
2014-09-22 09:04:24 +00:00
|
|
|
sec = int(m.groups()[0])
|
2014-03-20 15:52:37 +00:00
|
|
|
time_str = m.groups()[1]
|
|
|
|
correct_time_str = strftime("%Y-%m-%d %H:%M:%S %p", gmtime(float(sec)))
|
|
|
|
test_result = test_result and (time_str == correct_time_str)
|
2014-09-22 09:04:24 +00:00
|
|
|
result_msg = "OK" if (time_str == correct_time_str and sec > 0 and sec > sec_prev) else "FAIL"
|
2014-10-17 14:14:53 +00:00
|
|
|
self.notify("HOST: [%s] [%s] received time %+d sec after %.2f sec... %s"% (sec, time_str, sec - sec_prev, delta, result_msg))
|
2014-09-22 09:04:24 +00:00
|
|
|
sec_prev = sec
|
2014-09-04 14:30:08 +00:00
|
|
|
else:
|
|
|
|
test_result = False
|
|
|
|
break
|
2014-09-22 09:04:24 +00:00
|
|
|
start = time()
|
2014-10-17 14:14:53 +00:00
|
|
|
self.print_result(self.RESULT_SUCCESS if test_result else self.RESULT_FAILURE)
|
|
|
|
|
2014-03-20 15:52:37 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
RTCTest().run()
|