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_ci 1600600bfbSopenharmony_ciimport pytest 1700600bfbSopenharmony_ciimport re 1800600bfbSopenharmony_cifrom utils import * 1900600bfbSopenharmony_ci 2000600bfbSopenharmony_cidef CheckCpuUsageOutput(output): 2100600bfbSopenharmony_ci ret = re.search("PID Total Usage User Space Kernel Space Page Fault Minor Page Fault Major Name\n([^\n]+\n){4,}", output) 2200600bfbSopenharmony_ci return ret is not None 2300600bfbSopenharmony_ci 2400600bfbSopenharmony_cidef CheckCpuUsageWithPidOutput(output): 2500600bfbSopenharmony_ci ret = re.search("PID Total Usage User Space Kernel Space Page Fault Minor Page Fault Major Name\n([^\n]+\n){1,}", output) 2600600bfbSopenharmony_ci return ret is not None 2700600bfbSopenharmony_ci 2800600bfbSopenharmony_cidef CheckCpufreqOutput(output): 2900600bfbSopenharmony_ci ret = re.search("cmd is: cat /sys/devices/system/cpu/cpu\d/cpufreq/cpuinfo_cur_freq\n\n\d+", output) 3000600bfbSopenharmony_ci return ret is not None 3100600bfbSopenharmony_ci 3200600bfbSopenharmony_ciclass TestHidumperCpu: 3300600bfbSopenharmony_ci 3400600bfbSopenharmony_ci @pytest.mark.L0 3500600bfbSopenharmony_ci def test_cpuusage_all(self): 3600600bfbSopenharmony_ci command = "hidumper --cpuusage" 3700600bfbSopenharmony_ci # 校验命令行输出 3800600bfbSopenharmony_ci CheckCmd(command, CheckCpuUsageOutput) 3900600bfbSopenharmony_ci # 校验命令行重定向输出 4000600bfbSopenharmony_ci CheckCmdRedirect(command, CheckCpuUsageOutput) 4100600bfbSopenharmony_ci # 校验命令行输出到zip文件 4200600bfbSopenharmony_ci CheckCmdZip(command, CheckCpuUsageOutput) 4300600bfbSopenharmony_ci 4400600bfbSopenharmony_ci @pytest.mark.L0 4500600bfbSopenharmony_ci def test_cpuusage_pid(self): 4600600bfbSopenharmony_ci command = "hidumper --cpuusage 1" 4700600bfbSopenharmony_ci # 校验命令行输出 4800600bfbSopenharmony_ci CheckCmd(command, CheckCpuUsageWithPidOutput) 4900600bfbSopenharmony_ci # 校验命令行重定向输出 5000600bfbSopenharmony_ci CheckCmdRedirect(command, CheckCpuUsageWithPidOutput) 5100600bfbSopenharmony_ci # 校验命令行输出到zip文件 5200600bfbSopenharmony_ci CheckCmdZip(command, CheckCpuUsageWithPidOutput) 5300600bfbSopenharmony_ci 5400600bfbSopenharmony_ci @pytest.mark.L0 5500600bfbSopenharmony_ci def test_cpufreq(self): 5600600bfbSopenharmony_ci command = "hidumper --cpufreq" 5700600bfbSopenharmony_ci # 校验命令行输出 5800600bfbSopenharmony_ci CheckCmd(command, CheckCpufreqOutput) 5900600bfbSopenharmony_ci # 校验命令行重定向输出 6000600bfbSopenharmony_ci CheckCmdRedirect(command, CheckCpufreqOutput) 6100600bfbSopenharmony_ci # 校验命令行输出到zip文件 6200600bfbSopenharmony_ci CheckCmdZip(command, CheckCpufreqOutput)