xref: /OK3568_Linux_fs/yocto/poky/meta/lib/oeqa/runtime/cases/date.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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 --runtime 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 --runtime 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        sampleTimestamp = 1488800000
32        (status, output) = self.target.run("date -s @%d" % sampleTimestamp)
33        self.assertEqual(status, 0, msg='Date set failed, output: %s' % output)
34
35        (status, output) = self.target.run('date +"%s"')
36        msg = 'The date was not set correctly, output: %s' % output
37        self.assertTrue(int(output) - sampleTimestamp < 300, msg=msg)
38
39        (status, output) = self.target.run('date -s "%s"' % oldDate)
40        msg = 'Failed to reset date, output: %s' % output
41        self.assertEqual(status, 0, msg=msg)
42