From 2a81e2eaa8e2cb8484080d7e2954823fecded84d Mon Sep 17 00:00:00 2001 From: kun chen Date: Fri, 12 Sep 2025 16:28:08 +0800 Subject: [PATCH 1/2] pytest list targets Signed-off-by: kun chen --- .../testModule/test_hdc_list_targets.py | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 test/scripts/testModule/test_hdc_list_targets.py diff --git a/test/scripts/testModule/test_hdc_list_targets.py b/test/scripts/testModule/test_hdc_list_targets.py new file mode 100644 index 00000000..f0b9b8fb --- /dev/null +++ b/test/scripts/testModule/test_hdc_list_targets.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (C) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import pytest +from utils import GP, get_cmd_block_output_and_error + +class TestListTargetsOfUsb: + usbs = [] + + @classmethod + def setup_class(self): + cmd = f"{GP.hdc_exe} list targets -v" + result, _ = get_cmd_block_output_and_error(cmd) + print(result) + result = result.split(f"\n") + for item in result: + pattern = f"USB\tConnected\tlocalhost" + if pattern in item: + sn = item.split(f"\t")[0] + self.usbs.append(sn) + assert len(self.usbs) > 0 + + @classmethod + def teardown_class(self): + pass + + @pytest.mark.L0 + def test_shell_id(self): + count = 0 + for sn in self.usbs: + cmd = f"{GP.hdc_exe} -t {sn} shell id" + result, _ = get_cmd_block_output_and_error(cmd) + print(result) + assert result.find(f"uid=") >= 0 + count = count + 1 + assert count == len(self.usbs) + + @pytest.mark.L0 + def test_shell_ls(self): + count = 0 + for sn in self.usbs: + cmd = f"{GP.hdc_exe} -t {sn} shell ls" + result, _ = get_cmd_block_output_and_error(cmd) + print(result) + count = count + 1 + assert count == len(self.usbs) + + @pytest.mark.L0 + def test_shell_no_such_file(self): + count = 0 + for sn in self.usbs: + cmd = f"{GP.hdc_exe} -t {sn} find /system -name nosuchfile" + result, _ = get_cmd_block_output_and_error(cmd) + print(result) + count = count + 1 + assert count == len(self.usbs) + -- Gitee From 743f9ce43b36371185f1526ea316e7c9ab68d9fc Mon Sep 17 00:00:00 2001 From: kun chen Date: Fri, 12 Sep 2025 17:18:21 +0800 Subject: [PATCH 2/2] pytest list targets Signed-off-by: kun chen --- test/scripts/testModule/test_hdc_list_targets.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/scripts/testModule/test_hdc_list_targets.py b/test/scripts/testModule/test_hdc_list_targets.py index f0b9b8fb..6266458a 100644 --- a/test/scripts/testModule/test_hdc_list_targets.py +++ b/test/scripts/testModule/test_hdc_list_targets.py @@ -15,6 +15,7 @@ import pytest from utils import GP, get_cmd_block_output_and_error + class TestListTargetsOfUsb: usbs = [] -- Gitee