1# 2# Copyright OpenEmbedded Contributors 3# 4# SPDX-License-Identifier: MIT 5# 6 7import re 8 9from oeqa.runtime.case import OERuntimeTestCase 10from oeqa.core.decorator.depends import OETestDepends 11from oeqa.runtime.decorator.package import OEHasPackage 12 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') 18 self.target.run('systemctl disable --now --runtime systemd-timesyncd') 19 20 def tearDown(self): 21 if self.tc.td.get('VIRTUAL-RUNTIME_init_manager') == 'systemd': 22 self.logger.debug('Starting systemd-timesyncd daemon') 23 self.target.run('systemctl enable --now --runtime systemd-timesyncd') 24 25 @OETestDepends(['ssh.SSHTest.test_ssh']) 26 @OEHasPackage(['coreutils', 'busybox']) 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 33 sampleTimestamp = 1488800000 34 (status, output) = self.target.run("date -s @%d" % sampleTimestamp) 35 self.assertEqual(status, 0, msg='Date set failed, output: %s' % output) 36 37 (status, output) = self.target.run('date +"%s"') 38 msg = 'The date was not set correctly, output: %s' % output 39 self.assertTrue(int(output) - sampleTimestamp < 300, msg=msg) 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) 44