Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame^] | 1 | from oeqa.oetest import oeRuntimeTest |
| 2 | from oeqa.utils.decorators import * |
| 3 | import re |
| 4 | |
| 5 | class DateTest(oeRuntimeTest): |
| 6 | |
| 7 | def setUp(self): |
| 8 | if oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager", True) == "systemd": |
| 9 | self.target.run('systemctl stop systemd-timesyncd') |
| 10 | |
| 11 | def tearDown(self): |
| 12 | if oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager", True) == "systemd": |
| 13 | self.target.run('systemctl start systemd-timesyncd') |
| 14 | |
| 15 | @testcase(211) |
| 16 | @skipUnlessPassed("test_ssh") |
| 17 | def test_date(self): |
| 18 | (status, output) = self.target.run('date +"%Y-%m-%d %T"') |
| 19 | self.assertEqual(status, 0, msg="Failed to get initial date, output: %s" % output) |
| 20 | oldDate = output |
| 21 | |
| 22 | sampleDate = '"2016-08-09 10:00:00"' |
| 23 | (status, output) = self.target.run("date -s %s" % sampleDate) |
| 24 | self.assertEqual(status, 0, msg="Date set failed, output: %s" % output) |
| 25 | |
| 26 | (status, output) = self.target.run("date -R") |
| 27 | p = re.match('Tue, 09 Aug 2016 10:00:.. \+0000', output) |
| 28 | self.assertTrue(p, msg="The date was not set correctly, output: %s" % output) |
| 29 | |
| 30 | (status, output) = self.target.run('date -s "%s"' % oldDate) |
| 31 | self.assertEqual(status, 0, msg="Failed to reset date, output: %s" % output) |