Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: MIT |
| 3 | # |
| 4 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 5 | import re |
| 6 | |
| 7 | from oeqa.runtime.case import OERuntimeTestCase |
| 8 | from oeqa.core.decorator.depends import OETestDepends |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 9 | from oeqa.runtime.decorator.package import OEHasPackage |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 10 | |
| 11 | class 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') |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame^] | 16 | self.target.run('systemctl disable --now --runtime systemd-timesyncd') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 17 | |
| 18 | def tearDown(self): |
| 19 | if self.tc.td.get('VIRTUAL-RUNTIME_init_manager') == 'systemd': |
| 20 | self.logger.debug('Starting systemd-timesyncd daemon') |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame^] | 21 | self.target.run('systemctl enable --now --runtime systemd-timesyncd') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 22 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 23 | @OETestDepends(['ssh.SSHTest.test_ssh']) |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 24 | @OEHasPackage(['coreutils', 'busybox']) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 25 | 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) |