• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
18
19
20class TestUsbConnect:
21    @pytest.mark.L0
22    def test_usb_disconnect(self):
23        # 注意:断连后需要等待一段时间才能重新连接
24
25        assert check_hdc_targets()
26        cmd = 'shell "kill -9 `pidof hdcd`"'
27        check_hdc_cmd(f"{cmd}", "[Fail][E001003] USB communication abnormal, please check the USB communication link.")
28        time.sleep(3)
29        assert check_hdc_targets()
30
31    @pytest.mark.L0
32    def test_list_targets_multi_usb_device(self):
33        devices_str = check_shell_any_device(f"{GP.hdc_exe} list targets", None, True)
34        time.sleep(3) # sleep 3s to wait for the device to connect channel
35        devices_array = devices_str[1].split('\n')
36        if devices_array:
37            for device in devices_array:
38                if len(device) > 8:
39                    assert check_shell_any_device(f"{GP.hdc_exe} -t {device} shell id", "u:r:")[0]
40