Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
Andrew Geissler | c3d88e4 | 2020-10-02 09:45:00 -0500 | [diff] [blame] | 6 | from oeqa.runtime.case import OERuntimeTestCase |
| 7 | from oeqa.core.decorator.depends import OETestDepends |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 8 | from oeqa.core.decorator.data import skipIfFeature |
Andrew Geissler | c3d88e4 | 2020-10-02 09:45:00 -0500 | [diff] [blame] | 9 | from oeqa.runtime.decorator.package import OEHasPackage |
| 10 | |
| 11 | import re |
| 12 | |
| 13 | class 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 Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 18 | self.target.run('systemctl disable --now --runtime systemd-timesyncd') |
Andrew Geissler | c3d88e4 | 2020-10-02 09:45:00 -0500 | [diff] [blame] | 19 | |
| 20 | def tearDown(self): |
| 21 | if self.tc.td.get('VIRTUAL-RUNTIME_init_manager') == 'systemd': |
| 22 | self.logger.debug('Starting systemd-timesyncd daemon') |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 23 | self.target.run('systemctl enable --now --runtime systemd-timesyncd') |
Andrew Geissler | c3d88e4 | 2020-10-02 09:45:00 -0500 | [diff] [blame] | 24 | |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 25 | @skipIfFeature('read-only-rootfs', |
| 26 | 'Test does not work with read-only-rootfs in IMAGE_FEATURES') |
Andrew Geissler | c3d88e4 | 2020-10-02 09:45:00 -0500 | [diff] [blame] | 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) |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 32 | |
Andrew Geissler | c3d88e4 | 2020-10-02 09:45:00 -0500 | [diff] [blame] | 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) |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 43 | |
Andrew Geissler | c3d88e4 | 2020-10-02 09:45:00 -0500 | [diff] [blame] | 44 | (status, output) = self.target.run('hwclock -w') |
| 45 | self.assertEqual(status, 0, msg='Failed to reset RTC time, output: %s' % output) |