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 subprocess 1800600bfbSopenharmony_ciimport re 1900600bfbSopenharmony_cifrom utils import * 2000600bfbSopenharmony_ci 2100600bfbSopenharmony_ciOUTPUT_PATH = "testModule/output" 2200600bfbSopenharmony_ciLIB_PATH = "/system/lib" 2300600bfbSopenharmony_ciROM_BASE_SIZE = 1363 2400600bfbSopenharmony_ciRAM_LIMIT_SIZE = 20 * 1024 2500600bfbSopenharmony_ci 2600600bfbSopenharmony_cidef CheckRom(output): 2700600bfbSopenharmony_ci result = re.findall("(/d+)K", output) 2800600bfbSopenharmony_ci return sum(int(x) for x in result) <= ROM_BASE_SIZE 2900600bfbSopenharmony_ci 3000600bfbSopenharmony_cidef CheckRam(output): 3100600bfbSopenharmony_ci result = re.findall("\s*Total\s*(\d+)\s*", output)[0] 3200600bfbSopenharmony_ci return int(result) <= RAM_LIMIT_SIZE 3300600bfbSopenharmony_ci 3400600bfbSopenharmony_ciclass TestHidumperPerformance: 3500600bfbSopenharmony_ci 3600600bfbSopenharmony_ci @pytest.mark.L0 3700600bfbSopenharmony_ci def test_rom(self): 3800600bfbSopenharmony_ci # 校验命令行输出 3900600bfbSopenharmony_ci output = subprocess.check_output(f"hdc shell ls -lh /system/lib/libhidumper*", shell=True, text=True, encoding="utf-8") 4000600bfbSopenharmony_ci assert CheckRom(output) 4100600bfbSopenharmony_ci 4200600bfbSopenharmony_ci @pytest.mark.L0 4300600bfbSopenharmony_ci def test_ram(self): 4400600bfbSopenharmony_ci # 校验命令行输出 4500600bfbSopenharmony_ci subprocess.check_call(f"hdc shell hidumper --mem 1", shell=True, text=True, encoding="utf-8") 4600600bfbSopenharmony_ci output = subprocess.check_output(f"hdc shell hidumper --mem `pidof hidumper_service`", shell=True, text=True, encoding="utf-8") 4700600bfbSopenharmony_ci assert CheckRam(output) 4800600bfbSopenharmony_ci 4900600bfbSopenharmony_ci @pytest.mark.L0 5000600bfbSopenharmony_ci def test_file_tag(self): 5100600bfbSopenharmony_ci # 校验命令行输出 5200600bfbSopenharmony_ci output = subprocess.check_output(f"hdc shell \"ls -Z /system/bin | grep hidumper\"", shell=True, text=True, encoding="utf-8") 5300600bfbSopenharmony_ci assert "u:object_r:hidumper_exec:s0" in output 5400600bfbSopenharmony_ci 5500600bfbSopenharmony_ci @pytest.mark.L0 5600600bfbSopenharmony_ci def test_process_tag(self): 5700600bfbSopenharmony_ci # 校验命令行输出 5800600bfbSopenharmony_ci subprocess.check_call(f"hdc shell hidumper --mem 1", shell=True, text=True, encoding="utf-8") 5900600bfbSopenharmony_ci output = subprocess.check_output(f"hdc shell \"ps -eZ | grep hidumper\"", shell=True, text=True, encoding="utf-8") 6000600bfbSopenharmony_ci assert "u:r:hidumper_service:s0" in output 6100600bfbSopenharmony_ci 62