blob: 7750a7293f8e3fe7114072c080dad33dc168afd8 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: MIT
3#
4
Brad Bishop6e60e8b2018-02-01 10:27:11 -05005import re
6
7from oeqa.runtime.case import OERuntimeTestCase
8from oeqa.core.decorator.depends import OETestDepends
Brad Bishop977dc1a2019-02-06 16:01:43 -05009from oeqa.runtime.decorator.package import OEHasPackage
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010
11class DateTest(OERuntimeTestCase):
12
13 def setUp(self):
14 if self.tc.td.get('VIRTUAL-RUNTIME_init_manager') == 'systemd':
15 self.logger.debug('Stopping systemd-timesyncd daemon')
16 self.target.run('systemctl stop systemd-timesyncd')
17
18 def tearDown(self):
19 if self.tc.td.get('VIRTUAL-RUNTIME_init_manager') == 'systemd':
20 self.logger.debug('Starting systemd-timesyncd daemon')
21 self.target.run('systemctl start systemd-timesyncd')
22
Brad Bishop6e60e8b2018-02-01 10:27:11 -050023 @OETestDepends(['ssh.SSHTest.test_ssh'])
Brad Bishop977dc1a2019-02-06 16:01:43 -050024 @OEHasPackage(['coreutils', 'busybox'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050025 def test_date(self):
26 (status, output) = self.target.run('date +"%Y-%m-%d %T"')
27 msg = 'Failed to get initial date, output: %s' % output
28 self.assertEqual(status, 0, msg=msg)
29 oldDate = output
30
31 sampleDate = '"2016-08-09 10:00:00"'
32 (status, output) = self.target.run("date -s %s" % sampleDate)
33 self.assertEqual(status, 0, msg='Date set failed, output: %s' % output)
34
35 (status, output) = self.target.run("date -R")
36 p = re.match('Tue, 09 Aug 2016 10:00:.. \+0000', output)
37 msg = 'The date was not set correctly, output: %s' % output
38 self.assertTrue(p, msg=msg)
39
40 (status, output) = self.target.run('date -s "%s"' % oldDate)
41 msg = 'Failed to reset date, output: %s' % output
42 self.assertEqual(status, 0, msg=msg)