diff --git a/test/autotest/scenario_test/conftest.py b/test/autotest/scenario_test/conftest.py index 97f8597fade651b6f2b6794a70a2f2ff68623eb0..dd7164b52e2796a656ed746f12e534e54c173410 100644 --- a/test/autotest/scenario_test/conftest.py +++ b/test/autotest/scenario_test/conftest.py @@ -221,6 +221,50 @@ def test_suite_worker_03_debug(): return config +@pytest.fixture(scope='class') +def test_suite_singal_01_debug(): + logging.info('running performance in debug mode') + config = { + 'start_mode': '-D', + 'connect_server_port': 15802, + 'debugger_server_port': 15803, + 'bundle_name': 'com.example.perFormance1', + 'hap_name': 'PerFormance1.hap', + 'hap_path': rf'{os.path.dirname(__file__)}\..\resource\PerFormance1.hap', + 'file_path': { + 'entry_ability': 'entry|entry|1.0.0|src/main/ets/entryability/EntryAbility.ts', + 'index': 'entry|entry|1.0.0|src/main/ets/pages/Index.ts', + 'Test1': 'entry|entry|1.0.0|src/main/ets/pages/Test1.ts', + 'Test2': 'entry|entry|1.0.0|src/main/ets/pages/Test2.ts', + 'Test3': 'entry|entry|1.0.0|src/main/ets/pages/Test3.ts', + 'Test4': 'entry|entry|1.0.0|src/main/ets/pages/Test4.ts', + 'worker': 'entry|entry|1.0.0|src/main/ets/workers/Worker.ts', + } + } + launch_hap(config) + return config + + +@pytest.fixture(scope='class') +def test_suite_singal_02_debug(): + logging.info('running performance in debug mode') + config = { + 'start_mode': '-D', + 'connect_server_port': 15800, + 'debugger_server_port': 15801, + 'bundle_name': 'com.example.perFormance2', + 'hap_name': 'PerFormance1.hap', + 'hap_path': rf'{os.path.dirname(__file__)}\..\resource\PerFormance1.hap', + 'file_path': { + 'entry_ability': 'entry|entry|1.0.0|src/main/ets/entryability/EntryAbility.ts', + 'index': 'entry|entry|1.0.0|src/main/ets/pages/Index.ts', + 'worker': 'entry|entry|1.0.0|src/main/ets/workers/Worker.ts' + } + } + launch_hap(config) + return config + + @pytest.fixture(scope='class') def test_suite_worker_02_dumpheap(): logging.info('running worker_02 in profile mode') diff --git a/test/autotest/scenario_test/test_singal_point_01.py b/test/autotest/scenario_test/test_singal_point_01.py new file mode 100644 index 0000000000000000000000000000000000000000..f71b62813cc00058a2654854e7e310d72180f588 --- /dev/null +++ b/test/autotest/scenario_test/test_singal_point_01.py @@ -0,0 +1,421 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Copyright (c) 2025 Huawei Device Co., Ltd. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Description: Scenario test case. +""" + +import logging +import os +import time +from datetime import datetime +from pprint import PrettyPrinter + +import pytest + +from aw import Application +from aw import Utils +from aw import debugger, runtime +from aw.api import debugger_api, runtime_api + +from prettytable import PrettyTable + + +@pytest.mark.debug +@pytest.mark.timeout(6000) +class TestSingalPoint01: + """ + 测试用例: + evalute响应耗时性能测试用例 + GetProperties响应耗时性能测试用例 + stepinto 响应耗时性能测试用例 + stepout 响应耗时性能测试用例 + stepover 响应耗时性能测试用例 + smartStepinto 响应耗时性能测试用例 + BytecodePcChanged 响应耗时性能测试用例 + 测试步骤: + + """ + + def setup_method(self): + logging.info('Start running TestPerformanceEvaluteTime: setup') + + self.log_path = rf'{os.path.dirname(__file__)}\..\log' + self.hilog_file_name = 'test_performance_evalute_time.hilog.txt' + self.data_info = { + 'path': rf'{os.path.dirname(__file__)}\..\performance', + 'filename': 'testperformanceevalutetime.csv' + } + self.id_generator = Utils.message_id_generator() + self.Utils = Utils.get_time_data(self) + + # receive the hilog before the test start + Utils.clear_fault_log() + self.hilog_process, self.write_thread = Utils.save_hilog(log_path=self.log_path, + file_name=self.hilog_file_name, + debug_on=True) + + def teardown_method(self): + Application.uninstall(self.config['bundle_name']) + + # terminate the hilog receive process after the test done + time.sleep(3) + self.hilog_process.stdout.close() + self.hilog_process.terminate() + self.hilog_process.wait() + self.write_thread.join() + + # time_data = self.Utils.get_time_data() + time_data = Utils.get_time_data(self) + table = PrettyTable() + table.field_names = ['Test Case', 'Executions Number', 'Expected Time', 'Max Actual Time', + 'Min Actual Time', 'Avg Actual Time', 'Avg Actual Time / Expected Time'] + + for key, value in time_data.items(): + proportion = str(value.proportion()) + '' if value.proportion() < 100 else '' + table.add_row([key, value.rounds(), value.expected_time(), value.max_actual_time(), + value.min_actual_time(), f'{value.avg_actual_time():2f}',value.proportion()]) + self.driver.log_info("\n" + table.get_string() + "\n") + + # Utils.save_fault_log(log_path=self.log_path) + # logging.info('TestPerformanceEvaluteTime done') + + def test(self, test_suite_singal_01_debug): + logging.info('Start running TestPerformanceEvaluteTime: test') + self.config = test_suite_singal_01_debug + websocket = self.config['websocket'] + taskpool = self.config['taskpool'] + pid = self.config['pid'] + self.debugger_impl = debugger_api.DebuggerImpl(self.id_generator, websocket) + self.runtime_impl = runtime_api.RuntimeImpl(self.id_generator, websocket) + + taskpool.submit(websocket.main_task(taskpool, self.procedure, pid)) + taskpool.await_taskpool() + taskpool.task_join() + if taskpool.task_exception: + raise taskpool.task_exception + + async def procedure(self, websocket): + ################################################################################################################ + # main thread: connect the debugger server + ################################################################################################################ + main_thread = await self.debugger_impl.connect_to_debugger_server(self.config['pid'], True) + logging.info(f'Connect to the debugger server of instance: {main_thread.instance_id}') + ################################################################################################################ + # main thread: Runtime.enable + ################################################################################################################ + await self.runtime_impl.send("Runtime.enable", main_thread) + ################################################################################################################ + # main thread: Debugger.enable + ################################################################################################################ + await self.debugger_impl.send("Debugger.enable", main_thread) + ################################################################################################################ + # main thread: Runtime.runIfWaitingForDebugger + ################################################################################################################ + await self.runtime_impl.send("Runtime.runIfWaitingForDebugger", main_thread) + ################################################################################################################ + # main thread: Debugger.scriptParsed + ################################################################################################################ + start_time = datetime.now() + response = await self.debugger_impl.recv("Debugger.scriptParsed", main_thread) + assert response['params']['url'] == self.config['file_path']['entry_ability'] + assert response['params']['endLine'] == 0 + ################################################################################################################ + # main thread: Debugger.paused + ################################################################################################################ + response = await self.debugger_impl.recv("Debugger.paused", main_thread) + end_time = datetime.now() + Utils.add_time_data("Debugger.await_js", 10, 5,(end_time - start_time).microseconds // 1000) + assert response['params']['callFrames'][0]['url'] == self.config['file_path']['entry_ability'] + assert response['params']['reason'] == 'Break on start' + ################################################################################################################ + # main thread: Debugger.resume + ################################################################################################################ + await self.debugger_impl.send("Debugger.resume", main_thread) + ################################################################################################################ + # main thread: Debugger.scriptParsed + ################################################################################################################ + start_time = datetime.now() + response = await self.debugger_impl.recv("Debugger.scriptParsed", main_thread) + assert response['params']['url'] == self.config['file_path']['Test1'] + assert response['params']['endLine'] == 0 + ################################################################################################################ + # main thread: Debugger.paused + ################################################################################################################ + response = await self.debugger_impl.recv("Debugger.paused", main_thread) + end_time = datetime.now() + Utils.add_time_data("Debugger.await_js", 10, 5, (end_time - start_time).microseconds // 1000) + assert response['params']['callFrames'][0]['url'] == self.config['file_path']['Test1'] + assert response['params']['reason'] == 'Break on start' + ################################################################################################################ + # main thread: Debugger.resume + ################################################################################################################ + await self.debugger_impl.send("Debugger.resume", main_thread) + ################################################################################################################ + # main thread: Debugger.scriptParsed + ################################################################################################################ + start_time = datetime.now() + response = await self.debugger_impl.recv("Debugger.scriptParsed", main_thread) + assert response['params']['url'] == self.config['file_path']['Test2'] + assert response['params']['endLine'] == 0 + ################################################################################################################ + # main thread: Debugger.paused + ################################################################################################################ + response = await self.debugger_impl.recv("Debugger.paused", main_thread) + end_time = datetime.now() + Utils.add_time_data("Debugger.await_js", 10, 5, (end_time - start_time).microseconds // 1000) + assert response['params']['callFrames'][0]['url'] == self.config['file_path']['Test2'] + assert response['params']['reason'] == 'Break on start' + ################################################################################################################ + # main thread: Debugger.resume + ################################################################################################################ + await self.debugger_impl.send("Debugger.resume", main_thread) + ################################################################################################################ + # main thread: Debugger.scriptParsed + ################################################################################################################ + start_time = datetime.now() + response = await self.debugger_impl.recv("Debugger.scriptParsed", main_thread) + assert response['params']['url'] == self.config['file_path']['Test3'] + assert response['params']['endLine'] == 0 + ################################################################################################################ + # main thread: Debugger.paused + ################################################################################################################ + response = await self.debugger_impl.recv("Debugger.paused", main_thread) + end_time = datetime.now() + Utils.add_time_data("Debugger.await_js", 10, 5, (end_time - start_time).microseconds // 1000) + assert response['params']['callFrames'][0]['url'] == self.config['file_path']['Test3'] + assert response['params']['reason'] == 'Break on start' + ################################################################################################################ + # main thread: Debugger.resume + ################################################################################################################ + await self.debugger_impl.send("Debugger.resume", main_thread) + ################################################################################################################ + # main thread: Debugger.scriptParsed + ################################################################################################################ + start_time = datetime.now() + response = await self.debugger_impl.recv("Debugger.scriptParsed", main_thread) + assert response['params']['url'] == self.config['file_path']['Test4'] + assert response['params']['endLine'] == 0 + ################################################################################################################ + # main thread: Debugger.paused + ################################################################################################################ + response = await self.debugger_impl.recv("Debugger.paused", main_thread) + end_time = datetime.now() + Utils.add_time_data("Debugger.await_js", 10, 5, (end_time - start_time).microseconds // 1000) + assert response['params']['callFrames'][0]['url'] == self.config['file_path']['Test4'] + assert response['params']['reason'] == 'Break on start' + ################################################################################################################ + # main thread: Debugger.resume + ################################################################################################################ + await self.debugger_impl.send("Debugger.resume", main_thread) + ################################################################################################################ + # main thread: Debugger.scriptParsed + ################################################################################################################ + start_time = datetime.now() + response = await self.debugger_impl.recv("Debugger.scriptParsed", main_thread) + assert response['params']['url'] == self.config['file_path']['index'] + assert response['params']['endLine'] == 0 + ################################################################################################################ + # main thread: Debugger.paused + ################################################################################################################ + response = await self.debugger_impl.recv("Debugger.paused", main_thread) + end_time = datetime.now() + Utils.add_time_data("Debugger.await_js", 10, 5, (end_time - start_time).microseconds // 1000) + assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] + assert response['params']['reason'] == 'Break on start' + ################################################################################################################ + # main thread: Debugger.getPossibleAndSetBreakpointByUrl + ################################################################################################################ + locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=84), + debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=95), + debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=122), + debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=129),] + params = debugger.SetBreakpointsLocations(locations) + response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", + main_thread, params) + assert response['result']['locations'][0]['id'] == 'id:84:0:' + self.config['file_path']['index'] + assert response['result']['locations'][1]['id'] == 'id:95:0:' + self.config['file_path']['index'] + assert response['result']['locations'][2]['id'] == 'id:122:0:' + self.config['file_path']['index'] + assert response['result']['locations'][3]['id'] == 'id:129:0:' + self.config['file_path']['index'] + ################################################################################################################ + # main thread: Debugger.resume + ################################################################################################################ + await self.debugger_impl.send("Debugger.resume", main_thread) + ################################################################################################################ + # main thread: click on the screen + ################################################################################################################ + Application.click_on_middle() + ################################################################################################################ + # worker thread: connect the debugger server + ################################################################################################################ + worker_thread = await self.debugger_impl.connect_to_debugger_server(self.config['pid'], False) + logging.info(f'Connect to the debugger server of instance: {worker_thread.instance_id}') + ################################################################################################################ + # worker thread: Runtime.enable + ################################################################################################################ + await self.runtime_impl.send("Runtime.enable", worker_thread) + ################################################################################################################ + # worker thread: Debugger.enable + ################################################################################################################ + await self.debugger_impl.send("Debugger.enable", worker_thread) + ################################################################################################################ + # worker thread: Runtime.runIfWaitingForDebugger + ################################################################################################################ + await self.runtime_impl.send("Runtime.runIfWaitingForDebugger", worker_thread) + ################################################################################################################ + # worker thread: Debugger.scriptParsed + ################################################################################################################ + response_worker = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread) + assert response_worker['params']['url'] == self.config['file_path']['worker'] + assert response_worker['params']['endLine'] == 0 + ################################################################################################################ + # worker thread: Debugger.paused + ################################################################################################################ + response_worker = await self.debugger_impl.recv("Debugger.paused", worker_thread) + assert response_worker['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] + assert response_worker['params']['reason'] == 'Break on start' + ################################################################################################################ + # worker thread: Debugger.removeBreakpointsByUrl + ################################################################################################################ + params = debugger.RemoveBreakpointsUrl(self.config['file_path']['worker']) + await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", worker_thread, params) + ################################################################################################################ + # worker thread: Debugger.getPossibleAndSetBreakpointByUrl + ################################################################################################################ + locations = [] + line_numbers = [ + 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, + 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68 + ] + for line_number in line_numbers: + locations.append(debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=line_number)) + params_worker = debugger.SetBreakpointsLocations(locations) + for i in range(50): + response_worker = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", + worker_thread, params_worker) + for j in range(25): + expected_id = f'id:{44 + j}:0:' + self.config['file_path']['worker'] + assert response_worker['result']['locations'][j]['id'] == expected_id + params = debugger.RemoveBreakpointsUrl(self.config['file_path']['worker']) + await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", worker_thread, params) + ################################################################################################################ + # main thread: Debugger.paused, hit breakpoint + ################################################################################################################ + response = await self.debugger_impl.recv("Debugger.paused", main_thread) + assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] + assert response['params']['hitBreakpoints'] == ['id:84:8:' + self.config['file_path']['index']] + ################################################################################################################ + # main thread: Debugger.evaluateOnCallFrame + ################################################################################################################ + params = debugger.EvaluateOnCallFrameParams( + 'UEFOREEAAAAAAAAADAACAFABAAAAAAAAAAAAAAIAAAA8AAAAAQAAAEwBAAAAAAAARAAAAAEAAABEAAAAmgAAAM0AAA' + 'B8AAAAUAEAAAIAAABsAAAAAgAAAHQAAAD/////////////////////mgAAAM0AAAB8AAAAjgAAACFkZWJ1Z2dlckdld' + 'FZhbHVlABV0YXNrTnVtYmVyADNMX0VTU2xvdE51bWJlckFubm90YXRpb247AAAAAACBQAAAAgAAF2Z1bmNfbWFpbl8wA' + 'BNMX0dMT0JBTDsAAAAAAAEAAQIAAAEA///AAAAAiAIBFwEAAAIABUABAAAGCgEAAAAVU2xvdE51bWJlcgAAAAEA/gAAAA' + 'QAAAA3CAMgAESARJFEom1hBGAEQgAAAGEFPgEAYQYCYQdgBSsCBgdkC2sBDwD/////DwACABkAAAA7AQAA') + for i in range(500): + start_time = datetime.now() + response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) + end_time = datetime.now() + Utils.add_time_data("Debugger.evaluateOnCallFrame", 10, 5, (end_time - start_time).microseconds // 1000) + ################################################################################################################ + # main thread: Debugger.GetProperties + ################################################################################################################ + params = runtime.GetPropertiesParams('0') + for i in range(500): + start_time = datetime.now() + response = await self.runtime_impl.send("Runtime.getProperties", main_thread, params) + end_time = datetime.now() + Utils.add_time_data("Debugger.getProperties", 10, 5, (end_time - start_time).microseconds // 1000) + ################################################################################################################ + # main thread: Debugger.stepOver + ################################################################################################################ + for i in range(500): + start_time = datetime.now() + await self.debugger_impl.send("Debugger.stepOver", main_thread) + response = await self.debugger_impl.recv("Debugger.paused", main_thread) + end_time = datetime.now() + Utils.add_time_data("Debugger.stepOver", 10, 5, (end_time - start_time).microseconds // 1000) + ################################################################################################################ + # main thread: Debugger.stepInto + ################################################################################################################ + for i in range(500): + start_time = datetime.now() + await self.debugger_impl.send("Debugger.stepInto", main_thread) + response = await self.debugger_impl.recv("Debugger.paused", main_thread) + end_time = datetime.now() + Utils.add_time_data("Debugger.stepInto", 10, 5, (end_time - start_time).microseconds // 1000) + ################################################################################################################ + # main thread: Debugger.stepOut + ################################################################################################################ + for i in range(500): + start_time = datetime.now() + await self.debugger_impl.send("Debugger.stepOut", main_thread) + response = await self.debugger_impl.recv("Debugger.paused", main_thread) + end_time = datetime.now() + Utils.add_time_data("Debugger.stepOut", 10, 5, (end_time - start_time).microseconds // 1000) + ################################################################################################################ + await self.debugger_impl.send("Debugger.resume", main_thread) + ################################################################################################################ + # main thread: Debugger.paused, hit breakpoint + ################################################################################################################ + response = await self.debugger_impl.recv("Debugger.paused", main_thread) + assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] + assert response['params']['hitBreakpoints'] == ['id:122:21:' + self.config['file_path']['index']] + ################################################################################################################ + # main thread: Debugger.BytecodePcChanged + ################################################################################################################ + for i in range(4): + start_time = datetime.now() + await self.debugger_impl.send("Debugger.stepOut", main_thread) + response = await self.debugger_impl.recv("Debugger.paused", main_thread) + end_time = datetime.now() + Utils.add_time_data("Debugger.BytecodePcChanged", 10, 5, (end_time - start_time).microseconds // 1000) + ################################################################################################################ + await self.debugger_impl.send("Debugger.resume", main_thread) + ################################################################################################################ + # main thread: Debugger.paused, hit breakpoint + ################################################################################################################ + response = await self.debugger_impl.recv("Debugger.paused", main_thread) + assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] + assert response['params']['hitBreakpoints'] == ['id:129:8:' + self.config['file_path']['index']] + ################################################################################################################ + # main thread: Debugger.SendAbleTest + ################################################################################################################ + for i in range(2000): + start_time = datetime.now() + await self.debugger_impl.send("Debugger.stepOut", main_thread) + response = await self.debugger_impl.recv("Debugger.paused", main_thread) + end_time = datetime.now() + Utils.add_time_data("Debugger.SendAbleTest", 10, 5, (end_time - start_time).microseconds // 1000) + ################################################################################################################ + # worker thread: Debugger.resume + ################################################################################################################ + await self.debugger_impl.send("Debugger.resume", worker_thread) + ################################################################################################################ + # worker thread: Debugger.disable + ################################################################################################################ + await self.debugger_impl.send("Debugger.disable", worker_thread) + ################################################################################################################ + # main thread: Debugger.disable + ################################################################################################################ + await self.debugger_impl.send("Debugger.disable", main_thread) + ################################################################################################################ + # close the websocket connections + ################################################################################################################ + await websocket.send_msg_to_debugger_server(worker_thread.instance_id, worker_thread.send_msg_queue, 'close') + await websocket.send_msg_to_debugger_server(main_thread.instance_id, main_thread.send_msg_queue, 'close') + await websocket.send_msg_to_connect_server('close') + ################################################################################################################ \ No newline at end of file diff --git a/test/autotest/scenario_test/test_singal_point_02.py b/test/autotest/scenario_test/test_singal_point_02.py new file mode 100644 index 0000000000000000000000000000000000000000..edefc89f78355b330d7fd680d42038407aac5669 --- /dev/null +++ b/test/autotest/scenario_test/test_singal_point_02.py @@ -0,0 +1,196 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Copyright (c) 2024 Huawei Device Co., Ltd. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Description: Scenario test case. +""" + +import logging +import os +import time + +import pytest + +from aw import Application +from aw import Utils +from aw import heap_profiler +from aw.api import debugger_api, runtime_api, heap_profiler_api + + +@pytest.mark.heap_profiler +@pytest.mark.timeout(80) +class TestSingalPoint02: + """ + 测试用例:Release应用IDE连续进行两次调优 + 测试步骤: + 1. 拉起应用,attach 主线程 + 2. 连接 connect server 和主线程 debugger server + 3. 所有线程使能 Runtime(Runtime.enable) + 4. 所有线程获取内存使用情况(Runtime.getHeapUsage) + 5. 所有线程启动 Allocation 录制(HeapProfiler.startTrackingHeapObjects) + 6. 所有线程获取内存使用情况(Runtime.getHeapUsage) + 7. 等待 10 秒后关闭 Allocation 录制,获取数据(HeapProfiler.stopTrackingHeapObjects) + 8. 重新使得所有线程启动 Allocation 录制(HeapProfiler.startTrackingHeapObjects) + 9. 重新使得所有线程获取内存使用情况(Runtime.getHeapUsage) + 10. 等待 10 秒后关闭 Allocation 录制,获取数据(HeapProfiler.stopTrackingHeapObjects) + 11. 关闭主线程 debugger server 和 connect server 连接 + """ + + def setup_method(self): + logging.info('Start running TestReleaseProfilerAllocation01: setup') + + self.log_path = rf'{os.path.dirname(__file__)}\..\log' + self.hilog_file_name = 'test_release_profiler_allocation_01.hilog.txt' + self.id_generator = Utils.message_id_generator() + + # receive the hilog before the test start + Utils.clear_fault_log() + self.hilog_process, self.write_thread = Utils.save_hilog(log_path=self.log_path, + file_name=self.hilog_file_name, + debug_on=True) + + def teardown_method(self): + Application.uninstall(self.config['bundle_name']) + + # terminate the hilog receive process after the test done + time.sleep(3) + self.hilog_process.stdout.close() + self.hilog_process.terminate() + self.hilog_process.wait() + self.write_thread.join() + + Utils.save_fault_log(log_path=self.log_path) + logging.info('TestReleaseProfilerAllocation01 done') + + def test(self, test_suite_singal_02_debug): + logging.info('Start running TestReleaseProfileAllocation01: test') + self.config = test_suite_singal_02_debug + websocket = self.config['websocket'] + taskpool = self.config['taskpool'] + pid = self.config['pid'] + self.debugger_impl = debugger_api.DebuggerImpl(self.id_generator, websocket) + self.runtime_impl = runtime_api.RuntimeImpl(self.id_generator, websocket) + self.heap_profiler_impl = heap_profiler_api.HeapProfilerImpl(self.id_generator, websocket) + + Application.attach(self.config['bundle_name']) + taskpool.submit(websocket.main_task(taskpool, self.procedure, pid)) + taskpool.await_taskpool() + taskpool.task_join() + if taskpool.task_exception: + raise taskpool.task_exception + + async def procedure(self, websocket): + ################################################################################################################ + # main thread: connect the debugger server + ################################################################################################################ + main_thread = await self.debugger_impl.connect_to_debugger_server(self.config['pid'], True) + logging.info(f'Connect to the debugger server of instance: {main_thread.instance_id}') + ################################################################################################################ + # worker thread: connect the debugger server + ################################################################################################################ + worker_thread_1 = await self.debugger_impl.connect_to_debugger_server(self.config['pid'], False) + logging.info(f'Connect to the debugger server of instance: {worker_thread_1.instance_id}') + worker_thread_2 = await self.debugger_impl.connect_to_debugger_server(self.config['pid'], False) + logging.info(f'Connect to the debugger server of instance: {worker_thread_2.instance_id}') + ################################################################################################################ + # main thread: Runtime.enable + ################################################################################################################ + await self.runtime_impl.send("Runtime.enable", main_thread) + ################################################################################################################ + # worker thread: Runtime.enable + ################################################################################################################ + await self.runtime_impl.send("Runtime.enable", worker_thread_1) + await self.runtime_impl.send("Runtime.enable", worker_thread_2) + ################################################################################################################ + # main thread: Runtime.getHeapUsage + ################################################################################################################ + await self.runtime_impl.send("Runtime.getHeapUsage", main_thread) + ################################################################################################################ + # worker thread: Runtime.getHeapUsage + ################################################################################################################ + await self.runtime_impl.send("Runtime.getHeapUsage", worker_thread_1) + await self.runtime_impl.send("Runtime.getHeapUsage", worker_thread_2) + ################################################################################################################ + # main thread: HeapProfiler.startTrackingHeapObjects + ################################################################################################################ + params = heap_profiler.TrackingHeapObjectsParams(False) + await self.heap_profiler_impl.send("HeapProfiler.startTrackingHeapObjects", main_thread, params) + ################################################################################################################ + # worker thread: HeapProfiler.startTrackingHeapObjects + ################################################################################################################ + params = heap_profiler.TrackingHeapObjectsParams(False) + await self.heap_profiler_impl.send("HeapProfiler.startTrackingHeapObjects", worker_thread_1, params) + await self.heap_profiler_impl.send("HeapProfiler.startTrackingHeapObjects", worker_thread_2, params) + ################################################################################################################ + # main thread: Debugger.disable + ################################################################################################################ + await self.debugger_impl.send("Debugger.disable", main_thread) + ################################################################################################################ + # worker thread: Debugger.disable + ################################################################################################################ + await self.debugger_impl.send("Debugger.disable", worker_thread_1) + await self.debugger_impl.send("Debugger.disable", worker_thread_2) + ################################################################################################################ + # all thread: sleep 10 seconds + ################################################################################################################ + time.sleep(10) + ################################################################################################################ + # main thread: Runtime.getHeapUsage + ################################################################################################################ + await self.runtime_impl.send("Runtime.getHeapUsage", main_thread) + ################################################################################################################ + # worker thread: Runtime.getHeapUsage + ################################################################################################################ + await self.runtime_impl.send("Runtime.getHeapUsage", worker_thread_1) + await self.runtime_impl.send("Runtime.getHeapUsage", worker_thread_2) + ################################################################################################################ + # main thread: HeapProfiler.stopTrackingHeapObjects + ################################################################################################################ + await self.heap_profiler_impl.send("HeapProfiler.stopTrackingHeapObjects", main_thread) + ################################################################################################################ + # worker thread: HeapProfiler.stopTrackingHeapObjects + ################################################################################################################ + await self.heap_profiler_impl.send("HeapProfiler.stopTrackingHeapObjects", worker_thread_1) + await self.heap_profiler_impl.send("HeapProfiler.stopTrackingHeapObjects", worker_thread_2) + ################################################################################################################ + # worker thread: HeapProfiler.startTrackingHeapObjects + ################################################################################################################ + params = heap_profiler.TrackingHeapObjectsParams(False) + await self.heap_profiler_impl.send("HeapProfiler.startTrackingHeapObjects", worker_thread_1, params) + await self.heap_profiler_impl.send("HeapProfiler.startTrackingHeapObjects", worker_thread_2, params) + ################################################################################################################ + # all thread: sleep 10 seconds + ################################################################################################################ + time.sleep(10) + ################################################################################################################ + # worker thread: Runtime.getHeapUsage + ################################################################################################################ + await self.runtime_impl.send("Runtime.getHeapUsage", worker_thread_1) + await self.runtime_impl.send("Runtime.getHeapUsage", worker_thread_2) + ################################################################################################################ + # worker thread: HeapProfiler.stopTrackingHeapObjects + ################################################################################################################ + await self.heap_profiler_impl.send("HeapProfiler.stopTrackingHeapObjects", worker_thread_1) + await self.heap_profiler_impl.send("HeapProfiler.stopTrackingHeapObjects", worker_thread_2) + ################################################################################################################ + # close the websocket connections + ################################################################################################################ + await websocket.send_msg_to_debugger_server(worker_thread_1.instance_id, worker_thread_1.send_msg_queue, + 'close') + await websocket.send_msg_to_debugger_server(worker_thread_2.instance_id, worker_thread_2.send_msg_queue, + 'close') + await websocket.send_msg_to_debugger_server(main_thread.instance_id, main_thread.send_msg_queue, 'close') + await websocket.send_msg_to_connect_server('close') + ################################################################################################################ \ No newline at end of file