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 20def CheckSAList(output): 21 ret = "System ability list:" in output 22 return ret 23 24def CheckSAHelp(output): 25 result1 = re.search(r"-+HiviewService-+\n([^\n]+){4,}", output) 26 result2 = re.search(r"-+HiDumperService-+", output, re.DOTALL) 27 ret = all([result1, result2]) 28 return ret 29 30def CheckSAInterface(output): 31 result = re.search(r"-+WindowManagerService-+\n([^\n]+){4,}", output) 32 return result is not None 33 34def CheckHiviewServiceFaultloggerPlugin(output): 35 result1 = re.search(r"-+HiviewService-+\n([^\n]+){4,}", output) 36 result2 = re.search("log", output) 37 ret = all([result1, result2]) 38 return ret 39 40def CheckWindowManagerService(output): 41 result1 = re.search(r"-+WindowManagerService-+\n([^\n]+){4,}", output) 42 result2 = re.search("WindowName", output) 43 ret = all([result1, result2]) 44 return ret 45 46def CheckRsAllInfo(output): 47 result1 = re.search(r"-+RenderService-+\n([^\n]+){4,}", output) 48 result2 = re.search("ScreenInfo", output) 49 ret = all([result1, result2]) 50 return ret 51 52def CheckRsHelp(output): 53 result1 = re.search(r"-+RenderService-+\n([^\n]+){4,}", output) 54 result2 = re.search("Graphic", output) 55 ret = all([result1, result2]) 56 return ret 57 58def CheckWorkSchedule(output): 59 result1 = re.search(r"-+WorkSchedule-+\n([^\n]+){4,}", output) 60 result2 = re.search("Work", output) 61 ret = all([result1, result2]) 62 return ret 63 64def CheckAmsL(output): 65 result1 = re.search(r"-+AbilityManagerService-+\n([^\n]+){4,}", output) 66 result2 = re.search("User", output) 67 ret = all([result1, result2]) 68 return ret 69 70def CheckAmsA(output): 71 result1 = re.search(r"-+AbilityManagerService-+\n([^\n]+){4,}", output) 72 result2 = re.search("AppRunningRecord", output) 73 ret = all([result1, result2]) 74 return ret 75 76def CheckDmsSA(output): 77 result1 = re.search(r"-+DisplayManagerService-+\n([^\n]+){4,}", output) 78 result2 = re.search("Screen", output) 79 ret = all([result1, result2]) 80 return ret 81 82def CheckMultimodalInputW(output): 83 result1 = re.search(r"-+MultimodalInput-+\n([^\n]+){4,}", output) 84 result2 = re.search("Windows", output) 85 ret = all([result1, result2]) 86 return ret 87 88class TestHidumperSA: 89 90 @pytest.mark.L0 91 def test_sa_ls(self): 92 command = "hidumper -ls" 93 # 设置hisysevent相关信息 94 hidumperTmpCmd = "OPT:ls SUB_OPT:" 95 # 校验命令行输出 96 CheckCmd(command, CheckSAList, hidumperTmpCmd) 97 # 校验命令行重定向输出 98 CheckCmdRedirect(command, CheckSAList, None, hidumperTmpCmd) 99 # 校验命令行输出到zip文件 100 CheckCmdZip(command, CheckSAList) 101 102 @pytest.mark.L0 103 def test_sa_help(self): 104 command = "hidumper -s 1201 1212" 105 hidumperTmpCmd = "OPT:s SUB_OPT:" 106 # 校验命令行输出 107 CheckCmd(command, CheckSAHelp, hidumperTmpCmd) 108 # 校验命令行异常值输出输出 109 CheckCmd("hidumper -s 1201 -123", lambda output : "option pid missed." in output, hidumperTmpCmd) 110 111 @pytest.mark.L0 112 def test_sa_interface(self): 113 command = "hidumper -s WindowManagerService -a -h" 114 hidumperTmpCmd = "OPT:s SUB_OPT:a" 115 # 校验命令行输出 116 CheckCmd(command, CheckSAInterface, hidumperTmpCmd) 117 # 校验命令行重定向输出 118 CheckCmdRedirect(command, CheckSAInterface, None, hidumperTmpCmd) 119 # 校验命令行输出到zip文件 120 CheckCmdZip(command, CheckSAInterface) 121 122 @pytest.mark.L0 123 def test_sa_hiview(self): 124 command = "hidumper -s 1201 -a '-p Faultlogger'" 125 hidumperTmpCmd = "OPT:s SUB_OPT:a" 126 # 校验命令行输出 127 CheckCmd(command, CheckHiviewServiceFaultloggerPlugin, hidumperTmpCmd) 128 # 校验命令行重定向输出 129 CheckCmdRedirect(command, CheckHiviewServiceFaultloggerPlugin, None, hidumperTmpCmd) 130 # 校验命令行输出到zip文件 131 CheckCmdZip(command, CheckHiviewServiceFaultloggerPlugin) 132 133 @pytest.mark.L0 134 def test_sa_wms(self): 135 command = "hidumper -s WindowManagerService -a -a" 136 hidumperTmpCmd = "OPT:s SUB_OPT:a" 137 # 校验命令行输出 138 CheckCmd(command, CheckWindowManagerService, hidumperTmpCmd) 139 # 校验命令行重定向输出 140 CheckCmdRedirect(command, CheckWindowManagerService, None, hidumperTmpCmd) 141 # 校验命令行输出到zip文件 142 CheckCmdZip(command, CheckWindowManagerService) 143 # 校验命令行输出 144 hidumperTmpCmd = "OPT:s SUB_OPT:" 145 CheckCmd("hidumper -s WindowManagerService", lambda output : "Usage" in output, hidumperTmpCmd) 146 CheckCmd("hidumper -s 4606", lambda output : "Usage" in output, hidumperTmpCmd) 147 148 @pytest.mark.L0 149 def test_sa_rs_allinfo(self): 150 command = "hidumper -s 10 -a allInfo" 151 hidumperTmpCmd = "OPT:s SUB_OPT:a" 152 # 校验命令行输出 153 CheckCmd(command, CheckRsAllInfo, hidumperTmpCmd) 154 # 校验命令行重定向输出 155 CheckCmdRedirect(command, CheckRsAllInfo, None, hidumperTmpCmd) 156 # 校验命令行输出到zip文件 157 CheckCmdZip(command, CheckRsAllInfo) 158 159 @pytest.mark.L0 160 def test_sa_rs_help(self): 161 command = "hidumper -s 10 -a -h" 162 hidumperTmpCmd = "OPT:s SUB_OPT:a" 163 # 校验命令行输出 164 CheckCmd(command, CheckRsHelp, hidumperTmpCmd) 165 # 校验命令行重定向输出 166 CheckCmdRedirect(command, CheckRsHelp, None, hidumperTmpCmd) 167 # 校验命令行输出到zip文件 168 CheckCmdZip(command, CheckRsHelp) 169 170 @pytest.mark.L0 171 def test_sa_workschedule(self): 172 command = "hidumper -s 1904 -a -a" 173 hidumperTmpCmd = "OPT:s SUB_OPT:a" 174 # 校验命令行输出 175 CheckCmd(command, CheckWorkSchedule, hidumperTmpCmd) 176 # 校验命令行重定向输出 177 CheckCmdRedirect(command, CheckWorkSchedule, None, hidumperTmpCmd) 178 # 校验命令行输出到zip文件 179 CheckCmdZip(command, CheckWorkSchedule) 180 181 @pytest.mark.L0 182 def test_sa_ams_l(self): 183 command = "hidumper -s AbilityManagerService -a -l" 184 hidumperTmpCmd = "OPT:s SUB_OPT:a" 185 # 校验命令行输出 186 CheckCmd(command, CheckAmsL, hidumperTmpCmd) 187 # 校验命令行重定向输出 188 CheckCmdRedirect(command, CheckAmsL, None, hidumperTmpCmd) 189 # 校验命令行输出到zip文件 190 CheckCmdZip(command, CheckAmsL) 191 192 @pytest.mark.L0 193 def test_sa_ams_a(self): 194 command = "hidumper -s AbilityManagerService -a '-a'" 195 hidumperTmpCmd = "OPT:s SUB_OPT:a" 196 # 校验命令行输出 197 CheckCmd(command, CheckAmsA, hidumperTmpCmd) 198 # 校验命令行重定向输出 199 CheckCmdRedirect(command, CheckAmsA, None, hidumperTmpCmd) 200 # 校验命令行输出到zip文件 201 CheckCmdZip(command, CheckAmsA) 202 203 @pytest.mark.L0 204 def test_sa_dms_s_a(self): 205 command = "hidumper -s DisplayManagerService -a '-s -a'" 206 hidumperTmpCmd = "OPT:s SUB_OPT:a" 207 # 校验命令行输出 208 CheckCmd(command, CheckDmsSA, hidumperTmpCmd) 209 # 校验命令行重定向输出 210 CheckCmdRedirect(command, CheckDmsSA, None, hidumperTmpCmd) 211 # 校验命令行输出到zip文件 212 CheckCmdZip(command, CheckDmsSA) 213 214 @pytest.mark.L0 215 def test_sa_multimodalinput_w(self): 216 command = "hidumper -s MultimodalInput -a -w" 217 hidumperTmpCmd = "OPT:s SUB_OPT:a" 218 # 校验命令行输出 219 CheckCmd(command, CheckMultimodalInputW, hidumperTmpCmd) 220 # 校验命令行重定向输出 221 CheckCmdRedirect(command, CheckMultimodalInputW, None, hidumperTmpCmd) 222 # 校验命令行输出到zip文件 223 CheckCmdZip(command, CheckMultimodalInputW) 224 225 @pytest.mark.L0 226 def test_sa(self): 227 command = "hidumper -s" 228 hidumperTmpCmd = "OPT:s SUB_OPT:" 229 # 校验命令行输出 230 CheckCmd(command, lambda output : "HiDumperManagerService" in output, hidumperTmpCmd) 231 232 @pytest.mark.L0 233 def test_sa_error_option(self): 234 command = "hidumper -s abc;hidumper -s -123;hidumper -s 123456789123456789123456789123456789" 235 hidumperTmpCmd = "OPT:s SUB_OPT:" 236 # 校验命令行输出 237 CheckCmd(command, lambda output : "hidumper: invalid arg: abc\nhidumper: option pid missed. 1\nhidumper: invalid arg: 123456789123456789123456789123456789" in output, hidumperTmpCmd) 238 239