Small improvements to RTC test to check time elapsed and if timestamp is not zero

pull/505/head
Przemek Wirkus 2014-09-22 10:04:24 +01:00
parent 2e5c761dc8
commit ea59d77d85
2 changed files with 12 additions and 10 deletions

View File

@ -8,7 +8,7 @@ int main() {
while(1) {
time_t seconds = time(NULL);
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);
}
}

View File

@ -17,7 +17,7 @@ limitations under the License.
import re
from host_test import DefaultTest
from time import strftime, gmtime
from time import time, strftime, gmtime
from sys import stdout
class RTCTest(DefaultTest):
@ -26,27 +26,29 @@ class RTCTest(DefaultTest):
def run(self):
test_result = True
start = time()
sec_prev = 0
for i in range(0, 5):
c = self.mbed.serial_readline()
if c is None:
self.print_result("ioerr_serial")
return
print c.strip()
delta = time() - start
m = self.re_detect_rtc_value.search(c)
if m and len(m.groups()):
sec = m.groups()[0]
sec = int(m.groups()[0])
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)
result_msg = "OK" if (time_str == correct_time_str and sec > 0) else "FAIL"
print "Got RTC time: " + c[:-1] + " ... " + result_msg
stdout.flush()
result_msg = "OK" if (time_str == correct_time_str and sec > 0 and sec > sec_prev) else "FAIL"
print "HOST: [%s] [%s] received time %+d sec after %.2f sec... %s"% (sec, time_str, sec - sec_prev, delta, result_msg)
sec_prev = sec
else:
print c
stdout.flush()
test_result = False
break
start = time()
stdout.flush()
if test_result: # All numbers are the same
self.print_result('success')
else: