1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3# Copyright (C) 2024 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 pytest 16import re 17from utils import * 18 19@print_check_result 20def CheckNetTraffic(output): 21 result = re.search("Received Bytes:\d+\nSent Bytes:\d+\n", output) 22 return result is not None 23 24@print_check_result 25def CheckNetstat(output): 26 result = re.search("Proto RefCnt Flags\s+Type\s+State\s+I-Node Path\n([^\n]+\n){4,}", output) 27 return result is not None 28 29@print_check_result 30def CheckNetDev(output): 31 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) 32 return result is not None 33 34@print_check_result 35def CheckIfconfig(output): 36 result = re.search("cmd is: ifconfig -a\n\n([^\n]+){4,}\n", output) 37 return result is not None 38 39def CheckNetAllOutput(output): 40 ret = all([CheckNetTraffic(output), CheckNetstat(output), CheckNetDev(output), CheckIfconfig(output)]) 41 return ret 42 43class TestHidumperNet: 44 45 @pytest.mark.L0 46 def test_net_all(self): 47 command = f"hidumper --net" 48 # 校验命令行输出 49 CheckCmd(command, CheckNetAllOutput) 50 # 校验命令行重定向输出 51 CheckCmdRedirect(command, CheckNetAllOutput) 52 # 校验命令行输出到zip文件 53 CheckCmdZip(command, CheckNetAllOutput) 54 55 @pytest.mark.L0 56 def test_net_pid(self): 57 command = f"hidumper --net `pidof samgr`" 58 # 校验命令行输出 59 CheckCmd(command, CheckNetTraffic) 60 # 校验命令行重定向输出 61 CheckCmdRedirect(command, CheckNetTraffic) 62 # 校验命令行输出到zip文件 63 CheckCmdZip(command, CheckNetTraffic)