1134ec2c1ecfa243e9d7b0ebd18ed20a6bb6d7240J. Richard Barnette# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2489972641910a8a31e10af5d7eafff75f9d04fcaCraig Harrison# Use of this source code is governed by a BSD-style license that can be
3489972641910a8a31e10af5d7eafff75f9d04fcaCraig Harrison# found in the LICENSE file.
4489972641910a8a31e10af5d7eafff75f9d04fcaCraig Harrison
5134ec2c1ecfa243e9d7b0ebd18ed20a6bb6d7240J. Richard Barnettefrom autotest_lib.client.common_lib import error
6134ec2c1ecfa243e9d7b0ebd18ed20a6bb6d7240J. Richard Barnettefrom autotest_lib.server import test
7489972641910a8a31e10af5d7eafff75f9d04fcaCraig Harrison
8134ec2c1ecfa243e9d7b0ebd18ed20a6bb6d7240J. Richard Barnetteclass platform_CloseOpenLid(test.test):
9489972641910a8a31e10af5d7eafff75f9d04fcaCraig Harrison    """Uses servo to send the host to sleep and wake back up.
10489972641910a8a31e10af5d7eafff75f9d04fcaCraig Harrison
11489972641910a8a31e10af5d7eafff75f9d04fcaCraig Harrison    Uses pwr_button and lid_open gpios in various combinations.
12489972641910a8a31e10af5d7eafff75f9d04fcaCraig Harrison    """
13489972641910a8a31e10af5d7eafff75f9d04fcaCraig Harrison    version = 1
14489972641910a8a31e10af5d7eafff75f9d04fcaCraig Harrison
15489972641910a8a31e10af5d7eafff75f9d04fcaCraig Harrison
16489972641910a8a31e10af5d7eafff75f9d04fcaCraig Harrison    def run_once(self, host):
17489972641910a8a31e10af5d7eafff75f9d04fcaCraig Harrison        # lid only
18134ec2c1ecfa243e9d7b0ebd18ed20a6bb6d7240J. Richard Barnette        boot_id = host.get_boot_id()
19134ec2c1ecfa243e9d7b0ebd18ed20a6bb6d7240J. Richard Barnette        host.servo.lid_close()
20134ec2c1ecfa243e9d7b0ebd18ed20a6bb6d7240J. Richard Barnette        host.test_wait_for_shutdown()
21134ec2c1ecfa243e9d7b0ebd18ed20a6bb6d7240J. Richard Barnette
22134ec2c1ecfa243e9d7b0ebd18ed20a6bb6d7240J. Richard Barnette        host.servo.lid_open()
23134ec2c1ecfa243e9d7b0ebd18ed20a6bb6d7240J. Richard Barnette        host.servo.pass_devmode()
24134ec2c1ecfa243e9d7b0ebd18ed20a6bb6d7240J. Richard Barnette        host.test_wait_for_boot(boot_id)
25489972641910a8a31e10af5d7eafff75f9d04fcaCraig Harrison
26489972641910a8a31e10af5d7eafff75f9d04fcaCraig Harrison        # pwr_button and open lid
27134ec2c1ecfa243e9d7b0ebd18ed20a6bb6d7240J. Richard Barnette        boot_id = host.get_boot_id()
28134ec2c1ecfa243e9d7b0ebd18ed20a6bb6d7240J. Richard Barnette        host.servo.power_long_press()
29134ec2c1ecfa243e9d7b0ebd18ed20a6bb6d7240J. Richard Barnette        if host.is_up():
30134ec2c1ecfa243e9d7b0ebd18ed20a6bb6d7240J. Richard Barnette            raise error.TestError('DUT still up after long press power')
31134ec2c1ecfa243e9d7b0ebd18ed20a6bb6d7240J. Richard Barnette
32134ec2c1ecfa243e9d7b0ebd18ed20a6bb6d7240J. Richard Barnette        host.servo.lid_close()
33134ec2c1ecfa243e9d7b0ebd18ed20a6bb6d7240J. Richard Barnette        host.servo.lid_open()
34134ec2c1ecfa243e9d7b0ebd18ed20a6bb6d7240J. Richard Barnette        host.servo.pass_devmode()
35134ec2c1ecfa243e9d7b0ebd18ed20a6bb6d7240J. Richard Barnette        host.test_wait_for_boot(boot_id)
36