12707961254706817025b0121c992e9d73fb7bfaaMichael Spang# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
22707961254706817025b0121c992e9d73fb7bfaaMichael Spang# Use of this source code is governed by a BSD-style license that can be
32707961254706817025b0121c992e9d73fb7bfaaMichael Spang# found in the LICENSE file.
42707961254706817025b0121c992e9d73fb7bfaaMichael Spang
52707961254706817025b0121c992e9d73fb7bfaaMichael Spangimport logging, errno, shutil, os
62707961254706817025b0121c992e9d73fb7bfaaMichael Spangfrom autotest_lib.client.bin import test, utils
72707961254706817025b0121c992e9d73fb7bfaaMichael Spangfrom autotest_lib.client.common_lib import error
8be2a5f7dc952b674d8109d0cb48d82d648ae30bbPuthikorn Voravootivatfrom autotest_lib.client.cros import rtc
9be2a5f7dc952b674d8109d0cb48d82d648ae30bbPuthikorn Voravootivatfrom autotest_lib.client.cros.power import sys_power
102707961254706817025b0121c992e9d73fb7bfaaMichael Spang
112707961254706817025b0121c992e9d73fb7bfaaMichael SpangSYSFS_CONSOLE_SUSPEND = '/sys/module/printk/parameters/console_suspend'
122707961254706817025b0121c992e9d73fb7bfaaMichael Spang
132707961254706817025b0121c992e9d73fb7bfaaMichael Spangclass power_NoConsoleSuspend(test.test):
142707961254706817025b0121c992e9d73fb7bfaaMichael Spang    """Test suspend/resume with no_console_suspend option set."""
152707961254706817025b0121c992e9d73fb7bfaaMichael Spang
162707961254706817025b0121c992e9d73fb7bfaaMichael Spang    version = 1
172707961254706817025b0121c992e9d73fb7bfaaMichael Spang
182707961254706817025b0121c992e9d73fb7bfaaMichael Spang    def initialize(self):
192707961254706817025b0121c992e9d73fb7bfaaMichael Spang        # Save & disable console_suspend module param
202707961254706817025b0121c992e9d73fb7bfaaMichael Spang        self.old_console_suspend = utils.read_file(SYSFS_CONSOLE_SUSPEND)
212707961254706817025b0121c992e9d73fb7bfaaMichael Spang        utils.write_one_line(SYSFS_CONSOLE_SUSPEND, 'N')
222707961254706817025b0121c992e9d73fb7bfaaMichael Spang
232707961254706817025b0121c992e9d73fb7bfaaMichael Spang    def run_once(self):
240537d52c7b85e9454336449f2bc9efae5a4983a4Julius Werner        sys_power.kernel_suspend(10)
252707961254706817025b0121c992e9d73fb7bfaaMichael Spang
262707961254706817025b0121c992e9d73fb7bfaaMichael Spang    def cleanup(self):
272707961254706817025b0121c992e9d73fb7bfaaMichael Spang        # Restore old console_suspend module param
282707961254706817025b0121c992e9d73fb7bfaaMichael Spang        logging.info('restoring value for console_suspend: %s',
292707961254706817025b0121c992e9d73fb7bfaaMichael Spang                     self.old_console_suspend)
302707961254706817025b0121c992e9d73fb7bfaaMichael Spang        utils.open_write_close(SYSFS_CONSOLE_SUSPEND, self.old_console_suspend)
31