blob: 447987e0758c789c00dfe02684dd30e06fb6862b [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001from oeqa.oetest import oeRuntimeTest
2from oeqa.utils.decorators import *
3import re
4
5class DateTest(oeRuntimeTest):
6
Patrick Williamsf1e5d692016-03-30 15:21:19 -05007 def setUpLocal(self):
Patrick Williamsc124f4f2015-09-15 14:41:29 -05008 if oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager", True) == "systemd":
9 self.target.run('systemctl stop systemd-timesyncd')
10
Patrick Williamsf1e5d692016-03-30 15:21:19 -050011 def tearDownLocal(self):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012 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)