blob: b2159b1134dc0850831567f11125a2cc304e6f12 [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
8from oeqa.runtime.decorator.package import OEHasPackage
9
10import re
11
12class RTCTest(OERuntimeTestCase):
13
14 def setUp(self):
15 if self.tc.td.get('VIRTUAL-RUNTIME_init_manager') == 'systemd':
16 self.logger.debug('Stopping systemd-timesyncd daemon')
Andrew Geisslerc926e172021-05-07 16:11:35 -050017 self.target.run('systemctl disable --now --runtime systemd-timesyncd')
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050018
19 def tearDown(self):
20 if self.tc.td.get('VIRTUAL-RUNTIME_init_manager') == 'systemd':
21 self.logger.debug('Starting systemd-timesyncd daemon')
Andrew Geisslerc926e172021-05-07 16:11:35 -050022 self.target.run('systemctl enable --now --runtime systemd-timesyncd')
Andrew Geisslerc3d88e42020-10-02 09:45:00 -050023
24 @OETestDepends(['ssh.SSHTest.test_ssh'])
25 @OEHasPackage(['coreutils', 'busybox'])
26 def test_rtc(self):
27 (status, output) = self.target.run('hwclock -r')
28 self.assertEqual(status, 0, msg='Failed to get RTC time, output: %s' % output)
29
30 (status, current_datetime) = self.target.run('date +"%m%d%H%M%Y"')
31 self.assertEqual(status, 0, msg='Failed to get system current date & time, output: %s' % current_datetime)
32
33 example_datetime = '062309452008'
34 (status, output) = self.target.run('date %s ; hwclock -w ; hwclock -r' % example_datetime)
35 check_hwclock = re.search('2008-06-23 09:45:..', output)
36 self.assertTrue(check_hwclock, msg='The RTC time was not set correctly, output: %s' % output)
37
38 (status, output) = self.target.run('date %s' % current_datetime)
39 self.assertEqual(status, 0, msg='Failed to reset system date & time, output: %s' % output)
40
41 (status, output) = self.target.run('hwclock -w')
42 self.assertEqual(status, 0, msg='Failed to reset RTC time, output: %s' % output)
43