1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
import sh
import unittest
import time
import re
class Qrtc(unittest.TestCase):
params = None
__rtc = None
__resultlist = None # resultlist is a python list of python dictionaries
def __init__(self, testname, testfunc, varlist):
self.params = varlist
super(Qrtc, self).__init__(testfunc)
if "rtc" in varlist:
self.__rtc = varlist["rtc"]
else:
raise Exception('rtc param inside Qrtc must be defined')
self._testMethodDoc = testname
self.__resultlist = []
def execute(self):
# get time from RTC peripheral
p = sh.hwclock("-f", self.__rtc)
if p.exit_code == 0:
time1 = re.search("([01]?[0-9]{1}|2[0-3]{1})[:][0-5]{1}[0-9]{1}[:][0-5]{1}[0-9]{1}",
p.stdout.decode('ascii'))
time.sleep(1)
# get time from RTC another time
p = sh.hwclock("-f", self.__rtc)
if p.exit_code == 0:
time2 = re.search("([01]?[0-9]{1}|2[0-3]{1})[:][0-5]{1}[0-9]{1}[:][0-5]{1}[0-9]{1}",
p.stdout.decode('ascii'))
# check if the seconds of both times are different
if time1 == time2:
self.__resultlist.append(
{
"desc": "Test result",
"data": "FAILED: RTC is not running",
"type": "string"
}
)
self.fail("failed: RTC is not running")
else:
self.__resultlist.append(
{
"desc": "Test result",
"data": "FAILED: couldn't execute hwclock command for the second time",
"type": "string"
}
)
self.fail("failed: couldn't execute hwclock command for the second time")
else:
self.__resultlist.append(
{
"desc": "Test result",
"data": "FAILED: couldn't execute hwclock command",
"type": "string"
}
)
self.fail("failed: couldn't execute hwclock command")
# Test successful
self.__resultlist.append(
{
"desc": "Test result",
"data": "OK",
"type": "string"
}
)
def getresults(self):
return self.__resultlist
|