• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 subprocess
17import re
18from utils import *
19
20def CheckIpcStat(output):
21    result = re.search("CurrentPid:\d+\nTotalCount:\d+\nTotalTimeCost:\d+", output)
22    return result is not None
23
24def CheckIpcStartAll(output):
25    pass
26
27class TestHidumperIpc:
28
29    @pytest.mark.L0
30    def test_ipc_stat(self):
31        # 校验命令行输出
32        pid = GetPidByProcessName("samgr")
33        output = subprocess.check_output(f"hdc shell hidumper --ipc {pid} --start-stat", shell=True, text=True, encoding="utf-8")
34        assert "success" in output
35
36        command = f"hidumper --ipc {pid} --stat"
37        hidumperTmpCmd = "OPT:ipc SUB_OPT:stat"
38        CheckCmd(command, CheckIpcStat, hidumperTmpCmd)
39        CheckCmdRedirect(command, CheckIpcStat, None, hidumperTmpCmd)
40
41        output = subprocess.check_output(f"hdc shell hidumper --ipc {pid} --stop-stat", shell=True, text=True, encoding="utf-8")
42        assert "success" in output
43
44    @pytest.mark.L3
45    def test_ipc_error_pid(self):
46        command = f"hidumper --ipc 2147483647 --stat;hidumper --ipc -2147483647 --stat"
47        hidumperTmpCmd = "OPT:ipc SUB_OPT:stat"
48        # 校验命令行输出
49        CheckCmd(command, lambda output : "hidumper: No such process: 2147483647\nhidumper: option pid missed. 2" in output, hidumperTmpCmd)
50        command = f"hidumper --ipc 2147483648 --stat;hidumper --mem -2147483648 --stat"
51        CheckCmd(command, lambda output : "hidumper: option pid missed. 2" in output, hidumperTmpCmd)
52