100600bfbSopenharmony_ci#!/usr/bin/env python3 200600bfbSopenharmony_ci# -*- coding: utf-8 -*- 300600bfbSopenharmony_ci# Copyright (C) 2024 Huawei Device Co., Ltd. 400600bfbSopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 500600bfbSopenharmony_ci# you may not use this file except in compliance with the License. 600600bfbSopenharmony_ci# You may obtain a copy of the License at 700600bfbSopenharmony_ci# 800600bfbSopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 900600bfbSopenharmony_ci# 1000600bfbSopenharmony_ci# Unless required by applicable law or agreed to in writing, software 1100600bfbSopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 1200600bfbSopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1300600bfbSopenharmony_ci# See the License for the specific language governing permissions and 1400600bfbSopenharmony_ci# limitations under the License. 1500600bfbSopenharmony_ciimport pytest 1600600bfbSopenharmony_ciimport re 1700600bfbSopenharmony_cifrom utils import * 1800600bfbSopenharmony_ci 1900600bfbSopenharmony_ci@print_check_result 2000600bfbSopenharmony_cidef CheckNetTraffic(output): 2100600bfbSopenharmony_ci result = re.search("Received Bytes:\d+\nSent Bytes:\d+\n", output) 2200600bfbSopenharmony_ci return result is not None 2300600bfbSopenharmony_ci 2400600bfbSopenharmony_ci@print_check_result 2500600bfbSopenharmony_cidef CheckNetstat(output): 2600600bfbSopenharmony_ci result = re.search("Proto RefCnt Flags\s+Type\s+State\s+I-Node Path\n([^\n]+\n){4,}", output) 2700600bfbSopenharmony_ci return result is not None 2800600bfbSopenharmony_ci 2900600bfbSopenharmony_ci@print_check_result 3000600bfbSopenharmony_cidef CheckNetDev(output): 3100600bfbSopenharmony_ci result = re.search("face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compresse\n([^\n]+\n){4,}", output) 3200600bfbSopenharmony_ci return result is not None 3300600bfbSopenharmony_ci 3400600bfbSopenharmony_ci@print_check_result 3500600bfbSopenharmony_cidef CheckIfconfig(output): 3600600bfbSopenharmony_ci result = re.search("cmd is: ifconfig -a\n\n([^\n]+){4,}\n", output) 3700600bfbSopenharmony_ci return result is not None 3800600bfbSopenharmony_ci 3900600bfbSopenharmony_cidef CheckNetAllOutput(output): 4000600bfbSopenharmony_ci ret = all([CheckNetTraffic(output), CheckNetstat(output), CheckNetDev(output), CheckIfconfig(output)]) 4100600bfbSopenharmony_ci return ret 4200600bfbSopenharmony_ci 4300600bfbSopenharmony_ciclass TestHidumperNet: 4400600bfbSopenharmony_ci 4500600bfbSopenharmony_ci @pytest.mark.L0 4600600bfbSopenharmony_ci def test_net_all(self): 4700600bfbSopenharmony_ci command = f"hidumper --net" 4800600bfbSopenharmony_ci # 校验命令行输出 4900600bfbSopenharmony_ci CheckCmd(command, CheckNetAllOutput) 5000600bfbSopenharmony_ci # 校验命令行重定向输出 5100600bfbSopenharmony_ci CheckCmdRedirect(command, CheckNetAllOutput) 5200600bfbSopenharmony_ci # 校验命令行输出到zip文件 5300600bfbSopenharmony_ci CheckCmdZip(command, CheckNetAllOutput) 5400600bfbSopenharmony_ci 5500600bfbSopenharmony_ci @pytest.mark.L0 5600600bfbSopenharmony_ci def test_net_pid(self): 5700600bfbSopenharmony_ci command = f"hidumper --net `pidof samgr`" 5800600bfbSopenharmony_ci # 校验命令行输出 5900600bfbSopenharmony_ci CheckCmd(command, CheckNetTraffic) 6000600bfbSopenharmony_ci # 校验命令行重定向输出 6100600bfbSopenharmony_ci CheckCmdRedirect(command, CheckNetTraffic) 6200600bfbSopenharmony_ci # 校验命令行输出到zip文件 6300600bfbSopenharmony_ci CheckCmdZip(command, CheckNetTraffic)