Home | History | Annotate | Download | only in power_MemorySuspend
      1 # Copyright (c) 2013 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 logging
      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 sys_power
      9 
     10 class power_MemorySuspend(test.test):
     11     """Suspend the system via memory_suspend_test."""
     12 
     13     version = 1
     14 
     15     def initialize(self):
     16         utils.system('stop ui', ignore_status=True)
     17 
     18 
     19     def run_once(self, num_suspends=1, max_spurious_wakeup_ratio=0.01):
     20         spurious_wakeup_count = 0
     21         max_spurious_wakeup = num_suspends * max_spurious_wakeup_ratio
     22 
     23         for _ in range(num_suspends):
     24             try:
     25                 sys_power.memory_suspend(10)
     26             except sys_power.SpuriousWakeupError:
     27                 spurious_wakeup_count += 1
     28                 if spurious_wakeup_count > max_spurious_wakeup:
     29                     raise error.TestFail('Too many SpuriousWakeupError.')
     30 
     31         if spurious_wakeup_count > 0:
     32             logging.info("Have %d SpuriousWakeupError", spurious_wakeup_count)
     33 
     34         keyval = { 'numSpuriousWakeupError' : spurious_wakeup_count }
     35         self.write_perf_keyval(keyval)
     36 
     37     def cleanup(self):
     38         utils.system('start ui')
     39