1# Copyright 2020 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 5from autotest_lib.client.common_lib import utils 6from autotest_lib.server.hosts import cros_host 7 8AUTHOR = 'ncrews' 9DEPENDENCIES = "servo" 10NAME = 'policy_DeviceChargingServer.PowerPeakShift' 11TIME = 'LONG' 12TEST_CATEGORY = 'General' 13TEST_CLASS = 'enterprise' 14TEST_TYPE = 'server' 15ATTRIBUTES = "suite:wilco_bve" 16 17DOC = """ 18Ensures the DUT's battery level is in a testable range, clears the TPM if 19needed, and then runs the specified client test to verify charging behavior 20is consistent with policies. 21""" 22 23args_dict = utils.args_to_dict(args) 24servo_args = cros_host.CrosHost.get_servo_arguments(args_dict) 25 26client_test = 'policy_DeviceScheduledCharging' 27 28# The lowest |DevicePowerPeakShift.battery_threshold| we can set is 15%. We need 29# to be able to set it to below our current battery level. 30MIN_BATTERY_LEVEL = 16 31 32# Various interesting day_config values of the policy, assuming the time 33# is noon on a Monday. 34BEFORE_START_DAY_CONFIG = { 35 'entries': [{'day': 'MONDAY', 36 'start_time':{'hour':21, 'minute':0}, 37 'end_time':{'hour':22, 'minute':0}, 38 'charge_start_time':{'hour':23, 'minute':0}, 39 }] 40} 41START_THRU_END_DAY_CONFIG = { 42 'entries': [{'day': 'MONDAY', 43 'start_time':{'hour':1, 'minute':0}, 44 'end_time':{'hour':22, 'minute':0}, 45 'charge_start_time':{'hour':23, 'minute':0}, 46 }] 47} 48END_THRU_CHARGE_START_DAY_CONFIG = { 49 'entries': [{'day': 'MONDAY', 50 'start_time':{'hour':1, 'minute':0}, 51 'end_time':{'hour':2, 'minute':0}, 52 'charge_start_time':{'hour':23, 'minute':0}, 53 }] 54} 55AFTER_CHARGE_START_DAY_CONFIG = { 56 'entries': [{'day': 'MONDAY', 57 'start_time':{'hour':1, 'minute':0}, 58 'end_time':{'hour':2, 'minute':0}, 59 'charge_start_time':{'hour':3, 'minute':0}, 60 }] 61} 62 63# A test case consists of the policies, plus the expected power behavior. 64TEST_CASES = [ 65 ({'DevicePowerPeakShiftEnabled': False, 66 'DevicePowerPeakShiftBatteryThreshold': 0, 67 'DevicePowerPeakShiftDayConfig':{}}, 68 'ON_AC_AND_CHARGING'), 69 70 ({'DevicePowerPeakShiftEnabled': True, 71 'DevicePowerPeakShiftBatteryThreshold': 15, 72 'DevicePowerPeakShiftDayConfig': BEFORE_START_DAY_CONFIG}, 73 'ON_AC_AND_CHARGING'), 74 ({'DevicePowerPeakShiftEnabled': True, 75 'DevicePowerPeakShiftBatteryThreshold': 15, 76 'DevicePowerPeakShiftDayConfig': START_THRU_END_DAY_CONFIG}, 77 'NOT_ON_AC_AND_NOT_CHARGING'), 78 ({'DevicePowerPeakShiftEnabled': True, 79 'DevicePowerPeakShiftBatteryThreshold': 15, 80 'DevicePowerPeakShiftDayConfig': END_THRU_CHARGE_START_DAY_CONFIG}, 81 'ON_AC_AND_NOT_CHARGING'), 82 ({'DevicePowerPeakShiftEnabled': True, 83 'DevicePowerPeakShiftBatteryThreshold': 15, 84 'DevicePowerPeakShiftDayConfig': AFTER_CHARGE_START_DAY_CONFIG}, 85 'ON_AC_AND_CHARGING'), 86 87 ({'DevicePowerPeakShiftEnabled': True, 88 'DevicePowerPeakShiftBatteryThreshold': 100, 89 'DevicePowerPeakShiftDayConfig': BEFORE_START_DAY_CONFIG}, 90 'ON_AC_AND_CHARGING'), 91 ({'DevicePowerPeakShiftEnabled': True, 92 'DevicePowerPeakShiftBatteryThreshold': 100, 93 'DevicePowerPeakShiftDayConfig': START_THRU_END_DAY_CONFIG}, 94 'ON_AC_AND_NOT_CHARGING'), 95 ({'DevicePowerPeakShiftEnabled': True, 96 'DevicePowerPeakShiftBatteryThreshold': 100, 97 'DevicePowerPeakShiftDayConfig': END_THRU_CHARGE_START_DAY_CONFIG}, 98 'ON_AC_AND_NOT_CHARGING'), 99 ({'DevicePowerPeakShiftEnabled': True, 100 'DevicePowerPeakShiftBatteryThreshold': 100, 101 'DevicePowerPeakShiftDayConfig': AFTER_CHARGE_START_DAY_CONFIG}, 102 'ON_AC_AND_CHARGING'), 103] 104 105# These are used to cleanup the DUT and to prep the DUT before each test case. 106# See the test for more info. 107ON_AC_AND_NOT_CHARGING_POLICIES = { 108 'DevicePowerPeakShiftEnabled': True, 109 'DevicePowerPeakShiftBatteryThreshold': 15, 110 'DevicePowerPeakShiftDayConfig': END_THRU_CHARGE_START_DAY_CONFIG 111} 112ON_AC_AND_CHARGING_POLICIES = { 113 'DevicePowerPeakShiftEnabled': False, 114 'DevicePowerPeakShiftBatteryThreshold': 0, 115 'DevicePowerPeakShiftDayConfig': {} 116} 117PREP_POLICIES = { 118 'ON_AC_AND_CHARGING' : (ON_AC_AND_NOT_CHARGING_POLICIES, 119 'ON_AC_AND_NOT_CHARGING'), 120 'ON_AC_AND_NOT_CHARGING' : (ON_AC_AND_CHARGING_POLICIES, 121 'ON_AC_AND_CHARGING'), 122 'NOT_ON_AC_AND_NOT_CHARGING' : (ON_AC_AND_CHARGING_POLICIES, 123 'ON_AC_AND_CHARGING'), 124} 125def run(machine): 126 host = hosts.create_host(machine, servo_args=servo_args) 127 job.run_test('policy_DeviceChargingServer', 128 host=host, 129 client_test=client_test, 130 test_cases=TEST_CASES, 131 min_battery_level=MIN_BATTERY_LEVEL, 132 prep_policies=PREP_POLICIES) 133 134parallel_simple(run, machines) 135