1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3# Copyright (C) 2025 Huawei Device Co., Ltd. 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15import time 16import pytest 17from utils import GP, check_hdc_cmd, check_hdc_targets, check_shell_any_device, load_gp, check_shell 18 19 20class TestUsbConnect: 21 @pytest.mark.L0 22 @pytest.mark.repeat(10) 23 def test_usb_disconnect(self): 24 # 注意:断连后需要等待一段时间才能重新连接 25 26 assert check_hdc_targets() 27 cmd = 'shell "kill -9 `pidof hdcd`"' 28 check_hdc_cmd(f"{cmd}", "[Fail][E001003] USB communication abnormal, please check the USB communication link.") 29 assert check_shell(f"{GP.hdc_head} wait", "") 30 assert check_hdc_targets() 31 32 @pytest.mark.L0 33 @pytest.mark.repeat(10) 34 def test_list_targets_multi_usb_device(self): 35 devices_str = check_shell_any_device(f"{GP.hdc_exe} list targets", None, True) 36 assert check_shell(f"{GP.hdc_head} wait", "") 37 devices_array = devices_str[1].split('\n') 38 if devices_array: 39 for device in devices_array: 40 if len(device) > 8: 41 assert check_shell_any_device(f"{GP.hdc_exe} -t {device} shell id", "u:r:")[0] 42