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