Home | History | Annotate | Download | only in power_WakeupRTC
      1 # Copyright (c) 2012 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 
      5 import errno, logging, os, shutil, time
      6 from autotest_lib.client.bin import test, utils
      7 from autotest_lib.client.common_lib import error
      8 from autotest_lib.client.cros import rtc
      9 from autotest_lib.client.cros.power import sys_power
     10 
     11 
     12 def read_rtc_wakeup(rtc_device):
     13     """
     14     Read the wakeup setting for for the RTC device.
     15     """
     16     sysfs_path = '/sys/class/rtc/%s/device/power/wakeup' % rtc_device
     17     return file(sysfs_path).read().strip()
     18 
     19 
     20 def read_rtc_wakeup_count(rtc_device):
     21     """
     22     Read the current wakeup count for the RTC device.
     23     """
     24     sysfs_path = '/sys/class/rtc/%s/device/power/wakeup_count' % rtc_device
     25     return int(file(sysfs_path).read())
     26 
     27 
     28 def fire_wakealarm(rtc_device):
     29     """
     30     Schedule a wakealarm and wait for it to fire.
     31     """
     32     rtc.set_wake_alarm('+1', rtc_device)
     33     time.sleep(2)
     34 
     35 
     36 class power_WakeupRTC(test.test):
     37     """Test RTC wake events."""
     38 
     39     version = 1
     40 
     41     def run_once(self):
     42         for rtc_device in rtc.get_rtc_devices():
     43             self.run_once_rtc(rtc_device)
     44 
     45     def run_once_rtc(self, rtc_device):
     46         logging.info('testing rtc device %s', rtc_device)
     47 
     48         # Test that RTC wakeup is enabled
     49         rtc_wakeup = read_rtc_wakeup(rtc_device)
     50         if rtc_wakeup != 'enabled':
     51             raise error.TestError('RTC wakeup is not enabled: %s' % rtc_device)
     52 
     53         # Test that RTC can generate wake events
     54         old_sys_wakeup_count = sys_power.read_wakeup_count()
     55         old_rtc_wakeup_count = read_rtc_wakeup_count(rtc_device)
     56         fire_wakealarm(rtc_device)
     57         new_sys_wakeup_count = sys_power.read_wakeup_count()
     58         new_rtc_wakeup_count = read_rtc_wakeup_count(rtc_device)
     59         if new_rtc_wakeup_count == old_rtc_wakeup_count:
     60             raise error.TestFail(
     61                     'RTC alarm should increase RTC wakeup_count: %s'
     62                     % rtc_device)
     63         if new_sys_wakeup_count == old_sys_wakeup_count:
     64             raise error.TestFail(
     65                     'RTC alarm should increase system wakeup_count: %s'
     66                     % rtc_device)
     67