blob: 0887b831f42f5d685716f84e469f69be684d2e08 [file] [log] [blame]
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001import re
2
3from oeqa.runtime.case import OERuntimeTestCase
4from oeqa.core.decorator.depends import OETestDepends
5from oeqa.core.decorator.oeid import OETestID
Brad Bishop977dc1a2019-02-06 16:01:43 -05006from oeqa.runtime.decorator.package import OEHasPackage
Brad Bishop6e60e8b2018-02-01 10:27:11 -05007
8class DateTest(OERuntimeTestCase):
9
10 def setUp(self):
11 if self.tc.td.get('VIRTUAL-RUNTIME_init_manager') == 'systemd':
12 self.logger.debug('Stopping systemd-timesyncd daemon')
13 self.target.run('systemctl stop systemd-timesyncd')
14
15 def tearDown(self):
16 if self.tc.td.get('VIRTUAL-RUNTIME_init_manager') == 'systemd':
17 self.logger.debug('Starting systemd-timesyncd daemon')
18 self.target.run('systemctl start systemd-timesyncd')
19
20 @OETestID(211)
21 @OETestDepends(['ssh.SSHTest.test_ssh'])
Brad Bishop977dc1a2019-02-06 16:01:43 -050022 @OEHasPackage(['coreutils', 'busybox'])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050023 def test_date(self):
24 (status, output) = self.target.run('date +"%Y-%m-%d %T"')
25 msg = 'Failed to get initial date, output: %s' % output
26 self.assertEqual(status, 0, msg=msg)
27 oldDate = output
28
29 sampleDate = '"2016-08-09 10:00:00"'
30 (status, output) = self.target.run("date -s %s" % sampleDate)
31 self.assertEqual(status, 0, msg='Date set failed, output: %s' % output)
32
33 (status, output) = self.target.run("date -R")
34 p = re.match('Tue, 09 Aug 2016 10:00:.. \+0000', output)
35 msg = 'The date was not set correctly, output: %s' % output
36 self.assertTrue(p, msg=msg)
37
38 (status, output) = self.target.run('date -s "%s"' % oldDate)
39 msg = 'Failed to reset date, output: %s' % output
40 self.assertEqual(status, 0, msg=msg)