• 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.
15
16import pytest
17import subprocess
18import re
19import time
20import sys
21sys.path.append("..")
22from tools.utils import *
23import threading
24import sqlite3
25import datetime
26import os
27import stat
28from hypium import UiDriver, BY
29uiconn = UiDriver.connect()
30uiconn.find_component(BY.text("11"))
31
32DESTROY_SIZE = 41943040
33EXIST_SIZE = 40960
34SLEEP_TWO = 2
35SLEEP_FOUR = 4
36SLEEP_FIVE = 5
37SLEEP_TWENTY = 20
38SYMBOL_INDEX = 4
39APPLY_INDEX = 8
40RELEASE_INDEX = 9
41ALLOC_INDEX = 10
42TYPE_INDEX = 4
43FILE_SIZE_INDEX = 4
44MALLOC_TIMES = 10
45ADDR_INDEX = 9
46FILTER_THRESH = 5000
47DEPTH_FIVE = 5
48DEPTH_TEN = 10
49DEPTH_FIFTEEN = 15
50DEPTH_TWENTY = 20
51DEPTH_THIRTY = 30
52DEPTH_FIFTY = 50
53CALLSTACKID_INDEX = 4
54IPID_INDEX = 2
55PID_INDEX = 2
56MALLOC_THRESH = 1000
57SA_CLICK_TIMES = 67
58SA_WAIT_TIMES = 7
59SA_STATISTICS = 300
60SA_SAMPLE = 512
61SAMPLE_SMALL = 512
62SAMPLE_LARGE = 51200
63FILTER_SMALL = 256
64FILTER_LARGE = 10000
65CLICK_TWICE = 2
66CLICK_THREETIMES = 3
67STATISTICS_INTERVAL = 10
68MATCH_INTERVAL = 10
69
70
71def task_template(extend=False):
72    if extend:
73        subprocess.check_output("hdc shell hiprofiler_cmd -c /data/local/tmp/config.txt -o /data/local/tmp/test.htrace -t 50 -s -k")
74    else:
75        subprocess.check_output("hdc shell hiprofiler_cmd -c /data/local/tmp/config.txt -o /data/local/tmp/test.htrace -t 30 -s -k")
76
77
78def task_multiple_template(extend=False):
79    if extend:
80        subprocess.check_output("hdc shell hiprofiler_cmd -c /data/local/tmp/config_multipleprocess.txt -o /data/local/tmp/test.htrace -t 50 -s -k")
81    else:
82        subprocess.check_output("hdc shell hiprofiler_cmd -c /data/local/tmp/config_multipleprocess.txt -o /data/local/tmp/test.htrace -t 30 -s -k")
83
84
85def get_target_stack(result):
86    malloc_release_stack = [0, 0]
87    small_malloc_stack = [0, 0]
88    for row in result:
89        if 'Add(napi_env__*, napi_callback_info__*)' in row[1]:
90            small_malloc_stack[0] = row[0]
91            malloc_release_stack[0] = row[0]
92        if 'js_depth_released6' in row[1]:
93            malloc_release_stack[1] = row[0]
94        if 'js_depth_small7' in row[1]:
95            small_malloc_stack[1] = row[0]
96    return malloc_release_stack, small_malloc_stack
97
98
99def check_library_result(statistics, startup, offline, sample_interval, dwarf, filtersize, depth, touchtimes, malloc_match_interval):
100    conn = sqlite3.connect(r'./../outputfiles/nativehook.db')
101    cursor = conn.cursor()
102    cursor.execute('SELECT * FROM data_dict')
103    result = cursor.fetchall()
104    callstack_destroyed = []
105    callstack_exists = []
106    symbol_destroy = 0
107    symbol_exist = 0
108    for row in result:
109        if "createAndReleaseHeap" in row[1]:
110            symbol_destroy = row[0]
111        if "createMemory" in row[1]:
112            symbol_exist = row[0]
113
114    cursor.execute('SELECT * FROM native_hook_frame')
115    result = cursor.fetchall()
116    for row in result:
117        if row[SYMBOL_INDEX] == symbol_destroy:
118            callstack_destroyed.append(row[1])
119        if row[SYMBOL_INDEX] == symbol_exist:
120            callstack_exists.append(row[1])
121    check_destroyed = False
122    check_exists = False
123    if statistics > 0:
124        cursor.execute('SELECT * FROM native_hook_statistic')
125        result = cursor.fetchall()
126        if touchtimes != 0:
127            for row in result:
128                for callstackid in callstack_destroyed:
129                    if row[1] == callstackid:
130                        if row[APPLY_INDEX] == DESTROY_SIZE * touchtimes and row[RELEASE_INDEX] == DESTROY_SIZE * touchtimes:
131                            check_destroyed = True
132                for callstackid in callstack_exists:
133                    if row[1] == callstackid:
134                        if row[APPLY_INDEX] == EXIST_SIZE * touchtimes and row[RELEASE_INDEX] == 0:
135                            check_exists = True
136        else:
137            for row in result:
138                for callstackid in callstack_destroyed:
139                    if row[1] == callstackid:
140                        if (row[APPLY_INDEX] % DESTROY_SIZE == 0) and row[RELEASE_INDEX] == row[APPLY_INDEX]:
141                            check_destroyed = True
142                            check_exists = True
143    else:
144        cursor.execute('SELECT * FROM native_hook')
145        result = cursor.fetchall()
146        times_destroyed = 0
147        times_exists = 0
148        malloc_addrs = []
149        for row in result:
150            for callstackid in callstack_destroyed:
151                if row[1] == callstackid and row[ALLOC_INDEX] == (DESTROY_SIZE / MALLOC_TIMES) and row[TYPE_INDEX] == "AllocEvent":
152                    times_destroyed += 1
153                    malloc_addrs.append(row[ADDR_INDEX])
154            for callstackid in callstack_exists:
155                if row[1] == callstackid and row[ALLOC_INDEX] == (EXIST_SIZE / MALLOC_TIMES) and row[TYPE_INDEX] == "AllocEvent":
156                    times_exists += 1
157        if malloc_match_interval != 0:
158            if times_destroyed != 0:
159                return False
160        elif times_destroyed != (touchtimes * MALLOC_TIMES):
161            return False
162        for row in result:
163            if row[ADDR_INDEX] in malloc_addrs and row[ALLOC_INDEX] == (DESTROY_SIZE / MALLOC_TIMES) and row[TYPE_INDEX] == "FreeEvent":
164                times_destroyed -= 1
165                malloc_addrs.remove(row[ADDR_INDEX])
166
167        check_destroyed = (times_destroyed == 0)
168        check_exists = (times_exists == (touchtimes * MALLOC_TIMES))
169    if (sample_interval > FILTER_THRESH) or (filtersize > FILTER_THRESH):
170        check_exists = True
171    if malloc_match_interval > 0:
172        check_destroyed = True
173    cursor.close()
174    conn.close()
175    return check_destroyed and check_exists
176
177
178def check_result(statistics, startup, offline, sample_interval, dwarf, js_report, filtersize, depth, touchtimes, malloc_match_interval):
179    conn = sqlite3.connect(r'./../outputfiles/nativehook.db')
180    cursor = conn.cursor()
181    cursor.execute('SELECT * FROM data_dict')
182    result = cursor.fetchall()
183    malloc_release_stack, small_malloc_stack = get_target_stack(result)
184    cursor.execute('SELECT * FROM native_hook_frame')
185    result = cursor.fetchall()
186    callstack_ids_destroyed = []
187    callstack_ids_exists = []
188    callstack_ids_native = []
189    for row in result:
190        if row[CALLSTACKID_INDEX] == malloc_release_stack[1]:
191            callstack_ids_destroyed.append(row[1])
192        if row[CALLSTACKID_INDEX] == small_malloc_stack[1]:
193            callstack_ids_exists.append(row[1])
194        if row[CALLSTACKID_INDEX] == malloc_release_stack[0]:
195            callstack_ids_native.append(row[1])
196    if js_report:
197        callstack_ids_destroyed = list(set(callstack_ids_destroyed) & set(callstack_ids_native))
198        callstack_ids_exists = list(set(callstack_ids_exists) & set(callstack_ids_native))
199    else:
200        callstack_ids_destroyed = callstack_ids_native
201        callstack_ids_exists = callstack_ids_native
202    if depth == DEPTH_FIVE and (not dwarf) and js_report:
203        if len(callstack_ids_destroyed) != 0:
204            return False
205        if len(callstack_ids_exists) != 0:
206            return False
207        return True
208    if len(callstack_ids_destroyed) == 0 and (malloc_match_interval != 0):
209        return False
210    if (sample_interval < FILTER_THRESH and filtersize < FILTER_THRESH) and len(callstack_ids_exists) == 0:
211        return False
212    if (sample_interval >= FILTER_THRESH or filtersize >= FILTER_THRESH) and len(callstack_ids_exists) != 0 and js_report:
213        return False
214    check_destroyed = False
215    check_exists = False
216    if statistics > 0:
217        cursor.execute('SELECT * FROM native_hook_statistic')
218        result = cursor.fetchall()
219        if touchtimes != 0:
220            for row in result:
221                for callstackid in callstack_ids_destroyed:
222                    if row[1] == callstackid:
223                        if row[APPLY_INDEX] == DESTROY_SIZE * touchtimes and row[RELEASE_INDEX] == DESTROY_SIZE * touchtimes:
224                            check_destroyed = True
225                for callstackid in callstack_ids_exists:
226                    if row[1] == callstackid:
227                        if row[APPLY_INDEX] == EXIST_SIZE * touchtimes and row[RELEASE_INDEX] == 0:
228                            check_exists = True
229        else:
230            for row in result:
231                for callstackid in callstack_ids_destroyed:
232                    if row[1] == callstackid:
233                        if (row[APPLY_INDEX] % DESTROY_SIZE == 0) and row[RELEASE_INDEX] == row[APPLY_INDEX]:
234                            check_destroyed = True
235                            check_exists = True
236    else:
237        cursor.execute('SELECT * FROM native_hook')
238        result = cursor.fetchall()
239        times_destroyed = 0
240        times_exists = 0
241        malloc_addrs = []
242        for row in result:
243            for callstackid in callstack_ids_destroyed:
244                if row[1] == callstackid and row[ALLOC_INDEX] == (DESTROY_SIZE / MALLOC_TIMES) and row[TYPE_INDEX] == "AllocEvent":
245                    times_destroyed += 1
246                    malloc_addrs.append(row[ADDR_INDEX])
247            for callstackid in callstack_ids_exists:
248                if row[1] == callstackid and row[ALLOC_INDEX] == (EXIST_SIZE / MALLOC_TIMES) and row[TYPE_INDEX] == "AllocEvent":
249                    times_exists += 1
250        if malloc_match_interval != 0:
251            if times_destroyed != 0:
252                return False
253        elif times_destroyed != (touchtimes * MALLOC_TIMES) and (not ((sample_interval >= FILTER_THRESH) or (filtersize >= FILTER_THRESH))):
254            return False
255        for row in result:
256            if row[ADDR_INDEX] in malloc_addrs and row[ALLOC_INDEX] == (DESTROY_SIZE / MALLOC_TIMES) and row[TYPE_INDEX] == "FreeEvent":
257                times_destroyed -= 1
258                malloc_addrs.remove(row[ADDR_INDEX])
259
260        check_destroyed = (times_destroyed == 0)
261        check_exists = (times_exists == (touchtimes * MALLOC_TIMES))
262    if (sample_interval >= FILTER_THRESH) or (filtersize >= FILTER_THRESH):
263        check_exists = True
264    if malloc_match_interval > 0:
265        check_destroyed = True
266    cursor.close()
267    conn.close()
268    return check_destroyed and check_exists
269
270
271def check_nativehook_result(statistics, startup, offline, sample_interval, dwarf, js_report, filtersize, depth, touchtimes, malloc_match_interval=0, response_library=False,
272                            callframe_compress=True, string_compress=True):
273    try:
274        subprocess.check_output(r"del .\..\inputfiles\nativehook\config.txt", text=True, encoding="utf-8")
275        subprocess.check_output(r"del .\..\outputfiles\test.htrace", text=True, encoding="utf-8")
276        subprocess.check_output(r"del .\..\inputfiles\layout.json", text=True, encoding="utf-8")
277        subprocess.check_output(r"del .\..\outputfiles\nativehook.db", text=True, encoding="utf-8")
278        subprocess.check_output("hdc shell rm /data/local/tmp/test.htrace")
279        subprocess.check_output("hdc shell rm /data/log/faultlog/faultlogger/*")
280    except Exception as e:
281        print(f"An error occurred: {e}")
282        pass
283
284    with open(r".\..\inputfiles\nativehook\config_template.txt", 'r') as file:
285        content = file.read()
286    subprocess.check_output("hdc shell power-shell setmode 602")
287    modified_content = content.replace('sample_interval: 256', 'sample_interval: ' + str(sample_interval))
288    if malloc_match_interval == 0:
289        modified_content = modified_content.replace('statistics_interval: 10', 'statistics_interval: ' + str(statistics))
290    else:
291        modified_content = modified_content.replace('statistics_interval: 10', 'statistics_interval: ' + str(statistics) + '\n' +
292                                                    "    malloc_free_matching_interval: " + str(malloc_match_interval))
293    modified_content = modified_content.replace('filter_size: 500', 'filter_size: ' + str(filtersize))
294    modified_content = modified_content.replace('max_js_stack_depth: 20', 'max_js_stack_depth: ' + str(depth))
295
296    if not offline:
297        modified_content = modified_content.replace('offline_symbolization: true', 'offline_symbolization: false')
298
299    if not startup:
300        modified_content = modified_content.replace('startup_mode: true', 'startup_mode: false')
301
302    if dwarf:
303        modified_content = modified_content.replace('fp_unwind: true', 'fp_unwind: false')
304
305    if not js_report:
306        modified_content = modified_content.replace('js_stack_report: 1', 'js_stack_report: 0')
307        modified_content = modified_content.replace('max_js_stack_depth: 20', 'max_js_stack_depth: 0')
308
309    if response_library:
310        modified_content = modified_content.replace('response_library_mode: false', 'response_library_mode: true')
311
312    if not callframe_compress:
313        modified_content = modified_content.replace('callframe_compress: true', 'callframe_compress: false')
314
315    if not string_compress:
316        modified_content = modified_content.replace('string_compress: true', 'string_compress: false')
317
318    flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL
319    mode = stat.S_IWUSR | stat.S_IRUSR
320    with os.fdopen(os.open(r".\..\inputfiles\nativehook\config.txt", flags, mode), 'w') as file:
321        file.write(modified_content)
322
323    subprocess.check_output(r"hdc file send .\..\inputfiles\nativehook\config.txt /data/local/tmp/", text=True, encoding="utf-8")
324
325    task_thread = None
326    if (dwarf or startup):
327        task_thread = threading.Thread(target=task_template, args=(True,))
328    else:
329        task_thread = threading.Thread(target=task_template, args=())
330    task_thread.start()
331    time.sleep(SLEEP_TWO)
332    if (startup):
333        subprocess.check_output("hdc shell killall com.example.insight_test_stage")
334        subprocess.check_output("hdc shell aa start -a EntryAbility -b com.example.insight_test_stage")
335        time.sleep(SLEEP_FOUR)
336        if (dwarf):
337            time.sleep(SLEEP_FOUR)
338        touch_button("模板测试")
339        time.sleep(1)
340        subprocess.check_output("hdc shell uitest uiInput drag 100 800 100 100 1000")
341        time.sleep(1)
342        touch_button("Allocations_Js_Depth")
343
344    i = 0
345    while i < touchtimes:
346        touch_button("malloc-release(depth 6)")
347        touch_button("small-malloc(depth 7)")
348        i += 1
349    task_thread.join()
350
351    subprocess.check_output(r"hdc file recv /data/local/tmp/test.htrace .\..\outputfiles\ ", text=True, encoding="utf-8")
352    subprocess.check_output(r".\..\inputfiles\trace_streamer_nativehook.exe .\..\outputfiles\test.htrace -e .\..\outputfiles\nativehook.db", text=True, encoding="utf-8")
353
354    if response_library:
355        return check_library_result(statistics, startup, offline, sample_interval, dwarf, filtersize, depth, touchtimes, malloc_match_interval)
356    return check_result(statistics, startup, offline, sample_interval, dwarf, js_report, filtersize, depth, touchtimes, malloc_match_interval)
357
358
359def check_nativehook_multipleprocess(statistics, startup, offline, sample_interval, dwarf, filtersize, depth, touchtimes, malloc_match_interval=0, response_library=False):
360    subprocess.check_output(r"del .\..\inputfiles\nativehook\config_multipleprocess.txt", text=True, encoding="utf-8")
361    subprocess.check_output(r"del .\..\outputfiles\test.htrace", text=True, encoding="utf-8")
362    subprocess.check_output(r"del .\..\inputfiles\layout.json", text=True, encoding="utf-8")
363    subprocess.check_output(r"del .\..\outputfiles\nativehook.db", text=True, encoding="utf-8")
364    subprocess.check_output("hdc shell rm /data/local/tmp/test.htrace")
365
366    with open(r".\..\inputfiles\nativehook\config_multipleprocess_template.txt", 'r') as file:
367        content = file.read()
368    subprocess.check_output("hdc shell power-shell setmode 602")
369    sceneboard = get_pid("com.ohos.sceneboard")
370    modified_content = content.replace('sample_interval: 256', 'sample_interval: ' + str(sample_interval))
371    if malloc_match_interval == 0:
372        modified_content = modified_content.replace('statistics_interval: 10', 'statistics_interval: ' + str(statistics))
373    else:
374        modified_content = modified_content.replace('statistics_interval: 10', 'statistics_interval: ' + str(statistics) + '\n' +
375                                                    "    malloc_free_matching_interval: " + str(malloc_match_interval))
376    modified_content = modified_content.replace('filter_size: 500', 'filter_size: ' + str(filtersize))
377    modified_content = modified_content.replace('max_js_stack_depth: 20', 'max_js_stack_depth: ' + str(depth))
378    modified_content = modified_content.replace('expand_pids: 0', 'expand_pids: ' + str(sceneboard))
379    if not offline:
380        modified_content = modified_content.replace('offline_symbolization: true', 'offline_symbolization: false')
381
382    if not startup:
383        modified_content = modified_content.replace('startup_mode: true', 'startup_mode: false')
384
385    if dwarf:
386        modified_content = modified_content.replace('fp_unwind: true', 'fp_unwind: false')
387
388    if response_library:
389        modified_content = modified_content.replace('response_library_mode: false', 'response_library_mode: true')
390
391    flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL
392    mode = stat.S_IWUSR | stat.S_IRUSR
393    with os.fdopen(os.open(r".\..\inputfiles\nativehook\config_multipleprocess.txt", flags, mode), 'w') as file:
394        file.write(modified_content)
395
396    subprocess.check_output(r"hdc file send .\..\inputfiles\nativehook\config_multipleprocess.txt /data/local/tmp/", text=True, encoding="utf-8")
397    task_thread = None
398    if (dwarf or startup):
399        task_thread = threading.Thread(target=task_multiple_template, args=(True,))
400    else:
401        task_thread = threading.Thread(target=task_multiple_template, args=())
402    task_thread.start()
403    time.sleep(SLEEP_TWO)
404    if (startup):
405        subprocess.check_output("hdc shell killall com.example.insight_test_stage")
406        subprocess.check_output("hdc shell aa start -a EntryAbility -b com.example.insight_test_stage")
407        time.sleep(SLEEP_FOUR)
408        touch_button("模板测试")
409        time.sleep(1)
410        subprocess.check_output("hdc shell uitest uiInput drag 100 800 100 100 1000")
411        time.sleep(1)
412        touch_button("Allocations_Js_Depth")
413
414    i = 0
415    while i < touchtimes:
416        touch_button("malloc-release(depth 6)")
417        touch_button("small-malloc(depth 7)")
418        i += 1
419    task_thread.join()
420    subprocess.check_output(r"hdc file recv /data/local/tmp/test.htrace .\..\outputfiles\ ", text=True, encoding="utf-8")
421    subprocess.check_output(r".\..\inputfiles\trace_streamer_nativehook.exe .\..\outputfiles\test.htrace -e .\..\outputfiles\nativehook.db", text=True, encoding="utf-8")
422
423    first_process = False
424    if response_library:
425        first_process = check_library_result(statistics, startup, offline, sample_interval, dwarf, filtersize, depth, touchtimes, malloc_match_interval)
426    else:
427        first_process = check_result(statistics, startup, offline, sample_interval, dwarf, True, filtersize, depth, touchtimes, malloc_match_interval)
428
429    conn = sqlite3.connect(r'./../outputfiles/nativehook.db')
430    cursor = conn.cursor()
431    cursor.execute('SELECT * FROM process')
432    result = cursor.fetchall()
433    ipid = 0
434    sceneboard = get_pid("com.ohos.sceneboard")
435    for row in result:
436        if row[PID_INDEX] == int(sceneboard):
437            ipid = row[1]
438    if ipid == 0:
439        return False
440    second_process = False
441    if statistics > 0:
442        cursor.execute('SELECT * FROM native_hook_statistic')
443        result = cursor.fetchall()
444        for row in result:
445            if row[IPID_INDEX] == ipid and row[APPLY_INDEX] >= MALLOC_THRESH:
446                second_process = True
447    else:
448        cursor.execute('SELECT * FROM native_hook')
449        result = cursor.fetchall()
450        for row in result:
451            if row[IPID_INDEX] == ipid and row[ALLOC_INDEX] >= MALLOC_THRESH:
452                second_process = True
453    cursor.close()
454    conn.close()
455    return first_process and second_process
456
457
458def get_profiler_test_trace(process):
459    subprocess.check_output("hdc shell ls -lh /data/log/reliability/resource_leak/memory_leak/ > /data/local/tmp/leak.txt")
460    subprocess.check_output(r"hdc file recv /data/local/tmp/leak.txt .\..\outputfiles\ ", text=True, encoding="utf-8")
461    with open(r'.\..\outputfiles\leak.txt', 'r') as file:
462        lines = file.readlines()
463        for line in lines:
464            if process in line and ("smaps" not in line) and ("sample" not in line):
465                return line.split()[len(line.split()) - 1]
466    return ""
467
468def get_nmd_file(process):
469    subprocess.check_output("hdc shell ls -lh /data/log/reliability/resource_leak/memory_leak/ > /data/local/tmp/leak.txt")
470    subprocess.check_output(r"hdc file recv /data/local/tmp/leak.txt .\..\outputfiles\ ", text=True, encoding="utf-8")
471    with open(r'.\..\outputfiles\leak.txt', 'r') as file:
472        lines = file.readlines()
473        for line in lines:
474            if process in line and ("smaps" in line) and ("sample" not in line):
475                return line.split()[len(line.split()) - 1]
476    return ""
477
478
479def check_file_size(output):
480    result = output.split()[FILE_SIZE_INDEX]
481    multi = False
482    if (int(result[0]) > 2):
483        return True
484    else:
485        return False
486
487
488def check_sa_result(kill_process=False, multithread=False):
489    try:
490        subprocess.check_output(r"hdc shell rm /data/local/tmp/test.htrace")
491        subprocess.check_output("hdc shell rm /data/log/reliability/resource_leak/memory_leak/*")
492        subprocess.check_output(r"del .\..\outputfiles\nativehook.db ", text=True, encoding="utf-8")
493        subprocess.check_output(r"del .\..\outputfiles\test.htrace", text=True, encoding="utf-8")
494    except Exception as e:
495        print(f"An error occurred: {e}")
496        pass
497    subprocess.check_output("hdc target mount")
498    if not multithread:
499        subprocess.check_output(f"hdc file send .\..\inputfiles\process_resource_limit.json /system/variant/phone/base/etc/efficiency_manager", text=True, encoding="utf-8")
500    else:
501        subprocess.check_output(f"hdc file send .\..\inputfiles\process_resource_limit_multi.json /data/local/tmp/", text=True, encoding="utf-8")
502        subprocess.check_output(f"hdc shell mv /data/local/tmp/process_resource_limit_multi.json /data/local/tmp/process_resource_limit.json", text=True, encoding="utf-8")
503        subprocess.check_output(f"hdc shell cp -f /data/local/tmp/process_resource_limit.json /system/variant/phone/base/etc/efficiency_manager", text=True, encoding="utf-8")
504    subprocess.check_output("hdc shell reboot", text=True, encoding="utf-8")
505    time.sleep(SLEEP_TWENTY)
506    j = 0
507    while j < SA_WAIT_TIMES:
508        output = subprocess.check_output(r"hdc list targets", text=True, encoding="utf-8")
509        if output == '[Empty]\n\n':
510            time.sleep(SLEEP_FIVE)
511            j += 1
512        else:
513            break
514
515    #解除锁屏
516    subprocess.check_output("hdc shell uitest uiInput drag 100 500 100 100 1000")
517    time.sleep(SLEEP_FIVE)
518    subprocess.check_output("hdc shell uitest uiInput drag 100 500 100 100 1000")
519    time.sleep(SLEEP_FIVE)
520    subprocess.check_output("hdc shell uitest uiInput drag 100 500 100 100 1000")
521
522    subprocess.check_output("hdc shell power-shell setmode 602")
523
524    subprocess.check_output("hdc shell killall com.example.insight_test_stage")
525    subprocess.check_output("hdc shell param set hiview.memleak.test enable")
526    subprocess.check_output("hdc shell killall hiview")
527    subprocess.check_output("hdc shell uitest uiInput click 100 200")
528    subprocess.check_output("hdc shell aa start -a EntryAbility -b com.example.insight_test_stage")
529    time.sleep(SLEEP_FOUR)
530    touch_button("模板测试")
531    time.sleep(1)
532    subprocess.check_output("hdc shell uitest uiInput drag 100 800 100 100 1000")
533    time.sleep(1)
534    touch_button("Allocations_Js_Depth")
535    i = 0
536    process_hilog = None
537    daemonpid = 0
538    wait_time = 0
539    while i < SA_CLICK_TIMES:
540        daemonpid = get_pid("native_daemon")
541        if (kill_process and int(daemonpid) > 0):
542            wait_time += 1
543        if (wait_time == KILL_PROCESS_TIME):
544            if (kill_process):
545                subprocess.check_output("hdc shell killall com.example.insight_test_stage")
546                time.sleep(SLEEP_TWENTY)
547                break
548        touch_button("malloc-release(depth 6)")
549        touch_button("small-malloc(depth 7)")
550        i += 1
551
552    filename = get_profiler_test_trace("com.example.insight_test_stage")
553    nmdfile = get_nmd_file("com.example.insight_test_stage")
554    if nmdfile == "":
555        return False
556    subprocess.check_output("hdc shell cp /data/log/reliability/resource_leak/memory_leak/" + nmdfile + " /data/local/tmp/nmd.txt")
557    subprocess.check_output(f"hdc file recv /data/local/tmp/nmd.txt .\..\outputfiles\ ", text=True, encoding="utf-8")
558    nmd_result = False
559    with open(r'.\..\outputfiles\nmd.txt', 'r') as file:
560        lines = file.readlines()
561        for line in lines:
562            if "End jemalloc ohos statistics" in line:
563                nmd_result = True
564    if not nmd_result:
565        return False
566
567    if (multithread):
568        sceneboard_file = get_profiler_test_trace("com.ohos.sceneboard")
569        subprocess.check_output("hdc shell cp /data/log/reliability/resource_leak/memory_leak/" + sceneboard_file + " /data/local/tmp/test.htrace")
570        subprocess.check_output("hdc shell ls -lh /data/local/tmp/ > /data/local/tmp/tmp.txt")
571        subprocess.check_output(f"hdc file recv /data/local/tmp/tmp.txt .\..\outputfiles\ ", text=True, encoding="utf-8")
572        result = False
573        with open(r'.\..\outputfiles\tmp.txt', 'r') as file:
574            lines = file.readlines()
575            for line in lines:
576                if "test.htrace" in line:
577                    result = (line.split()[SIZE_INDEX][-1] == 'M')
578        if not result:
579            return False
580
581    subprocess.check_output("hdc shell cp /data/log/reliability/resource_leak/memory_leak/" + filename + " /data/local/tmp/test.htrace")
582    subprocess.check_output(r"hdc file recv /data/local/tmp/test.htrace .\..\outputfiles\ ", text=True, encoding="utf-8")
583    subprocess.check_output(r".\..\inputfiles\trace_streamer_nativehook.exe .\..\outputfiles\test.htrace -e .\..\outputfiles\nativehook.db", text=True, encoding="utf-8")
584
585    return check_result(SA_STATISTICS, False, True, SA_SAMPLE, False, 0, 0, DEPTH_TWENTY, 0, 0)
586
587
588class TestNativehook:
589    @pytest.mark.L0
590    def test_sa(self):
591        assert check_sa_result()
592
593    @pytest.mark.L0
594    def test_startup_statistics_sample(self):
595        assert check_nativehook_result(STATISTICS_INTERVAL, True, False, SAMPLE_SMALL, False, False, 0, DEPTH_TEN, 1, 0, False, False, False)
596
597    @pytest.mark.L0
598    def test_complete_data(self):
599        assert check_nativehook_result(0, False, False, 0, False, False, 0, DEPTH_TEN, 1, 0, False, False, False)
600
601    @pytest.mark.L0
602    def test_dwarf(self):
603        assert check_nativehook_result(0, False, False, 0, True, False, 0, DEPTH_TEN, 1, 0, False, False, False)
604
605    @pytest.mark.L0
606    def test_dwarf_stringcompress(self):
607        assert check_nativehook_result(0, False, False, 0, True, False, 0, DEPTH_TEN, CLICK_TWICE, 0, False, False, True)
608
609    @pytest.mark.L0
610    def test_dwarf_stringcompress_callframecompress(self):
611        assert check_nativehook_result(0, False, False, 0, True, False, 0, DEPTH_TEN, CLICK_THREETIMES, 0, False, True, True)
612
613    @pytest.mark.L0
614    def test_dwarf_offline(self):
615        assert check_nativehook_result(0, False, True, 0, True, False, 0, DEPTH_TEN, 1, 0, False, False, False)
616
617    @pytest.mark.L0
618    def test_match(self):
619        assert check_nativehook_result(0, False, False, 0, False, False, 0, DEPTH_TEN, CLICK_TWICE, 10, False, False, False)
620
621
622    @pytest.mark.L0
623    def test_jsreport(self):
624        assert check_nativehook_result(0, False, False, 0, False, True, 0, DEPTH_TEN, CLICK_THREETIMES, 0, False, False, False)
625
626    @pytest.mark.L0
627    def test_dwarf_jsreport(self):
628        assert check_nativehook_result(0, False, False, 0, True, True, 0, DEPTH_TEN, 1, 0, False, False, False)
629
630    @pytest.mark.L0
631    def test_filter(self):
632        assert check_nativehook_result(0, False, False, 0, False, False, FILTER_LARGE, DEPTH_TEN, CLICK_TWICE, 0, False, False, False)
633
634    @pytest.mark.L0
635    def test_dwarf_filter(self):
636        assert check_nativehook_result(0, False, False, 0, True, False, FILTER_LARGE, DEPTH_TEN, CLICK_THREETIMES, 0, False, False, False)
637
638    @pytest.mark.L0
639    def test_dwarf_startup(self):
640        assert check_nativehook_result(0, True, False, 0, True, False, 0, DEPTH_TEN, 1, 0, False, False, False)
641
642    @pytest.mark.L0
643    def test_startup(self):
644        assert check_nativehook_result(0, True, False, 0, False, False, 0, DEPTH_TEN, CLICK_TWICE, 0, False, False, False)
645
646    @pytest.mark.L0
647    def test_response_library(self):
648        assert check_nativehook_result(0, False, False, 0, False, False, 0, DEPTH_TEN, CLICK_THREETIMES, 0, True, False, False)
649
650    @pytest.mark.L0
651    def test_dwarf_response_library(self):
652        assert check_nativehook_result(0, False, False, 0, True, False, 0, DEPTH_TEN, 1, 0, True, False, False)
653
654    @pytest.mark.L0
655    def test_startup_response_library(self):
656        assert check_nativehook_result(0, True, False, 0, False, False, 0, DEPTH_TEN, CLICK_TWICE, 0, True, False, False)
657
658    @pytest.mark.L0
659    def test_sample(self):
660        assert check_nativehook_result(0, False, False, SAMPLE_SMALL, False, False, 0, DEPTH_TEN, CLICK_THREETIMES, 0, False, False, False)
661
662    @pytest.mark.L0
663    def test_statistics_complete_data(self):
664        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, 0, False, False, 0, DEPTH_TEN, 1, 0, False, False, False)
665
666    @pytest.mark.L0
667    def test_statistics_dwarf_stringcompress(self):
668        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, 0, True, False, 0, DEPTH_TEN, CLICK_TWICE, 0, False, False, True)
669
670    @pytest.mark.L0
671    def test_statistics_dwarf_stringcompress_callframecompress(self):
672        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, 0, True, False, 0, DEPTH_TEN, CLICK_THREETIMES, 0, False, True, True)
673
674    @pytest.mark.L0
675    def test_statistics_dwarf_offline(self):
676        assert check_nativehook_result(STATISTICS_INTERVAL, False, True, 0, True, False, 0, DEPTH_TEN, 1, 0, False, False, False)
677
678    @pytest.mark.L0
679    def test_statistics_jsreport(self):
680        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, 0, False, True, 0, DEPTH_TEN, CLICK_TWICE, 0, False, False, False)
681
682    @pytest.mark.L0
683    def test_statistics_dwarf_jsreport(self):
684        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, 0, True, True, 0, DEPTH_TEN, CLICK_THREETIMES, 0, False, False, False)
685
686    @pytest.mark.L0
687    def test_statistics_filter(self):
688        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, 0, False, False, FILTER_LARGE, DEPTH_TEN, 1, 0, False, False, False)
689
690    @pytest.mark.L0
691    def test_statistics_dwarf_filter(self):
692        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, 0, True, False, FILTER_LARGE, DEPTH_TEN, CLICK_TWICE, 0, False, False, False)
693
694    @pytest.mark.L0
695    def test_statistics_dwarf_startup(self):
696        assert check_nativehook_result(STATISTICS_INTERVAL, True, False, 0, True, False, 0, DEPTH_TEN, CLICK_THREETIMES, 0, False, False, False)
697
698    @pytest.mark.L0
699    def test_statistics_startup(self):
700        assert check_nativehook_result(STATISTICS_INTERVAL, True, False, 0, False, False, 0, DEPTH_TEN, 1, 0, False, False, False)
701
702    @pytest.mark.L0
703    def test_statistics_response_library(self):
704        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, 0, False, False, 0, DEPTH_TEN, CLICK_TWICE, 0, True, False, False)
705
706    @pytest.mark.L0
707    def test_statistics_dwarf_response_library(self):
708        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, 0, True, False, 0, DEPTH_TEN, CLICK_THREETIMES, 0, True, False, False)
709
710    @pytest.mark.L0
711    def test_statistics_startup_response_library(self):
712        assert check_nativehook_result(STATISTICS_INTERVAL, True, False, 0, False, False, 0, DEPTH_TEN, 1, 0, True, False, False)
713
714    @pytest.mark.L0
715    def test_statistics_sample(self):
716        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, SAMPLE_SMALL, False, False, 0, DEPTH_TEN, CLICK_TWICE, 0, False, False, False)
717
718    @pytest.mark.L0
719    def test_no_dataqueue(self):
720        assert check_nativehook_result(STATISTICS_INTERVAL, False, True, SAMPLE_SMALL, False, False, 0, DEPTH_TEN, CLICK_THREETIMES)
721
722    @pytest.mark.L0
723    def test_dwarf_depth_five(self):
724        assert check_nativehook_result(0, False, False, 0, True, False, 0, DEPTH_FIVE, 1, 0, False, False, False)
725
726    @pytest.mark.L0
727    def test_depth_five(self):
728        assert check_nativehook_result(0, False, False, 0, False, False, 0, DEPTH_FIVE, CLICK_TWICE, 0, False, False, False)
729
730    @pytest.mark.L0
731    def test_startup_depth_five(self):
732        assert check_nativehook_result(0, True, False, 0, False, False, 0, DEPTH_FIVE, CLICK_THREETIMES, 0, False, False, False)
733
734    @pytest.mark.L0
735    def test_offline_depth_five(self):
736        assert check_nativehook_result(0, False, True, 0, False, False, 0, DEPTH_FIVE, 1, 0, False, False, False)
737
738    @pytest.mark.L0
739    def test_filter_depth_five(self):
740        assert check_nativehook_result(0, False, False, 0, False, False, FILTER_SMALL, DEPTH_FIVE, CLICK_TWICE, 0, False, False, False)
741
742    @pytest.mark.L0
743    def test_statistics_depth_five(self):
744        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, 0, False, False, 0, DEPTH_FIVE, CLICK_THREETIMES, 0, False, False, False)
745
746    @pytest.mark.L1
747    def test_js_sample(self):
748        assert check_nativehook_result(0, False, True, SAMPLE_SMALL, False, True, 0, DEPTH_TEN, CLICK_TWICE)
749
750    @pytest.mark.L1
751    def test_js_statistics_dwarf(self):
752        assert check_nativehook_result(STATISTICS_INTERVAL, False, True, SAMPLE_SMALL, True, True, 0, DEPTH_TEN, CLICK_THREETIMES)
753
754    @pytest.mark.L1
755    def test_js_match(self):
756        assert check_nativehook_result(0, False, False, SAMPLE_SMALL, False, True, 0, DEPTH_TEN, 1, MATCH_INTERVAL)
757
758    @pytest.mark.L1
759    def test_js_startup(self):
760        assert check_nativehook_result(0, True, True, SAMPLE_SMALL, False, True, 0, DEPTH_TEN, CLICK_TWICE)
761
762    @pytest.mark.L1
763    def test_js_statistics_response_library(self):
764        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, SAMPLE_SMALL, False, True, 0, DEPTH_TEN, CLICK_THREETIMES, 0, True)
765
766    @pytest.mark.L1
767    def test_js_statistics_dwarf_online(self):
768        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, SAMPLE_SMALL, True, True, FILTER_SMALL, DEPTH_TEN, 1)
769
770    @pytest.mark.L1
771    def test_js_statistics_dwarf_startup(self):
772        assert check_nativehook_result(STATISTICS_INTERVAL, True, False, SAMPLE_SMALL, True, True, 0, DEPTH_TEN, CLICK_TWICE)
773
774    @pytest.mark.L1
775    def test_js_statistics_dwarf_sample_interval(self):
776        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, SAMPLE_SMALL, True, True, 0, DEPTH_TEN, CLICK_THREETIMES)
777
778    @pytest.mark.L1
779    def test_js_statistics_dwarf_filtersize(self):
780        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, SAMPLE_SMALL, True, True, FILTER_LARGE, DEPTH_TEN, CLICK_TWICE)
781
782    @pytest.mark.L1
783    def test_js_dwarf_match(self):
784        assert check_nativehook_result(0, False, False, SAMPLE_SMALL, True, True, FILTER_SMALL, DEPTH_TEN, 1, False)
785
786    @pytest.mark.L1
787    def test_js_statistics_dwarf_response_library(self):
788        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, SAMPLE_SMALL, True, True, 0, DEPTH_TEN, 1, 0, True)
789
790    @pytest.mark.L1
791    def test_js_response_library(self):
792        assert check_nativehook_result(0, False, False, SAMPLE_SMALL, True, True, 0, DEPTH_TEN, 1, 0, True)
793
794    @pytest.mark.L1
795    def test_js_match_response_library(self):
796        assert check_nativehook_result(0, False, False, SAMPLE_SMALL, True, True, 0, DEPTH_TEN, 1, MATCH_INTERVAL, True)
797
798    @pytest.mark.L1
799    def test_js_statistics_startup_filter(self):
800        assert check_nativehook_result(STATISTICS_INTERVAL, True, True, SAMPLE_SMALL, False, True, FILTER_LARGE, DEPTH_TEN, CLICK_TWICE)
801
802    @pytest.mark.L1
803    def test_js_statistics_startup_non_statistics(self):
804        assert check_nativehook_result(0, True, True, SAMPLE_SMALL, False, True, 0, DEPTH_TEN, CLICK_TWICE)
805
806    @pytest.mark.L1
807    def test_js_startup_online(self):
808        assert check_nativehook_result(0, True, False, SAMPLE_SMALL, False, True, 0, DEPTH_TEN, CLICK_TWICE)
809
810    @pytest.mark.L1
811    def test_js_startup_match(self):
812        assert check_nativehook_result(0, True, False, SAMPLE_SMALL, False, True, 0, DEPTH_TEN, 1, MATCH_INTERVAL, False)
813
814    @pytest.mark.L1
815    def test_js_statistics_startup_sample_interval(self):
816        assert check_nativehook_result(STATISTICS_INTERVAL, True, False, SAMPLE_SMALL, False, True, 0, DEPTH_TEN, CLICK_THREETIMES)
817
818    @pytest.mark.L1
819    def test_js_statistics_startup_response_library(self):
820        assert check_nativehook_result(STATISTICS_INTERVAL, True, False, SAMPLE_SMALL, False, True, 0, DEPTH_TEN, CLICK_TWICE, 0, True)
821
822    @pytest.mark.L1
823    def test_js_statistics_startup_response_library_sample_interval(self):
824        assert check_nativehook_result(STATISTICS_INTERVAL, True, False, SAMPLE_SMALL, False, True, 0, DEPTH_TEN, CLICK_THREETIMES, 0, True)
825
826    @pytest.mark.L1
827    def test_js_statistics_startup_response_library_filter(self):
828        assert check_nativehook_result(STATISTICS_INTERVAL, True, False, SAMPLE_SMALL, False, True, FILTER_LARGE, DEPTH_TEN, CLICK_TWICE, 0, True)
829
830    @pytest.mark.L1
831    def test_js_statistics_startup_sample_interval_filter(self):
832        assert check_nativehook_result(STATISTICS_INTERVAL, True, False, SAMPLE_SMALL, False, True, FILTER_LARGE, DEPTH_TEN, CLICK_TWICE)
833
834    @pytest.mark.L1
835    def test_js_startup_sample_interval(self):
836        assert check_nativehook_result(0, True, False, SAMPLE_SMALL, False, True, 0, DEPTH_TEN, CLICK_TWICE)
837
838    @pytest.mark.L1
839    def test_js_startup_sample_interval_match(self):
840        assert check_nativehook_result(0, True, False, SAMPLE_SMALL, False, True, 0, DEPTH_TEN, CLICK_TWICE, MATCH_INTERVAL, False)
841
842    @pytest.mark.L1
843    def test_js_statistics_sample_interval_filter_size(self):
844        assert check_nativehook_result(STATISTICS_INTERVAL, True, False, SAMPLE_SMALL, False, True, FILTER_LARGE, DEPTH_TEN, 1)
845
846    @pytest.mark.L1
847    def test_js_sample_interval_filter_size(self):
848        assert check_nativehook_result(0, True, False, SAMPLE_SMALL, False, True, FILTER_LARGE, DEPTH_TEN, 1)
849
850    @pytest.mark.L1
851    def test_js_startup_filter_match(self):
852        assert check_nativehook_result(0, True, False, SAMPLE_SMALL, False, True, FILTER_LARGE, DEPTH_TEN, CLICK_TWICE, MATCH_INTERVAL, False)
853
854    @pytest.mark.L1
855    def test_js_statistics_online_filtersize(self):
856        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, SAMPLE_SMALL, True, True, FILTER_LARGE, DEPTH_TEN, 1)
857
858    @pytest.mark.L1
859    def test_js_statistics_online_sample_interval(self):
860        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, SAMPLE_SMALL, False, True, FILTER_SMALL, DEPTH_TEN, 1)
861
862    @pytest.mark.L1
863    def test_js_statistics_online_sample_interval_filter(self):
864        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, SAMPLE_SMALL, False, True, FILTER_LARGE, DEPTH_TEN, 1)
865
866    @pytest.mark.L1
867    def test_js_statistics_online_response_library_filter(self):
868        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, SAMPLE_SMALL, False, True, FILTER_LARGE, DEPTH_TEN, 1, 0, True)
869
870    @pytest.mark.L1
871    def test_statistics_js_online(self):
872        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, SAMPLE_SMALL, False, True, FILTER_SMALL, DEPTH_TEN, CLICK_THREETIMES)
873
874    @pytest.mark.L1
875    def test_js_online_match(self):
876        assert check_nativehook_result(0, False, False, SAMPLE_SMALL, False, True, FILTER_SMALL, MATCH_INTERVAL, 1, DEPTH_TEN, False)
877
878    @pytest.mark.L1
879    def test_statistics_js_online_response_library(self):
880        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, SAMPLE_SMALL, False, True, FILTER_SMALL, DEPTH_TEN, 1, 0, True)
881
882    @pytest.mark.L1
883    def test_js_statistics_response_library_startup(self):
884        assert check_nativehook_result(STATISTICS_INTERVAL, True, False, SAMPLE_SMALL, False, True, FILTER_SMALL, DEPTH_TEN, 1, 0, True)
885
886    @pytest.mark.L1
887    def test_js_response_library_startup(self):
888        assert check_nativehook_result(0, True, True, SAMPLE_SMALL, False, True, FILTER_SMALL, DEPTH_TEN, 1, 0, True)
889
890    @pytest.mark.L1
891    def test_js_online_match_filter(self):
892        assert check_nativehook_result(0, False, False, 0, False, True, FILTER_LARGE, DEPTH_TEN, 1, MATCH_INTERVAL, False)
893
894    @pytest.mark.L1
895    def test_js_startup_online_match_filter(self):
896        assert check_nativehook_result(0, True, False, 0, False, True, FILTER_LARGE, DEPTH_TEN, 1, MATCH_INTERVAL, False)
897
898    @pytest.mark.L1
899    def test_js_online_match_filter_sample_interval(self):
900        assert check_nativehook_result(0, False, False, SAMPLE_SMALL, False, True, FILTER_LARGE, DEPTH_TEN, 1, MATCH_INTERVAL, False)
901
902    @pytest.mark.L1
903    def test_js_online_filter(self):
904        assert check_nativehook_result(0, False, False, SAMPLE_SMALL, False, True, FILTER_LARGE, DEPTH_TEN, 1)
905
906    @pytest.mark.L1
907    def test_js_statistics_no_dataqueue(self):
908        assert check_nativehook_result(STATISTICS_INTERVAL, False, True, SAMPLE_SMALL, False, True, 0, DEPTH_TEN, CLICK_THREETIMES)
909
910    @pytest.mark.L1
911    def test_js_statistics_no_dataqueue_startup(self):
912        assert check_nativehook_result(STATISTICS_INTERVAL, True, True, SAMPLE_SMALL, False, True, 0, DEPTH_TEN, CLICK_TWICE)
913
914    @pytest.mark.L1
915    def test_js_statistics_no_dataqueue_online(self):
916        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, SAMPLE_SMALL, False, True, 0, DEPTH_TEN, CLICK_TWICE)
917
918    @pytest.mark.L1
919    def test_js_statistics_no_dataqueue_dwarf(self):
920        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, SAMPLE_SMALL, True, True, 0, DEPTH_TEN, CLICK_TWICE)
921
922    @pytest.mark.L1
923    def test_sa_multi(self):
924        assert check_sa_result(False, True)
925
926    @pytest.mark.L1
927    def test_sa_killprocess(self):
928        assert check_sa_result(True)
929
930
931    @pytest.mark.L2
932    def test_js_statistics_depth_five_dwarf(self):
933        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, SAMPLE_SMALL, True, True, 0, DEPTH_FIVE, 1)
934
935    @pytest.mark.L2
936    def test_js_statistics_depth_five(self):
937        assert check_nativehook_result(STATISTICS_INTERVAL, False, True, SAMPLE_SMALL, False, True, 0, DEPTH_FIVE, CLICK_THREETIMES)
938
939    @pytest.mark.L2
940    def test_js_statistics_depth_five_startup(self):
941        assert check_nativehook_result(STATISTICS_INTERVAL, True, True, SAMPLE_SMALL, False, True, 0, DEPTH_FIVE, CLICK_THREETIMES)
942
943    @pytest.mark.L2
944    def test_js_statistics_depth_five_online(self):
945        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, SAMPLE_SMALL, False, True, 0, DEPTH_FIVE, CLICK_TWICE)
946
947    @pytest.mark.L2
948    def test_js_statistics_depth_five_filtersize(self):
949        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, SAMPLE_SMALL, False, True, FILTER_LARGE, DEPTH_FIVE, CLICK_THREETIMES)
950
951    @pytest.mark.L2
952    def test_js_statistics_depth_five(self):
953        assert check_nativehook_result(0, False, False, SAMPLE_SMALL, False, True, 0, DEPTH_FIVE, CLICK_THREETIMES)
954
955    @pytest.mark.L2
956    def test_js_statistics_depth_fifteen(self):
957        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, SAMPLE_SMALL, True, True, 0, DEPTH_FIFTEEN, CLICK_THREETIMES)
958
959    @pytest.mark.L2
960    def test_js_statistics_depth_twenty(self):
961        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, SAMPLE_SMALL, True, True, 0, DEPTH_TWENTY, CLICK_THREETIMES)
962
963    @pytest.mark.L2
964    def test_js_statistics_depth_thirty(self):
965        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, SAMPLE_SMALL, True, True, 0, DEPTH_THIRTY, CLICK_TWICE)
966
967    @pytest.mark.L2
968    def test_js_statistics_depth_fifty(self):
969        assert check_nativehook_result(STATISTICS_INTERVAL, False, False, SAMPLE_SMALL, True, True, 0, DEPTH_FIFTY, CLICK_THREETIMES)
970
971    @pytest.mark.L2
972    def test_js_statistics_usermode_nondebug_app_startup(self):
973        assert check_nativehook_multipleprocess(STATISTICS_INTERVAL, False, True, 0, False, 0, DEPTH_TEN, 1)
974
975    @pytest.mark.L2
976    def test_multipleprocess_statistics_online(self):
977        assert check_nativehook_multipleprocess(STATISTICS_INTERVAL, False, False, 0, False, 0, DEPTH_TEN, 1)
978
979    @pytest.mark.L2
980    def test_multipleprocess_statistics(self):
981        assert check_nativehook_multipleprocess(STATISTICS_INTERVAL, False, False, 0, False, 0, DEPTH_TEN, 1)
982
983    @pytest.mark.L2
984    def test_multipleprocess_statistics_offline(self):
985        assert check_nativehook_multipleprocess(STATISTICS_INTERVAL, False, True, SAMPLE_SMALL, False, 0, DEPTH_TWENTY, CLICK_TWICE)
986
987    @pytest.mark.L2
988    def test_multipleprocess_statistics_dwarf(self):
989        assert check_nativehook_multipleprocess(STATISTICS_INTERVAL, False, False, SAMPLE_SMALL, True, 0, DEPTH_THIRTY, CLICK_THREETIMES)
990
991    @pytest.mark.L2
992    def test_multipleprocess_statistics_offline_sample(self):
993        assert check_nativehook_multipleprocess(STATISTICS_INTERVAL, False, True, SAMPLE_SMALL, False, 0, DEPTH_THIRTY, CLICK_TWICE)
994
995    @pytest.mark.L2
996    def test_multipleprocess_dwarf(self):
997        assert check_nativehook_multipleprocess(0, False, True, SAMPLE_SMALL, False, 0, DEPTH_THIRTY, CLICK_THREETIMES)
998
999    @pytest.mark.L2
1000    def test_multipleprocess_statistics_dwarf_response_library(self):
1001        assert check_nativehook_multipleprocess(STATISTICS_INTERVAL, False, True, SAMPLE_SMALL, True, 0, DEPTH_TEN, CLICK_TWICE, 0, True)
1002
1003    @pytest.mark.L2
1004    def test_multipleprocess_response_library(self):
1005        assert check_nativehook_multipleprocess(0, False, True, SAMPLE_SMALL, False, 0, DEPTH_TEN, CLICK_THREETIMES, 0, True)
1006
1007    @pytest.mark.L2
1008    def test_multipleprocess_statistics_nodataqueue_dwarf(self):
1009        assert check_nativehook_multipleprocess(STATISTICS_INTERVAL, False, True, SAMPLE_SMALL, True, 0, DEPTH_TEN, CLICK_TWICE)
1010
1011    @pytest.mark.L2
1012    def test_multipleprocess_statistics_depth_five_dwarf(self):
1013        assert check_nativehook_multipleprocess(STATISTICS_INTERVAL, False, True, SAMPLE_SMALL, True, 0, DEPTH_FIVE, CLICK_TWICE)
1014
1015    @pytest.mark.L2
1016    def test_multipleprocess_statistics_depth_five(self):
1017        assert check_nativehook_multipleprocess(STATISTICS_INTERVAL, False, True, SAMPLE_SMALL, False, 0, DEPTH_FIVE, CLICK_THREETIMES)
1018
1019    @pytest.mark.L2
1020    def test_multipleprocess_statistics_depth_five_filter(self):
1021        assert check_nativehook_multipleprocess(STATISTICS_INTERVAL, False, True, SAMPLE_SMALL, False, FILTER_LARGE, DEPTH_FIVE, 1)
1022
1023    @pytest.mark.L2
1024    def test_multipleprocess_statistics_depth_five_online(self):
1025        assert check_nativehook_multipleprocess(STATISTICS_INTERVAL, False, False, SAMPLE_SMALL, False, 0, DEPTH_FIVE, 1)
1026
1027    @pytest.mark.L2
1028    def test_multipleprocess_statistics_depth_five_filtersize(self):
1029        assert check_nativehook_multipleprocess(STATISTICS_INTERVAL, False, True, SAMPLE_SMALL, False, FILTER_LARGE, DEPTH_FIVE, 1)
1030
1031    @pytest.mark.L2
1032    def test_multipleprocess_depth_five(self):
1033        assert check_nativehook_multipleprocess(0, False, True, SAMPLE_SMALL, False, 0, DEPTH_FIVE, 1)
1034
1035    @pytest.mark.L2
1036    def test_appfreeze(self):
1037        subprocess.check_output(f"hdc shell ls -lh /data/log/faultlog/faultlogger/ > /data/local/tmp/faultlog.txt")
1038        subprocess.check_output(r"hdc file recv /data/local/tmp/faultlog.txt .\..\outputfiles\ ", text=True, encoding="utf-8")
1039        check = True
1040        with open(r'.\..\outputfiles\faultlog.txt', 'r') as file:
1041            lines = file.readlines()
1042            for line in lines:
1043                if "com.ohos.sceneboard" in line and ("syswarning" not in line):
1044                    check = False
1045                if "com.example.insight_test_stage" in line:
1046                    check = False
1047        assert check == True
1048
1049    @pytest.mark.L2
1050    def test_nocrash(self):
1051        check = True
1052        with open(r'.\..\outputfiles\faultlog.txt', 'r') as file:
1053            lines = file.readlines()
1054            for line in lines:
1055                if "hiprofilerd" in line:
1056                    check = False
1057                if "hiprofiler_plugins" in line:
1058                    check = False
1059                if "native_daemon" in line:
1060                    check = False
1061        assert check == True