1# 2# SPDX-License-Identifier: MIT 3# 4 5import re 6 7from oeqa.runtime.case import OERuntimeTestCase 8from oeqa.core.decorator.depends import OETestDepends 9from oeqa.runtime.decorator.package import OEHasPackage 10 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 disable --now 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 enable --now systemd-timesyncd') 22 23 @OETestDepends(['ssh.SSHTest.test_ssh']) 24 @OEHasPackage(['coreutils', 'busybox']) 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) 43