mirror of https://github.com/ARMmbed/mbed-os.git
Small improvements to RTC test to check time elapsed and if timestamp is not zero
parent
2e5c761dc8
commit
ea59d77d85
|
@ -8,7 +8,7 @@ int main() {
|
||||||
while(1) {
|
while(1) {
|
||||||
time_t seconds = time(NULL);
|
time_t seconds = time(NULL);
|
||||||
strftime(buffer, 32, "%Y-%m-%d %H:%M:%S %p", localtime(&seconds));
|
strftime(buffer, 32, "%Y-%m-%d %H:%M:%S %p", localtime(&seconds));
|
||||||
printf("[%ld] [%s]\n", seconds, buffer);
|
printf("MBED: [%ld] [%s]\r\n", seconds, buffer);
|
||||||
wait(1);
|
wait(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ limitations under the License.
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from host_test import DefaultTest
|
from host_test import DefaultTest
|
||||||
from time import strftime, gmtime
|
from time import time, strftime, gmtime
|
||||||
from sys import stdout
|
from sys import stdout
|
||||||
|
|
||||||
class RTCTest(DefaultTest):
|
class RTCTest(DefaultTest):
|
||||||
|
@ -26,27 +26,29 @@ class RTCTest(DefaultTest):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
test_result = True
|
test_result = True
|
||||||
|
start = time()
|
||||||
|
sec_prev = 0
|
||||||
for i in range(0, 5):
|
for i in range(0, 5):
|
||||||
c = self.mbed.serial_readline()
|
c = self.mbed.serial_readline()
|
||||||
if c is None:
|
if c is None:
|
||||||
self.print_result("ioerr_serial")
|
self.print_result("ioerr_serial")
|
||||||
return
|
return
|
||||||
|
print c.strip()
|
||||||
|
delta = time() - start
|
||||||
m = self.re_detect_rtc_value.search(c)
|
m = self.re_detect_rtc_value.search(c)
|
||||||
if m and len(m.groups()):
|
if m and len(m.groups()):
|
||||||
sec = m.groups()[0]
|
sec = int(m.groups()[0])
|
||||||
time_str = m.groups()[1]
|
time_str = m.groups()[1]
|
||||||
correct_time_str = strftime("%Y-%m-%d %H:%M:%S %p", gmtime(float(sec)))
|
correct_time_str = strftime("%Y-%m-%d %H:%M:%S %p", gmtime(float(sec)))
|
||||||
test_result = test_result and (time_str == correct_time_str)
|
test_result = test_result and (time_str == correct_time_str)
|
||||||
result_msg = "OK" if (time_str == correct_time_str and sec > 0) else "FAIL"
|
result_msg = "OK" if (time_str == correct_time_str and sec > 0 and sec > sec_prev) else "FAIL"
|
||||||
print "Got RTC time: " + c[:-1] + " ... " + result_msg
|
print "HOST: [%s] [%s] received time %+d sec after %.2f sec... %s"% (sec, time_str, sec - sec_prev, delta, result_msg)
|
||||||
stdout.flush()
|
sec_prev = sec
|
||||||
else:
|
else:
|
||||||
print c
|
|
||||||
stdout.flush()
|
|
||||||
test_result = False
|
test_result = False
|
||||||
break
|
break
|
||||||
|
start = time()
|
||||||
|
stdout.flush()
|
||||||
if test_result: # All numbers are the same
|
if test_result: # All numbers are the same
|
||||||
self.print_result('success')
|
self.print_result('success')
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue