1b0e7dd80Sopenharmony_ci#!/usr/bin/env python3
2b0e7dd80Sopenharmony_ci# -*- coding: utf-8 -*-
3b0e7dd80Sopenharmony_ci# Copyright (C) 2024 Huawei Device Co., Ltd.
4b0e7dd80Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
5b0e7dd80Sopenharmony_ci# you may not use this file except in compliance with the License.
6b0e7dd80Sopenharmony_ci# You may obtain a copy of the License at
7b0e7dd80Sopenharmony_ci#
8b0e7dd80Sopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
9b0e7dd80Sopenharmony_ci#
10b0e7dd80Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
11b0e7dd80Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
12b0e7dd80Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13b0e7dd80Sopenharmony_ci# See the License for the specific language governing permissions and
14b0e7dd80Sopenharmony_ci# limitations under the License.
15b0e7dd80Sopenharmony_ci
16b0e7dd80Sopenharmony_ciimport subprocess
17b0e7dd80Sopenharmony_ciimport pytest
18b0e7dd80Sopenharmony_ci
19b0e7dd80Sopenharmony_ci
20b0e7dd80Sopenharmony_cidef get_shell_result(cmd, words=''):
21b0e7dd80Sopenharmony_ci    print(f"\nexecuting command: {cmd}")
22b0e7dd80Sopenharmony_ci    output = subprocess.check_output(cmd.split()).decode()
23b0e7dd80Sopenharmony_ci    print(f"\noutput: {output}")
24b0e7dd80Sopenharmony_ci    if len(words) > 0:
25b0e7dd80Sopenharmony_ci        assert words in output
26b0e7dd80Sopenharmony_ci
27b0e7dd80Sopenharmony_ci
28b0e7dd80Sopenharmony_ciclass TestHitraceCmd:
29b0e7dd80Sopenharmony_ci    def prepare_steps(self):
30b0e7dd80Sopenharmony_ci        word_cmds = {
31b0e7dd80Sopenharmony_ci            "hdc shell hitrace --stop_bgsrv",
32b0e7dd80Sopenharmony_ci            "hdc shell hitrace --trace_finish_nodump",
33b0e7dd80Sopenharmony_ci            "hdc shell hitrace --trace_finish_nodump --record",
34b0e7dd80Sopenharmony_ci        }
35b0e7dd80Sopenharmony_ci
36b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds:
37b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd)
38b0e7dd80Sopenharmony_ci
39b0e7dd80Sopenharmony_ci    @pytest.mark.L0
40b0e7dd80Sopenharmony_ci    def test_help1(self):
41b0e7dd80Sopenharmony_ci        word_cmds = {
42b0e7dd80Sopenharmony_ci            'hdc shell hitrace -h -b 2048':'running_state is SHOW_HELP',
43b0e7dd80Sopenharmony_ci            'hdc shell hitrace -b 2048 -h':'running_state is SHOW_HELP',
44b0e7dd80Sopenharmony_ci            'hdc shell hitrace -h -b':'error: parsing args failed',
45b0e7dd80Sopenharmony_ci            'hdc shell hitrace -b -h': 'error: buffer size is illegal input.'
46b0e7dd80Sopenharmony_ci        }
47b0e7dd80Sopenharmony_ci
48b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds:
49b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds.get(word_cmd))
50b0e7dd80Sopenharmony_ci
51b0e7dd80Sopenharmony_ci    @pytest.mark.L0
52b0e7dd80Sopenharmony_ci    def test_help2(self):
53b0e7dd80Sopenharmony_ci        word_cmds = {
54b0e7dd80Sopenharmony_ci            'hdc shell hitrace -h --trace_begin': 'cannot coexist.',
55b0e7dd80Sopenharmony_ci            'hdc shell hitrace --trace_begin app -h': 'cannot coexist.'
56b0e7dd80Sopenharmony_ci        }
57b0e7dd80Sopenharmony_ci
58b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds:
59b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds.get(word_cmd))
60b0e7dd80Sopenharmony_ci
61b0e7dd80Sopenharmony_ci    @pytest.mark.L0
62b0e7dd80Sopenharmony_ci    def test_list1(self):
63b0e7dd80Sopenharmony_ci        word_cmds = {
64b0e7dd80Sopenharmony_ci            'hdc shell hitrace -l':'running_state is SHOW_LIST_CATEGORY',
65b0e7dd80Sopenharmony_ci        }
66b0e7dd80Sopenharmony_ci
67b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds:
68b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds.get(word_cmd))
69b0e7dd80Sopenharmony_ci
70b0e7dd80Sopenharmony_ci    @pytest.mark.L0
71b0e7dd80Sopenharmony_ci    def test_list2(self):
72b0e7dd80Sopenharmony_ci        word_cmds = {
73b0e7dd80Sopenharmony_ci            'hdc shell hitrace -b 102400 -l':'running_state is SHOW_LIST_CATEGORY',
74b0e7dd80Sopenharmony_ci            'hdc shell hitrace app -l':'running_state is SHOW_LIST_CATEGORY',
75b0e7dd80Sopenharmony_ci            'hdc shell hitrace --trace_begin -l': 'cannot coexist.',
76b0e7dd80Sopenharmony_ci        }
77b0e7dd80Sopenharmony_ci
78b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds:
79b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds.get(word_cmd))
80b0e7dd80Sopenharmony_ci
81b0e7dd80Sopenharmony_ci    @pytest.mark.L0
82b0e7dd80Sopenharmony_ci    def test_unsupported_tag(self):
83b0e7dd80Sopenharmony_ci        word_cmds = {
84b0e7dd80Sopenharmony_ci            'hdc shell hitrace --trace_begin appoo': 'error: appoo is not support category on this device.',
85b0e7dd80Sopenharmony_ci        }
86b0e7dd80Sopenharmony_ci
87b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds:
88b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds.get(word_cmd))
89b0e7dd80Sopenharmony_ci
90b0e7dd80Sopenharmony_ci    @pytest.mark.L0
91b0e7dd80Sopenharmony_ci    def test_capture_trace(self):
92b0e7dd80Sopenharmony_ci        word_cmds1 = {
93b0e7dd80Sopenharmony_ci            'hdc shell hitrace -b 256 -t 5 sched --trace_begin':'hitrace enter, running_state is RECORDING_LONG_BEGIN',
94b0e7dd80Sopenharmony_ci            'hdc shell cat /sys/kernel/debug/tracing/tracing_on':'1',
95b0e7dd80Sopenharmony_ci        }
96b0e7dd80Sopenharmony_ci
97b0e7dd80Sopenharmony_ci        word_cmds2 = {
98b0e7dd80Sopenharmony_ci            "hdc shell hitrace --trace_finish_nodump",
99b0e7dd80Sopenharmony_ci        }
100b0e7dd80Sopenharmony_ci
101b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds1:
102b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds1.get(word_cmd))
103b0e7dd80Sopenharmony_ci
104b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds2:
105b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd)
106b0e7dd80Sopenharmony_ci
107b0e7dd80Sopenharmony_ci    @pytest.mark.L0
108b0e7dd80Sopenharmony_ci    def test_double_capture_trace(self):
109b0e7dd80Sopenharmony_ci        word_cmds1 = {
110b0e7dd80Sopenharmony_ci            'hdc shell hitrace -b 256 -t 5 sched --trace_begin': 'hitrace enter, running_state is RECORDING_LONG_BEGIN',
111b0e7dd80Sopenharmony_ci        }
112b0e7dd80Sopenharmony_ci
113b0e7dd80Sopenharmony_ci        word_cmds2 = {
114b0e7dd80Sopenharmony_ci            'hdc shell hitrace -b 256 -t 5 sched --trace_begin': 'error: OpenRecording failed, errorCode(1002)',
115b0e7dd80Sopenharmony_ci        }
116b0e7dd80Sopenharmony_ci
117b0e7dd80Sopenharmony_ci        word_cmds3 = {
118b0e7dd80Sopenharmony_ci            'hdc shell hitrace --trace_finish_nodump',
119b0e7dd80Sopenharmony_ci        }
120b0e7dd80Sopenharmony_ci
121b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds1:
122b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds1.get(word_cmd))
123b0e7dd80Sopenharmony_ci
124b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds2:
125b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds2.get(word_cmd))
126b0e7dd80Sopenharmony_ci
127b0e7dd80Sopenharmony_ci        for cmd in word_cmds3:
128b0e7dd80Sopenharmony_ci            get_shell_result(cmd)
129b0e7dd80Sopenharmony_ci
130b0e7dd80Sopenharmony_ci    @pytest.mark.L0
131b0e7dd80Sopenharmony_ci    def test_capture_tags_trace(self):
132b0e7dd80Sopenharmony_ci        word_cmds1 = {
133b0e7dd80Sopenharmony_ci            'hdc shell hitrace ability accesscontrol accessibility account ace animation sched --trace_begin':'hitrace enter, running_state is RECORDING_LONG_BEGIN',
134b0e7dd80Sopenharmony_ci        }
135b0e7dd80Sopenharmony_ci
136b0e7dd80Sopenharmony_ci        word_cmds2 = {
137b0e7dd80Sopenharmony_ci            'hdc shell cat /sys/kernel/debug/tracing/tracing_on':'1',
138b0e7dd80Sopenharmony_ci        }
139b0e7dd80Sopenharmony_ci
140b0e7dd80Sopenharmony_ci        word_cmds3 = {
141b0e7dd80Sopenharmony_ci            'hdc shell hitrace --trace_dump -o /data/local/tmp/trace.ftrace': 'trace read done',
142b0e7dd80Sopenharmony_ci        }
143b0e7dd80Sopenharmony_ci
144b0e7dd80Sopenharmony_ci        word_cmds4 = [
145b0e7dd80Sopenharmony_ci            "hdc shell hitrace --trace_finish_nodump",
146b0e7dd80Sopenharmony_ci        ]
147b0e7dd80Sopenharmony_ci
148b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds1:
149b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds1.get(word_cmd))
150b0e7dd80Sopenharmony_ci
151b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds2:
152b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds2.get(word_cmd))
153b0e7dd80Sopenharmony_ci
154b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds3:
155b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds3.get(word_cmd))
156b0e7dd80Sopenharmony_ci
157b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds4:
158b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd)
159b0e7dd80Sopenharmony_ci
160b0e7dd80Sopenharmony_ci    @pytest.mark.L0
161b0e7dd80Sopenharmony_ci    def test_capture_trace_with_overwrite_and_traceclock(self):
162b0e7dd80Sopenharmony_ci        word_cmds1 = {
163b0e7dd80Sopenharmony_ci            'hdc shell hitrace sched --trace_begin --overwrite --trace_clock boot': 'clockType:boot overwrite:0',
164b0e7dd80Sopenharmony_ci        }
165b0e7dd80Sopenharmony_ci
166b0e7dd80Sopenharmony_ci        word_cmds2 = {
167b0e7dd80Sopenharmony_ci            'hdc shell hitrace --trace_dump -o /data/local/tmp/trace.ftrace': 'trace read done, output: /data/local/tmp/trace.ftrace',
168b0e7dd80Sopenharmony_ci        }
169b0e7dd80Sopenharmony_ci
170b0e7dd80Sopenharmony_ci        word_cmds3 = {
171b0e7dd80Sopenharmony_ci            'hdc shell cat /sys/kernel/debug/tracing/tracing_on': '1',
172b0e7dd80Sopenharmony_ci        }
173b0e7dd80Sopenharmony_ci
174b0e7dd80Sopenharmony_ci        word_cmds4 = [
175b0e7dd80Sopenharmony_ci            "hdc shell hitrace --trace_finish_nodump",
176b0e7dd80Sopenharmony_ci        ]
177b0e7dd80Sopenharmony_ci
178b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds1:
179b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds1.get(word_cmd))
180b0e7dd80Sopenharmony_ci
181b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds2:
182b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds2.get(word_cmd))
183b0e7dd80Sopenharmony_ci
184b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds3:
185b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds3.get(word_cmd))
186b0e7dd80Sopenharmony_ci
187b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds4:
188b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd)
189b0e7dd80Sopenharmony_ci
190b0e7dd80Sopenharmony_ci    @pytest.mark.L0
191b0e7dd80Sopenharmony_ci    def test_raw_parameter(self):
192b0e7dd80Sopenharmony_ci        word_cmds = {
193b0e7dd80Sopenharmony_ci            'hdc shell hitrace sched --trace_begin --raw': 'RECORDING_LONG_BEGIN and RECORDING_SHORT_RAW cannot coexist',
194b0e7dd80Sopenharmony_ci            'hdc shell cat /sys/kernel/debug/tracing/tracing_on': '0',
195b0e7dd80Sopenharmony_ci            'hdc shell hitrace sched --trace_begin --record --raw': 'RECORDING_LONG_BEGIN_RECORD and RECORDING_SHORT_RAW cannot coexist',
196b0e7dd80Sopenharmony_ci            'hdc shell cat /sys/kernel/debug/tracing/tracing_on': '0',
197b0e7dd80Sopenharmony_ci            'hdc shell hitrace sched -t 10 --raw': 'hitrace enter, running_state is RECORDING_SHORT_RAW',
198b0e7dd80Sopenharmony_ci        }
199b0e7dd80Sopenharmony_ci
200b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds:
201b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds.get(word_cmd))
202b0e7dd80Sopenharmony_ci
203b0e7dd80Sopenharmony_ci    @pytest.mark.L0
204b0e7dd80Sopenharmony_ci    def test_text_parameter(self):
205b0e7dd80Sopenharmony_ci        word_cmds = {
206b0e7dd80Sopenharmony_ci            'hdc shell hitrace sched --trace_begin --text': 'RECORDING_LONG_BEGIN and RECORDING_SHORT_TEXT cannot coexist',
207b0e7dd80Sopenharmony_ci            'hdc shell cat /sys/kernel/debug/tracing/tracing_on': '0',
208b0e7dd80Sopenharmony_ci            'hdc shell hitrace sched --trace_begin --record --text': 'RECORDING_LONG_BEGIN_RECORD and RECORDING_SHORT_TEXT cannot coexist',
209b0e7dd80Sopenharmony_ci            'hdc shell cat /sys/kernel/debug/tracing/tracing_on': '0',
210b0e7dd80Sopenharmony_ci            'hdc shell hitrace sched -t 10 --text': 'start capture, please wait 10s',
211b0e7dd80Sopenharmony_ci        }
212b0e7dd80Sopenharmony_ci
213b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds:
214b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds.get(word_cmd))
215b0e7dd80Sopenharmony_ci
216b0e7dd80Sopenharmony_ci    @pytest.mark.L0
217b0e7dd80Sopenharmony_ci    def test_capture_trace_with_filesize_and_filename(self):
218b0e7dd80Sopenharmony_ci        word_cmds1 = {
219b0e7dd80Sopenharmony_ci            'hdc shell hitrace sched --trace_begin --file_size 51200': 'The current state does not support specifying the file size',
220b0e7dd80Sopenharmony_ci            'hdc shell cat /sys/kernel/debug/tracing/tracing_on': '1',
221b0e7dd80Sopenharmony_ci            'hdc shell hitrace sched --trace_dump -o /data/local/tmp/trace.ftrace': 'trace read done, output: /data/local/tmp/trace.ftrace',
222b0e7dd80Sopenharmony_ci        }
223b0e7dd80Sopenharmony_ci
224b0e7dd80Sopenharmony_ci        word_cmds2 = [
225b0e7dd80Sopenharmony_ci            "hdc shell hitrace sched --trace_finish_nodump",
226b0e7dd80Sopenharmony_ci        ]
227b0e7dd80Sopenharmony_ci
228b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds1:
229b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds1.get(word_cmd))
230b0e7dd80Sopenharmony_ci
231b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds2:
232b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd)
233b0e7dd80Sopenharmony_ci
234b0e7dd80Sopenharmony_ci    @pytest.mark.L0
235b0e7dd80Sopenharmony_ci    def test_capture_trace_record_with_filesize_and_filename(self):
236b0e7dd80Sopenharmony_ci        word_cmds1 = {
237b0e7dd80Sopenharmony_ci            'hdc shell hitrace sched --trace_begin --record --file_size 51200': 'tags:sched bufferSize:18432 overwrite:1 fileSize:51200',
238b0e7dd80Sopenharmony_ci            'hdc shell cat /sys/kernel/debug/tracing/tracing_on': '1',
239b0e7dd80Sopenharmony_ci            'hdc shell hitrace --trace_dump --record -o /data/local/tmp/trace.ftrace': 'error: "--record" is set incorrectly. eg: "--trace_begin --record", "--trace_finish --record"',
240b0e7dd80Sopenharmony_ci        }
241b0e7dd80Sopenharmony_ci
242b0e7dd80Sopenharmony_ci        word_cmds2 = [
243b0e7dd80Sopenharmony_ci            "hdc shell hitrace --trace_finish_nodump --record",
244b0e7dd80Sopenharmony_ci        ]
245b0e7dd80Sopenharmony_ci
246b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds1:
247b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds1.get(word_cmd))
248b0e7dd80Sopenharmony_ci
249b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds2:
250b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd)
251b0e7dd80Sopenharmony_ci
252b0e7dd80Sopenharmony_ci    @pytest.mark.L0
253b0e7dd80Sopenharmony_ci    def test_capture_trace_with_buffersize_time_trackclock_and_overwrite(self):
254b0e7dd80Sopenharmony_ci        word_cmds1 = {
255b0e7dd80Sopenharmony_ci            'hdc shell hitrace sched --trace_begin -b 10240 -t 5 --trace_clock global --overwrite': 'tags:sched bufferSize:10240 clockType:global overwrite:0',
256b0e7dd80Sopenharmony_ci            'hdc shell cat /sys/kernel/debug/tracing/tracing_on': '1',
257b0e7dd80Sopenharmony_ci            'hdc shell hitrace --trace_dump -o /data/local/tmp/trace.ftrace': 'trace read done, output: /data/local/tmp/trace.ftrace',
258b0e7dd80Sopenharmony_ci        }
259b0e7dd80Sopenharmony_ci
260b0e7dd80Sopenharmony_ci        word_cmds2 = [
261b0e7dd80Sopenharmony_ci            "hdc shell hitrace --trace_finish_nodump",
262b0e7dd80Sopenharmony_ci        ]
263b0e7dd80Sopenharmony_ci
264b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds1:
265b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds1.get(word_cmd))
266b0e7dd80Sopenharmony_ci
267b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds2:
268b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd)
269b0e7dd80Sopenharmony_ci
270b0e7dd80Sopenharmony_ci    @pytest.mark.L0
271b0e7dd80Sopenharmony_ci    def test_capture_trace_with_wrong_time(self):
272b0e7dd80Sopenharmony_ci        word_cmds = {
273b0e7dd80Sopenharmony_ci            'hdc shell hitrace sched --trace_begin -b 10240 -t -1 --trace_clock global --overwrite': 'error: "-t -1" to be greater than zero. eg: "--time 5"',
274b0e7dd80Sopenharmony_ci            'hdc shell cat /sys/kernel/debug/tracing/tracing_on': '0',
275b0e7dd80Sopenharmony_ci        }
276b0e7dd80Sopenharmony_ci
277b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds:
278b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds.get(word_cmd))
279b0e7dd80Sopenharmony_ci
280b0e7dd80Sopenharmony_ci    @pytest.mark.L0
281b0e7dd80Sopenharmony_ci    def test_capture_trace_with_wrong_buffersize(self):
282b0e7dd80Sopenharmony_ci        word_cmds = {
283b0e7dd80Sopenharmony_ci            'hdc shell hitrace sched --trace_begin -b -10240 -t 5 --trace_clock global --overwrite': 'error: buffer size must be from 256 KB to 300 MB. eg: "--buffer_size 18432"',
284b0e7dd80Sopenharmony_ci            'hdc shell cat /sys/kernel/debug/tracing/tracing_on': '0',
285b0e7dd80Sopenharmony_ci        }
286b0e7dd80Sopenharmony_ci
287b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds:
288b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds.get(word_cmd))
289b0e7dd80Sopenharmony_ci
290b0e7dd80Sopenharmony_ci    @pytest.mark.L0
291b0e7dd80Sopenharmony_ci    def test_capture_trace_with_max_and_min_buffersize(self):
292b0e7dd80Sopenharmony_ci        word_cmds1 = {
293b0e7dd80Sopenharmony_ci            'hdc shell hitrace sched --trace_begin -b 307200': 'hitrace enter, running_state is RECORDING_LONG_BEGIN',
294b0e7dd80Sopenharmony_ci            'hdc shell cat /sys/kernel/debug/tracing/tracing_on': '1',
295b0e7dd80Sopenharmony_ci        }
296b0e7dd80Sopenharmony_ci
297b0e7dd80Sopenharmony_ci        word_cmds2 = [
298b0e7dd80Sopenharmony_ci            "hdc shell hitrace --trace_finish_nodump",
299b0e7dd80Sopenharmony_ci        ]
300b0e7dd80Sopenharmony_ci
301b0e7dd80Sopenharmony_ci        word_cmds4 = {
302b0e7dd80Sopenharmony_ci            'hdc shell hitrace sched --trace_begin -b 256': 'hitrace enter, running_state is RECORDING_LONG_BEGIN',
303b0e7dd80Sopenharmony_ci            'hdc shell cat /sys/kernel/debug/tracing/tracing_on': '1',
304b0e7dd80Sopenharmony_ci        }
305b0e7dd80Sopenharmony_ci
306b0e7dd80Sopenharmony_ci        word_cmds5 = [
307b0e7dd80Sopenharmony_ci            "hdc shell hitrace --trace_finish_nodump",
308b0e7dd80Sopenharmony_ci        ]
309b0e7dd80Sopenharmony_ci
310b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds1:
311b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds1.get(word_cmd))
312b0e7dd80Sopenharmony_ci
313b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds2:
314b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd)
315b0e7dd80Sopenharmony_ci
316b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds4:
317b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds4.get(word_cmd))
318b0e7dd80Sopenharmony_ci
319b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds5:
320b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd)
321b0e7dd80Sopenharmony_ci
322b0e7dd80Sopenharmony_ci    @pytest.mark.L0
323b0e7dd80Sopenharmony_ci    def test_wrong_command(self):
324b0e7dd80Sopenharmony_ci        word_cmds1 = {
325b0e7dd80Sopenharmony_ci            'hdc shell hitrace sched --trace_begin --trace_finish': 'the parameter is set incorrectly',
326b0e7dd80Sopenharmony_ci            'hdc shell cat /sys/kernel/debug/tracing/tracing_on': '0',
327b0e7dd80Sopenharmony_ci        }
328b0e7dd80Sopenharmony_ci
329b0e7dd80Sopenharmony_ci        word_cmds2 = {
330b0e7dd80Sopenharmony_ci            'hdc shell hitrace sched --trace_begin --trace_dump': 'the parameter is set incorrectly',
331b0e7dd80Sopenharmony_ci            'hdc shell cat /sys/kernel/debug/tracing/tracing_on': '0',
332b0e7dd80Sopenharmony_ci        }
333b0e7dd80Sopenharmony_ci
334b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds1:
335b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds1.get(word_cmd))
336b0e7dd80Sopenharmony_ci
337b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds2:
338b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds2.get(word_cmd))
339b0e7dd80Sopenharmony_ci
340b0e7dd80Sopenharmony_ci    @pytest.mark.L0
341b0e7dd80Sopenharmony_ci    def test_start_and_stop_bgsrv(self):
342b0e7dd80Sopenharmony_ci        word_cmds1 = {
343b0e7dd80Sopenharmony_ci            'hdc shell hitrace --start_bgsrv': 'hitrace enter, running_state is SNAPSHOT_START',
344b0e7dd80Sopenharmony_ci            'hdc shell cat /sys/kernel/debug/tracing/tracing_on': '1',
345b0e7dd80Sopenharmony_ci            'hdc shell hitrace --stop_bgsrv': 'hitrace enter, running_state is SNAPSHOT_STOP',
346b0e7dd80Sopenharmony_ci        }
347b0e7dd80Sopenharmony_ci
348b0e7dd80Sopenharmony_ci        word_cmds2 = {
349b0e7dd80Sopenharmony_ci            'hdc shell cat /sys/kernel/debug/tracing/tracing_on': '0',
350b0e7dd80Sopenharmony_ci        }
351b0e7dd80Sopenharmony_ci
352b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds1:
353b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds1.get(word_cmd))
354b0e7dd80Sopenharmony_ci
355b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds2:
356b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds2.get(word_cmd))
357b0e7dd80Sopenharmony_ci
358b0e7dd80Sopenharmony_ci    @pytest.mark.L0
359b0e7dd80Sopenharmony_ci    def test_snapshot_with_wrong_command(self):
360b0e7dd80Sopenharmony_ci        word_cmds1 = {
361b0e7dd80Sopenharmony_ci            'hdc shell hitrace --start_bgsrv': 'hitrace enter, running_state is SNAPSHOT_START',
362b0e7dd80Sopenharmony_ci            'hdc shell cat /sys/kernel/debug/tracing/tracing_on': '1',
363b0e7dd80Sopenharmony_ci        }
364b0e7dd80Sopenharmony_ci
365b0e7dd80Sopenharmony_ci        word_cmds2 = {
366b0e7dd80Sopenharmony_ci            'hdc shell hitrace --start_bgsrv': 'error: OpenSnapshot failed, errorCode(1006)',
367b0e7dd80Sopenharmony_ci            'hdc shell cat /sys/kernel/debug/tracing/tracing_on': '1',
368b0e7dd80Sopenharmony_ci        }
369b0e7dd80Sopenharmony_ci
370b0e7dd80Sopenharmony_ci        word_cmds3 = {
371b0e7dd80Sopenharmony_ci            'hdc shell hitrace --stop_bgsrv': 'hitrace enter, running_state is SNAPSHOT_STOP',
372b0e7dd80Sopenharmony_ci            'hdc shell cat /sys/kernel/debug/tracing/tracing_on': '0',
373b0e7dd80Sopenharmony_ci        }
374b0e7dd80Sopenharmony_ci
375b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds1:
376b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds1.get(word_cmd))
377b0e7dd80Sopenharmony_ci
378b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds2:
379b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds2.get(word_cmd))
380b0e7dd80Sopenharmony_ci
381b0e7dd80Sopenharmony_ci        for word_cmd in word_cmds3:
382b0e7dd80Sopenharmony_ci            get_shell_result(word_cmd, word_cmds3.get(word_cmd))
383b0e7dd80Sopenharmony_ci
384b0e7dd80Sopenharmony_ci
385