blob: a2523de67ab33dbc60d6a37bd2e9316812c2c48a [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Patrick Williams92b42cb2022-09-03 06:53:57 -05002# Copyright OpenEmbedded Contributors
3#
Brad Bishopc342db32019-05-15 21:57:59 -04004# SPDX-License-Identifier: MIT
5#
6
Brad Bishop6e60e8b2018-02-01 10:27:11 -05007import re
8
9from oeqa.runtime.case import OERuntimeTestCase
10from oeqa.core.decorator.depends import OETestDepends
Brad Bishop977dc1a2019-02-06 16:01:43 -050011from oeqa.runtime.decorator.package import OEHasPackage
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012
13class DateTest(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')
Brad Bishop6e60e8b2018-02-01 10:27:11 -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')
Brad Bishop6e60e8b2018-02-01 10:27:11 -050024
Brad Bishop6e60e8b2018-02-01 10:27:11 -050025 @OETestDepends(['ssh.SSHTest.test_ssh'])
Brad Bishop977dc1a2019-02-06 16:01:43 -050026 @OEHasPackage(['coreutils', 'busybox'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050027 def test_date(self):
28 (status, output) = self.target.run('date +"%Y-%m-%d %T"')
29 msg = 'Failed to get initial date, output: %s' % output
30 self.assertEqual(status, 0, msg=msg)
31 oldDate = output
32
Patrick Williams0ca19cc2021-08-16 14:03:13 -050033 sampleTimestamp = 1488800000
34 (status, output) = self.target.run("date -s @%d" % sampleTimestamp)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050035 self.assertEqual(status, 0, msg='Date set failed, output: %s' % output)
36
Patrick Williams0ca19cc2021-08-16 14:03:13 -050037 (status, output) = self.target.run('date +"%s"')
Brad Bishop6e60e8b2018-02-01 10:27:11 -050038 msg = 'The date was not set correctly, output: %s' % output
Patrick Williams0ca19cc2021-08-16 14:03:13 -050039 self.assertTrue(int(output) - sampleTimestamp < 300, msg=msg)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050040
41 (status, output) = self.target.run('date -s "%s"' % oldDate)
42 msg = 'Failed to reset date, output: %s' % output
43 self.assertEqual(status, 0, msg=msg)