blob: 6e45c5db4f6e5f3d1c57db23b25d4c92852c28fd [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
Andrew Geisslerc3d88e42020-10-02 09:45:00 -05006from oeqa.runtime.case import OERuntimeTestCase
7from oeqa.core.decorator.depends import OETestDepends
Andrew Geisslerfc113ea2023-03-31 09:59:46 -05008from oeqa.core.decorator.data import skipIfFeature
Andrew Geisslerc3d88e42020-10-02 09:45:00 -05009from 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')
Andrew Geisslerc926e172021-05-07 16:11:35 -050018 self.target.run('systemctl disable --now --runtime systemd-timesyncd')
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050019
20 def tearDown(self):
21 if self.tc.td.get('VIRTUAL-RUNTIME_init_manager') == 'systemd':
22 self.logger.debug('Starting systemd-timesyncd daemon')
Andrew Geisslerc926e172021-05-07 16:11:35 -050023 self.target.run('systemctl enable --now --runtime systemd-timesyncd')
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050024
Andrew Geisslerfc113ea2023-03-31 09:59:46 -050025 @skipIfFeature('read-only-rootfs',
26 'Test does not work with read-only-rootfs in IMAGE_FEATURES')
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050027 @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)
Andrew Geisslerfc113ea2023-03-31 09:59:46 -050032
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050033 (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)
Andrew Geisslerfc113ea2023-03-31 09:59:46 -050043
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050044 (status, output) = self.target.run('hwclock -w')
45 self.assertEqual(status, 0, msg='Failed to reset RTC time, output: %s' % output)