1#!/usr/bin/python3 2# Copyright 2021 The Chromium OS Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6# pylint: disable=missing-docstring 7 8import unittest 9from unittest import mock 10 11import common 12from autotest_lib.server.hosts import servo_repair 13from autotest_lib.server.hosts import repair_utils 14 15SERVO_VERIFY_DAG = ( 16 (servo_repair._ConnectionVerifier, 'connection', []), 17 (servo_repair._RootServoPresentVerifier, 'servo_root_present', 18 ['connection']), 19 (servo_repair._RootServoV3PresentVerifier, 'servo_v3_root_present', 20 ['connection']), 21 (servo_repair._ServoFwVerifier, 'servo_fw', ['servo_root_present']), 22 (servo_repair._StartServodVerifier, 'start_servod', 23 ['servo_fw', 'servo_v3_root_present']), 24 (servo_repair._DiskSpaceVerifier, 'servo_disk_space', ['connection']), 25 (servo_repair._UpdateVerifier, 'servo_update', 26 ['servo_v3_root_present']), 27 (servo_repair._BoardConfigVerifier, 'servo_config_board', 28 ['connection']), 29 (servo_repair._SerialConfigVerifier, 'servo_config_serial', 30 ['connection']), 31 (servo_repair._ServodJobVerifier, 'servod_started', [ 32 'start_servod', 'servo_config_board', 'servo_config_serial', 33 'servo_disk_space' 34 ]), 35 (servo_repair._ServodEchoVerifier, 'servod_echo', ['servod_started']), 36 (servo_repair._TopologyVerifier, 'servo_topology', ['servod_echo']), 37 (servo_repair._ServodConnectionVerifier, 'servod_connection', 38 ['servod_echo']), 39 (servo_repair._Cr50LowSBUVerifier, 'servo_cr50_low_sbu', 40 ['servod_connection']), 41 (servo_repair.ServodDutControllerMissingVerifier, 42 'servod_dut_controller_missing', ['servod_connection']), 43 (servo_repair._Cr50OffVerifier, 'servo_cr50_off', 44 ['servod_connection']), 45 (servo_repair._ServodControlVerifier, 'servod_control', 46 ['servod_connection']), 47 (servo_repair._DUTConnectionVerifier, 'servo_dut_connected', 48 ['servod_connection']), 49 (servo_repair._ServoHubConnectionVerifier, 'servo_hub_connected', 50 ['servo_dut_connected']), 51 (servo_repair._PowerButtonVerifier, 'servo_pwr_button', 52 ['servo_hub_connected']), 53 (servo_repair._BatteryVerifier, 'servo_battery', 54 ['servo_hub_connected']), 55 (servo_repair._LidVerifier, 'servo_lid_open', ['servo_hub_connected']), 56 (servo_repair.ECConsoleVerifier, 'servo_ec_console', 57 ['servo_dut_connected']), 58 (servo_repair._Cr50ConsoleVerifier, 'servo_cr50_console', 59 ['servo_dut_connected']), 60 (servo_repair._CCDTestlabVerifier, 'servo_ccd_testlab', 61 ['servo_cr50_console']), 62 (servo_repair._CCDPowerDeliveryVerifier, 'servo_power_delivery', 63 ['servod_connection']), 64) 65 66SERVO_REPAIR_ACTIONS = ( 67 (servo_repair._ServoFwUpdateRepair, 'servo_fw_update', ['connection'], 68 ['servo_fw']), 69 (servo_repair._DiskCleanupRepair, 'servo_disk_cleanup', ['connection'], 70 ['servo_disk_space']), 71 (servo_repair._ServoMicroFlashRepair, 'servo_micro_flash', 72 ['connection', 'servo_topology'], ['servo_dut_connected']), 73 (servo_repair._RestartServod, 'servod_restart', 74 ['connection', 'servo_fw'], [ 75 'servo_config_board', 'servo_config_serial', 'start_servod', 76 'servod_started', 'servo_topology', 'servod_connection', 77 'servod_echo', 'servod_control', 'servo_dut_connected', 78 'servo_hub_connected', 'servo_pwr_button', 79 'servo_cr50_console', 'servo_cr50_low_sbu', 'servo_cr50_off', 80 'servo_power_delivery', 'servod_dut_controller_missing' 81 ]), 82 (servo_repair._ServoRebootRepair, 'servo_reboot', ['connection'], [ 83 'servo_topology', 'servo_root_present', 'servo_disk_space', 84 'servo_power_delivery' 85 ]), 86 (servo_repair._PowerDeliveryRepair, 'servo_pd_recover', 87 ['servod_connection'], [ 88 'servod_started', 'servo_topology', 'servod_connection', 89 'servod_echo', 'servod_control', 'servo_dut_connected', 90 'servo_hub_connected', 'servo_pwr_button', 91 'servo_cr50_console', 'servo_cr50_low_sbu', 'servo_cr50_off', 92 'servo_power_delivery', 'servod_dut_controller_missing' 93 ]), 94 (servo_repair._FakedisconnectRepair, 'servo_fakedisconnect', 95 ['servod_connection'], [ 96 'servod_started', 'servo_topology', 'servod_connection', 97 'servod_echo', 'servod_control', 'servo_dut_connected', 98 'servo_hub_connected', 'servo_pwr_button', 99 'servo_cr50_console', 'servo_cr50_low_sbu', 'servo_cr50_off', 100 'servo_power_delivery', 'servod_dut_controller_missing' 101 ]), 102 (servo_repair._ToggleCCLineRepair, 'servo_cc', ['servod_connection'], [ 103 'servod_started', 'servo_topology', 'servod_connection', 104 'servod_echo', 'servod_control', 'servo_dut_connected', 105 'servo_hub_connected', 'servo_pwr_button', 106 'servo_cr50_console', 'servo_cr50_low_sbu', 'servo_cr50_off', 107 'servo_power_delivery', 'servod_dut_controller_missing' 108 ]), 109 (servo_repair._DutRebootRepair, 'servo_dut_reboot', 110 ['servod_connection'], [ 111 'servod_control', 'servo_lid_open', 'servo_ec_console', 112 'servo_topology', 'servo_dut_connected', 113 'servo_hub_connected', 'servo_cr50_low_sbu', 'servo_cr50_off', 114 'servo_cr50_console', 'servo_power_delivery', 115 'servod_dut_controller_missing' 116 ]), 117 (servo_repair._ECRebootRepair, 'servo_ec_reboot', 118 ['servod_connection'], [ 119 'servod_control', 'servo_lid_open', 'servo_ec_console', 120 'servo_topology', 'servo_dut_connected', 121 'servo_hub_connected', 'servo_cr50_low_sbu', 'servo_cr50_off', 122 'servo_cr50_console', 'servo_power_delivery', 123 'servod_dut_controller_missing' 124 ]), 125) 126 127 128class ServoRepairUnittests(unittest.TestCase): 129 130 # Allow to show all diff when compare tuple. 131 maxDiff = None 132 133 def test_servo_repair_components(self): 134 verify_dag = servo_repair._servo_verifier_actions() 135 self.assertTupleEqual(verify_dag, SERVO_VERIFY_DAG) 136 self.check_verify_dag(verify_dag) 137 repair_actions = servo_repair._servo_repair_actions() 138 self.assertTupleEqual(repair_actions, SERVO_REPAIR_ACTIONS) 139 self.check_repair_actions(verify_dag, repair_actions) 140 141 def test_servo_repair_strategy(self): 142 servo_repair.create_servo_repair_strategy() 143 144 def check_verify_dag(self, verify_dag): 145 """Checks that dependency labels are defined.""" 146 labels = [n[1] for n in verify_dag] 147 for node in verify_dag: 148 for dep in node[2]: 149 self.assertIn(dep, labels) 150 151 def check_repair_actions(self, verify_dag, repair_actions): 152 """Checks that dependency and trigger labels are defined.""" 153 verify_labels = [n[1] for n in verify_dag] 154 for action in repair_actions: 155 deps = action[2] 156 triggers = action[3] 157 for label in deps + triggers: 158 self.assertIn(label, verify_labels) 159 160 161if __name__ == '__main__': 162 unittest.main() 163