date.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #
  2. # SPDX-License-Identifier: MIT
  3. #
  4. import re
  5. from oeqa.runtime.case import OERuntimeTestCase
  6. from oeqa.core.decorator.depends import OETestDepends
  7. from oeqa.runtime.decorator.package import OEHasPackage
  8. class DateTest(OERuntimeTestCase):
  9. def setUp(self):
  10. if self.tc.td.get('VIRTUAL-RUNTIME_init_manager') == 'systemd':
  11. self.logger.debug('Stopping systemd-timesyncd daemon')
  12. self.target.run('systemctl stop systemd-timesyncd')
  13. def tearDown(self):
  14. if self.tc.td.get('VIRTUAL-RUNTIME_init_manager') == 'systemd':
  15. self.logger.debug('Starting systemd-timesyncd daemon')
  16. self.target.run('systemctl start systemd-timesyncd')
  17. @OETestDepends(['ssh.SSHTest.test_ssh'])
  18. @OEHasPackage(['coreutils', 'busybox'])
  19. def test_date(self):
  20. (status, output) = self.target.run('date +"%Y-%m-%d %T"')
  21. msg = 'Failed to get initial date, output: %s' % output
  22. self.assertEqual(status, 0, msg=msg)
  23. oldDate = output
  24. sampleDate = '"2016-08-09 10:00:00"'
  25. (status, output) = self.target.run("date -s %s" % sampleDate)
  26. self.assertEqual(status, 0, msg='Date set failed, output: %s' % output)
  27. (status, output) = self.target.run("date -R")
  28. p = re.match('Tue, 09 Aug 2016 10:00:.. \+0000', output)
  29. msg = 'The date was not set correctly, output: %s' % output
  30. self.assertTrue(p, msg=msg)
  31. (status, output) = self.target.run('date -s "%s"' % oldDate)
  32. msg = 'Failed to reset date, output: %s' % output
  33. self.assertEqual(status, 0, msg=msg)