xref: /OK3568_Linux_fs/yocto/poky/meta/lib/oeqa/runtime/cases/rtc.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyunfrom oeqa.runtime.case import OERuntimeTestCase
2*4882a593Smuzhiyunfrom oeqa.core.decorator.depends import OETestDepends
3*4882a593Smuzhiyunfrom oeqa.core.decorator.data import skipIfFeature
4*4882a593Smuzhiyunfrom oeqa.runtime.decorator.package import OEHasPackage
5*4882a593Smuzhiyun
6*4882a593Smuzhiyunimport re
7*4882a593Smuzhiyun
8*4882a593Smuzhiyunclass RTCTest(OERuntimeTestCase):
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun    def setUp(self):
11*4882a593Smuzhiyun        if self.tc.td.get('VIRTUAL-RUNTIME_init_manager') == 'systemd':
12*4882a593Smuzhiyun            self.logger.debug('Stopping systemd-timesyncd daemon')
13*4882a593Smuzhiyun            self.target.run('systemctl disable --now --runtime systemd-timesyncd')
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun    def tearDown(self):
16*4882a593Smuzhiyun        if self.tc.td.get('VIRTUAL-RUNTIME_init_manager') == 'systemd':
17*4882a593Smuzhiyun            self.logger.debug('Starting systemd-timesyncd daemon')
18*4882a593Smuzhiyun            self.target.run('systemctl enable --now --runtime systemd-timesyncd')
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun    @skipIfFeature('read-only-rootfs',
21*4882a593Smuzhiyun                   'Test does not work with read-only-rootfs in IMAGE_FEATURES')
22*4882a593Smuzhiyun    @OETestDepends(['ssh.SSHTest.test_ssh'])
23*4882a593Smuzhiyun    @OEHasPackage(['coreutils', 'busybox'])
24*4882a593Smuzhiyun    def test_rtc(self):
25*4882a593Smuzhiyun        (status, output) = self.target.run('hwclock -r')
26*4882a593Smuzhiyun        self.assertEqual(status, 0, msg='Failed to get RTC time, output: %s' % output)
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun        (status, current_datetime) = self.target.run('date +"%m%d%H%M%Y"')
29*4882a593Smuzhiyun        self.assertEqual(status, 0, msg='Failed to get system current date & time, output: %s' % current_datetime)
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun        example_datetime = '062309452008'
32*4882a593Smuzhiyun        (status, output) = self.target.run('date %s ; hwclock -w ; hwclock -r' % example_datetime)
33*4882a593Smuzhiyun        check_hwclock = re.search('2008-06-23 09:45:..', output)
34*4882a593Smuzhiyun        self.assertTrue(check_hwclock, msg='The RTC time was not set correctly, output: %s' % output)
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun        (status, output) = self.target.run('date %s' % current_datetime)
37*4882a593Smuzhiyun        self.assertEqual(status, 0, msg='Failed to reset system date & time, output: %s' % output)
38*4882a593Smuzhiyun
39*4882a593Smuzhiyun        (status, output) = self.target.run('hwclock -w')
40*4882a593Smuzhiyun        self.assertEqual(status, 0, msg='Failed to reset RTC time, output: %s' % output)
41