mbligh | fa15d4e | 2010-03-24 21:50:59 +0000 | [diff] [blame] | 1 | from autotest_lib.client.bin import test, utils |
| 2 | from autotest_lib.client.common_lib import error |
lmr | 28f0298 | 2010-03-31 16:33:57 +0000 | [diff] [blame^] | 3 | import re, os, logging |
mbligh | fa15d4e | 2010-03-24 21:50:59 +0000 | [diff] [blame] | 4 | |
| 5 | class hwclock(test.test): |
| 6 | version = 1 |
| 7 | |
lmr | 28f0298 | 2010-03-31 16:33:57 +0000 | [diff] [blame^] | 8 | def run_once(self): |
| 9 | """ |
| 10 | Set hwclock back to a date in 1980 and verify if the changes took |
| 11 | effect in the system. |
| 12 | """ |
| 13 | logging.info('Setting hwclock to 2/2/80 03:04:00') |
mbligh | fa15d4e | 2010-03-24 21:50:59 +0000 | [diff] [blame] | 14 | utils.system('/sbin/hwclock --set --date "2/2/80 03:04:00"') |
lmr | 28f0298 | 2010-03-31 16:33:57 +0000 | [diff] [blame^] | 15 | date = utils.system_output('LC_ALL=C /sbin/hwclock') |
mbligh | fa15d4e | 2010-03-24 21:50:59 +0000 | [diff] [blame] | 16 | if not re.match('Sat *Feb *2 *03:04:.. 1980', date): |
lmr | 28f0298 | 2010-03-31 16:33:57 +0000 | [diff] [blame^] | 17 | raise error.TestFail("Failed to set hwclock back to the eighties. " |
| 18 | "Output of hwclock is '%s'" % date) |
mbligh | fa15d4e | 2010-03-24 21:50:59 +0000 | [diff] [blame] | 19 | |
| 20 | |
| 21 | def cleanup(self): |
lmr | 28f0298 | 2010-03-31 16:33:57 +0000 | [diff] [blame^] | 22 | """ |
| 23 | Restore hardware clock to current system time. |
| 24 | """ |
| 25 | logging.info('Restoring the hardware clock') |
mbligh | fa15d4e | 2010-03-24 21:50:59 +0000 | [diff] [blame] | 26 | utils.system('/sbin/hwclock --systohc --noadjfile --utc') |