Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 7 | import re |
| 8 | |
| 9 | from oeqa.runtime.case import OERuntimeTestCase |
| 10 | from oeqa.core.decorator.depends import OETestDepends |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 11 | from oeqa.runtime.decorator.package import OEHasPackage |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 12 | |
| 13 | class 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 Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 18 | self.target.run('systemctl disable --now --runtime systemd-timesyncd') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 19 | |
| 20 | def tearDown(self): |
| 21 | if self.tc.td.get('VIRTUAL-RUNTIME_init_manager') == 'systemd': |
| 22 | self.logger.debug('Starting systemd-timesyncd daemon') |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 23 | self.target.run('systemctl enable --now --runtime systemd-timesyncd') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 24 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 25 | @OETestDepends(['ssh.SSHTest.test_ssh']) |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 26 | @OEHasPackage(['coreutils', 'busybox']) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 27 | 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 Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 33 | sampleTimestamp = 1488800000 |
| 34 | (status, output) = self.target.run("date -s @%d" % sampleTimestamp) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 35 | self.assertEqual(status, 0, msg='Date set failed, output: %s' % output) |
| 36 | |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 37 | (status, output) = self.target.run('date +"%s"') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 38 | msg = 'The date was not set correctly, output: %s' % output |
Patrick Williams | 0ca19cc | 2021-08-16 14:03:13 -0500 | [diff] [blame] | 39 | self.assertTrue(int(output) - sampleTimestamp < 300, msg=msg) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 40 | |
| 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) |