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