1# Copyright 2019 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5from autotest_lib.client.bin import test, utils
6from autotest_lib.client.common_lib import error
7import re, logging
8
9class hwclock(test.test):
10    version = 1
11
12    def run_once(self):
13        """
14        Set hwclock back to a date in 1980 and verify if the changes took
15        effect in the system.
16        """
17        logging.info('Setting hwclock to 2/2/80 03:04:00')
18        utils.set_hwclock(time='2/2/80 03:04:00')
19        date = utils.system_output('LC_ALL=C /sbin/hwclock')
20        if not re.match('Sat *Feb *2 *03:04:.. 1980', date):
21            raise error.TestFail("Failed to set hwclock back to the eighties. "
22                                 "Output of hwclock is '%s'" % date)
23
24
25    def cleanup(self):
26        """
27        Restore hardware clock to current system time.
28        """
29        logging.info('Restoring the hardware clock')
30        utils.set_hwclock(time='system', utc=True, noadjfile=True)
31