import sh import unittest import time import re class Qrtc(unittest.TestCase): params = None __rtc = None 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 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.fail("failed: RTC is not running") else: self.fail("failed: couldn't execute hwclock command 2nd time") else: self.fail("failed: couldn't execute hwclock command")