1# Copyright 2019 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
5AUTHOR = "puthik"
6NAME = "power_Dashboard.full_lab"
7TIME = "MEDIUM"
8TEST_CATEGORY = "Stress"
9TEST_CLASS = "suite"
10TEST_TYPE = "server"
11
12DOC = """
13Sequence for upload common power test data to dashboard.
14"""
15
16import datetime
17from autotest_lib.client.common_lib import error
18from autotest_lib.client.common_lib import utils
19
20CLIENT_TESTS = [
21    ('power_LoadTest', {
22        'tag' : '1hour', 'loop_time' : 3600, 'loop_count' : 1,
23        'test_low_batt_p' : 6}),
24    ('power_Idle', {}),
25    ('power_VideoPlayback', {}),
26    ('power_VideoPlayback', {
27        'tag' : 'sw_decoder', 'use_hw_decode' : False}),
28    ('power_Display', {}),
29    ('power_WebGL', {}),
30    ('power_Standby', {
31        'tag' : 'fast', 'sample_hours' : 0.334, 'test_hours' : 0.334}),
32]
33
34SERVO_V4_ETH_VENDOR = '0bda'
35SERVO_V4_ETH_PRODUCT = '8153'
36WIFI_SSID = 'powertest_ap'
37
38# Workaround to make it compatible with moblab autotest UI.
39global args_dict
40try:
41    args_dict
42except NameError:
43    args_dict = utils.args_to_dict(args)
44
45# Use time as pdash_note if not supplied to track all tests in same suite.
46pdash_note = args_dict.get('pdash_note',
47                           NAME + '_' + datetime.datetime.utcnow().isoformat())
48
49def run_client_test(machine):
50    client = hosts.create_host(machine)
51
52    wlan_ip = client.get_wlan_ip()
53    if not wlan_ip:
54        autotest.Autotest(client).run_test('dummy_Pass')
55        if not client.connect_to_wifi(WIFI_SSID):
56            raise error.TestFail('Can not connect to wifi.')
57        wlan_ip = client.get_wlan_ip()
58        if not wlan_ip:
59            raise error.TestFail('Can not find wlan ip.')
60
61    # Check if we have servo v4 ethernet and can switch to wlan.
62    eth_usb = client.find_usb_devices(SERVO_V4_ETH_VENDOR, SERVO_V4_ETH_PRODUCT)
63    can_switch_to_wlan = len(eth_usb) == 1 and eth_usb[0] and wlan_ip
64    if can_switch_to_wlan:
65        wlan_machine = machine
66        if utils.host_is_in_power_lab(machine['hostname']):
67            wlan_machine['hostname'] = \
68                utils.get_power_lab_wlan_hostname(machine['hostname'])
69        else:
70            wlan_machine['hostname'] = wlan_ip
71        client = hosts.create_host(wlan_machine)
72        eth_node = eth_usb[0]
73
74    client_at = autotest.Autotest(client)
75
76    for test, argv in CLIENT_TESTS:
77        client.reboot()
78        if can_switch_to_wlan:
79            client.unbind_usb_device(eth_node)
80        argv['pdash_note'] = pdash_note
81        argv['force_discharge'] = True
82        client_at.run_test(test, **argv)
83
84    client.reboot()
85
86
87parallel_simple(run_client_test, machines)
88