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_state:WORKING" 10NAME = 'policy_DeviceChargingServer.AdvancedBatteryChargeMode' 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# When AdvancedBatteryChargeMode is enabled, and the time is outside of the work 29# period, the battery should not charge above 90%. Therefore we need to be above 30# 90% so we can test this. 31MIN_BATTERY_LEVEL = 91 32 33# Various interesting day_config values of the policy, assuming the time 34# is noon on a Monday. 35BEFORE_START_DAY_CONFIG = { 36 'entries': [{'day': 'MONDAY', 37 'charge_start_time':{'hour':22, 'minute':0}, 38 'charge_end_time':{'hour':23, 'minute':0}, 39 }] 40} 41START_THRU_END_DAY_CONFIG = { 42 'entries': [{'day': 'MONDAY', 43 'charge_start_time':{'hour':1, 'minute':0}, 44 'charge_end_time':{'hour':23, 'minute':0}, 45 }] 46} 47AFTER_END_DAY_CONFIG = { 48 'entries': [{'day': 'MONDAY', 49 'charge_start_time':{'hour':1, 'minute':0}, 50 'charge_end_time':{'hour':2, 'minute':0}, 51 }] 52} 53 54# A test case consists of the policies, plus the expected power behavior. 55TEST_CASES = [ 56 ({'DeviceAdvancedBatteryChargeModeEnabled': False, 57 'DeviceAdvancedBatteryChargeModeDayConfig': BEFORE_START_DAY_CONFIG}, 58 'ON_AC_AND_CHARGING'), 59 ({'DeviceAdvancedBatteryChargeModeEnabled': False, 60 'DeviceAdvancedBatteryChargeModeDayConfig': START_THRU_END_DAY_CONFIG}, 61 'ON_AC_AND_CHARGING'), 62 ({'DeviceAdvancedBatteryChargeModeEnabled': False, 63 'DeviceAdvancedBatteryChargeModeDayConfig': AFTER_END_DAY_CONFIG}, 64 'ON_AC_AND_CHARGING'), 65 66 ({'DeviceAdvancedBatteryChargeModeEnabled': True, 67 'DeviceAdvancedBatteryChargeModeDayConfig': BEFORE_START_DAY_CONFIG}, 68 'ON_AC_AND_NOT_CHARGING'), 69 ({'DeviceAdvancedBatteryChargeModeEnabled': True, 70 'DeviceAdvancedBatteryChargeModeDayConfig': START_THRU_END_DAY_CONFIG}, 71 'ON_AC_AND_CHARGING'), 72 ({'DeviceAdvancedBatteryChargeModeEnabled': True, 73 'DeviceAdvancedBatteryChargeModeDayConfig': AFTER_END_DAY_CONFIG}, 74 'ON_AC_AND_NOT_CHARGING'), 75] 76 77# These are used to cleanup the DUT and to prep the DUT before each test case. 78# See the test for more info. 79ON_AC_AND_CHARGING_POLICIES = { 80 'DeviceAdvancedBatteryChargeModeEnabled': False, 81 'DeviceAdvancedBatteryChargeModeDayConfig': BEFORE_START_DAY_CONFIG 82} 83ON_AC_AND_NOT_CHARGING_POLICIES = { 84 'DeviceAdvancedBatteryChargeModeEnabled': True, 85 'DeviceAdvancedBatteryChargeModeDayConfig': BEFORE_START_DAY_CONFIG 86} 87PREP_POLICIES = { 88 'ON_AC_AND_CHARGING' : (ON_AC_AND_NOT_CHARGING_POLICIES, 89 'ON_AC_AND_NOT_CHARGING'), 90 'ON_AC_AND_NOT_CHARGING' : (ON_AC_AND_CHARGING_POLICIES, 91 'ON_AC_AND_CHARGING'), 92 'NOT_ON_AC_AND_NOT_CHARGING' : (ON_AC_AND_CHARGING_POLICIES, 93 'ON_AC_AND_CHARGING'), 94} 95 96 97def run(machine): 98 host = hosts.create_host(machine, servo_args=servo_args) 99 job.run_test('policy_DeviceChargingServer', 100 host=host, 101 client_test=client_test, 102 test_cases=TEST_CASES, 103 min_battery_level=MIN_BATTERY_LEVEL, 104 prep_policies=PREP_POLICIES) 105 106parallel_simple(run, machines) 107