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. 15 16import pytest 17import re 18from utils import * 19 20@print_check_result 21def check_df_k(output): 22 result = re.search("cmd is: df -k\n\n([^\n]+\n){4,}", output) 23 return result is not None 24 25@print_check_result 26def check_lsof(output): 27 result = re.search("cmd is: lsof\n\n([^\n]+\n){4,}", output) 28 return result is not None 29 30@print_check_result 31def check_iotop(output): 32 result = re.search("cmd is: iotop -n 1 -m 100\n([^\n]+\n){4,}", output) 33 return result is not None 34 35@print_check_result 36def check_proc_mount(output): 37 result = re.search("/proc/mounts\n\n([^\n]+\n){4,}", output) 38 return result is not None 39 40def CheckStorageWithoutPid(output): 41 ret = all(check(output) for check in [check_df_k, check_lsof, check_iotop, check_proc_mount]) 42 return ret 43 44def CheckStorageWithPid(output): 45 result = re.search("storage io", output) 46 return result is not None 47 48class TestHidumperStorage: 49 @pytest.mark.L0 50 def test_storage_all(self): 51 command = "hidumper --storage" 52 # 校验命令行输出 53 CheckCmd(command, CheckStorageWithoutPid) 54 # 校验命令行重定向输出 55 CheckCmdRedirect(command, CheckStorageWithoutPid) 56 # 校验命令行输出到zip文件 57 CheckCmdZip(command, CheckStorageWithoutPid) 58 59 @pytest.mark.L0 60 def test_storage_pid(self): 61 command = f"hidumper --storage 1" 62 # 校验命令行输出 63 CheckCmd(command, CheckStorageWithPid) 64 # 校验命令行重定向输出 65 CheckCmdRedirect(command, CheckStorageWithPid) 66 # 校验命令行输出到zip文件 67 CheckCmdZip(command, CheckStorageWithPid)