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        CheckCmd(command, CheckIpcStat)
38        CheckCmdRedirect(command, CheckIpcStat)
39
40        output = subprocess.check_output(f"hdc shell hidumper --ipc {pid} --stop-stat", shell=True, text=True, encoding="utf-8")
41        assert "success" in output
42