diff --git a/test/autotest/scenario_test/conftest.py b/test/autotest/scenario_test/conftest.py deleted file mode 100644 index 97f8597fade651b6f2b6794a70a2f2ff68623eb0..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/conftest.py +++ /dev/null @@ -1,471 +0,0 @@ -#!/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: Fixtures of pytest. -""" - -import logging -import os - -import pytest - -from aw import Application, Fport, WebSocket, TaskPool, Utils - - -@pytest.fixture(scope='class') -def test_suite_main_instance_01_debug(): - logging.info('running main_instance_01 in debug mode') - config = { - 'start_mode': '-D', - 'connect_server_port': 15700, - 'debugger_server_port': 15701, - 'bundle_name': 'com.example.mainInstance01', - 'hap_name': 'MainInstance01.hap', - 'hap_path': rf'{os.path.dirname(__file__)}\..\resource\MainInstance01.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', - } - } - launch_hap(config) - return config - - -@pytest.fixture(scope='class') -def test_suite_main_instance_02_debug(): - logging.info('running main_instance_02 in debug mode') - config = { - 'start_mode': '-D', - 'connect_server_port': 15702, - 'debugger_server_port': 15703, - 'bundle_name': 'com.example.mainInstance02', - 'hap_name': 'MainInstance02.hap', - 'hap_path': rf'{os.path.dirname(__file__)}\..\resource\MainInstance02.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', - } - } - launch_hap(config) - return config - - -@pytest.fixture(scope='class') -def test_suite_main_instance_03_debug(): - logging.info('running main_instance_03 in debug mode') - config = { - 'start_mode': '-D', - 'connect_server_port': 15704, - 'debugger_server_port': 15705, - 'bundle_name': 'com.example.mainInstance03', - 'hap_name': 'MainInstance03.hap', - 'hap_path': rf'{os.path.dirname(__file__)}\..\resource\MainInstance03.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', - } - } - launch_hap(config) - return config - - -@pytest.fixture(scope='class') -def test_suite_main_instance_04_debug(): - logging.info('running main_instance_04 in debug mode') - config = { - 'start_mode': '-D', - 'connect_server_port': 15706, - 'debugger_server_port': 15707, - 'bundle_name': 'com.example.mainInstance04', - 'hap_name': 'MainInstance04.hap', - 'hap_path': rf'{os.path.dirname(__file__)}\..\resource\MainInstance04.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', - } - } - launch_hap(config) - return config - - -@pytest.fixture(scope='class') -def test_suite_worker_08_debug(): - logging.info('running worker_08 in debug mode') - config = { - 'start_mode': '-D', - 'connect_server_port': 15698, - 'debugger_server_port': 15699, - 'bundle_name': 'com.example.multiWorker08', - 'hap_name': 'MultiWorker08.hap', - 'hap_path': rf'{os.path.dirname(__file__)}\..\resource\MultiWorker08.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_07_debug(): - logging.info('running worker_07 in debug mode') - config = { - 'start_mode': '-D', - 'connect_server_port': 15696, - 'debugger_server_port': 15697, - 'bundle_name': 'com.example.multiWorker07', - 'hap_name': 'MultiWorker07.hap', - 'hap_path': rf'{os.path.dirname(__file__)}\..\resource\MultiWorker07.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_06_debug(): - logging.info('running worker_06 in debug mode') - config = { - 'start_mode': '-D', - 'connect_server_port': 15694, - 'debugger_server_port': 15695, - 'bundle_name': 'com.example.multiWorker06', - 'hap_name': 'MultiWorker06.hap', - 'hap_path': rf'{os.path.dirname(__file__)}\..\resource\MultiWorker06.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_05_debug(): - logging.info('running worker_05 in debug mode') - config = { - 'start_mode': '-D', - 'connect_server_port': 15692, - 'debugger_server_port': 15693, - 'bundle_name': 'com.example.multiWorker05', - 'hap_name': 'MultiWorker05.hap', - 'hap_path': rf'{os.path.dirname(__file__)}\..\resource\MultiWorker05.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_04_debug(): - logging.info('running worker_04 in debug mode') - config = { - 'start_mode': '-D', - 'connect_server_port': 15690, - 'debugger_server_port': 15691, - 'bundle_name': 'com.example.multiWorker04', - 'hap_name': 'MultiWorker04.hap', - 'hap_path': rf'{os.path.dirname(__file__)}\..\resource\MultiWorker04.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_03_debug(): - logging.info('running worker_03 in debug mode') - config = { - 'start_mode': '-D', - 'connect_server_port': 15688, - 'debugger_server_port': 15689, - 'bundle_name': 'com.example.multiWorker03', - 'hap_name': 'MultiWorker03.hap', - 'hap_path': rf'{os.path.dirname(__file__)}\..\resource\MultiWorker03.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') - config = { - 'start_mode': '-p dumpheap', - 'connect_server_port': 15686, - 'debugger_server_port': 15687, - 'bundle_name': 'com.example.multiWorker02', - 'hap_name': 'MultiWorker02.hap', - 'hap_path': rf'{os.path.dirname(__file__)}\..\resource\MultiWorker02.hap' - } - launch_hap(config) - return config - - -@pytest.fixture(scope='class') -def test_suite_worker_02_profile_jsperf(): - logging.info('running worker_02 in profile mode') - config = { - 'start_mode': '-p profile jsperf', - 'connect_server_port': 15686, - 'debugger_server_port': 15687, - 'bundle_name': 'com.example.multiWorker02', - 'hap_name': 'MultiWorker02.hap', - 'hap_path': rf'{os.path.dirname(__file__)}\..\resource\MultiWorker02.hap' - } - launch_hap(config) - return config - - -@pytest.fixture(scope='class') -def test_suite_worker_02(): - logging.info('running worker_02 in default mode') - config = { - 'start_mode': None, - 'connect_server_port': 15684, - 'debugger_server_port': 15685, - 'bundle_name': 'com.example.multiWorker02', - 'hap_name': 'MultiWorker02.hap', - 'hap_path': rf'{os.path.dirname(__file__)}\..\resource\MultiWorker02.hap' - } - launch_hap(config) - return config - - -@pytest.fixture(scope='class') -def test_suite_worker_01_debug(): - logging.info('running worker_01 in debug mode') - config = { - 'start_mode': '-D', - 'connect_server_port': 15682, - 'debugger_server_port': 15683, - 'bundle_name': 'com.example.multiWorker01', - 'hap_name': 'MultiWorker01.hap', - 'hap_path': rf'{os.path.dirname(__file__)}\..\resource\MultiWorker01.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_01(): - logging.info('running worker_01 in default mode') - config = { - 'start_mode': None, - 'connect_server_port': 15680, - 'debugger_server_port': 15681, - 'bundle_name': 'com.example.multiWorker01', - 'hap_name': 'MultiWorker01.hap', - 'hap_path': rf'{os.path.dirname(__file__)}\..\resource\MultiWorker01.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_native_02_debug(): - logging.info('running native_02 in debug mode') - config = { - 'start_mode': '-D', - 'connect_server_port': 15678, - 'debugger_server_port': 15679, - 'bundle_name': 'com.example.native02', - 'hap_name': 'Native02.hap', - 'hap_path': rf'{os.path.dirname(__file__)}\..\resource\Native02.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_native_01_debug(): - logging.info('running native_01 in debug mode') - config = { - 'start_mode': '-D', - 'connect_server_port': 15676, - 'debugger_server_port': 15677, - 'bundle_name': 'com.example.native01', - 'hap_name': 'Native01.hap', - 'hap_path': rf'{os.path.dirname(__file__)}\..\resource\Native01.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' - } - } - launch_hap(config) - return config - - -@pytest.fixture(scope='class') -def test_suite_taskpool_02_debug(): - logging.info('running taskpool_02 in debug mode') - config = { - 'start_mode': '-D', - 'connect_server_port': 15674, - 'debugger_server_port': 15675, - 'bundle_name': 'com.example.taskPool02', - 'hap_name': 'TaskPool02.hap', - 'hap_path': rf'{os.path.dirname(__file__)}\..\resource\TaskPool02.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', - } - } - launch_hap(config) - return config - - -@pytest.fixture(scope='class') -def test_suite_taskpool_01(): - logging.info('running taskpool_01 in default mode') - config = { - 'start_mode': None, - 'connect_server_port': 15672, - 'debugger_server_port': 15673, - 'bundle_name': 'com.example.taskPool01', - 'hap_name': 'TaskPool01.hap', - 'hap_path': rf'{os.path.dirname(__file__)}\..\resource\TaskPool01.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', - } - } - launch_hap(config) - return config - - -@pytest.fixture(scope='class') -def test_suite_taskpool_01_debug(): - logging.info('running taskpool_01 in debug mode') - config = { - 'start_mode': '-D', - 'connect_server_port': 15670, - 'debugger_server_port': 15671, - 'bundle_name': 'com.example.taskPool01', - 'hap_name': 'TaskPool01.hap', - 'hap_path': rf'{os.path.dirname(__file__)}\..\resource\TaskPool01.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', - } - } - launch_hap(config) - return config - - -@pytest.fixture(scope='class') -def test_suite_hotreload_har_hsp_01(): - logging.info('running application HotReloadHarHsp01') - config = { - 'bundle_name': 'com.example.HotReloadHarHsp01', - 'hap_dir': rf'{os.path.dirname(__file__)}\..\resource\HotReloadHarHsp01', - 'hap_entry_name': 'HotReloadHarHsp01.hap', - 'hsp_discovery_name': 'HspDiscovery.hsp', - - 'local_hqf_entry_path': rf'{os.path.dirname(__file__)}\..\resource\HotReloadHarHsp01.hqf', - 'remote_hqf_entry_path': '/data/HotReloadHarHsp01.hqf', - 'hqf_entry_name': 'HotReloadHarHsp01.hqf', - - 'local_hqf_discovery_path': rf'{os.path.dirname(__file__)}\..\resource\HspDiscovery.hqf', - 'remote_hqf_discovery_path': '/data/HspDiscovery.hqf', - 'hqf_discovery_name': 'HspDiscovery.hap', - } - pid = Application.launch_application(config['bundle_name'], config['hap_dir']) - assert pid != 0, logging.error(f'Pid of {config["bundle_name"]} is 0!') - config['pid'] = pid - return config - - -@pytest.fixture(scope='class') -def test_suite_hotreload_pages_01(): - logging.info('running application HotReloadPages01') - config = { - 'bundle_name': 'com.example.HotReloadPages01', - 'hap_path': rf'{os.path.dirname(__file__)}\..\resource\HotReloadPages01.hap', - - 'hqf_01_name': 'HotReloadPages01.01.hqf', - 'local_hqf_01_path': rf'{os.path.dirname(__file__)}\..\resource\HotReloadPages01.01.hqf', - 'remote_hqf_01_path': '/data/HotReloadPages01.01.hqf', - - 'hqf_02_name': 'HotReloadPages01.02.hqf', - 'local_hqf_02_path': rf'{os.path.dirname(__file__)}\..\resource\HotReloadPages01.02.hqf', - 'remote_hqf_02_path': '/data/HotReloadPages01.02.hqf', - - 'hqf_03_name': 'HotReloadPages01.03.hqf', - 'local_hqf_03_path': rf'{os.path.dirname(__file__)}\..\resource\HotReloadPages01.03.hqf', - 'remote_hqf_03_path': '/data/HotReloadPages01.03.hqf', - - 'hqf_04_name': 'HotReloadPages01.04.hqf', - 'local_hqf_04_path': rf'{os.path.dirname(__file__)}\..\resource\HotReloadPages01.04.hqf', - 'remote_hqf_04_path': '/data/HotReloadPages01.04.hqf', - } - pid = Application.launch_application(config['bundle_name'], config['hap_path']) - assert pid != 0, logging.error(f'Pid of {config["bundle_name"]} is 0!') - config['pid'] = pid - return config - - -def launch_hap(config): - pid = Application.launch_application(config['bundle_name'], config['hap_path'], start_mode=config['start_mode']) - assert pid != 0, logging.error(f'Pid of {config["hap_name"]} is 0!') - config['pid'] = pid - - Fport.clear_fport() - connect_server_port = Fport.fport_connect_server(config['connect_server_port'], - config['pid'], - config['bundle_name']) - assert connect_server_port > 0, logging.error('Failed to fport connect server for 3 times, ' - 'the port is very likely occupied') - config['connect_server_port'] = connect_server_port - - config['websocket'] = WebSocket(config['connect_server_port'], config['debugger_server_port']) - config['taskpool'] = TaskPool() diff --git a/test/autotest/scenario_test/test_attach_task_pool.py b/test/autotest/scenario_test/test_attach_task_pool.py deleted file mode 100644 index 297ce29fb835c29c0881b4431b6b85817ef67d9b..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_attach_task_pool.py +++ /dev/null @@ -1,263 +0,0 @@ -#!/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 debugger, runtime -from aw.api import debugger_api, runtime_api - - -@pytest.mark.debug -@pytest.mark.timeout(60) -class TestAttachTaskPool: - """ - 测试用例:多 task 实例 attach 调试 - 测试步骤: - 1. 连接 connect server 和主线程 debugger server - 2. 连接子线程 debugger server,用于执行 task 任务 - 3. 所有线程使能 Runtime 和 Debugger - 4. 主线程 Index.ts 文件设置断点(Debugger.getPossibleAndSetBreakpointByUrl) - 5. 触发点击事件,主线程命中断点 - 6. 子线程 Index.ts 文件设置断点(Debugger.getPossibleAndSetBreakpointByUrl) - 7. 子线程 resume,命中断点(Debugger.resume) - 8. 子线程 getProperties,返回给定对象的属性(Runtime.getProperties) - 9. 子线程 stepOut,主线程命中断点(Debugger.stepOut) - 10. 主线程 getProperties(Runtime.getProperties) - 11. 主线程 resume(Debugger.resume) - 11. 子线程命中断点后 resume(Debugger.resume) - 12. 关闭所有线程 debugger server 和 connect server 连接 - 关键代码: - Index.ets - @Concurrent - function add(args1, args2) { - return args1 + args2 - } - @Concurrent - function sub(args1, args2) { - return args1 - args2 - } - let taskAdd = new taskpool.Task(add, 200, 100) - let taskSub = new taskpool.Task(sub, 200, 100) - async function taskpoolTest() { - let valueAdd = await taskpool.execute(taskAdd) - let valueSub = await taskpool.execute(taskSub) - } - .OnClick(() => { - taskpoolTest() - }) - """ - - def setup_method(self): - logging.info('Start running TestAttachTaskPool: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_attach_task_pool.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('TestAttachTaskPool done') - - def test(self, test_suite_taskpool_01): - logging.info('Start running TestAttachTaskPool: test') - self.config = test_suite_taskpool_01 - 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) - - 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 = 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}') - ################################################################################################################ - # 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) - ################################################################################################################ - # 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) - ################################################################################################################ - # 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) - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=10), - debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=17), - debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=25)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:10:0:' + self.config['file_path']['index'] - assert response['result']['locations'][1]['id'] == 'id:17:0:' + self.config['file_path']['index'] - assert response['result']['locations'][2]['id'] == 'id:25:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: click on the screen - ################################################################################################################ - Application.click_on_middle() - ################################################################################################################ - # worker thread: Debugger.scriptParsed - ################################################################################################################ - response = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread) - assert response['params']['url'] == self.config['file_path']['index'] - assert response['params']['endLine'] == 0 - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # worker thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", worker_thread, params) - ################################################################################################################ - # worker thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=10), - debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=17), - debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=25)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread, params) - assert response['result']['locations'][0]['id'] == 'id:10:0:' + self.config['file_path']['index'] - assert response['result']['locations'][1]['id'] == 'id:17:0:' + self.config['file_path']['index'] - assert response['result']['locations'][2]['id'] == 'id:25:0:' + self.config['file_path']['index'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:10:14:' + self.config['file_path']['index']] - ################################################################################################################ - # worker thread: Runtime.getProperties - ################################################################################################################ - params = runtime.GetPropertiesParams('0') - response = await self.runtime_impl.send("Runtime.getProperties", worker_thread, params) - assert response['result']['result'][0]['name'] == 'add' - assert response['result']['result'][0]['value']['type'] == 'function' - ################################################################################################################ - # worker thread: Debugger.stepOut - ################################################################################################################ - await self.debugger_impl.send("Debugger.stepOut", worker_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:25:4:' + self.config['file_path']['index']] - ################################################################################################################ - # main thread: Runtime.getProperties - ################################################################################################################ - params = runtime.GetPropertiesParams('0') - response = await self.runtime_impl.send("Runtime.getProperties", main_thread, params) - assert response['result']['result'][0]['name'] == 'taskpoolTest' - assert response['result']['result'][0]['value']['type'] == 'function' - assert response['result']['result'][1]['name'] == 'valueSub' - assert response['result']['result'][1]['value']['type'] == 'undefined' - assert response['result']['result'][2]['name'] == 'valueAdd' - assert response['result']['result'][2]['value']['type'] == 'number' - assert response['result']['result'][2]['value']['description'] == '300' - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - ################################################################################################################ - # worker thread: Debugger.paused - ################################################################################################################ - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['hitBreakpoints'] == ['id:17:14:' + self.config['file_path']['index']] - ################################################################################################################ - # 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_attach_worker_step.py b/test/autotest/scenario_test/test_attach_worker_step.py deleted file mode 100644 index ed45ba6b0b6705e6170beb7d93b93259fadf6dff..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_attach_worker_step.py +++ /dev/null @@ -1,328 +0,0 @@ -#!/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 debugger -from aw.api import debugger_api, runtime_api - - -@pytest.mark.debug -@pytest.mark.timeout(60) -class TestAttachWorkerStep: - """ - 测试用例:多实例 attach 调试,执行单步操作进行跨线程通信 - 测试步骤: - 1. 拉起应用,attach 主线程 - 2. 连接 connect server 和主线程 debugger server - 3. 创建两个子线程,连接子线程 debugger server - 4. 所有线程使能 Runtime 和 Debugger - 5. 主线程 Index.ts 文件设置断点(Debugger.getPossibleAndSetBreakpointByUrl) - 6. 触发点击事件,主线程命中断点 - 7. 销毁其中一个子线程 - 8. 子线程 Worker.ts 文件设置断点(Debugger.getPossibleAndSetBreakpointByUrl) - 9. 主线程 resume,暂停在下一断点(Debugger.resume) - 10. 重新创建一个子线程,使能并设置断点 - 11. 主线程 resume,发送消息给子线程,主线程暂停在下一断点(Debugger.resume) - 12. 子线程命中断点后 stepOut,发消息给主线程(Debugger.stepOut) - 13. 主线程 stepOver,发送消息给另一子线程,主线程暂停在下一行(Debugger.stepOver) - 14. 子线程命中断点后 resume,发消息给主线程(Debugger.resume) - 15. 销毁所有子线程,对应的 debugger server 连接断开 - 16. 关闭主线程 debugger server 和 connect server 连接 - 关键代码: - Index.ets - let workerIndex = 0 - function newWorker() {} // 创建一个子线程, workerIndex++ - function terminateWorker() {} // 销毁一个子线程, workerIndex-- - for (let i = 0; i < 2; i++) { - newWorker() - } - .OnClick(() => { - terminateWorker() - newWorker() - for (let i = 0; i < workerIndex; i++) { - workers[i].postMessage("hello world") - } - while (workerIndex) { - terminateWorker() - } - }) - Worker.ets - const workerPort: ThreadWorkerGlobalScope = worker.workerPort; - workerPort.onmessage = (e: MessageEvents) => { - workerPort.postMessage(e.data); - } - """ - - def setup_method(self): - logging.info('Start running TestAttachWorkerStep: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_attach_worker_step.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('TestAttachWorkerStep done') - - def test(self, test_suite_worker_01): - logging.info('Start running TestAttachWorkerStep: test') - self.config = test_suite_worker_01 - 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) - - 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}') - ################################################################################################################ - # worker thread: Runtime.enable - ################################################################################################################ - await self.runtime_impl.send("Runtime.enable", worker_thread_1) - await self.runtime_impl.send("Runtime.enable", worker_thread_2) - ################################################################################################################ - # worker thread: Debugger.enable - ################################################################################################################ - await self.debugger_impl.send("Debugger.enable", worker_thread_1) - await self.debugger_impl.send("Debugger.enable", worker_thread_2) - ################################################################################################################ - # worker thread: Runtime.runIfWaitingForDebugger - ################################################################################################################ - await self.runtime_impl.send("Runtime.runIfWaitingForDebugger", worker_thread_1) - await self.runtime_impl.send("Runtime.runIfWaitingForDebugger", worker_thread_2) - ################################################################################################################ - # 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.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=53), - debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=57)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:53:0:' + self.config['file_path']['index'] - assert response['result']['locations'][1]['id'] == 'id:57:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: click on the screen - ################################################################################################################ - Application.click_on_middle() - ################################################################################################################ - # 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:53:16:' + self.config['file_path']['index']] - ################################################################################################################ - # worker thread: destroy instance - ################################################################################################################ - response = await self.debugger_impl.destroy_instance() - if response['instanceId'] == worker_thread_1.instance_id: - worker_thread_1 = worker_thread_2 - ################################################################################################################ - # worker thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['worker']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", worker_thread_1, params) - ################################################################################################################ - # worker thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=11)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread_1, params) - assert response['result']['locations'][0]['id'] == 'id:11:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - 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:57:20:' + self.config['file_path']['index']] - ################################################################################################################ - # worker thread: connect the debugger server - ################################################################################################################ - 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}') - ################################################################################################################ - # worker thread: Runtime.enable - ################################################################################################################ - await self.runtime_impl.send("Runtime.enable", worker_thread_2) - ################################################################################################################ - # worker thread: Debugger.enable - ################################################################################################################ - await self.debugger_impl.send("Debugger.enable", worker_thread_2) - ################################################################################################################ - # worker thread: Runtime.runIfWaitingForDebugger - ################################################################################################################ - await self.runtime_impl.send("Runtime.runIfWaitingForDebugger", worker_thread_2) - # worker thread: Debugger.scriptParsed - response = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread_2) - assert response['params']['url'] == self.config['file_path']['worker'] - assert response['params']['endLine'] == 0 - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_2) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['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_2, params) - ################################################################################################################ - # worker thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=11)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread_2, params) - assert response['result']['locations'][0]['id'] == 'id:11:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread_2) - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:57:20:' + self.config['file_path']['index']] - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_1) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'Break on start' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread_1) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_1) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:11:4:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.stepOut - ################################################################################################################ - await self.debugger_impl.send("Debugger.stepOut", worker_thread_1) - ################################################################################################################ - # worker thread: Debugger.disable - ################################################################################################################ - await self.debugger_impl.send("Debugger.disable", worker_thread_1) - ################################################################################################################ - # main thread: Debugger.stepOver - ################################################################################################################ - await self.debugger_impl.send("Debugger.stepOver", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_2) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:11:4:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread_2) - ################################################################################################################ - # worker thread: Debugger.disable - ################################################################################################################ - await self.debugger_impl.send("Debugger.disable", worker_thread_2) - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - ################################################################################################################ - # worker thread: destroy instance - ################################################################################################################ - response = await self.debugger_impl.destroy_instance() - assert response['instanceId'] != self.config['pid'] - response = await self.debugger_impl.destroy_instance() - assert response['instanceId'] != self.config['pid'] - ################################################################################################################ - # main thread: Debugger.disable - ################################################################################################################ - await self.debugger_impl.send("Debugger.disable", main_thread) - ################################################################################################################ - # close the websocket connections - ################################################################################################################ - 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_hot_reload_01.py b/test/autotest/scenario_test/test_hot_reload_01.py deleted file mode 100644 index 211f52dc5703eb02510fe8dff54a699110c55c38..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_hot_reload_01.py +++ /dev/null @@ -1,142 +0,0 @@ -#!/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 - - -@pytest.mark.hot_reload -@pytest.mark.timeout(120) -class TestHotReload01: - """ - 测试用例:热重载基础功能, 重载文件impact HAR, 重载文件import HSP - 测试步骤: - 1、启动应用 - 2、点击屏幕中央,调用foo函数,输出日志: - Test Application HotReloadHarHsp01 => foo(): base function foo - Test Application HotReloadHarHsp01 => calc(): 8 - 3、触发热重载 - 4、Hilog输出:Load patch success! - 5、点击屏幕中央,调用foo函数,输出日志: - Test Application HotReloadHarHsp01 => foo(): patch function foo - Test Application HotReloadHarHsp01 => calc(): 48 - 测试应用代码示例: - import {Sum} from '@ohos/HarLibrary' - import {Multiply} from '@ohos/HspDiscovery' - 修改前: - .onClick(() => { - console.log('Test HotReload Application 01 => foo():', foo()) - console.log('Test HotReload Application 01 => calc():', calc(1, 2)) - }) - function foo() { - return "base function foo" - } - function calc(x: number, y: number): number { - return Multiply(Sum(x, x), Sum(y, y)) - } - 修改后:HotReloadHarHsp01.hap - .onClick(() => { - console.log('Test HotReload Application 01 => foo():', foo()) - console.log('Test HotReload Application 01 => calc():', calc(3, 4)) - }) - function foo() { - return "patch function foo" - } - function calc(x: number, y: number): number { - return Multiply(Sum(x, x), Sum(y, y)) - } - """ - - def setup_method(self): - logging.info('Start running test_hot_reload_01: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_hot_reload_01.hilog.txt' - self.hilog_file_path = os.path.join(self.log_path, self.hilog_file_name) - 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=False) - - 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('test_hot_reload_01 done') - - def test(self, test_suite_hotreload_har_hsp_01): - logging.info('Start running test_hot_reload_01: test') - self.config = test_suite_hotreload_har_hsp_01 - ################################################################################################################ - # trigger onclick event - ################################################################################################################ - logging.info(f'{"=" * 30} Before Hot Reload {"=" * 30}') - Application.click_on_middle() - time.sleep(3) - matched_log = Utils.search_hilog(self.hilog_file_path, key_world=b'base function foo') - logging.info(matched_log) - assert len(matched_log) == 1 - matched_log = Utils.search_hilog(self.hilog_file_path, - key_world=b'Test Application HotReloadHarHsp01 => calc(): 8') - logging.info(matched_log) - assert len(matched_log) == 1 - ################################################################################################################ - # perform Hot Reload - ################################################################################################################ - logging.info(f'{"=" * 30} Perform Hot Reload {"=" * 30}') - Utils.hdc_file_send(source=self.config['local_hqf_entry_path'], sink=self.config['remote_hqf_entry_path']) - Application.hot_reload(self.config['remote_hqf_entry_path']) - time.sleep(3) - matched_log = Utils.search_hilog(self.hilog_file_path, key_world=b'Load patch success!') - logging.info(matched_log) - assert len(matched_log) == 1 - ################################################################################################################ - # after hot reload - ################################################################################################################ - logging.info(f'{"=" * 30} After Hot Reload {"=" * 30}') - Application.click_on_middle() # trigger onclick event - time.sleep(3) - matched_log = Utils.search_hilog(self.hilog_file_path, key_world=b'patch function foo') - logging.info(matched_log) - assert len(matched_log) == 1 - matched_log = Utils.search_hilog(self.hilog_file_path, - key_world=b'Test Application HotReloadHarHsp01 => calc(): 48') - logging.info(matched_log) - assert len(matched_log) == 1 - ################################################################################################################ - # check if the application is running normally - ################################################################################################################ - pid = Application.get_pid(self.config['bundle_name']) - assert pid == self.config['pid'], logging.error(f'App is no longer running with pid: {pid}') diff --git a/test/autotest/scenario_test/test_hot_reload_02.py b/test/autotest/scenario_test/test_hot_reload_02.py deleted file mode 100644 index f1d11009058f8d253365f58b40926342636a79f5..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_hot_reload_02.py +++ /dev/null @@ -1,153 +0,0 @@ -#!/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 - - -@pytest.mark.hot_reload -@pytest.mark.timeout(120) -class TestHotReload02: - """ - 测试用例:热重载_重载页面未启动 - 测试步骤: - 1、启动应用,加载Index.ets页面 - 2、修改Index.ets,触发热重载,输出日志: - Test Application HotReloadPages01::Index => fontSize: 30 - 3、修改Index.ets和跳转页面Mine.ets,触发热重载,输出日志: - Test Application HotReloadPages01::Index => fontSize: 10 - 4、点击Index.ets屏幕中央,跳转到Mine.ets页面,点击Mine.ets页面屏幕中央,输出日志: - Test Application HotReloadPages01::Mine => add(): 3 - - 测试应用代码示例: - 修改前: - Index.ets - .fontSize(getFontSize()) - .onClick(() => { - router.pushUrl({'url': 'pages/Mine'}) - }) - function getFontSize() { - let fontSize = 50 - console.log("Test Application HotReloadPages01::Index => fontSize:", fontSize); - return fontSize - } - Mine.ets - .onClick(() => { - console.log("Test Application HotReloadPages01::Mine => add():", add(1, 2)); - }) - 第一次修改:HotReloadPages01.01.hqf - Index.ets - .fontSize(getFontSize()) - .onClick(() => { - router.pushUrl({'url': 'pages/Mine'}) - }) - function getFontSize() { - let fontSize = 30 - console.log("Test Application HotReloadPages01::Index => fontSize:", fontSize); - return fontSize - } - 第二次修改:HotReloadPages01.02.hqf - Index.ets - .fontSize(getFontSize()) - .onClick(() => { - router.pushUrl({'url': 'pages/Mine'}) - }) - function getFontSize() { - let fontSize = 10 - console.log("Test Application HotReloadPages01::Index => fontSize:", fontSize); - return fontSize - } - Mine.ets - .onClick(() => { - console.log("Test Application HotReloadPages01::Mine => add():", add(12, 34)); - }) - """ - - def setup_method(self): - logging.info('Start running test_hot_reload_02: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_hot_reload_02.hilog.txt' - self.hilog_file_path = os.path.join(self.log_path, self.hilog_file_name) - 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=False) - - 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('test_hot_reload_02 done') - - def test(self, test_suite_hotreload_pages_01): - logging.info('Start running test_hot_reload_02: test') - self.config = test_suite_hotreload_pages_01 - ################################################################################################################ - # 1st hot reload - ################################################################################################################ - logging.info(f'{"=" * 30} 1st Hot Reload {"=" * 30}') - Utils.hdc_file_send(source=self.config['local_hqf_01_path'], sink=self.config['remote_hqf_01_path']) - Application.hot_reload(self.config['remote_hqf_01_path']) - time.sleep(3) - matched_log = Utils.search_hilog(self.hilog_file_path, - key_world=b"Test Application HotReloadPages01::Index => fontSize: 30") - logging.info(matched_log) - assert len(matched_log) == 2 - ################################################################################################################ - # 2nd hot reload - ################################################################################################################ - logging.info(f'{"=" * 30} 2nd Hot Reload {"=" * 30}') - Utils.hdc_file_send(source=self.config['local_hqf_02_path'], sink=self.config['remote_hqf_02_path']) - Application.hot_reload(self.config['remote_hqf_02_path']) - time.sleep(3) - matched_log = Utils.search_hilog(self.hilog_file_path, - key_world=b"Test Application HotReloadPages01::Index => fontSize: 10") - logging.info(matched_log) - assert len(matched_log) == 2 - - Application.click_on_middle() # jump to the Mine page - time.sleep(3) - Application.click_on_middle() # trigger onclick event - time.sleep(3) - matched_log = Utils.search_hilog(self.hilog_file_path, - key_world=b"Test Application HotReloadPages01::Mine => add(): 3") - logging.info(matched_log) - assert len(matched_log) == 1 - ################################################################################################################ - # check if the application is running normally - ################################################################################################################ - pid = Application.get_pid(self.config['bundle_name']) - assert pid == self.config['pid'], logging.error(f'App is no longer running with pid: {pid}') diff --git a/test/autotest/scenario_test/test_hot_reload_03.py b/test/autotest/scenario_test/test_hot_reload_03.py deleted file mode 100644 index b26a4c35f2cfc1a759a390eb4b51536c7c5c223b..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_hot_reload_03.py +++ /dev/null @@ -1,159 +0,0 @@ -#!/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 - - -@pytest.mark.hot_reload -@pytest.mark.timeout(180) -class TestHotReload03: - """ - 测试用例:热重载_重载页面未启动 - 测试步骤: - 1、启动应用,加载Index页面 - 2、点击进入Mine页面,点击屏幕,输出日志: - Test Application HotReloadPages01::Mine => add(): 3 - 3、触发热重载,输出日志: - Test Application HotReloadPages01::Mine => add(): 46 - 4、返回Index页面,重新进入Mine页面,点击屏幕,输出日志: - Test Application HotReloadPages01::Mine => add(): 46 - 4、在Mine页面再次触发热重载,输出日志: - Test Application HotReloadPages01::Mine => add(): 134 - - 测试应用代码示例: - 修改前: - Index.ets - .fontSize(getFontSize()) - .onClick(() => { - router.pushUrl({'url': 'pages/Mine'}) - }) - function getFontSize() { - let fontSize = 50 - console.log("Test Application HotReloadPages01::Index => fontSize:", fontSize); - return fontSize - } - Mine.ets - .onClick(() => { - console.log("Test Application HotReloadPages01::Mine => add():", add(1, 2)); - }) - 第一次修改:HotReloadPages01.03.hqf - Mine.ets - .onClick(() => { - console.log("Test Application HotReloadPages01::Mine => add():", add(12, 34)); - }) - 第二次修改:HotReloadPages01.04.hqf - Mine.ets - .onClick(() => { - console.log("Test Application HotReloadPages01::Mine => add():", add(56, 78)); - }) - """ - - def setup_method(self): - logging.info('Start running test_hot_reload_03: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_hot_reload_03.hilog.txt' - self.hilog_file_path = os.path.join(self.log_path, self.hilog_file_name) - 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=False) - - 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('test_hot_reload_03 done') - - def test(self, test_suite_hotreload_pages_01): - logging.info('Start running test_hot_reload_03: test') - self.config = test_suite_hotreload_pages_01 - ################################################################################################################ - # jump to the Mine page - ################################################################################################################ - Application.click_on_middle() - time.sleep(3) - Application.click_on_middle() # trigger onclick event - time.sleep(3) - matched_log = Utils.search_hilog(self.hilog_file_path, - key_world=b"Test Application HotReloadPages01::Mine => add(): 3") - logging.info(matched_log) - assert len(matched_log) == 1 - ################################################################################################################ - # 1st hot reload - ################################################################################################################ - logging.info(f'{"=" * 30} 1st Hot Reload {"=" * 30}') - Utils.hdc_file_send(source=self.config['local_hqf_03_path'], sink=self.config['remote_hqf_03_path']) - Application.hot_reload(self.config['remote_hqf_03_path']) - time.sleep(3) - Application.click_on_middle() # trigger onclick event - time.sleep(3) - matched_log = Utils.search_hilog(self.hilog_file_path, - key_world=b"Test Application HotReloadPages01::Mine => add(): 46") - logging.info(matched_log) - assert len(matched_log) == 1 - ################################################################################################################ - # back to the Index page, the re-enter the Mine page - ################################################################################################################ - logging.info(f'{"=" * 30} Back and re-enter the Mine page {"=" * 30}') - Application.back() - time.sleep(3) - Application.click_on_middle() # jump to the Mine page - time.sleep(3) - Application.click_on_middle() # trigger onclick event - time.sleep(3) - matched_log = Utils.search_hilog(self.hilog_file_path, - key_world=b"Test Application HotReloadPages01::Mine => add(): 46") - logging.info(matched_log) - assert len(matched_log) == 2 # Counting the previous one. - ################################################################################################################ - # 2nd hot reload - ################################################################################################################ - logging.info(f'{"=" * 30} 2nd Hot Reload {"=" * 30}') - Utils.hdc_file_send(source=self.config['local_hqf_04_path'], sink=self.config['remote_hqf_04_path']) - Application.hot_reload(self.config['remote_hqf_04_path']) - time.sleep(3) - Application.click_on_middle() # trigger onclick event - time.sleep(3) - matched_log = Utils.search_hilog(self.hilog_file_path, - key_world=b"Test Application HotReloadPages01::Mine => add(): 134") - logging.info(matched_log) - assert len(matched_log) == 1 - ################################################################################################################ - # check if the application is running normally - ################################################################################################################ - pid = Application.get_pid(self.config['bundle_name']) - assert pid == self.config['pid'], logging.error(f'App is no longer running with pid: {pid}') diff --git a/test/autotest/scenario_test/test_main_breakpoint.py b/test/autotest/scenario_test/test_main_breakpoint.py deleted file mode 100644 index d27c82bb885632ded6d36f29e8ca93db231c35db..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_main_breakpoint.py +++ /dev/null @@ -1,185 +0,0 @@ -#!/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 debugger, runtime -from aw.api import debugger_api, runtime_api - - -@pytest.mark.debug -@pytest.mark.timeout(60) -class TestDebug21: - """ - 测试用例:单实例Sendable对象成员方法上普通断点的设置/取消 - 测试步骤: - 1. 连接 connect server 和主线程 debugger server - 2. 主线程使能 Runtime 和 Debugger - 3. 主线程运行等待的调试器 - 4. 主线程解析 entry_ability 和 index 文件 - 5. 主线程 Index.ts 文件设置断点并运行 - 6. 主线程 resume 验证是否正确命中断点 - 7. 关闭主线程 debugger server 和 connect server 连接 - 测试代码: - @Sendable - class TestClass { - desc: string = "XXXXXXXX";// 自定义设置类成员 - taskNum: number = XXXXXXXX; - get getTaskNum(): number {// 自定义设置类成员方法 - return this.taskNum;// 实例debug21断点 - } - } - const testInstance = new TestClass(); - let taskNumber = testInstance.getTaskNum; - """ - - def setup_method(self): - logging.info('Start running TestDebug21: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_debug_21.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('TestDebug21 done') - - def test(self, test_suite_main_instance_02_debug): - logging.info('Start running TestDebug21: test') - self.config = test_suite_main_instance_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) - - 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 - ################################################################################################################ - 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) - 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 - ################################################################################################################ - 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) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=74)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:74:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - 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:74:15:' + 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() - ################################################################################################################ - # main thread: Debugger.disable - ################################################################################################################ - await self.debugger_impl.send("Debugger.disable", main_thread) - ################################################################################################################ - # close the websocket connections - ################################################################################################################ - 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_main_breakpoint_class.py b/test/autotest/scenario_test/test_main_breakpoint_class.py deleted file mode 100644 index 8f857de447d91714ddfe395e7278a76a76523cf9..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_main_breakpoint_class.py +++ /dev/null @@ -1,192 +0,0 @@ -#!/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 debugger, runtime -from aw.api import debugger_api, runtime_api - - -@pytest.mark.debug -@pytest.mark.timeout(60) -class TestDebug22: - """ - 测试用例:单实例Sendable类信息查看 - 测试步骤: - 1. 连接 connect server 和主线程 debugger server - 2. 主线程使能 Runtime 和 Debugger - 3. 主线程运行等待的调试器 - 4. 主线程解析 entry_ability 和 index 文件 - 5. 主线程 Index.ts 文件设置断点 - 6. 主线程 resume 验证是否正确命中断点 - 7. 主线程查询类对象并验证是否携带 Sendable 标签 - 8. 关闭主线程 debugger server 和 connect server 连接 - 测试代码: - @Sendable - class TestClass { - desc: string = "XXXXXXXX";// 自定义设置类成员 - taskNum: number = XXXXXXXX; - get getTaskNum(): number {// 自定义设置类成员方法 - return this.taskNum; - } - } - const testInstance = new TestClass(); - let taskNumber = testInstance.getTaskNum;// 实例debug22断点查询处 - """ - - def setup_method(self): - logging.info('Start running TestDebug22: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_debug_22.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('TestDebug22 done') - - def test(self, test_suite_main_instance_02_debug): - logging.info('Start running TestDebug22: test') - self.config = test_suite_main_instance_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) - - 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 - ################################################################################################################ - 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) - 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 - ################################################################################################################ - 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) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=78)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:78:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - 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:78:17:' + self.config['file_path']['index']] - ################################################################################################################ - # main thread: Runtime.getProperties and check sendable - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('testInstance') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert '[Sendable]' in response['result']['result']['description'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - ################################################################################################################ - # main thread: click on the screen - ################################################################################################################ - Application.click_on_middle() - ################################################################################################################ - # main thread: Debugger.disable - ################################################################################################################ - await self.debugger_impl.send("Debugger.disable", main_thread) - ################################################################################################################ - # close the websocket connections - ################################################################################################################ - 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_main_drop_frame.py b/test/autotest/scenario_test/test_main_drop_frame.py deleted file mode 100644 index 14cd4637e98950e868adfa090c18208b23d629e9..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_main_drop_frame.py +++ /dev/null @@ -1,1320 +0,0 @@ -#!/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 debugger -from aw.api import debugger_api, runtime_api - - -@pytest.mark.debug -@pytest.mark.timeout(80) -class TestMainDropFrame: - """ - 测试用例:主线程 debug 调试之 drop frame - 测试步骤: - 1. 连接 connect server 和主线程 debugger server - 2. 主线程使能 Runtime 和 Debugger - 3. 创建子线程用于执行 task,连接子线程 debugger server - 4. 子线程使能 Runtime 和 Debugger - 5. 主线程 Index.ets 文件设置断点(Debugger.getPossibleAndSetBreakpointByUrl) - 6. 主线程 resume,停在断点处(Debugger.resume) - 7. 主线程 evaluateOnCallFrame,观察指定变量的值(Debugger.evaluateOnCallFrame) - 8. 主线程时光调试,回到方法调用前(Debugger.dropFrame) - 9. 主线程 evaluateOnCallFrame,观察指定变量的值是否变化(Debugger.evaluateO*nCallFrame) - 10. 主线程重复步骤 6-10,测试 dropFrame 在不同方法内的执行情况 - 11. 执行到 taskpool 任务时切换到子线程进行 dropFrame 操作(Debugger.dropFrame) - 12. 所有线程去使能 debugger(Debugger.disable) - 13. 关闭所有线程 debugger server 和 connect server 连接 - """ - - def setup_method(self): - logging.info('Start running TestMainDropFrame: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_main_drop_frame.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('TestMainDropFrame done') - - def test(self, test_suite_main_instance_01_debug): - logging.info('Start running TestMainDropFrame: test') - self.config = test_suite_main_instance_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 - ################################################################################################################ - 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) - 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 - ################################################################################################################ - 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) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # 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) - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=79)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:79:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:79:9:' + self.config['file_path']['index']] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('b') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "3", "description": "3"} - params = debugger.EvaluateOnCallFrameParams('c') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "4", "description": "4"} - params = debugger.EvaluateOnCallFrameParams('e') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - ################################################################################################################ - # main thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", main_thread, params) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('b') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "3", "description": "3"} - params = debugger.EvaluateOnCallFrameParams('c') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "0", "description": "0"} - params = debugger.EvaluateOnCallFrameParams('e') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "0", "description": "0"} - ################################################################################################################ - # main thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", main_thread, params) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('b') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "0", "description": "0"} - params = debugger.EvaluateOnCallFrameParams('c') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "0", "description": "0"} - params = debugger.EvaluateOnCallFrameParams('e') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result']['type'] == "undefined" - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=91)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:91:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:91:5:' + self.config['file_path']['index']] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "2", "description": "2"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "4", "description": "4"} - ################################################################################################################ - # main thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", main_thread, params) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "2", "description": "2"} - ################################################################################################################ - # main thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", main_thread, params) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=105)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:105:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:105:5:' + self.config['file_path']['index']] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:105:5:' + self.config['file_path']['index']] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "4", "description": "4"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "24", "description": "24"} - ################################################################################################################ - # main thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", main_thread, params) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "2", "description": "2"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "4", "description": "4"} - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=119)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:119:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:119:13:' + self.config['file_path']['index']] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:119:13:' + self.config['file_path']['index']] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "3", "description": "3"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "26", "description": "26"} - ################################################################################################################ - # main thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", main_thread, params) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "2", "description": "2"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "12", "description": "12"} - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=134)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:134:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:134:13:' + self.config['file_path']['index']] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('s') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "3", "description": "3"} - params = debugger.EvaluateOnCallFrameParams('func') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - function_info = response['result']['result'] - assert function_info['type'] == 'function' - ################################################################################################################ - # main thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", main_thread, params) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('s') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "2", "description": "2"} - params = debugger.EvaluateOnCallFrameParams('func') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result']['description'] == function_info['description'] - ################################################################################################################ - # main thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", main_thread, params) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('s') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result']['type'] == "undefined" - params = debugger.EvaluateOnCallFrameParams('func') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result']['description'] != function_info['description'] - assert response['result']['result']['type'] == 'function' - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=151)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:151:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:151:1:' + self.config['file_path']['index']] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "11", "description": "11"} - params = debugger.EvaluateOnCallFrameParams('x') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "8", "description": "8"} - ################################################################################################################ - # main thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", main_thread, params) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "9", "description": "9"} - params = debugger.EvaluateOnCallFrameParams('x') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "7", "description": "7"} - ################################################################################################################ - # main thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", main_thread, params) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "8", "description": "8"} - params = debugger.EvaluateOnCallFrameParams('x') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "7", "description": "7"} - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=161)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:161:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:161:5:' + self.config['file_path']['index']] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "10", "description": "10"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "12", "description": "12"} - ################################################################################################################ - # main thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", main_thread, params) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "0", "description": "0"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=175)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:175:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:175:13:' + self.config['file_path']['index']] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "5", "description": "5"} - params = debugger.EvaluateOnCallFrameParams('e') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "12", "description": "12"} - ################################################################################################################ - # main thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", main_thread, params) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - params = debugger.EvaluateOnCallFrameParams('e') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - ################################################################################################################ - # main thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", main_thread, params) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "0", "description": "0"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - params = debugger.EvaluateOnCallFrameParams('e') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result']['type'] == "undefined" - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=186)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:186:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:186:13:' + self.config['file_path']['index']] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "2", "description": "2"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "9", "description": "9"} - params = debugger.EvaluateOnCallFrameParams('e') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "22", "description": "22"} - ################################################################################################################ - # main thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", main_thread, params) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "2", "description": "2"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "5", "description": "5"} - params = debugger.EvaluateOnCallFrameParams('e') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - ################################################################################################################ - # main thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", main_thread, params) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "5", "description": "5"} - params = debugger.EvaluateOnCallFrameParams('e') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result']['type'] == "undefined" - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=204)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:204:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:204:13:' + self.config['file_path']['index']] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "14", "description": "14"} - params = debugger.EvaluateOnCallFrameParams('e') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "21", "description": "21"} - ################################################################################################################ - # main thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", main_thread, params) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "10", "description": "10"} - params = debugger.EvaluateOnCallFrameParams('e') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - ################################################################################################################ - # main thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", main_thread, params) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "0", "description": "0"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "10", "description": "10"} - params = debugger.EvaluateOnCallFrameParams('e') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result']['type'] == "undefined" - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=220)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:220:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:220:9:' + self.config['file_path']['index']] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "3", "description": "3"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "17", "description": "17"} - ################################################################################################################ - # main thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", main_thread, params) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "2", "description": "2"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "14", "description": "14"} - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=236)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:236:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:236:5:' + self.config['file_path']['index']] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - P1_INTRODUCE = ( - 'UEFOREEAAAAAAAAADAACAGQBAAAAAAAAAAAAAAIAAAA8AAAAAQAAAGABAAAAAAAARAAAAAEAAABEAAAAoQAAANQAAACAAAAAZAEAAAIAAA' - 'BsAAAAAwAAAHQAAAD/////////////////////oQAAANQAAACAAAAAkgAAAJ0AAAAhZGVidWdnZXJHZXRWYWx1ZQATaW50cm9kdWNlAAVw' - 'MQAzTF9FU1Nsb3ROdW1iZXJBbm5vdGF0aW9uOwAAAAAAgUAAAAIAABdmdW5jX21haW5fMAATTF9HTE9CQUw7AAAAAAABAAECAAABAP//xw' - 'AAAIgCAR4BAAACAAVWAQAABhEBAAAAFVNsb3ROdW1iZXIAAAABAAUBAAAIAAAANwoDLwBEoESxRMJtYQZgBkIAAABhBz4CAGEIAmEJYAcr' - 'AggJYQVgBUIEAQBhBGAELQYFZAtrAQ8A/////w8AAgAoAFEBAAA=') - ARR_JOIN = ( - 'UEFOREEAAAAAAAAADAACAGABAAAAAAAAAAAAAAIAAAA8AAAAAQAAAFwBAAAAAAAARAAAAAEAAABEAAAAnQAAANAAAACAAAAAYAEAAAIAAA' - 'BsAAAAAwAAAHQAAAD/////////////////////nQAAANAAAACAAAAAhQAAAJcAAAAHYXJyACFkZWJ1Z2dlckdldFZhbHVlAAlqb2luADNM' - 'X0VTU2xvdE51bWJlckFubm90YXRpb247AAAAAACBQAAAAgAAF2Z1bmNfbWFpbl8wABNMX0dMT0JBTDsAAAAAAAEAAQIAAAEA///DAAAAiA' - 'IBGgEAAAIABVIBAAAGDQEAAAAVU2xvdE51bWJlcgAAAAEAAQEAAAgAAAA3CgMvAESgRLFEwm1hBmAGQgABAGEHPgAAYQgCYQlgBysCCAlh' - 'BWAFQgQCAGEEYAQtBgVkC2sBDwD/////DwACACgATQEAAA==') - params = debugger.EvaluateOnCallFrameParams(P1_INTRODUCE) - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result']['description'] == "name = Kate; age = 10" - params = debugger.EvaluateOnCallFrameParams('map') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result']['description'].startswith("Map(2) {0 => 'str0', 1 => 'str1'}") - params = debugger.EvaluateOnCallFrameParams(ARR_JOIN) - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result']['description'] == "10,11,2,3" - ################################################################################################################ - # main thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", main_thread, params) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams(P1_INTRODUCE) - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result']['description'] == "name = Kate; age = 10" - params = debugger.EvaluateOnCallFrameParams('map') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result']['description'].startswith("Map(2) {0 => 'str0', 1 => 'str1'}") - params = debugger.EvaluateOnCallFrameParams(ARR_JOIN) - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result']['description'] == "10,11,2,3" - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=244)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:244:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:244:5:' + self.config['file_path']['index']] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams(P1_INTRODUCE) - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result']['description'] == "name = Tony; age = 30" - params = debugger.EvaluateOnCallFrameParams('map') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result']['description'].startswith("Map(1) {2 => 'str2'}") - params = debugger.EvaluateOnCallFrameParams(ARR_JOIN) - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result']['description'] == "4,3,2,1,0" - ################################################################################################################ - # main thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", main_thread, params) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams(P1_INTRODUCE) - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result']['description'] == "name = Kate; age = 10" - params = debugger.EvaluateOnCallFrameParams('map') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result']['description'].startswith("Map(2) {0 => 'str0', 1 => 'str1'}") - params = debugger.EvaluateOnCallFrameParams(ARR_JOIN) - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result']['description'] == "10,11,2,3" - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=251)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:251:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:251:19:' + self.config['file_path']['index']] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('c') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "3", "description": "3"} - ################################################################################################################ - # main thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", main_thread, params) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('c') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "2", "description": "2"} - ################################################################################################################ - # main thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", main_thread, params) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('c') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=266)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:266:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:266:22:' + self.config['file_path']['index']] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('b') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "2", "description": "2"} - ################################################################################################################ - # main thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", main_thread, params) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('b') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=272)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:272:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:272:8:' + self.config['file_path']['index']] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('b') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "3", "description": "3"} - ################################################################################################################ - # main thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", main_thread, params) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('b') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", main_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "0", "description": "0"} - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - ################################################################################################################ - # worker thread: Debugger.scriptParsed - ################################################################################################################ - response = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread) - assert response['params']['url'] == self.config['file_path']['index'] - assert response['params']['endLine'] == 0 - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # worker thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", worker_thread, params) - ################################################################################################################ - # worker thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=29)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread, params) - assert response['result']['locations'][0]['id'] == 'id:29:0:' + self.config['file_path']['index'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:29:9:' + self.config['file_path']['index']] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('ac') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "20", "description": "20"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('ac') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "10", "description": "10"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - response = await self.debugger_impl.send("Debugger.dropFrame", worker_thread, params) - assert response['result']['message'] == 'Not yet support sendable method' - ################################################################################################################ - # worker thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", worker_thread, params) - ################################################################################################################ - # worker thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=283)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread, params) - assert response['result']['locations'][0]['id'] == 'id:283:0:' + self.config['file_path']['index'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:283:9:' + self.config['file_path']['index']] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('ia') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "200", "description": "200"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('ia') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "120", "description": "120"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('ia') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "100", "description": "100"} - ################################################################################################################ - # worker thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", worker_thread, params) - ################################################################################################################ - # 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_main_exception_breakpoint_01.py b/test/autotest/scenario_test/test_main_exception_breakpoint_01.py deleted file mode 100644 index 600c0e1e908df8653a2a73ce3e1f22cdfa158203..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_main_exception_breakpoint_01.py +++ /dev/null @@ -1,182 +0,0 @@ -#!/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 debugger, runtime -from aw.api import debugger_api, runtime_api - - -@pytest.mark.debug -@pytest.mark.timeout(60) -class TestDebug24: - """ - 测试用例:单实例异常断点的设置/取消 - 测试步骤: - 1. 连接 connect server 和主线程 debugger server - 2. 主线程使能 Runtime 和 Debugger - 3. 主线程运行等待的调试器 - 4. 主线程解析 entry_ability 和 index 文件 - 5. 设置异常捕获状态 ALL - 6. 主线程 resume(Debugger.resume)命中异常断点,验证异常断点信息 CAUGHT 类型异常 - 7. 主线程 resume(Debugger.resume)命中异常断点,验证异常断点信息 UNCAUGHT 类型异常 - 8. 关闭主线程 debugger server 和 connect server 连接 - 测试代码: - function main() { - try { - throw new Error("This is a caught error"); - } catch (error) { - console.log("After error"); - } - throw new Error("This is a uncaught error"); - } - - main(); - """ - - def setup_method(self): - logging.info('Start running TestDebug24: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_debug_24.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('TestDebug24 done') - - def test(self, test_suite_main_instance_04_debug): - logging.info('Start running TestDebug24: test') - self.config = test_suite_main_instance_04_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 - ################################################################################################################ - 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) - 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 - ################################################################################################################ - 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) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # main thread: Debugger.setPauseOnExceptions - ################################################################################################################ - params = debugger.PauseOnExceptionsState.ALL - await self.debugger_impl.send("Debugger.setPauseOnExceptions", main_thread, params) - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - ################################################################################################################ - # main thread: Debugger.paused - ################################################################################################################ - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'exception' - assert 'This is a caught error' in response['params']['data']['unserializableValue'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - ################################################################################################################ - # main thread: Debugger.paused - ################################################################################################################ - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'exception' - assert 'This is a uncaught error' in response['params']['data']['unserializableValue'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - ################################################################################################################ - # close the websocket connections - ################################################################################################################ - 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_main_exception_breakpoint_02.py b/test/autotest/scenario_test/test_main_exception_breakpoint_02.py deleted file mode 100644 index 214faa151db868fed79d794b61f7ad3540f6c261..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_main_exception_breakpoint_02.py +++ /dev/null @@ -1,170 +0,0 @@ -#!/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 debugger, runtime -from aw.api import debugger_api, runtime_api - - -@pytest.mark.debug -@pytest.mark.timeout(60) -class TestDebug25: - """ - 测试用例:单实例异常断点的设置/取消 - 测试步骤: - 1. 连接 connect server 和主线程 debugger server - 2. 主线程使能 Runtime 和 Debugger - 3. 主线程运行等待的调试器 - 4. 主线程解析 entry_ability 和 index 文件 - 5. 设置异常捕获状态 UNCAUGHT - 6. 主线程 resume(Debugger.resume)命中异常断点,验证异常断点信息 UNCAUGHT 类型异常 - 7. 关闭主线程 debugger server 和 connect server 连接 - 测试代码: - function main() { - try { - throw new Error("This is a caught error"); - } catch (error) { - console.log("After error"); - } - throw new Error("This is a uncaught error"); - } - - main(); - """ - - def setup_method(self): - logging.info('Start running TestDebug25: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_debug_25.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('TestDebug25 done') - - def test(self, test_suite_main_instance_04_debug): - logging.info('Start running TestDebug25: test') - self.config = test_suite_main_instance_04_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 - ################################################################################################################ - 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) - 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 - ################################################################################################################ - 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) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # main thread: Debugger.setPauseOnExceptions - ################################################################################################################ - params = debugger.PauseOnExceptionsState.UNCAUGHT - await self.debugger_impl.send("Debugger.setPauseOnExceptions", main_thread, params) - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - ################################################################################################################ - # main thread: Debugger.paused - ################################################################################################################ - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'exception' - assert 'This is a uncaught error' in response['params']['data']['unserializableValue'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - ################################################################################################################ - # close the websocket connections - ################################################################################################################ - 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_main_exception_breakpoint_03.py b/test/autotest/scenario_test/test_main_exception_breakpoint_03.py deleted file mode 100644 index 57725be8777dd0a2ee6c96836f15be6700fcd56d..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_main_exception_breakpoint_03.py +++ /dev/null @@ -1,159 +0,0 @@ -#!/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 debugger, runtime -from aw.api import debugger_api, runtime_api - - -@pytest.mark.debug -@pytest.mark.timeout(60) -class TestDebug26: - """ - 测试用例:单实例异常断点的设置/取消 - 测试步骤: - 1. 连接 connect server 和主线程 debugger server - 2. 主线程使能 Runtime 和 Debugger - 3. 主线程运行等待的调试器 - 4. 主线程解析 entry_ability 和 index 文件 - 5. 设置异常捕获状态 NONE - 6. 不捕获异常无法命中异常断点 - 7. 关闭主线程 debugger server 和 connect server 连接 - 测试代码: - function main() { - try { - throw new Error("This is a caught error"); - } catch (error) { - console.log("After error"); - } - throw new Error("This is a uncaught error"); - } - - main(); - """ - - def setup_method(self): - logging.info('Start running TestDebug26: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_debug_26.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('TestDebug26 done') - - def test(self, test_suite_main_instance_04_debug): - logging.info('Start running TestDebug26: test') - self.config = test_suite_main_instance_04_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 - ################################################################################################################ - 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) - 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 - ################################################################################################################ - 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) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # main thread: Debugger.setPauseOnExceptions - ################################################################################################################ - params = debugger.PauseOnExceptionsState.NONE - await self.debugger_impl.send("Debugger.setPauseOnExceptions", main_thread, params) - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - ################################################################################################################ - # close the websocket connections - ################################################################################################################ - 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_main_mixed_debug.py b/test/autotest/scenario_test/test_main_mixed_debug.py deleted file mode 100644 index c82e47182b27729ef0c75a0908be066c5642cab3..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_main_mixed_debug.py +++ /dev/null @@ -1,219 +0,0 @@ -#!/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 debugger -from aw.api import debugger_api, runtime_api - - -@pytest.mark.debug -@pytest.mark.timeout(60) -class TestMainMixedDebug: - """ - 测试用例:主线程 debug 混合调试 - 测试步骤: - 1. 连接 connect server 和主线程 debugger server - 2. 主线程使能 Runtime 和 Debugger - 3. 主线程使能混合调试(Debugger.setMixedDebugEnabled) - 4. 主线程 Index.ets 文件设置断点(Debugger.getPossibleAndSetBreakpointByUrl) - 5. 触发点击事件,主线程暂停在断点处 - 6. 主线程 stepInto,进入 native 调试(Debugger.stepInto) - 7. 主线程收到 native 返回的消息后应答,停在下一断点处(Debugger.replyNativeCalling) - 8. 主线程 stepOver,停在下一行(Debugger.stepOver) - 9. 主线程 resume(Debugger.resume) - 10. 主线程去使能 debugger(Debugger.disable) - 11. 关闭主线程 debugger server 和 connect server 连接 - 关键代码: - Index.ets - import testNapi from 'libentry.so'; - .OnClick(() => { - let num = testNapi.add(1, 2) - let ans = testNapi.add(num, 3) - console.log("testNapi.add run successfully, ans = ", ans) - }) - """ - - def setup_method(self): - logging.info('Start running TestMainMixedDebug: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_main_mixed_debug.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('TestMainMixedDebug done') - - def test(self, test_suite_native_01_debug): - logging.info('Start running TestMainMixedDebug: test') - self.config = test_suite_native_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: Debugger.setMixedDebugEnabled - ################################################################################################################ - params = debugger.SetMixedDebugEnabledParams(enabled=True, mixed_stack_enabled=False) - await self.debugger_impl.send("Debugger.setMixedDebugEnabled", main_thread, params) - ################################################################################################################ - # main thread: Runtime.runIfWaitingForDebugger - ################################################################################################################ - await self.runtime_impl.send("Runtime.runIfWaitingForDebugger", main_thread) - ################################################################################################################ - # main thread: Debugger.scriptParsed - ################################################################################################################ - 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) - 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 - ################################################################################################################ - 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) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=53), - debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=54)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:53:0:' + self.config['file_path']['index'] - assert response['result']['locations'][1]['id'] == 'id:54: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() - ################################################################################################################ - # 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:53:26:' + self.config['file_path']['index']] - ################################################################################################################ - # main thread: Debugger.stepInto - ################################################################################################################ - await self.debugger_impl.send("Debugger.stepInto", main_thread) - ################################################################################################################ - # main thread: Debugger.nativeCalling - ################################################################################################################ - response = await self.debugger_impl.recv("Debugger.nativeCalling", main_thread) - assert response['params']['isStepInto'] is True - ################################################################################################################ - # main thread: Debugger.replyNativeCalling - ################################################################################################################ - params = debugger.ReplyNativeCallingParams() - await self.debugger_impl.send("Debugger.replyNativeCalling", main_thread, params) - # main thread: Debugger.paused - 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:54:26:' + self.config['file_path']['index']] - ################################################################################################################ - # main thread: Debugger.stepOver - ################################################################################################################ - await self.debugger_impl.send("Debugger.stepOver", main_thread) - # main thread: Debugger.paused - 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'] == [] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_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(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_task_pool.py b/test/autotest/scenario_test/test_task_pool.py deleted file mode 100644 index 95410beeeb39bd6d472b16d09d5ddaac6019526c..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_task_pool.py +++ /dev/null @@ -1,295 +0,0 @@ -#!/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 debugger, runtime -from aw.api import debugger_api, runtime_api - - -@pytest.mark.debug -@pytest.mark.timeout(60) -class TestTaskPool: - """ - 测试用例:多 task 实例 debug 调试 - 测试步骤: - 1. 连接 connect server 和主线程 debugger server - 2. 主线程使能 Runtime 和 Debugger - 3. 连接子线程 debugger server,用于执行 task 任务 - 4. 子线程使能 Runtime 和 Debugger - 5. 主线程 Index.ts 文件设置断点(Debugger.getPossibleAndSetBreakpointByUrl) - 6. 触发点击事件,主线程命中断点 - 7. 子线程 Index.ts 文件设置断点(Debugger.getPossibleAndSetBreakpointByUrl) - 8. 子线程 resume,命中断点(Debugger.resume) - 9. 子线程 getProperties,返回给定对象的属性(Runtime.getProperties) - 10. 子线程 stepOut,主线程命中断点(Debugger.stepOut) - 11. 主线程 getProperties(Runtime.getProperties) - 12. 主线程 resume(Debugger.resume) - 13. 子线程命中断点后 resume(Debugger.resume) - 14. 关闭所有线程 debugger server 和 connect server 连接 - 关键代码: - Index.ets - @Concurrent - function add(args1, args2) { - return args1 + args2 - } - @Concurrent - function sub(args1, args2) { - return args1 - args2 - } - let taskAdd = new taskpool.Task(add, 200, 100) - let taskSub = new taskpool.Task(sub, 200, 100) - async function taskpoolTest() { - let valueAdd = await taskpool.execute(taskAdd) - let valueSub = await taskpool.execute(taskSub) - } - .OnClick(() => { - taskpoolTest() - }) - """ - - def setup_method(self): - logging.info('Start running TestTaskPool: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_task_pool.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('TestTaskPool done') - - def test(self, test_suite_taskpool_01_debug): - logging.info('Start running TestTaskPool: test') - self.config = test_suite_taskpool_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 - ################################################################################################################ - 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) - 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 - ################################################################################################################ - 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) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - ################################################################################################################ - # 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) - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=10), - debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=17), - debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=25)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:10:0:' + self.config['file_path']['index'] - assert response['result']['locations'][1]['id'] == 'id:17:0:' + self.config['file_path']['index'] - assert response['result']['locations'][2]['id'] == 'id:25:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: click on the screen - ################################################################################################################ - Application.click_on_middle() - ################################################################################################################ - # worker thread: Debugger.scriptParsed - ################################################################################################################ - response = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread) - assert response['params']['url'] == self.config['file_path']['index'] - assert response['params']['endLine'] == 0 - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # worker thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", worker_thread, params) - ################################################################################################################ - # worker thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=10), - debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=17), - debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=25)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread, params) - assert response['result']['locations'][0]['id'] == 'id:10:0:' + self.config['file_path']['index'] - assert response['result']['locations'][1]['id'] == 'id:17:0:' + self.config['file_path']['index'] - assert response['result']['locations'][2]['id'] == 'id:25:0:' + self.config['file_path']['index'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:10:14:' + self.config['file_path']['index']] - ################################################################################################################ - # worker thread: Runtime.getProperties - ################################################################################################################ - params = runtime.GetPropertiesParams('0') - response = await self.runtime_impl.send("Runtime.getProperties", worker_thread, params) - assert response['result']['result'][0]['name'] == 'add' - assert response['result']['result'][0]['value']['type'] == 'function' - ################################################################################################################ - # worker thread: Debugger.stepOut - ################################################################################################################ - await self.debugger_impl.send("Debugger.stepOut", worker_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:25:4:' + self.config['file_path']['index']] - ################################################################################################################ - # main thread: Runtime.getProperties - ################################################################################################################ - params = runtime.GetPropertiesParams('0') - response = await self.runtime_impl.send("Runtime.getProperties", main_thread, params) - assert response['result']['result'][0]['name'] == 'taskpoolTest' - assert response['result']['result'][0]['value']['type'] == 'function' - assert response['result']['result'][1]['name'] == 'valueSub' - assert response['result']['result'][1]['value']['type'] == 'undefined' - assert response['result']['result'][2]['name'] == 'valueAdd' - assert response['result']['result'][2]['value']['type'] == 'number' - assert response['result']['result'][2]['value']['description'] == '300' - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - ################################################################################################################ - # worker thread: Debugger.paused - ################################################################################################################ - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['hitBreakpoints'] == ['id:17:14:' + self.config['file_path']['index']] - ################################################################################################################ - # 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_task_pool_sendable.py b/test/autotest/scenario_test/test_task_pool_sendable.py deleted file mode 100644 index ba16296829c7529868ec5535aa55cd9bea9527b3..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_task_pool_sendable.py +++ /dev/null @@ -1,275 +0,0 @@ -#!/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 debugger, runtime -from aw.api import debugger_api, runtime_api - - -@pytest.mark.debug -@pytest.mark.timeout(60) -class TestTaskPoolSendable: - """ - 测试用例:跨线程传递 Sendable 对象 - 测试步骤: - 1. 连接 connect server 和主线程 debugger server - 2. 主线程使能 Runtime 和 Debugger - 3. 主线程 resume(Debugger.resume) - 4. 创建子线程,连接子线程 debugger server - 5. 子线程使能 Runtime 和 Debugger - 6. 主线程 Index.ets 文件设置断点(Debugger.getPossibleAndSetBreakpointByUrl) - 7. 触发点击事件,子线程 Index.ets 文件设置断点(Debugger.getPossibleAndSetBreakpointByUrl) - 8. 子线程 resume,停在断点处(Debugger.resume) - 9. 子线程 getProperties,获取 Sendable 对象方法(Debugger.getProperties) - 10. 子线程 resume,停在下一断点处(Debugger.resume) - 11. 子线程 getProperties,获取 Sendable 对象方法(Debugger.getProperties) - 12. 子线程 resume(Debugger.resume) - 13. 所有线程去使能 debugger(Debugger.disable) - 14. 关闭所有线程 debugger server 和 connect server 连接 - 关键代码; - Index.ets - @Concurrent - async function taskFunc(person: Person) { - let ans = person.calculate(21, 50) - person.setScore(100) - } - async function sendableTest() { - let p = new Person('Tony', 9) - let task: taskpool.Task = new taskpool.Task(taskFunc, p) - await taskpool.execute(task) - } - .OnClick(() => { - sendableTest() - }) - @Sendable - class Person { - name: string - age: number - score: number = 0 - constructor(name: string, age: number) { - this.name = name - this.age = age - } - setScore(score: number) { - this.score = score // b1 - } - addNumber(num1: number, num2: number) { - let result = num1 + num2 // b2 - return result - } - } - """ - - def setup_method(self): - logging.info('Start running TestTaskPoolSendable: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_task_pool_sendable.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('TestTaskPoolSendable done') - - def test(self, test_suite_taskpool_02_debug): - logging.info('Start running TestTaskPoolSendable: test') - self.config = test_suite_taskpool_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) - - 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 - ################################################################################################################ - 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) - 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 - ################################################################################################################ - 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) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - ################################################################################################################ - # 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) - ################################################################################################################ - # main thread: click on the screen - ################################################################################################################ - Application.click_on_middle() - ################################################################################################################ - # worker thread: Debugger.scriptParsed - ################################################################################################################ - response = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread) - assert response['params']['url'] == self.config['file_path']['index'] - assert response['params']['endLine'] == 0 - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # worker thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", worker_thread, params) - ################################################################################################################ - # worker thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=95), - debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=98)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread, params) - assert response['result']['locations'][0]['id'] == 'id:95:0:' + self.config['file_path']['index'] - assert response['result']['locations'][1]['id'] == 'id:98:0:' + self.config['file_path']['index'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['callFrames'][0]['functionName'] == 'addNumber' - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:98:21:' + self.config['file_path']['index']] - ################################################################################################################ - # worker thread: Runtime.getProperties - ################################################################################################################ - params = runtime.GetPropertiesParams('0') - response = await self.runtime_impl.send("Runtime.getProperties", worker_thread, params) - assert response['result']['result'][0]['name'] == 'addNumber' - assert response['result']['result'][0]['value']['description'].endswith('[Sendable]') - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['callFrames'][0]['functionName'] == 'setScore' - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:95:8:' + self.config['file_path']['index']] - ################################################################################################################ - # worker thread: Runtime.getProperties - ################################################################################################################ - params = runtime.GetPropertiesParams('0') - response = await self.runtime_impl.send("Runtime.getProperties", worker_thread, params) - assert response['result']['result'][0]['name'] == 'setScore' - assert response['result']['result'][0]['value']['description'].endswith('[Sendable]') - ################################################################################################################ - # 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_worker_conditional_breakpoints.py b/test/autotest/scenario_test/test_worker_conditional_breakpoints.py deleted file mode 100644 index 60240f14e73fd6d44f0482b76203d30b074a6092..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_worker_conditional_breakpoints.py +++ /dev/null @@ -1,263 +0,0 @@ -#!/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 debugger -from aw.api import debugger_api, runtime_api - - -@pytest.mark.debug -@pytest.mark.timeout(60) -class TestWorkerConditionalBreakpoints: - """ - 测试用例:多实例 debug 调试之设置条件断点 - 测试步骤: - 1. 连接 connect server 和主线程 debugger server - 2. 主线程使能 Runtime 和 Debugger - 4. 触发点击事件,创建子线程,连接子线程 debugger server - 5. 子线程使能 Runtime 和 Debugger - 7. 子线程 Worker.ets 文件设置断点,其中包括条件断点(Debugger.getPossibleAndSetBreakpointByUrl) - 8. 子线程 resume,停在普通断点处(Debugger.resume) - 9. 子线程 resume,停在条件断点处(Debugger.resume) - 7. 子线程 resume,停在普通断点处(Debugger.resume) - 9. 子线程 resume(Debugger.resume) - 10. 所有线程去使能 debugger(Debugger.disable) - 10. 关闭所有线程 debugger server 和 connect server 连接 - 关键代码: - Index.ets - .OnClick(() => { - let myWorker = new worker.ThreadWorker("entry/ets/workers/Worker.ets") - myWorker.postMessage("hello world") - }) - Worker.ets - const workerPort: ThreadWorkerGlobalScope = worker.workerPort; - workerPort.onmessage = (e: MessageEvents) => { - let person = new Person('Tim', add(10, 11)) - person.introduce() // b1 - let age = add(3, 6) + sub(4, 1) - } // b2 - function add(num1, num2) { - let result = num1 + num2 - return result // b3: condition = "result == 9" - } - """ - - def setup_method(self): - logging.info('Start running TestWorkerConditionalBreakpoints: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_worker_conditional_breakpoints.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('TestWorkerConditionalBreakpoints done') - - def test(self, test_suite_worker_06_debug): - logging.info('Start running TestWorkerConditionalBreakpoints: test') - self.config = test_suite_worker_06_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 - ################################################################################################################ - 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) - 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 - ################################################################################################################ - 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) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # 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 = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread) - assert response['params']['url'] == self.config['file_path']['worker'] - assert response['params']['endLine'] == 0 - ################################################################################################################ - # worker thread: Debugger.paused - ################################################################################################################ - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['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 - ################################################################################################################ - RESULT_IS_9 = ( - 'UEFOREEAAAAAAAAADAACAFQBAAAAAAAAAAAAAAIAAAA8AAAAAQAAAFABAAAAAAAARAAAAAEAAABEAAAAlgAAAMkAAAB8AAAAVAEAAAIAAA' - 'BsAAAAAgAAAHQAAAD/////////////////////lgAAAMkAAAB8AAAAjgAAACFkZWJ1Z2dlckdldFZhbHVlAA1yZXN1bHQAM0xfRVNTbG90' - 'TnVtYmVyQW5ub3RhdGlvbjsAAAAAAIFAAAACAAAXZnVuY19tYWluXzAAE0xfR0xPQkFMOwAAAAAAAQABAgAAAQD//7wAAACIAgETAQAAAg' - 'AFRgEAAAYGAQAAABVTbG90TnVtYmVyAAAAAQD6AAAABQAAADcJAyoARJBEoUSybWEFYAVCAAAAYQY+AQBhBwJhCGAGKwIHCGEEYgkAAAAP' - 'BARkC2sBDwD/////DwACACMAQQEAAA==') - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=17), - debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=59), - debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=36, - condition=RESULT_IS_9)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread, params) - assert response['result']['locations'][0]['id'] == 'id:17:0:' + self.config['file_path']['worker'] - assert response['result']['locations'][1]['id'] == 'id:59:0:' + self.config['file_path']['worker'] - assert response['result']['locations'][2]['id'] == 'id:36:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['callFrames'][0]['functionName'] == 'introduce' - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:59:8:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['callFrames'][0]['functionName'] == 'add' - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:36:11:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:17:1:' + self.config['file_path']['worker']] - ################################################################################################################ - # 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_worker_debugger_pause.py b/test/autotest/scenario_test/test_worker_debugger_pause.py deleted file mode 100644 index 592502e51f216ca9ef740822ab9b6573588ad8d1..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_worker_debugger_pause.py +++ /dev/null @@ -1,246 +0,0 @@ -#!/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.api import debugger_api, runtime_api - - -@pytest.mark.debug -@pytest.mark.timeout(60) -class TestWorkerDebuggerPause: - """ - 测试用例:多实例 debug 暂停恢复调试 - 测试步骤: - 1. 连接 connect server 和主线程 debugger server - 2. 主线程使能 Runtime 和 Debugger - 3. 主线程 resume(Debugger.resume) - 4. 触发点击事件,创建子线程,连接子线程 debugger server - 5. 子线程使能 Runtime 和 Debugger - 6. 子线程 resume,停在 debugger代码处(Debugger.resume) - 7. 子线程 resume,所有线程等待2秒(Debugger.resume) - 8. 暂停子线程(Debugger.pause) - 9. 再次恢复子线程(Debugger.resume) - 10. 子线程去使能 debugger(Debugger.disable) - 11. 暂停主线程(Debugger.pause) - 12. 再次恢复主线程(Debugger.resume) - 13. 主线程去使能 debugger(Debugger.disable) - 14. 关闭所有线程 debugger server 和 connect server 连接 - 关键代码: - Index.ets - .OnClick(() => { - let myWorker = new worker.ThreadWorker("entry/ets/workers/Worker.ets") - myWorker.postMessage("hello world") - const start = Date.now() - while (Date.now() - start < 10000) {} - }) - Worker.ets - const workerPort: ThreadWorkerGlobalScope = worker.workerPort; - workerPort.onmessage = (e: MessageEvents) => { - workerPort.postMessage(e.data) - debugger - const start = Date.now() - while (Date.now() - start < 10000) {} - } - """ - - def setup_method(self): - logging.info('Start running TestWorkerDebuggerPause: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_worker_debugger_pause.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('TestWorkerDebuggerPause done') - - def test(self, test_suite_worker_05_debug): - logging.info('Start running TestWorkerDebuggerPause: test') - self.config = test_suite_worker_05_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 - ################################################################################################################ - 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) - 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 - ################################################################################################################ - 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) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # 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 = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread) - assert response['params']['url'] == self.config['file_path']['worker'] - assert response['params']['endLine'] == 0 - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:0:0:'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - ################################################################################################################ - # all thread: sleep 2 seconds - ################################################################################################################ - time.sleep(2) - ################################################################################################################ - # worker thread: Debugger.pause - ################################################################################################################ - await self.debugger_impl.send("Debugger.pause", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # 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.pause - ################################################################################################################ - await self.debugger_impl.send("Debugger.pause", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_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_worker_drop_frame_01.py b/test/autotest/scenario_test/test_worker_drop_frame_01.py deleted file mode 100644 index c19b9aa3a7f6f5a9c908afde3e960e15efc8eacc..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_worker_drop_frame_01.py +++ /dev/null @@ -1,918 +0,0 @@ -#!/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 debugger -from aw.api import debugger_api, runtime_api - - -@pytest.mark.debug -@pytest.mark.timeout(80) -class TestWorkerDropFrame01: - """ - 测试用例:多线程 debug 调试之 drop frame - 测试步骤: - 1. 连接 connect server 和主线程 debugger server - 2. 主线程使能 Runtime 和 Debugger - 3. 主线程 resume(Debugger.resume) - 4. 触发点击事件,创建子线程,连接子线程 debugger server - 5. 子线程使能 Runtime 和 Debugger - 6. 子线程 Worker.ets 文件设置断点(Debugger.getPossibleAndSetBreakpointByUrl) - 7. 子线程 resume,停在断点处(Debugger.resume) - 8. 子线程 evaluateOnCallFrame,观察指定变量的值(Debugger.evaluateOnCallFrame) - 9. 子线程时光调试,回到方法调用前(Debugger.dropFrame) - 10. 子线程 evaluateOnCallFrame,观察指定变量的值是否变化(Debugger.evaluateOnCallFrame) - 11. 子线程重复步骤 6-10,测试 dropFrame 在不同方法内的执行情况 - 12. 所有线程去使能 debugger(Debugger.disable) - 13. 关闭所有线程 debugger server 和 connect server 连接 - """ - - def setup_method(self): - logging.info('Start running TestWorkerDropFrame01: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_worker_drop_frame_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('TestWorkerDropFrame01 done') - - def test(self, test_suite_worker_08_debug): - logging.info('Start running TestWorkerDropFrame01: test') - self.config = test_suite_worker_08_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 - ################################################################################################################ - 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) - 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 - ################################################################################################################ - 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) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # 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 = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread) - assert response['params']['url'] == self.config['file_path']['worker'] - assert response['params']['endLine'] == 0 - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['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 = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=64)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread, params) - assert response['result']['locations'][0]['id'] == 'id:64:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:64:9:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('b') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "3", "description": "3"} - params = debugger.EvaluateOnCallFrameParams('c') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "4", "description": "4"} - params = debugger.EvaluateOnCallFrameParams('e') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('b') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "3", "description": "3"} - params = debugger.EvaluateOnCallFrameParams('c') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "0", "description": "0"} - params = debugger.EvaluateOnCallFrameParams('e') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "0", "description": "0"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('b') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "0", "description": "0"} - params = debugger.EvaluateOnCallFrameParams('c') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "0", "description": "0"} - params = debugger.EvaluateOnCallFrameParams('e') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result']['type'] == "undefined" - ################################################################################################################ - # 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 = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=76)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread, params) - assert response['result']['locations'][0]['id'] == 'id:76:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:76:5:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "2", "description": "2"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "4", "description": "4"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "2", "description": "2"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - ################################################################################################################ - # 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 = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=90)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread, params) - assert response['result']['locations'][0]['id'] == 'id:90:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:90:5:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:90:5:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "4", "description": "4"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "24", "description": "24"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "2", "description": "2"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "4", "description": "4"} - ################################################################################################################ - # 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 = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=104)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread, params) - assert response['result']['locations'][0]['id'] == 'id:104:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:104:13:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:104:13:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "3", "description": "3"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "26", "description": "26"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "2", "description": "2"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "12", "description": "12"} - ################################################################################################################ - # 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 = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=121)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread, params) - assert response['result']['locations'][0]['id'] == 'id:121:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:121:9:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('s') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "3", "description": "3"} - params = debugger.EvaluateOnCallFrameParams('func') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - function_info = response['result']['result'] - assert function_info['type'] == 'function' - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('s') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result']['type'] == "undefined" - params = debugger.EvaluateOnCallFrameParams('func') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result']['description'] != function_info['description'] - assert response['result']['result']['type'] == 'function' - ################################################################################################################ - # 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 = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=136)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread, params) - assert response['result']['locations'][0]['id'] == 'id:136:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:136:1:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "11", "description": "11"} - params = debugger.EvaluateOnCallFrameParams('x') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "8", "description": "8"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "9", "description": "9"} - params = debugger.EvaluateOnCallFrameParams('x') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "7", "description": "7"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "8", "description": "8"} - params = debugger.EvaluateOnCallFrameParams('x') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "7", "description": "7"} - ################################################################################################################ - # 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 = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=146)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread, params) - assert response['result']['locations'][0]['id'] == 'id:146:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:146:5:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "10", "description": "10"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "12", "description": "12"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "0", "description": "0"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - ################################################################################################################ - # 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 = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=160)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread, params) - assert response['result']['locations'][0]['id'] == 'id:160:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:160:13:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "5", "description": "5"} - params = debugger.EvaluateOnCallFrameParams('e') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "12", "description": "12"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - params = debugger.EvaluateOnCallFrameParams('e') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "0", "description": "0"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - params = debugger.EvaluateOnCallFrameParams('e') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result']['type'] == "undefined" - ################################################################################################################ - # 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 = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=171)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread, params) - assert response['result']['locations'][0]['id'] == 'id:171:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:171:13:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "2", "description": "2"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "9", "description": "9"} - params = debugger.EvaluateOnCallFrameParams('e') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "22", "description": "22"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "2", "description": "2"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "5", "description": "5"} - params = debugger.EvaluateOnCallFrameParams('e') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "5", "description": "5"} - params = debugger.EvaluateOnCallFrameParams('e') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result']['type'] == "undefined" - ################################################################################################################ - # 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 = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=189)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread, params) - assert response['result']['locations'][0]['id'] == 'id:189:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:189:13:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "14", "description": "14"} - params = debugger.EvaluateOnCallFrameParams('e') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "21", "description": "21"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "10", "description": "10"} - params = debugger.EvaluateOnCallFrameParams('e') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "0", "description": "0"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "10", "description": "10"} - params = debugger.EvaluateOnCallFrameParams('e') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result']['type'] == "undefined" - ################################################################################################################ - # 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 = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=205)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread, params) - assert response['result']['locations'][0]['id'] == 'id:205:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:205:9:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "3", "description": "3"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "17", "description": "17"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('a') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "2", "description": "2"} - params = debugger.EvaluateOnCallFrameParams('d') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "14", "description": "14"} - ################################################################################################################ - # 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.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_worker_drop_frame_02.py b/test/autotest/scenario_test/test_worker_drop_frame_02.py deleted file mode 100644 index 2ef05e527b7cc214674b678142f3786276bcf4b8..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_worker_drop_frame_02.py +++ /dev/null @@ -1,625 +0,0 @@ -#!/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 debugger -from aw.api import debugger_api, runtime_api - - -@pytest.mark.debug -@pytest.mark.timeout(80) -class TestWorkerDropFrame02: - """ - 测试用例:多线程 debug 调试之 drop frame - 测试步骤: - 1. 连接 connect server 和主线程 debugger server - 2. 主线程使能 Runtime 和 Debugger - 3. 主线程 resume(Debugger.resume) - 4. 触发点击事件,创建子线程,连接子线程 debugger server - 5. 子线程使能 Runtime 和 Debugger - 6. 创建 taskpool 线程,连接 debugger server,使能 Runtime 和 Debugger - 7. 子线程 Worker.ets 文件设置断点(Debugger.getPossibleAndSetBreakpointByUrl) - 8. 子线程 resume,停在断点处(Debugger.resume) - 9. 子线程 evaluateOnCallFrame,观察指定变量的值(Debugger.evaluateOnCallFrame) - 10. 子线程时光调试,回到方法调用前(Debugger.dropFrame) - 11. 子线程 evaluateOnCallFrame,观察指定变量的值是否变化(Debugger.evaluateOnCallFrame) - 12. 子线程重复步骤 6-10,测试 dropFrame 在不同方法内的执行情况 - 13. 执行到 taskpool 任务时切换到 taskpool 线程进行 dropFrame 操作(Debugger.dropFrame) - 14. 所有线程去使能 debugger(Debugger.disable) - 15. 关闭所有线程 debugger server 和 connect server 连接 - """ - - def setup_method(self): - logging.info('Start running TestWorkerDropFrame02: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_worker_drop_frame_02.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('TestWorkerDropFrame02 done') - - def test(self, test_suite_worker_07_debug): - logging.info('Start running TestWorkerDropFrame02: test') - self.config = test_suite_worker_07_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 - ################################################################################################################ - 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) - 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 - ################################################################################################################ - 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) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # 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_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: Runtime.enable - ################################################################################################################ - await self.runtime_impl.send("Runtime.enable", worker_thread_1) - ################################################################################################################ - # worker thread: Debugger.enable - ################################################################################################################ - await self.debugger_impl.send("Debugger.enable", worker_thread_1) - ################################################################################################################ - # worker thread: Runtime.runIfWaitingForDebugger - ################################################################################################################ - await self.runtime_impl.send("Runtime.runIfWaitingForDebugger", worker_thread_1) - ################################################################################################################ - # worker thread: Debugger.scriptParsed - ################################################################################################################ - response = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread_1) - assert response['params']['url'] == self.config['file_path']['worker'] - assert response['params']['endLine'] == 0 - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_1) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # worker thread: connect the debugger server - ################################################################################################################ - 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}') - ################################################################################################################ - # worker thread: Runtime.enable - ################################################################################################################ - await self.runtime_impl.send("Runtime.enable", worker_thread_2) - ################################################################################################################ - # worker thread: Debugger.enable - ################################################################################################################ - await self.debugger_impl.send("Debugger.enable", worker_thread_2) - ################################################################################################################ - # worker thread: Runtime.runIfWaitingForDebugger - ################################################################################################################ - await self.runtime_impl.send("Runtime.runIfWaitingForDebugger", worker_thread_2) - ################################################################################################################ - # worker thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['worker']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", worker_thread_1, params) - ################################################################################################################ - # worker thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=64)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread_1, params) - assert response['result']['locations'][0]['id'] == 'id:64:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread_1) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_1) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:64:5:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - P1_INTRODUCE = ( - 'UEFOREEAAAAAAAAADAACAGQBAAAAAAAAAAAAAAIAAAA8AAAAAQAAAGABAAAAAAAARAAAAAEAAABEAAAAoQAAANQAAACAAAAAZAEAAAIAAA' - 'BsAAAAAwAAAHQAAAD/////////////////////oQAAANQAAACAAAAAkgAAAJ0AAAAhZGVidWdnZXJHZXRWYWx1ZQATaW50cm9kdWNlAAVw' - 'MQAzTF9FU1Nsb3ROdW1iZXJBbm5vdGF0aW9uOwAAAAAAgUAAAAIAABdmdW5jX21haW5fMAATTF9HTE9CQUw7AAAAAAABAAECAAABAP//xw' - 'AAAIgCAR4BAAACAAVWAQAABhEBAAAAFVNsb3ROdW1iZXIAAAABAAUBAAAIAAAANwoDLwBEoESxRMJtYQZgBkIAAABhBz4CAGEIAmEJYAcr' - 'AggJYQVgBUIEAQBhBGAELQYFZAtrAQ8A/////w8AAgAoAFEBAAA=') - ARR_JOIN = ( - 'UEFOREEAAAAAAAAADAACAGABAAAAAAAAAAAAAAIAAAA8AAAAAQAAAFwBAAAAAAAARAAAAAEAAABEAAAAnQAAANAAAACAAAAAYAEAAAIAAA' - 'BsAAAAAwAAAHQAAAD/////////////////////nQAAANAAAACAAAAAhQAAAJcAAAAHYXJyACFkZWJ1Z2dlckdldFZhbHVlAAlqb2luADNM' - 'X0VTU2xvdE51bWJlckFubm90YXRpb247AAAAAACBQAAAAgAAF2Z1bmNfbWFpbl8wABNMX0dMT0JBTDsAAAAAAAEAAQIAAAEA///DAAAAiA' - 'IBGgEAAAIABVIBAAAGDQEAAAAVU2xvdE51bWJlcgAAAAEAAQEAAAgAAAA3CgMvAESgRLFEwm1hBmAGQgABAGEHPgAAYQgCYQlgBysCCAlh' - 'BWAFQgQCAGEEYAQtBgVkC2sBDwD/////DwACACgATQEAAA==') - params = debugger.EvaluateOnCallFrameParams(P1_INTRODUCE) - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread_1, params) - assert response['result']['result']['description'] == "name = Kate; age = 10" - params = debugger.EvaluateOnCallFrameParams('map') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread_1, params) - assert response['result']['result']['description'].startswith("Map(2) {0 => 'str0', 1 => 'str1'}") - params = debugger.EvaluateOnCallFrameParams(ARR_JOIN) - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread_1, params) - assert response['result']['result']['description'] == "10,11,2,3" - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread_1, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_1) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams(P1_INTRODUCE) - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread_1, params) - assert response['result']['result']['description'] == "name = Kate; age = 10" - params = debugger.EvaluateOnCallFrameParams('map') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread_1, params) - assert response['result']['result']['description'].startswith("Map(2) {0 => 'str0', 1 => 'str1'}") - params = debugger.EvaluateOnCallFrameParams(ARR_JOIN) - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread_1, params) - assert response['result']['result']['description'] == "10,11,2,3" - ################################################################################################################ - # worker thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['worker']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", worker_thread_1, params) - ################################################################################################################ - # worker thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=72)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread_1, params) - assert response['result']['locations'][0]['id'] == 'id:72:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread_1) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_1) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:72:5:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams(P1_INTRODUCE) - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread_1, params) - assert response['result']['result']['description'] == "name = Tony; age = 30" - params = debugger.EvaluateOnCallFrameParams('map') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread_1, params) - assert response['result']['result']['description'].startswith("Map(1) {2 => 'str2'}") - params = debugger.EvaluateOnCallFrameParams(ARR_JOIN) - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread_1, params) - assert response['result']['result']['description'] == "4,3,2,1,0" - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread_1, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_1) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams(P1_INTRODUCE) - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread_1, params) - assert response['result']['result']['description'] == "name = Kate; age = 10" - params = debugger.EvaluateOnCallFrameParams('map') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread_1, params) - assert response['result']['result']['description'].startswith("Map(2) {0 => 'str0', 1 => 'str1'}") - params = debugger.EvaluateOnCallFrameParams(ARR_JOIN) - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread_1, params) - assert response['result']['result']['description'] == "10,11,2,3" - ################################################################################################################ - # worker thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['worker']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", worker_thread_1, params) - ################################################################################################################ - # worker thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=79)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread_1, params) - assert response['result']['locations'][0]['id'] == 'id:79:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread_1) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_1) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:79:19:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('c') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread_1, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "3", "description": "3"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread_1, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_1) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('c') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread_1, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "2", "description": "2"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread_1, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_1) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('c') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread_1, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - ################################################################################################################ - # worker thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['worker']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", worker_thread_1, params) - ################################################################################################################ - # worker thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=94)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread_1, params) - assert response['result']['locations'][0]['id'] == 'id:94:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread_1) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_1) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:94:22:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('b') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread_1, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "2", "description": "2"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread_1, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_1) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('b') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread_1, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "1", "description": "1"} - ################################################################################################################ - # worker thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['worker']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", worker_thread_1, params) - ################################################################################################################ - # worker thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=100)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread_1, params) - assert response['result']['locations'][0]['id'] == 'id:100:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread_1) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_1) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:100:8:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('b') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread_1, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "3", "description": "3"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread_1, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_1) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('b') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread_1, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "0", "description": "0"} - ################################################################################################################ - # worker thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['worker']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", worker_thread_1, params) - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread_1) - ################################################################################################################ - # worker thread: Debugger.scriptParsed - ################################################################################################################ - response = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread_2) - assert response['params']['url'] == self.config['file_path']['worker'] - assert response['params']['endLine'] == 0 - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_2) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['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_2, params) - ################################################################################################################ - # worker thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=127)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread_2, params) - assert response['result']['locations'][0]['id'] == 'id:127:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread_2) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_2) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:127:9:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('ac') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread_2, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "20", "description": "20"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread_2, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_2) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('ac') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread_2, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "10", "description": "10"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - response = await self.debugger_impl.send("Debugger.dropFrame", worker_thread_2, params) - assert response['result']['message'] == 'Not yet support sendable method' - ################################################################################################################ - # worker thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['worker']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", worker_thread_2, params) - ################################################################################################################ - # worker thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=111)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread_2, params) - assert response['result']['locations'][0]['id'] == 'id:111:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread_2) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_2) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:111:9:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('ia') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread_2, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "200", "description": "200"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread_2, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_2) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('ia') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread_2, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "120", "description": "120"} - ################################################################################################################ - # worker thread: Debugger.dropFrame - ################################################################################################################ - params = debugger.DropFrameParams() - await self.debugger_impl.send("Debugger.dropFrame", worker_thread_2, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_2) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('ia') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread_2, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "100", "description": "100"} - ################################################################################################################ - # worker thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['worker']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", worker_thread_2, params) - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread_2) - ################################################################################################################ - # worker thread: Debugger.disable - ################################################################################################################ - await self.debugger_impl.send("Debugger.disable", worker_thread_2) - ################################################################################################################ - # worker thread: Debugger.disable - ################################################################################################################ - await self.debugger_impl.send("Debugger.disable", worker_thread_1) - ################################################################################################################ - # 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_2.instance_id, worker_thread_2.send_msg_queue, - 'close') - 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(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_worker_evaluate_on_call_frame.py b/test/autotest/scenario_test/test_worker_evaluate_on_call_frame.py deleted file mode 100644 index 33ea055055be1f3aeb3709a56b6fa2b493e79fcc..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_worker_evaluate_on_call_frame.py +++ /dev/null @@ -1,345 +0,0 @@ -#!/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 debugger -from aw.api import debugger_api, runtime_api - - -@pytest.mark.debug -@pytest.mark.timeout(60) -class TestWorkerEvaluateOnCallFrame: - """ - 测试用例:多实例 debug 调试 evaluateOnCallFrame - 测试步骤: - 1. 连接 connect server 和主线程 debugger server - 2. 主线程使能 Runtime 和 Debugger - 3. 主线程 Index.ts 文件设置断点(Debugger.getPossibleAndSetBreakpointByUrl) - 4. 主线程 resume,暂停在下一断点(Debugger.resume) - 5. 创建子线程,连接子线程 debugger server - 6. 子线程使能 Runtime 和 Debugger - 7. 子线程 Worker.ets 文件设置断点(Debugger.getPossibleAndSetBreakpointByUrl) - 8. 主线程 resume,发送消息给子线程,子线程暂停在断点(Debugger.resume) - 9. 子线程对 local/closure/module/global 作用域变量进行查看、修改等操作(Debugger.evaluateOnCallFrame) - 10. 触发点击事件,销毁子线程,对应的 debugger server 连接断开 - 11. 关闭主线程 debugger server 和 connect server 连接 - 关键代码: - Index.ets - let myWorker = new worker.ThreadWorker("entry/ets/workers/Worker.ets") - myWorker.postMessage("hello world") - .OnClick(() => { - myWorker.terminate() - }) - Worker.ets - const workerPort: ThreadWorkerGlobalScope = worker.workerPort; - let closureBoolean = false - ...... // 定义不同的闭包变量 - globalThis.globalBool = new Boolean(closureBoolean) - ...... // 定义不同的全局变量 - workerPort.onmessage = (e: MessageEvents) => { - let localNull = null - ...... // 定义不同的局部变量 - workerPort.postMessage(e.data) - } - """ - - def setup_method(self): - logging.info('Start running TestWorkerEvaluateOnCallFrame: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_worker_evaluate_on_call_frame.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('TestWorkerEvaluateOnCallFrame done') - - def test(self, test_suite_worker_04_debug): - logging.info('Start running TestWorkerEvaluateOnCallFrame: test') - self.config = test_suite_worker_04_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 - ################################################################################################################ - 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) - 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 - ################################################################################################################ - 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) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=12)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:12:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - 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:12:0:' + self.config['file_path']['index']] - ################################################################################################################ - # 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 = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread) - assert response['params']['url'] == self.config['file_path']['worker'] - assert response['params']['endLine'] == 0 - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['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 = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=116)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread, params) - assert response['result']['locations'][0]['id'] == 'id:116:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:116:4:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - LOCALPERSON_AGE = ( - 'UEFOREEAAAAAAAAADAACAGABAAAAAAAAAAAAAAIAAAA8AAAAAQAAAFwBAAAAAAAARAAAAAEAAABEAAAApAAAANcAAACAAAAAYAEAAAIAAA' - 'BsAAAAAwAAAHQAAAD/////////////////////pAAAANcAAACAAAAAhQAAAJcAAAAHYWdlACFkZWJ1Z2dlckdldFZhbHVlABdsb2NhbFBl' - 'cnNvbgAzTF9FU1Nsb3ROdW1iZXJBbm5vdGF0aW9uOwAAAAAAgUAAAAIAABdmdW5jX21haW5fMAATTF9HTE9CQUw7AAAAAAABAAECAAABAP' - '//ygAAAIgCASEBAAACAAVSAQAABhQBAAAAFVNsb3ROdW1iZXIAAAABAAgBAAAGAAAANwkDKABEkEShRLJtYQVgBUIAAQBhBj4CAGEHAmEI' - 'YAYrAgcIYQRgBEIEAABkC2sBDwD/////DwACACEATQEAAA==') - params = debugger.EvaluateOnCallFrameParams(LOCALPERSON_AGE) - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "20", "description": "20"} - SET_LOCALPERSON_AGE_22 = ( - 'UEFOREEAAAAAAAAADAACAGQBAAAAAAAAAAAAAAIAAAA8AAAAAQAAAGABAAAAAAAARAAAAAEAAABEAAAApAAAANcAAACAAAAAZAEAAAIAAA' - 'BsAAAAAwAAAHQAAAD/////////////////////pAAAANcAAACAAAAAhQAAAJcAAAAHYWdlACFkZWJ1Z2dlckdldFZhbHVlABdsb2NhbFBl' - 'cnNvbgAzTF9FU1Nsb3ROdW1iZXJBbm5vdGF0aW9uOwAAAAAAgUAAAAIAABdmdW5jX21haW5fMAATTF9HTE9CQUw7AAAAAAABAAECAAABAP' - '//ygAAAIgCASEBAAACAAVWAQAABhQBAAAAFVNsb3ROdW1iZXIAAAABAAgBAAAGAAAANwkDLABEkEShRLJtYQVgBUIAAQBhBj4CAGEHAmEI' - 'YAYrAgcIYQRiFgAAAEMEAAAEZAtrAQ8A/////w8AAgAlAFEBAAA=') - params = debugger.EvaluateOnCallFrameParams(SET_LOCALPERSON_AGE_22) - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "22", "description": "22"} - LOCALPERSON_AGE_PLUS_10 = ( - 'UEFOREEAAAAAAAAADAACAGwBAAAAAAAAAAAAAAIAAAA8AAAAAQAAAGgBAAAAAAAARAAAAAEAAABEAAAApAAAANcAAACAAAAAbAEAAAIAAA' - 'BsAAAAAwAAAHQAAAD/////////////////////pAAAANcAAACAAAAAhQAAAJcAAAAHYWdlACFkZWJ1Z2dlckdldFZhbHVlABdsb2NhbFBl' - 'cnNvbgAzTF9FU1Nsb3ROdW1iZXJBbm5vdGF0aW9uOwAAAAAAgUAAAAIAABdmdW5jX21haW5fMAATTF9HTE9CQUw7AAAAAAABAAECAAABAP' - '//ygAAAIgCASEBAAACAAVcAQAABhQBAAAAFVNsb3ROdW1iZXIAAAABAAgBAAAHAAAANwoDMgBEoESxRMJtYQZgBkIAAQBhBz4CAGEIAmEJ' - 'YAcrAggJYQVgBUIEAABhBGIKAAAACgYEZAtrAQ8A/////w8AAgArAAAAVwEAAA==') - params = debugger.EvaluateOnCallFrameParams(LOCALPERSON_AGE_PLUS_10) - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "32", "description": "32"} - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('closureString') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "string", "unserializableValue": "closure", - "description": "closure"} - params = debugger.EvaluateOnCallFrameParams('closureString = "modified"') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "string", "unserializableValue": "modified", - "description": "modified"} - params = debugger.EvaluateOnCallFrameParams('closureString') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "string", "unserializableValue": "modified", - "description": "modified"} - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - params = debugger.EvaluateOnCallFrameParams('globalArray') - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result']['description'].startswith('Array(3)') - GLOBALARRAY_PUSH_999 = ( - 'UEFOREEAAAAAAAAADAACAHABAAAAAAAAAAAAAAIAAAA8AAAAAQAAAGwBAAAAAAAARAAAAAEAAABEAAAApQAAANgAAACAAAAAcAEAAAIAAA' - 'BsAAAAAwAAAHQAAAD/////////////////////pQAAANgAAACAAAAAkgAAAJ8AAAAhZGVidWdnZXJHZXRWYWx1ZQAXZ2xvYmFsQXJyYXkA' - 'CXB1c2gAM0xfRVNTbG90TnVtYmVyQW5ub3RhdGlvbjsAAAAAAIFAAAACAAAXZnVuY19tYWluXzAAE0xfR0xPQkFMOwAAAAAAAQABAgAAAQ' - 'D//8sAAACIAgEiAQAAAgAFYgEAAAYVAQAAABVTbG90TnVtYmVyAAAAAQAJAQAACAAAADcKAzcARKBEsUTCbWEGYAZCAAAAYQc+AQBhCAJh' - 'CWAHKwIICWEFYAVCBAIAYQRi5wMAAGEGYAQuBgUGZAtrAQ8A/////w8AAgAwAF0BAAA=') - params = debugger.EvaluateOnCallFrameParams(GLOBALARRAY_PUSH_999) - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "4", "description": "4"} - GLOBALARRAY_INDEX_3 = ( - 'UEFOREEAAAAAAAAADAACAGABAAAAAAAAAAAAAAIAAAA8AAAAAQAAAFwBAAAAAAAARAAAAAEAAABEAAAAmwAAAM4AAAB8AAAAYAEAAAIAAA' - 'BsAAAAAgAAAHQAAAD/////////////////////mwAAAM4AAAB8AAAAjgAAACFkZWJ1Z2dlckdldFZhbHVlABdnbG9iYWxBcnJheQAzTF9F' - 'U1Nsb3ROdW1iZXJBbm5vdGF0aW9uOwAAAAAAgUAAAAIAABdmdW5jX21haW5fMAATTF9HTE9CQUw7AAAAAAABAAECAAABAP//wQAAAIgCAR' - 'gBAAACAAVPAQAABgsBAAAAFVNsb3ROdW1iZXIAAAABAP8AAAAGAAAANwkDLgBEkEShRLJtYQVgBUIAAABhBj4BAGEHAmEIYAYrAgcIYQRi' - 'AwAAAGEFYAU3BARkC2sBDwD/////DwACACcAAAAASgEAAA==') - params = debugger.EvaluateOnCallFrameParams(GLOBALARRAY_INDEX_3) - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result'] == {"type": "number", "unserializableValue": "999", "description": "999"} - ################################################################################################################ - # worker thread: Debugger.evaluateOnCallFrame - ################################################################################################################ - WORKER_WORKERPORT = ( - 'UEFOREEAAAAAAAAADAACAGQBAAAAAAAAAAAAAAIAAAA8AAAAAQAAAGABAAAAAAAARAAAAAEAAABEAAAApgAAANkAAACAAAAAZAEAAAIAAA' - 'BsAAAAAwAAAHQAAAD/////////////////////pgAAANkAAACAAAAAkgAAAJoAAAAhZGVidWdnZXJHZXRWYWx1ZQANd29ya2VyABV3b3Jr' - 'ZXJQb3J0ADNMX0VTU2xvdE51bWJlckFubm90YXRpb247AAAAAACBQAAAAgAAF2Z1bmNfbWFpbl8wABNMX0dMT0JBTDsAAAAAAAEAAQIAAA' - 'EA///MAAAAiAIBIwEAAAIABVQBAAAGFgEAAAAVU2xvdE51bWJlcgAAAAEACgEAAAYAAAA3CQMoAESQRKFEsm1hBWAFQgAAAGEGPgEAYQcC' - 'YQhgBisCBwhhBGAEQgQCAGQLawEPAP////8PAAIAIQAAAE8BAAA=') - params = debugger.EvaluateOnCallFrameParams(WORKER_WORKERPORT) - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result']['type'] == 'object' - SET_WORKER_WORKERPORT_UNDEFINED = ( - 'UEFOREEAAAAAAAAADAACAGQBAAAAAAAAAAAAAAIAAAA8AAAAAQAAAGABAAAAAAAARAAAAAEAAABEAAAApgAAANkAAACAAAAAZAEAAAIAAA' - 'BsAAAAAwAAAHQAAAD/////////////////////pgAAANkAAACAAAAAkgAAAJoAAAAhZGVidWdnZXJHZXRWYWx1ZQANd29ya2VyABV3b3Jr' - 'ZXJQb3J0ADNMX0VTU2xvdE51bWJlckFubm90YXRpb247AAAAAACBQAAAAgAAF2Z1bmNfbWFpbl8wABNMX0dMT0JBTDsAAAAAAAEAAQIAAA' - 'EA///MAAAAiAIBIwEAAAIABVQBAAAGFgEAAAAVU2xvdE51bWJlcgAAAAEACgEAAAYAAAA3CQMoAESQRKFEsm1hBWAFQgAAAGEGPgEAYQcC' - 'YQhgBisCBwhhBABDBAIABGQLawEPAP////8PAAIAIQAAAE8BAAA=') - params = debugger.EvaluateOnCallFrameParams(SET_WORKER_WORKERPORT_UNDEFINED) - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result']['type'] == 'undefined' - params = debugger.EvaluateOnCallFrameParams(WORKER_WORKERPORT) - response = await self.debugger_impl.send("Debugger.evaluateOnCallFrame", worker_thread, params) - assert response['result']['result']['type'] == 'undefined' - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - ################################################################################################################ - # main thread: click on the screen - ################################################################################################################ - Application.click_on_middle() - ################################################################################################################ - # worker thread: destroy instance - ################################################################################################################ - response = await self.debugger_impl.destroy_instance() - assert response['instanceId'] == worker_thread.instance_id - ################################################################################################################ - # main thread: Debugger.disable - ################################################################################################################ - await self.debugger_impl.send("Debugger.disable", main_thread) - ################################################################################################################ - # close the websocket connections - ################################################################################################################ - 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_worker_exception_breakpoints_01.py b/test/autotest/scenario_test/test_worker_exception_breakpoints_01.py deleted file mode 100644 index adcde42fd66549cf803cbbc4cb5eb15424b83aec..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_worker_exception_breakpoints_01.py +++ /dev/null @@ -1,295 +0,0 @@ -#!/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 debugger -from aw.api import debugger_api, runtime_api - - -@pytest.mark.debug -@pytest.mark.timeout(60) -class TestWorkerExceptionBreakpoints01: - """ - 测试用例:多实例 debug 调试异常断点 ALL 和 NONE 模式 - 测试步骤: - 1. 连接 connect server 和主线程 debugger server - 2. 主线程使能 Runtime 和 Debugger - 3. 主线程 Index.ts 文件设置断点(Debugger.getPossibleAndSetBreakpointByUrl) - 4. 主线程 resume,停在断点处(Debugger.resume) - 5. 创建子线程1,连接 debugger server - 6. 主线程 resume,停在断点处(Debugger.resume) - 7. 创建子线程2,连接 debugger server - 8. 所有子线程使能 Runtime 和 Debugger - 9. 子线程1设置异常断点类型为 ALL(Debugger.setPauseOnExceptions) - 10. 主线程 resume,停在断点处,子线程1停在第一个异常处(Debugger.resume) - 11. 子线程1 resume,停在第二个异常断点处(Debugger.resume) - 12. 子线程1 resume,抛出异常 - 13. 子线程2设置异常断点类型为 NONE(Debugger.setPauseOnExceptions) - 14. 主线程 resume,子线程2抛出异常 - 15. 关闭所有线程 debugger server 和 connect server 连接 - 关键代码: - Index.ets - let workerIndex = 0 - function newWorker() {} // 创建一个子线程, workerIndex++ - function terminateWorker() {} // 销毁一个子线程, workerIndex-- - for (let i = 0; i < 2; i++) { - newWorker() - } - for (let i = 0; i < workerIndex; i++) { - workers[i].postMessage("hello world") - } - Worker.ets - const workerPort: ThreadWorkerGlobalScope = worker.workerPort; - workerPort.onmessage = (e: MessageEvents) => { - workerPort.postMessage(e.data) - try { - throw new Error('[worker] caught error') - } catch (e) { - console.info('[worker] caught error') - } - throw new Error('[worker] uncaught error') - } - """ - - def setup_method(self): - logging.info('Start running TestWorkerExceptionBreakpoints01: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_worker_exception_breakpoints_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('TestWorkerExceptionBreakpoints01 done') - - def test(self, test_suite_worker_03_debug): - logging.info('Start running TestWorkerExceptionBreakpoints01: test') - self.config = test_suite_worker_03_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 - ################################################################################################################ - 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) - 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 - ################################################################################################################ - 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) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=16), - debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=84)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:16:0:' + self.config['file_path']['index'] - assert response['result']['locations'][1]['id'] == 'id:84:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - 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:84:1:' + self.config['file_path']['index']] - ################################################################################################################ - # 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}') - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # main thread: Debugger.paused - 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:1:' + self.config['file_path']['index']] - ################################################################################################################ - # worker thread: connect the debugger server - ################################################################################################################ - 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}') - ################################################################################################################ - # worker thread: Runtime.enable - ################################################################################################################ - await self.runtime_impl.send("Runtime.enable", worker_thread_1) - await self.runtime_impl.send("Runtime.enable", worker_thread_2) - ################################################################################################################ - # worker thread: Debugger.enable - ################################################################################################################ - await self.debugger_impl.send("Debugger.enable", worker_thread_1) - await self.debugger_impl.send("Debugger.enable", worker_thread_2) - ################################################################################################################ - # worker thread: Runtime.runIfWaitingForDebugger - ################################################################################################################ - # worker thread 1: Runtime.runIfWaitingForDebugger - await self.runtime_impl.send("Runtime.runIfWaitingForDebugger", worker_thread_1) - # worker thread 1: Debugger.scriptParsed - response = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread_1) - assert response['params']['url'] == self.config['file_path']['worker'] - assert response['params']['endLine'] == 0 - # worker thread 1: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_1) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'Break on start' - # worker thread 2: Runtime.runIfWaitingForDebugger - await self.runtime_impl.send("Runtime.runIfWaitingForDebugger", worker_thread_2) - # worker thread 2: Debugger.scriptParsed - response = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread_2) - assert response['params']['url'] == self.config['file_path']['worker'] - assert response['params']['endLine'] == 0 - # worker thread 2: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_2) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread_1) - await self.debugger_impl.send("Debugger.resume", worker_thread_2) - ################################################################################################################ - # worker thread: Debugger.setPauseOnExceptions - ################################################################################################################ - params = debugger.PauseOnExceptionsState.ALL - await self.debugger_impl.send("Debugger.setPauseOnExceptions", worker_thread_1, params) - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:16:4:' + self.config['file_path']['index']] - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_1) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'exception' - assert 'caught error' in response['params']['data']['description'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread_1) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_1) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'exception' - assert 'uncaught error' in response['params']['data']['description'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread_1) - ################################################################################################################ - # worker thread: Debugger.setPauseOnExceptions - ################################################################################################################ - params = debugger.PauseOnExceptionsState.NONE - await self.debugger_impl.send("Debugger.setPauseOnExceptions", worker_thread_2, params) - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - ################################################################################################################ - # close the websocket connections - ################################################################################################################ - 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(worker_thread_1.instance_id, worker_thread_1.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_worker_exception_breakpoints_02.py b/test/autotest/scenario_test/test_worker_exception_breakpoints_02.py deleted file mode 100644 index cfb489c23a50a1c77a9afd7eb4864fc362434a55..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_worker_exception_breakpoints_02.py +++ /dev/null @@ -1,305 +0,0 @@ -#!/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 debugger -from aw.api import debugger_api, runtime_api - - -@pytest.mark.debug -@pytest.mark.timeout(60) -class TestWorkerExceptionBreakpoints02: - """ - 测试用例:多实例 debug 调试异常断点 CAUGHT 和 UNCAUGHT 模式 - 测试步骤: - 1. 连接 connect server 和主线程 debugger server - 2. 主线程使能 Runtime 和 Debugger - 3. 主线程 Index.ts 文件设置断点(Debugger.getPossibleAndSetBreakpointByUrl) - 4. 主线程 resume,停在断点处(Debugger.resume) - 5. 创建子线程1,连接 debugger server - 6. 主线程 resume,停在断点处(Debugger.resume) - 7. 创建子线程2,连接 debugger server - 8. 所有子线程使能 Runtime 和 Debugger - 9. 子线程1设置异常断点类型为 CAUGHT(Debugger.setPauseOnExceptions) - 10. 主线程 resume,停在断点处,子线程1停在第一个异常处(Debugger.resume) - 11. 子线程1 resume,停在第二个异常断点处(Debugger.resume) - 12. 子线程1 resume,抛出异常 - 13. 子线程2设置异常断点类型为 UNCAUGHT(Debugger.setPauseOnExceptions) - 14. 主线程 resume,子线程2停在第二个异常处(Debugger.resume) - 15. 子线程2 resume,抛出异常 - 16. 关闭所有线程 debugger server 和 connect server 连接 - 关键代码: - Index.ets - let workerIndex = 0 - function newWorker() {} // 创建一个子线程, workerIndex++ - function terminateWorker() {} // 销毁一个子线程, workerIndex-- - for (let i = 0; i < 2; i++) { - newWorker() - } - for (let i = 0; i < workerIndex; i++) { - workers[i].postMessage("hello world") - } - Worker.ets - const workerPort: ThreadWorkerGlobalScope = worker.workerPort; - workerPort.onmessage = (e: MessageEvents) => { - workerPort.postMessage(e.data) - try { - throw new Error('[worker] caught error') - } catch (e) { - console.info('[worker] caught error') - } - throw new Error('[worker] uncaught error') - } - """ - - def setup_method(self): - logging.info('Start running TestWorkerExceptionBreakpoints02: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_worker_exception_breakpoints_02.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('TestWorkerExceptionBreakpoints02 done') - - def test(self, test_suite_worker_03_debug): - logging.info('Start running TestWorkerExceptionBreakpoints02: test') - self.config = test_suite_worker_03_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 - ################################################################################################################ - 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) - 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 - ################################################################################################################ - 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) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=16), - debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=84)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:16:0:' + self.config['file_path']['index'] - assert response['result']['locations'][1]['id'] == 'id:84:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - 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:84:1:' + self.config['file_path']['index']] - ################################################################################################################ - # 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}') - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # main thread: Debugger.paused - 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:1:' + self.config['file_path']['index']] - ################################################################################################################ - # worker thread: connect the debugger server - ################################################################################################################ - 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}') - ################################################################################################################ - # worker thread: Runtime.enable - ################################################################################################################ - await self.runtime_impl.send("Runtime.enable", worker_thread_1) - await self.runtime_impl.send("Runtime.enable", worker_thread_2) - ################################################################################################################ - # worker thread: Debugger.enable - ################################################################################################################ - await self.debugger_impl.send("Debugger.enable", worker_thread_1) - await self.debugger_impl.send("Debugger.enable", worker_thread_2) - ################################################################################################################ - # worker thread: Runtime.runIfWaitingForDebugger - ################################################################################################################ - # worker thread 1: Runtime.runIfWaitingForDebugger - await self.runtime_impl.send("Runtime.runIfWaitingForDebugger", worker_thread_1) - # worker thread 1: Debugger.scriptParsed - response = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread_1) - assert response['params']['url'] == self.config['file_path']['worker'] - assert response['params']['endLine'] == 0 - # worker thread 1: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_1) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'Break on start' - # worker thread 2: Runtime.runIfWaitingForDebugger - await self.runtime_impl.send("Runtime.runIfWaitingForDebugger", worker_thread_2) - # worker thread 2: Debugger.scriptParsed - response = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread_2) - assert response['params']['url'] == self.config['file_path']['worker'] - assert response['params']['endLine'] == 0 - # worker thread 2: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_2) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread_1) - await self.debugger_impl.send("Debugger.resume", worker_thread_2) - ################################################################################################################ - # worker thread: Debugger.setPauseOnExceptions - ################################################################################################################ - params = debugger.PauseOnExceptionsState.CAUGHT - await self.debugger_impl.send("Debugger.setPauseOnExceptions", worker_thread_1, params) - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:16:4:' + self.config['file_path']['index']] - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_1) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'exception' - assert 'caught error' in response['params']['data']['description'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread_1) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_1) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'exception' - assert 'uncaught error' in response['params']['data']['description'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread_1) - ################################################################################################################ - # worker thread: Debugger.setPauseOnExceptions - ################################################################################################################ - params = debugger.PauseOnExceptionsState.UNCAUGHT - await self.debugger_impl.send("Debugger.setPauseOnExceptions", worker_thread_2, params) - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_2) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'exception' - assert 'uncaught error' in response['params']['data']['description'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread_2) - ################################################################################################################ - # close the websocket connections - ################################################################################################################ - 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(worker_thread_1.instance_id, worker_thread_1.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_worker_get_properties.py b/test/autotest/scenario_test/test_worker_get_properties.py deleted file mode 100644 index 71b7726baf20a43505c337ca31ad0b69c97df702..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_worker_get_properties.py +++ /dev/null @@ -1,329 +0,0 @@ -#!/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 debugger, runtime -from aw.api import debugger_api, runtime_api - - -@pytest.mark.debug -@pytest.mark.timeout(60) -class TestWorkerGetProperties: - """ - 测试用例:多实例 getProperties 调试 - 测试步骤: - 1. 连接 connect server 和主线程 debugger server - 2. 主线程使能 Runtime 和 Debugger - 3. 主线程 Index.ts 文件设置断点(Debugger.getPossibleAndSetBreakpointByUrl) - 4. 主线程 resume,暂停在下一断点(Debugger.resume) - 5. 创建子线程,连接子线程 debugger server - 6. 子线程使能 Runtime 和 Debugger - 7. 子线程 Worker.ets 文件设置断点(Debugger.getPossibleAndSetBreakpointByUrl) - 8. 主线程 resume,发送消息给子线程,子线程暂停在断点(Debugger.resume) - 9. 子线程 getProperties 获取 local/closure/module/global作用域变量信息(Debugger.getProperties) - 10. 销毁子线程,对应的 debugger server 连接断开 - 11. 关闭主线程 debugger server 和 connect server 连接 - 关键代码: - Index.ets - let myWorker = new worker.ThreadWorker("entry/ets/workers/Worker.ets") - myWorker.postMessage("hello world") - .OnClick(() => { - myWorker.terminate() - }) - Worker.ets - const workerPort: ThreadWorkerGlobalScope = worker.workerPort; - let closureBoolean = false - ...... // 定义不同的闭包变量 - globalThis.globalBool = new Boolean(closureBoolean) - ...... // 定义不同的全局变量 - workerPort.onmessage = (e: MessageEvents) => { - let localNull = null - ...... // 定义不同的局部变量 - workerPort.postMessage(e.data) - } - """ - - def setup_method(self): - logging.info('Start running TestWorkerGetProperties: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_worker_get_properties.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('TestWorkerGetProperties done') - - def test(self, test_suite_worker_04_debug): - logging.info('Start running TestWorkerGetProperties: test') - self.config = test_suite_worker_04_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 - ################################################################################################################ - 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) - 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 - ################################################################################################################ - 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) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=12)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:12:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - 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:12:0:' + self.config['file_path']['index']] - ################################################################################################################ - # 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 = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread) - assert response['params']['url'] == self.config['file_path']['worker'] - assert response['params']['endLine'] == 0 - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['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 = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=116)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread, params) - assert response['result']['locations'][0]['id'] == 'id:116:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:116:4:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Runtime.getProperties - ################################################################################################################ - params = runtime.GetPropertiesParams('0') - response = await self.runtime_impl.send("Runtime.getProperties", worker_thread, params) - variables = self.get_variables_from_result(response['result']['result'], 'local') - assert variables == {'localArrayList': 'ArrayList', 'localBigInt64Array': 'BigInt64Array', - 'localBigUint64Array': 'BigUint64Array', 'localDataView': 'DataView(20)', - 'localDeque': 'Deque', 'localFloat32Array': 'Float32Array', - 'localFloat64Array': 'Float64Array', 'localHashMap': 'HashMap', 'localHashSet': 'HashSet', - 'localInt16Array': 'Int16Array(0)', 'localInt32Array': 'Int32Array(0)', - 'localInt8Array': 'Int8Array(0)', 'localLightWeightMap': 'LightWeightMap', - 'localLightWeightSet': 'LightWeightSet', 'localLinkedList': 'LinkedList', - 'localList': 'List', 'localMapIter': 'function entries( { [native code] }', - 'localNull': 'null', 'localPerson': 'Person', 'localPlainArray': 'PlainArray', - 'localPromise': 'Promise', 'localProxy': 'Proxy', 'localQueue': 'Queue', - 'localSendableClass': 'SendableClass[Sendable]', - 'localSharedArrayBuffer': 'SharedArrayBuffer(32)', 'localStack': 'Stack', - 'localTreeMap': 'TreeMap', 'localTreeSet': 'TreeSet', 'localUint16Array': 'Uint16Array', - 'localUint32Array': 'Uint32Array', 'localUint8Array': 'Uint8Array(3)', - 'localUint8ClampedArray': 'Uint8ClampedArray', 'localUndefined': 'undefined', - 'localWeakMap': 'WeakMap(0)', 'localWeakRef': 'WeakRef {}', 'localWeakSet': 'WeakSet(0)'} - ################################################################################################################ - # worker thread: Runtime.getProperties - ################################################################################################################ - params = runtime.GetPropertiesParams('1') - response = await self.runtime_impl.send("Runtime.getProperties", worker_thread, params) - variables = self.get_variables_from_result(response['result']['result'], 'closure') - assert variables == {'closureArray': 'Array(3)', 'closureArrayBuffer': 'Arraybuffer(20)', - 'closureMap': 'Map(0)', 'closureNum': '20', 'closureRegExp': '/^ab+c/g', - 'closureSet': "Set(1) {'closure'}", 'closureString': 'closure'} - ################################################################################################################ - # worker thread: Runtime.getProperties - ################################################################################################################ - params = runtime.GetPropertiesParams('2') - response = await self.runtime_impl.send("Runtime.getProperties", worker_thread, params) - variables = self.get_variables_from_result(response['result']['result'], '') - assert variables == {'ArrayList': 'function ArrayList( { [native code] }', - 'Deque': 'function Deque( { [native code] }', - 'HashMap': 'function HashMap( { [native code] }', - 'HashSet': 'function HashSet( { [native code] }', - 'LightWeightMap': 'function LightWeightMap( { [native code] }', - 'LightWeightSet': 'function LightWeightSet( { [native code] }', - 'LinkedList': 'function LinkedList( { [native code] }', - 'List': 'function List( { [native code] }', - 'PlainArray': 'function PlainArray( { [native code] }', - 'Queue': 'function Queue( { [native code] }', 'Stack': 'function Stack( { [native code] }', - 'TreeMap': 'function TreeMap( { [native code] }', - 'TreeSet': 'function TreeSet( { [native code] }', 'worker': 'Object'} - ################################################################################################################ - # worker thread: Runtime.getProperties - ################################################################################################################ - params = runtime.GetPropertiesParams('3') - response = await self.runtime_impl.send("Runtime.getProperties", worker_thread, params) - variables = self.get_variables_from_result(response['result']['result'], 'global') - assert variables == {'globalArray': 'Array(3)', 'globalBigInt': '9007199254740991n', - 'globalBool': 'Boolean{[[PrimitiveValue]]: false}', - 'globalDate': 'Wed Aug 28 2024 02:41:00 GMT+0800', - 'globalNum': 'Number{[[PrimitiveValue]]: 20}', - 'globalObject': 'String{[[PrimitiveValue]]: globalObject}', - 'globalStr': 'String{[[PrimitiveValue]]: globalStr}', 'globalThis': 'Object'} - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - ################################################################################################################ - # main thread: click on the screen - ################################################################################################################ - Application.click_on_middle() - ################################################################################################################ - # worker thread: destroy instance - ################################################################################################################ - response = await self.debugger_impl.destroy_instance() - assert response['instanceId'] == worker_thread.instance_id - ################################################################################################################ - # main thread: Debugger.disable - ################################################################################################################ - await self.debugger_impl.send("Debugger.disable", main_thread) - ################################################################################################################ - # close the websocket connections - ################################################################################################################ - 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') - ################################################################################################################ - - def get_variables_from_result(self, result, prefix_name): - variables = {} - for var in result: - if var['name'].startswith(prefix_name): - name = var['name'] - value = var['value'] - description = value.get('description') - if description is not None: - index_of_at = description.find('@') - variables[name] = description if index_of_at == -1 else \ - (description[:index_of_at] + description[index_of_at + 9:].strip()) - else: - subtype = value.get('subtype') - variables[name] = subtype if subtype is not None else value.get('type') - return variables \ No newline at end of file diff --git a/test/autotest/scenario_test/test_worker_mixed_debug.py b/test/autotest/scenario_test/test_worker_mixed_debug.py deleted file mode 100644 index ad11fd1ac863c66b211b103324162c5697379adc..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_worker_mixed_debug.py +++ /dev/null @@ -1,266 +0,0 @@ -#!/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 debugger -from aw.api import debugger_api, runtime_api - - -@pytest.mark.debug -@pytest.mark.timeout(60) -class TestWorkerMixedDebug: - """ - 测试用例:多实例 debug 混合调试 - 测试步骤: - 1. 连接 connect server 和主线程 debugger server - 2. 主线程使能 Runtime 和 Debugger - 3. 主线程使能混合调试(Debugger.setMixedDebugEnabled) - 4. 触发点击事件,创建子线程,连接子线程 debugger server - 5. 子线程使能 Runtime 和 Debugger - 6. 子线程使能混合调试(Debugger.setMixedDebugEnabled) - 7. 子线程 Worker.ets 文件设置断点(Debugger.getPossibleAndSetBreakpointByUrl) - 8. 子线程 resume,停在断点处(Debugger.resume) - 9. 子线程 stepInto,进入 native 调试(Debugger.stepInto) - 7. 子线程收到 native 返回的消息后应答,停在下一断点处(Debugger.replyNativeCalling) - 8. 子线程 stepOver,停在下一行(Debugger.stepOver) - 9. 子线程 resume(Debugger.resume) - 10. 所有线程去使能 debugger(Debugger.disable) - 10. 关闭所有线程 debugger server 和 connect server 连接 - 关键代码: - Index.ets - .OnClick(() => { - let myWorker = new worker.ThreadWorker("entry/ets/workers/Worker.ets") - myWorker.onmessage = (e: MessageEvents) => {} - myWorker.postMessage("message from the main thread") - }) - Worker.ets - const workerPort: ThreadWorkerGlobalScope = worker.workerPort; - workerPort.onmessage = (e: MessageEvents) => { - let num = testNapi.add(1, 2) - let ans = testNapi.add(num, 3) - workerPort.postMessage("message from worker thread") - } - """ - - def setup_method(self): - logging.info('Start running TestWorkerMixedDebug: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_worker_mixed_debug.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('TestWorkerMixedDebug done') - - def test(self, test_suite_native_02_debug): - logging.info('Start running TestWorkerMixedDebug: test') - self.config = test_suite_native_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) - - 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: Debugger.setMixedDebugEnabled - ################################################################################################################ - params = debugger.SetMixedDebugEnabledParams(enabled=True, mixed_stack_enabled=False) - await self.debugger_impl.send("Debugger.setMixedDebugEnabled", main_thread, params) - ################################################################################################################ - # main thread: Runtime.runIfWaitingForDebugger - ################################################################################################################ - await self.runtime_impl.send("Runtime.runIfWaitingForDebugger", main_thread) - ################################################################################################################ - # main thread: Debugger.scriptParsed - ################################################################################################################ - 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) - 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 - ################################################################################################################ - 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) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # 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: Debugger.setMixedDebugEnabled - ################################################################################################################ - params = debugger.SetMixedDebugEnabledParams(enabled=True, mixed_stack_enabled=False) - await self.debugger_impl.send("Debugger.setMixedDebugEnabled", worker_thread, params) - ################################################################################################################ - # worker thread: Runtime.runIfWaitingForDebugger - ################################################################################################################ - await self.runtime_impl.send("Runtime.runIfWaitingForDebugger", worker_thread) - ################################################################################################################ - # worker thread: Debugger.scriptParsed - ################################################################################################################ - response = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread) - assert response['params']['url'] == self.config['file_path']['worker'] - assert response['params']['endLine'] == 0 - ################################################################################################################ - # worker thread: Debugger.paused - ################################################################################################################ - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['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 = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=12), - debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=13)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread, params) - assert response['result']['locations'][0]['id'] == 'id:12:0:' + self.config['file_path']['worker'] - assert response['result']['locations'][1]['id'] == 'id:13:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:12:14:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.stepInto - ################################################################################################################ - await self.debugger_impl.send("Debugger.stepInto", worker_thread) - ################################################################################################################ - # worker thread: Debugger.nativeCalling - ################################################################################################################ - response = await self.debugger_impl.recv("Debugger.nativeCalling", worker_thread) - assert response['params']['isStepInto'] is True - ################################################################################################################ - # worker thread: Debugger.replyNativeCalling - ################################################################################################################ - params = debugger.ReplyNativeCallingParams() - await self.debugger_impl.send("Debugger.replyNativeCalling", worker_thread, params) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['hitBreakpoints'] == ['id:13:14:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.stepOver - ################################################################################################################ - await self.debugger_impl.send("Debugger.stepOver", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # 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_worker_smart_step_into.py b/test/autotest/scenario_test/test_worker_smart_step_into.py deleted file mode 100644 index 058ad9a05fa05e4be9f8782b69c574bb2c123aa6..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_worker_smart_step_into.py +++ /dev/null @@ -1,309 +0,0 @@ -#!/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 debugger -from aw.api import debugger_api, runtime_api - - -@pytest.mark.debug -@pytest.mark.timeout(60) -class TestWorkerSmartStepInto: - """ - 测试用例:多实例 debug 调试 smartStepInto - 测试步骤: - 1. 连接 connect server 和主线程 debugger server - 2. 主线程使能 Runtime 和 Debugger - 3. 主线程 resume(Debugger.resume) - 4. 触发点击事件,创建子线程,连接子线程 debugger server - 5. 子线程使能 Runtime 和 Debugger - 6. 子线程 Worker.ets 文件设置断点(Debugger.getPossibleAndSetBreakpointByUrl) - 7. 子线程 resume,停在断点处(Debugger.resume) - 8. 子线程 smartStepInto 进入 introduce 方法(Debugger.smartStepInto) - 9. 子线程 stepOut 跳出 introduce 方法(Debugger.stepOut) - 10. 子线程 smartStepInto 进入 add 方法(Debugger.smartStepInto) - 11. 子线程 stepOut 跳出 add 方法(Debugger.stepOut) - 12. 子线程 smartStepInto 进入 sub 方法(Debugger.smartStepInto) - 13. 子线程 resume(Debugger.resume) - 14. 所有线程去使能 debugger(Debugger.disable) - 15. 关闭所有线程 debugger server 和 connect server 连接 - 关键代码: - Index.ets - .OnClick(() => { - let myWorker = new worker.ThreadWorker("entry/ets/workers/Worker.ets") - myWorker.onmessage = (e: MessageEvents) => {} - myWorker.postMessage("hello world") - }) - Worker.ets - const workerPort: ThreadWorkerGlobalScope = worker.workerPort; - workerPort.onmessage = (e: MessageEvents) => { - let person = new Person('Tim', add(10, 11)) - person.introduce() - let age = add(3, 6) + sub(4, 1) - workerPort.postMessage(e.data) - } - function add(args1, args2) { - return args1 + args2 - } - function sub(args1, args2) { - return args1 - args2 - } - class Person { - name: string - age: number - constructor(name, age){} - introduce() {} - } - """ - - def setup_method(self): - logging.info('Start running TestWorkerSmartStepInto: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_worker_smart_step_into.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('TestWorkerSmartStepInto done') - - def test(self, test_suite_worker_06_debug): - logging.info('Start running TestWorkerSmartStepInto: test') - self.config = test_suite_worker_06_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 - ################################################################################################################ - 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) - 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 - ################################################################################################################ - 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) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # 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 = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread) - assert response['params']['url'] == self.config['file_path']['worker'] - assert response['params']['endLine'] == 0 - ################################################################################################################ - # worker thread: Debugger.paused - ################################################################################################################ - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['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 = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=12)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread, params) - assert response['result']['locations'][0]['id'] == 'id:12:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:12:4:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.smartStepInto - ################################################################################################################ - params = debugger.SmartStepIntoParams(url=self.config['file_path']['worker'], line_number=59) - await self.debugger_impl.send("Debugger.smartStepInto", worker_thread, params) - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['callFrames'][0]['functionName'] == 'introduce' - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:59:8:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.stepOut - ################################################################################################################ - await self.debugger_impl.send("Debugger.stepOut", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.smartStepInto - ################################################################################################################ - params = debugger.SmartStepIntoParams(url=self.config['file_path']['worker'], line_number=35) - await self.debugger_impl.send("Debugger.smartStepInto", worker_thread, params) - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['callFrames'][0]['functionName'] == 'add' - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:35:17:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.stepOut - ################################################################################################################ - await self.debugger_impl.send("Debugger.stepOut", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - ################################################################################################################ - # worker thread: Debugger.smartStepInto - ################################################################################################################ - params = debugger.SmartStepIntoParams(url=self.config['file_path']['worker'], line_number=39) - await self.debugger_impl.send("Debugger.smartStepInto", worker_thread, params) - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread) - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['callFrames'][0]['functionName'] == 'sub' - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:39:17:' + self.config['file_path']['worker']] - ################################################################################################################ - # 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_worker_step.py b/test/autotest/scenario_test/test_worker_step.py deleted file mode 100644 index 741b0442f076341bf0baefb99104b203913bfafe..0000000000000000000000000000000000000000 --- a/test/autotest/scenario_test/test_worker_step.py +++ /dev/null @@ -1,430 +0,0 @@ -#!/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 debugger, runtime -from aw.api import debugger_api, runtime_api - - -@pytest.mark.debug -@pytest.mark.timeout(60) -class TestWorkerStep: - """ - 测试用例:多实例 debug 调试,执行单步操作进行跨线程通信 - 测试步骤: - 1. 连接 connect server 和主线程 debugger server - 2. 主线程使能 Runtime 和 Debugger - 3. 主线程 Index.ts 文件设置断点(Debugger.getPossibleAndSetBreakpointByUrl) - 4. 主线程 stepOut,暂停在下一断点(Debugger.stepOut) - 5. 创建第一个子线程,连接子线程 debugger server - 6. 主线程 resume,暂停在下一断点(Debugger.resume) - 7. 创建另一个子线程,连接子线程 debugger server - 8. 所有子线程使能 Runtime 和 Debugger - 9. 所有子线程 Worker.ts 文件设置断点(Debugger.getPossibleAndSetBreakpointByUrl) - 10. 触发点击事件,主线程命中断点 - 11. 销毁其中一个子线程 - 12. 主线程 stepInto,暂停在下一行(Debugger.stepInto) - 13. 主线程 getProperties,返回给定对象的属性(Runtime.getProperties) - 14. 主线程 resume,暂停在下一断点(Debugger.resume) - 15. 重新创建一个子线程,使能并设置断点 - 16. 主线程 stepOut,发送消息给子线程,主线程暂停在下一断点(Debugger.stepOut) - 17. 子线程命中断点后 getProperties(Runtime.getProperties) - 18. 子线程 stepOut 发消息给主线程(Debugger.stepOut) - 19. 主线程 stepInto,发送消息给另一子线程,主线程暂停在下一行(Debugger.stepInto) - 20. 子线程命中断点后 resume,发消息给主线程(Debugger.resume) - 21. 销毁所有子线程,对应的 debugger server 连接断开 - 22. 关闭主线程 debugger server 和 connect server 连接 - 关键代码: - Index.ets - let workerIndex = 0 - function newWorker() {} // 创建一个子线程, workerIndex++ - function terminateWorker() {} // 销毁一个子线程, workerIndex-- - for (let i = 0; i < 2; i++) { - newWorker() - } - .onClick(() => { - terminateWorker() - newWorker() - for (let i = 0; i < workerIndex; i++) { - workers[i].postMessage("hello world") - } - while (workerIndex) { - terminateWorker() - } - }) - Worker.ets - const workerPort: ThreadWorkerGlobalScope = worker.workerPort; - workerPort.onmessage = (e: MessageEvents) => { - workerPort.postMessage(e.data); - } - """ - - def setup_method(self): - logging.info('Start running TestWorkerStep: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_worker_step.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('TestWorkerStep done') - - def test(self, test_suite_worker_01_debug): - logging.info('Start running TestWorkerStep: test') - self.config = test_suite_worker_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 - ################################################################################################################ - 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) - 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 - ################################################################################################################ - 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) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'Break on start' - ################################################################################################################ - # main thread: Debugger.removeBreakpointsByUrl - ################################################################################################################ - params = debugger.RemoveBreakpointsUrl(self.config['file_path']['index']) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", main_thread, params) - ################################################################################################################ - # main thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=12), - debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=53), - debugger.BreakLocationUrl(url=self.config['file_path']['index'], line_number=57)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - main_thread, params) - assert response['result']['locations'][0]['id'] == 'id:12:0:' + self.config['file_path']['index'] - assert response['result']['locations'][1]['id'] == 'id:53:0:' + self.config['file_path']['index'] - assert response['result']['locations'][2]['id'] == 'id:57:0:' + self.config['file_path']['index'] - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - 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:12:4:' + self.config['file_path']['index']] - ################################################################################################################ - # main thread: Debugger.stepOut - ################################################################################################################ - await self.debugger_impl.send("Debugger.stepOut", main_thread) - 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:12:4:' + self.config['file_path']['index']] - ################################################################################################################ - # 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}') - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - ################################################################################################################ - # worker thread: connect the debugger server - ################################################################################################################ - 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}') - ################################################################################################################ - # worker thread: Runtime.enable - ################################################################################################################ - await self.runtime_impl.send("Runtime.enable", worker_thread_1) - await self.runtime_impl.send("Runtime.enable", worker_thread_2) - ################################################################################################################ - # worker thread: Debugger.enable - ################################################################################################################ - await self.debugger_impl.send("Debugger.enable", worker_thread_1) - await self.debugger_impl.send("Debugger.enable", worker_thread_2) - ################################################################################################################ - # worker thread: Runtime.runIfWaitingForDebugger - ################################################################################################################ - # worker thread 1: Runtime.runIfWaitingForDebugger - await self.runtime_impl.send("Runtime.runIfWaitingForDebugger", worker_thread_1) - # worker thread 1: Debugger.scriptParsed - response = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread_1) - assert response['params']['url'] == self.config['file_path']['worker'] - assert response['params']['endLine'] == 0 - # worker thread 1: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_1) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'Break on start' - # worker thread 2: Runtime.runIfWaitingForDebugger - await self.runtime_impl.send("Runtime.runIfWaitingForDebugger", worker_thread_2) - # worker thread 2: Debugger.scriptParsed - response = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread_2) - assert response['params']['url'] == self.config['file_path']['worker'] - assert response['params']['endLine'] == 0 - # worker thread 2: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_2) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['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_1, params) - await self.debugger_impl.send("Debugger.removeBreakpointsByUrl", worker_thread_2, params) - ################################################################################################################ - # worker thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=11)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread_1, params) - assert response['result']['locations'][0]['id'] == 'id:11:0:' + self.config['file_path']['worker'] - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread_2, params) - assert response['result']['locations'][0]['id'] == 'id:11:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread_1) - await self.debugger_impl.send("Debugger.resume", worker_thread_2) - ################################################################################################################ - # main thread: click on the screen - ################################################################################################################ - Application.click_on_middle() - ################################################################################################################ - # 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:53:16:' + self.config['file_path']['index']] - ################################################################################################################ - # worker thread: destroy instance - ################################################################################################################ - # worker thread 2 destroyed - response = await self.debugger_impl.destroy_instance() - assert response['instanceId'] == worker_thread_2.instance_id - ################################################################################################################ - # main thread: Debugger.stepInto - ################################################################################################################ - await self.debugger_impl.send("Debugger.stepInto", main_thread) - await self.debugger_impl.recv("Debugger.paused", main_thread) - ################################################################################################################ - # main thread: Runtime.getProperties - ################################################################################################################ - params = runtime.GetPropertiesParams('0', True, False, True) - response = await self.runtime_impl.send("Runtime.getProperties", main_thread, params) - assert response['result']['result'][0]['name'] == 'set message' - assert response['result']['result'][0]['value']['type'] == 'function' - assert response['result']['result'][1]['name'] == 'newValue' - assert response['result']['result'][1]['value']['type'] == 'string' - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - 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:57:20:' + self.config['file_path']['index']] - ################################################################################################################ - # worker thread: connect the debugger server - ################################################################################################################ - 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}') - ################################################################################################################ - # worker thread: Runtime.enable - ################################################################################################################ - await self.runtime_impl.send("Runtime.enable", worker_thread_2) - ################################################################################################################ - # worker thread: Debugger.enable - ################################################################################################################ - await self.debugger_impl.send("Debugger.enable", worker_thread_2) - ################################################################################################################ - # worker thread: Runtime.runIfWaitingForDebugger - ################################################################################################################ - await self.runtime_impl.send("Runtime.runIfWaitingForDebugger", worker_thread_2) - # worker thread: Debugger.scriptParsed - response = await self.debugger_impl.recv("Debugger.scriptParsed", worker_thread_2) - assert response['params']['url'] == self.config['file_path']['worker'] - assert response['params']['endLine'] == 0 - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_2) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['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_2, params) - ################################################################################################################ - # worker thread: Debugger.getPossibleAndSetBreakpointByUrl - ################################################################################################################ - locations = [debugger.BreakLocationUrl(url=self.config['file_path']['worker'], line_number=11)] - params = debugger.SetBreakpointsLocations(locations) - response = await self.debugger_impl.send("Debugger.getPossibleAndSetBreakpointsByUrl", - worker_thread_2, params) - assert response['result']['locations'][0]['id'] == 'id:11:0:' + self.config['file_path']['worker'] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread_2) - ################################################################################################################ - # main thread: Debugger.stepOut - ################################################################################################################ - await self.debugger_impl.send("Debugger.stepOut", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:57:20:' + self.config['file_path']['index']] - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_1) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:11:4:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Runtime.getProperties - ################################################################################################################ - params = runtime.GetPropertiesParams('0', True, False, True) - response = await self.runtime_impl.send("Runtime.getProperties", worker_thread_1, params) - assert response['result']['result'][0]['name'] == '' - assert response['result']['result'][0]['value']['type'] == 'function' - assert response['result']['result'][1]['name'] == 'e' - assert response['result']['result'][1]['value']['type'] == 'object' - ################################################################################################################ - # worker thread: Debugger.stepOut - ################################################################################################################ - await self.debugger_impl.send("Debugger.stepOut", worker_thread_1) - ################################################################################################################ - # worker thread: Debugger.disable - ################################################################################################################ - await self.debugger_impl.send("Debugger.disable", worker_thread_1) - ################################################################################################################ - # main thread: Debugger.stepInto - ################################################################################################################ - await self.debugger_impl.send("Debugger.stepInto", main_thread) - # main thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", main_thread) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['index'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == [] - # worker thread: Debugger.paused - response = await self.debugger_impl.recv("Debugger.paused", worker_thread_2) - assert response['params']['callFrames'][0]['url'] == self.config['file_path']['worker'] - assert response['params']['reason'] == 'other' - assert response['params']['hitBreakpoints'] == ['id:11:4:' + self.config['file_path']['worker']] - ################################################################################################################ - # worker thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", worker_thread_2) - ################################################################################################################ - # worker thread: Debugger.disable - ################################################################################################################ - await self.debugger_impl.send("Debugger.disable", worker_thread_2) - ################################################################################################################ - # main thread: Debugger.resume - ################################################################################################################ - await self.debugger_impl.send("Debugger.resume", main_thread) - ################################################################################################################ - # worker thread: destroy instance - ################################################################################################################ - response = await self.debugger_impl.destroy_instance() - assert response['instanceId'] != self.config['pid'] - response = await self.debugger_impl.destroy_instance() - assert response['instanceId'] != self.config['pid'] - ################################################################################################################ - # main thread: Debugger.disable - ################################################################################################################ - await self.debugger_impl.send("Debugger.disable", main_thread) - ################################################################################################################ - # close the websocket connections - ################################################################################################################ - 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/testcases/toolchain/profiler/TestProfilerHeapDump.json b/test/autotest/testcases/toolchain/profiler/TestProfilerHeapDump.json new file mode 100644 index 0000000000000000000000000000000000000000..e98b73f7ba5267481d30ba3219e4e464234116bc --- /dev/null +++ b/test/autotest/testcases/toolchain/profiler/TestProfilerHeapDump.json @@ -0,0 +1,15 @@ +{ + "description": "Config for TestProfilerHeapDump", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "toolchain/profiler/TestProfilerHeapDump.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/scenario_test/test_worker_profiler_heap_dump.py b/test/autotest/testcases/toolchain/profiler/TestProfilerHeapDump.py similarity index 61% rename from test/autotest/scenario_test/test_worker_profiler_heap_dump.py rename to test/autotest/testcases/toolchain/profiler/TestProfilerHeapDump.py index bfd2f849d93fbf14abebc43ae199223c53d54f36..14235388d8d69b6d7b9a272b0520e140889c5fc5 100644 --- a/test/autotest/scenario_test/test_worker_profiler_heap_dump.py +++ b/test/autotest/testcases/toolchain/profiler/TestProfilerHeapDump.py @@ -1,153 +1,164 @@ -#!/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.api import debugger_api, runtime_api, heap_profiler_api - - -@pytest.mark.heap_profiler -@pytest.mark.timeout(80) -class TestProfilerHeapDump: - """ - 测试用例:多实例内存调优 HeapDump 录制 - 测试步骤: - 1. 拉起应用,attach 主线程 - 2. 连接 connect server 和主线程 debugger server - 3. 连接 worker 线程 debugger server - 4. 所有线程使能 Runtime(Runtime.enable) - 5. 所有线程去使能 Debugger(Debugger.disable) - 5. 所有线程拍摄内存快照(HeapProfiler.takeHeapSnapshot) - 6. 等待 10 秒后,所有线程再次拍摄内存快照(HeapProfiler.takeHeapSnapshot) - 7. 销毁 worker 线程,对应的 debugger server 连接断开 - 8. 关闭主线程 debugger server 和 connect server 连接 - """ - - def setup_method(self): - logging.info('Start running TestWorkerProfilerHeapDump: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_worker_profiler_heap_dump.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('TestWorkerProfilerHeapDump done') - - def test(self, test_suite_worker_02): - logging.info('Start running TestWorkerProfilerHeapDump: test') - self.config = test_suite_worker_02 - 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: 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) - ################################################################################################################ - # main thread: HeapProfiler.takeHeapSnapshot - ################################################################################################################ - await self.heap_profiler_impl.send("HeapProfiler.takeHeapSnapshot", main_thread) - ################################################################################################################ - # worker thread: HeapProfiler.takeHeapSnapshot - ################################################################################################################ - await self.heap_profiler_impl.send("HeapProfiler.takeHeapSnapshot", worker_thread_1) - await self.heap_profiler_impl.send("HeapProfiler.takeHeapSnapshot", worker_thread_2) - ################################################################################################################ - # all thread: sleep 10 seconds - ################################################################################################################ - time.sleep(10) - ################################################################################################################ - # main thread: HeapProfiler.takeHeapSnapshot - ################################################################################################################ - await self.heap_profiler_impl.send("HeapProfiler.takeHeapSnapshot", main_thread) - ################################################################################################################ - # worker thread: HeapProfiler.takeHeapSnapshot - ################################################################################################################ - await self.heap_profiler_impl.send("HeapProfiler.takeHeapSnapshot", worker_thread_1) - await self.heap_profiler_impl.send("HeapProfiler.takeHeapSnapshot", 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') +#!/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. + +#================================================================== +#文 件 名: TestProfilerHeapDump.py +#文件说明: 多实例内存调优 HeapDump 录制 +#================================================================== +测试步骤: + 1. 拉起应用,attach 主线程 + 2. 连接 connect server 和主线程 debugger server + 3. 连接 worker 线程 debugger server + 4. 所有线程使能 Runtime(Runtime.enable) + 5. 所有线程去使能 Debugger(Debugger.disable) + 5. 所有线程拍摄内存快照(HeapProfiler.takeHeapSnapshot) + 6. 等待 10 秒后,所有线程再次拍摄内存快照(HeapProfiler.takeHeapSnapshot) + 7. 销毁 worker 线程,对应的 debugger server 连接断开 + 8. 关闭主线程 debugger server 和 connect server 连接 +#!!================================================================ +""" +import sys +import time +from pathlib import Path + +root_path = Path(__file__).parent.parent.parent.parent +resource_path = root_path / 'resource' +sys.path.append(str(root_path / 'aw')) # add aw path to sys.path + +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from all_utils import CommonUtils, UiUtils +from implement_api import debugger_api, runtime_api, heap_profiler_api + + +class TestProfilerHeapDump(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + TestCase.__init__(self, self.TAG, controllers) + self.driver = UiDriver(self.device1) + self.ui_utils = UiUtils(self.driver) + self.common_utils = CommonUtils(self.driver) + self.id_generator = CommonUtils.message_id_generator() + self.config = { + 'start_mode': '', + 'connect_server_port': 15702, + 'debugger_server_port': 15703, + 'bundle_name': 'com.example.multiWorker02', + 'hap_name': 'MultiWorker02.hap', + 'hap_path': str(resource_path / 'hap' / 'MultiWorker02.hap') + } + + def setup(self): + Step('1.下载应用') + self.driver.install_app(self.config['hap_path'], "-r") + Step('2.启动应用') + self.driver.start_app(package_name=self.config['bundle_name'], params=self.config['start_mode']) + self.config['pid'] = self.common_utils.get_pid(self.config['bundle_name']) + assert self.config['pid'] != 0, f'Failed to get pid of {self.config["bundle_name"]}' + Step('3.设置屏幕常亮') + self.ui_utils.keep_awake() + Step('4.端口映射,连接server') + self.common_utils.connect_server(self.config) + self.debugger_impl = debugger_api.DebuggerImpl(self.id_generator, self.config['websocket']) + self.runtime_impl = runtime_api.RuntimeImpl(self.id_generator, self.config['websocket']) + self.heap_profiler_impl = heap_profiler_api.HeapProfilerImpl(self.id_generator, self.config['websocket']) + Step('5.attach调试应用') + self.common_utils.attach(self.config['bundle_name']) + + def process(self): + Step('6.执行测试用例') + websocket = self.config['websocket'] + taskpool = self.config['taskpool'] + taskpool.submit(websocket.main_task(taskpool, self.test, self.config['pid'])) + taskpool.await_taskpool() + taskpool.task_join() + if taskpool.task_exception: + raise taskpool.task_exception + + def teardown(self): + Step('7.关闭应用') + self.driver.stop_app(self.config['bundle_name']) + Step('8.卸载应用') + self.driver.uninstall_app(self.config['bundle_name']) + + async def test(self, websocket): + ################################################################################################################ + # main thread: connect the debugger server + ################################################################################################################ + main_thread = await self.debugger_impl.connect_to_debugger_server(self.config['pid'], True) + ################################################################################################################ + # main thread: Runtime.enable + ################################################################################################################ + await self.runtime_impl.send("Runtime.enable", main_thread) + ################################################################################################################ + # main thread: Debugger.disable + ################################################################################################################ + await self.debugger_impl.send("Debugger.disable", main_thread) + ################################################################################################################ + # main thread: HeapProfiler.takeHeapSnapshot + ################################################################################################################ + await self.heap_profiler_impl.send("HeapProfiler.takeHeapSnapshot", main_thread) + ################################################################################################################ + # main thread: sleep 10 seconds + ################################################################################################################ + time.sleep(10) + ################################################################################################################ + # main thread: HeapProfiler.takeHeapSnapshot + ################################################################################################################ + await self.heap_profiler_impl.send("HeapProfiler.takeHeapSnapshot", main_thread) + ################################################################################################################ + # main thread: click on the screen + ################################################################################################################ + self.ui_utils.click_on_middle() + ################################################################################################################ + # worker thread: connect the debugger server + ################################################################################################################ + worker_thread_1 = await self.debugger_impl.connect_to_debugger_server(self.config['pid'], False) + worker_thread_2 = await self.debugger_impl.connect_to_debugger_server(self.config['pid'], False) + ################################################################################################################ + # worker thread: Runtime.enable + ################################################################################################################ + await self.runtime_impl.send("Runtime.enable", worker_thread_1) + await self.runtime_impl.send("Runtime.enable", worker_thread_2) + ################################################################################################################ + # worker thread: Debugger.disable + ################################################################################################################ + await self.debugger_impl.send("Debugger.disable", worker_thread_1) + await self.debugger_impl.send("Debugger.disable", worker_thread_2) + ################################################################################################################ + # worker thread: HeapProfiler.takeHeapSnapshot + ################################################################################################################ + await self.heap_profiler_impl.send("HeapProfiler.takeHeapSnapshot", worker_thread_1) + await self.heap_profiler_impl.send("HeapProfiler.takeHeapSnapshot", worker_thread_2) + ################################################################################################################ + # worker thread: sleep 10 seconds + ################################################################################################################ + time.sleep(10) + ################################################################################################################ + # worker thread: HeapProfiler.takeHeapSnapshot + ################################################################################################################ + await self.heap_profiler_impl.send("HeapProfiler.takeHeapSnapshot", worker_thread_1) + await self.heap_profiler_impl.send("HeapProfiler.takeHeapSnapshot", 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 diff --git a/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerAllocation01.json b/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerAllocation01.json new file mode 100644 index 0000000000000000000000000000000000000000..fc262f3abaafaf4b08db0985911121f7637fe3b4 --- /dev/null +++ b/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerAllocation01.json @@ -0,0 +1,15 @@ +{ + "description": "Config for TestWorkerProfilerAllocation01", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "toolchain/profiler/TestWorkerProfilerAllocation01.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/scenario_test/test_worker_profiler_allocation_02.py b/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerAllocation01.py similarity index 66% rename from test/autotest/scenario_test/test_worker_profiler_allocation_02.py rename to test/autotest/testcases/toolchain/profiler/TestWorkerProfilerAllocation01.py index 938eba387ea11a8bf437b2289e9e47e74a49364e..a5bc4665ad038bf3a8df3eab4638d70eafdaebe2 100644 --- a/test/autotest/scenario_test/test_worker_profiler_allocation_02.py +++ b/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerAllocation01.py @@ -1,174 +1,186 @@ -#!/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 TestWorkerProfilerAllocation02: - """ - 测试用例:多实例内存调优 Allocation 录制(-p dumpheap启动) - 测试步骤: - 1. -p dumpheap方式拉起应用 - 2. 连接 connect server 和主线程 debugger server - 3. 连接 worker 线程 debugger server - 4. 所有线程使能 Runtime(Runtime.enable) - 5. 所有线程获取内存使用情况(Runtime.getHeapUsage) - 6. 所有线程启动 Allocation 录制(HeapProfiler.startTrackingHeapObjects) - 7. 所有线程获取内存使用情况(Runtime.getHeapUsage) - 8. 等待 10 秒后关闭 Allocation 录制,获取数据(HeapProfiler.stopTrackingHeapObjects) - 9. 销毁 worker 线程,对应的 debugger server 连接断开 - 10. 关闭主线程 debugger server 和 connect server 连接 - """ - - def setup_method(self): - logging.info('Start running TestWorkerProfilerAllocation02: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_worker_profiler_allocation_02.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('TestWorkerProfilerAllocation02 done') - - def test(self, test_suite_worker_02_dumpheap): - logging.info('Start running TestWorkerProfilerAllocation02: test') - self.config = test_suite_worker_02_dumpheap - 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) - - 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: Runtime.getHeapUsage - ################################################################################################################ - await self.runtime_impl.send("Runtime.getHeapUsage", main_thread) - ################################################################################################################ - # main thread: HeapProfiler.startTrackingHeapObjects - ################################################################################################################ - params = heap_profiler.TrackingHeapObjectsParams(False) - await self.heap_profiler_impl.send("HeapProfiler.startTrackingHeapObjects", main_thread, params) - ################################################################################################################ - # main thread: Debugger.disable - ################################################################################################################ - await self.debugger_impl.send("Debugger.disable", main_thread) - ################################################################################################################ - # 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}') - ################################################################################################################ - # worker thread: Runtime.enable - ################################################################################################################ - await self.runtime_impl.send("Runtime.enable", worker_thread_1) - await self.runtime_impl.send("Runtime.enable", worker_thread_2) - ################################################################################################################ - # 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.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) - ################################################################################################################ - # 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) - ################################################################################################################ - # 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') +#!/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. + +#================================================================== +#文 件 名: TestWorkerProfilerAllocation01.py +#文件说明: 多实例内存调优 Allocation 录制(attach启动) +#================================================================== +测试步骤: + 1. 拉起应用,attach 主线程 + 2. 连接 connect server 和主线程 debugger server + 3. 连接 worker 线程 debugger server + 4. 所有线程使能 Runtime(Runtime.enable) + 5. 所有线程获取内存使用情况(Runtime.getHeapUsage) + 6. 所有线程启动 Allocation 录制(HeapProfiler.startTrackingHeapObjects) + 7. 所有线程获取内存使用情况(Runtime.getHeapUsage) + 8. 等待 10 秒后关闭 Allocation 录制,获取数据(HeapProfiler.stopTrackingHeapObjects) + 9. 销毁 worker 线程,对应的 debugger server 连接断开 + 10. 关闭主线程 debugger server 和 connect server 连接 +#!!================================================================ +""" +import sys +import time +from pathlib import Path + +root_path = Path(__file__).parent.parent.parent.parent +resource_path = root_path / 'resource' +sys.path.append(str(root_path / 'aw')) # add aw path to sys.path + +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from all_utils import CommonUtils, UiUtils +from cdp import heap_profiler +from implement_api import debugger_api, runtime_api, heap_profiler_api + + +class TestWorkerProfilerAllocation01(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + TestCase.__init__(self, self.TAG, controllers) + self.driver = UiDriver(self.device1) + self.ui_utils = UiUtils(self.driver) + self.common_utils = CommonUtils(self.driver) + self.id_generator = CommonUtils.message_id_generator() + self.config = { + 'start_mode': '', + 'connect_server_port': 15704, + 'debugger_server_port': 15705, + 'bundle_name': 'com.example.multiWorker02', + 'hap_name': 'MultiWorker02.hap', + 'hap_path': str(resource_path / 'hap' / 'MultiWorker02.hap') + } + + def setup(self): + Step('1.下载应用') + self.driver.install_app(self.config['hap_path'], "-r") + Step('2.启动应用') + self.driver.start_app(package_name=self.config['bundle_name'], params=self.config['start_mode']) + self.config['pid'] = self.common_utils.get_pid(self.config['bundle_name']) + assert self.config['pid'] != 0, f'Failed to get pid of {self.config["bundle_name"]}' + Step('3.设置屏幕常亮') + self.ui_utils.keep_awake() + Step('4.端口映射,连接server') + self.common_utils.connect_server(self.config) + self.debugger_impl = debugger_api.DebuggerImpl(self.id_generator, self.config['websocket']) + self.runtime_impl = runtime_api.RuntimeImpl(self.id_generator, self.config['websocket']) + self.heap_profiler_impl = heap_profiler_api.HeapProfilerImpl(self.id_generator, self.config['websocket']) + Step('5.attach调试应用') + self.common_utils.attach(self.config['bundle_name']) + + def process(self): + Step('6.执行测试用例') + websocket = self.config['websocket'] + taskpool = self.config['taskpool'] + taskpool.submit(websocket.main_task(taskpool, self.test, self.config['pid'])) + taskpool.await_taskpool() + taskpool.task_join() + if taskpool.task_exception: + raise taskpool.task_exception + + def teardown(self): + Step('7.关闭应用') + self.driver.stop_app(self.config['bundle_name']) + Step('8.卸载应用') + self.driver.uninstall_app(self.config['bundle_name']) + + async def test(self, websocket): + ################################################################################################################ + # main thread: connect the debugger server + ################################################################################################################ + main_thread = await self.debugger_impl.connect_to_debugger_server(self.config['pid'], True) + ################################################################################################################ + # main thread: Runtime.enable + ################################################################################################################ + await self.runtime_impl.send("Runtime.enable", main_thread) + ################################################################################################################ + # main thread: Runtime.getHeapUsage + ################################################################################################################ + await self.runtime_impl.send("Runtime.getHeapUsage", main_thread) + ################################################################################################################ + # main thread: HeapProfiler.startTrackingHeapObjects + ################################################################################################################ + params = heap_profiler.TrackingHeapObjectsParams(False) + await self.heap_profiler_impl.send("HeapProfiler.startTrackingHeapObjects", main_thread, params) + ################################################################################################################ + # main thread: Debugger.disable + ################################################################################################################ + await self.debugger_impl.send("Debugger.disable", main_thread) + ################################################################################################################ + # main thread: sleep 10 seconds + ################################################################################################################ + time.sleep(10) + ################################################################################################################ + # main thread: Runtime.getHeapUsage + ################################################################################################################ + await self.runtime_impl.send("Runtime.getHeapUsage", main_thread) + ################################################################################################################ + # main thread: HeapProfiler.stopTrackingHeapObjects + ################################################################################################################ + await self.heap_profiler_impl.send("HeapProfiler.stopTrackingHeapObjects", main_thread) + ################################################################################################################ + # main thread: click on the screen + ################################################################################################################ + self.ui_utils.click_on_middle() + ################################################################################################################ + # worker thread: connect the debugger server + ################################################################################################################ + worker_thread_1 = await self.debugger_impl.connect_to_debugger_server(self.config['pid'], False) + worker_thread_2 = await self.debugger_impl.connect_to_debugger_server(self.config['pid'], False) + ################################################################################################################ + # worker thread: Runtime.enable + ################################################################################################################ + await self.runtime_impl.send("Runtime.enable", worker_thread_1) + await self.runtime_impl.send("Runtime.enable", worker_thread_2) + ################################################################################################################ + # 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.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) + ################################################################################################################ + # worker thread: Debugger.disable + ################################################################################################################ + await self.debugger_impl.send("Debugger.disable", worker_thread_1) + await self.debugger_impl.send("Debugger.disable", worker_thread_2) + ################################################################################################################ + # worker 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 diff --git a/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerAllocation02.json b/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerAllocation02.json new file mode 100644 index 0000000000000000000000000000000000000000..086da51bd323fc5642344443ed0f2f6b81b97d9d --- /dev/null +++ b/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerAllocation02.json @@ -0,0 +1,15 @@ +{ + "description": "Config for TestWorkerProfilerAllocation02", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "toolchain/profiler/TestWorkerProfilerAllocation02.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/scenario_test/test_worker_profiler_allocation_01.py b/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerAllocation02.py similarity index 67% rename from test/autotest/scenario_test/test_worker_profiler_allocation_01.py rename to test/autotest/testcases/toolchain/profiler/TestWorkerProfilerAllocation02.py index f230640ec1bb2adf57a645e3dd1f034a3d5eeb83..b602f1c0e24d1f11c3fd9b47e329a43f92752062 100644 --- a/test/autotest/scenario_test/test_worker_profiler_allocation_01.py +++ b/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerAllocation02.py @@ -1,175 +1,184 @@ -#!/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 TestWorkerProfilerAllocation01: - """ - 测试用例:多实例内存调优 Allocation 录制(attach启动) - 测试步骤: - 1. 拉起应用,attach 主线程 - 2. 连接 connect server 和主线程 debugger server - 3. 连接 worker 线程 debugger server - 4. 所有线程使能 Runtime(Runtime.enable) - 5. 所有线程获取内存使用情况(Runtime.getHeapUsage) - 6. 所有线程启动 Allocation 录制(HeapProfiler.startTrackingHeapObjects) - 7. 所有线程获取内存使用情况(Runtime.getHeapUsage) - 8. 等待 10 秒后关闭 Allocation 录制,获取数据(HeapProfiler.stopTrackingHeapObjects) - 9. 销毁 worker 线程,对应的 debugger server 连接断开 - 10. 关闭主线程 debugger server 和 connect server 连接 - """ - - def setup_method(self): - logging.info('Start running TestWorkerProfilerAllocation01: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_worker_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('TestWorkerProfilerAllocation01 done') - - def test(self, test_suite_worker_02): - logging.info('Start running TestWorkerProfilerAllocation01: test') - self.config = test_suite_worker_02 - 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) - ################################################################################################################ - # 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') +#!/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. + +#================================================================== +#文 件 名: TestWorkerProfilerAllocation02.py +#文件说明: 多实例内存调优 Allocation 录制(-p dumpheap启动) +#================================================================== +测试步骤: + 1. -p dumpheap方式拉起应用 + 2. 连接 connect server 和主线程 debugger server + 3. 连接 worker 线程 debugger server + 4. 所有线程使能 Runtime(Runtime.enable) + 5. 所有线程获取内存使用情况(Runtime.getHeapUsage) + 6. 所有线程启动 Allocation 录制(HeapProfiler.startTrackingHeapObjects) + 7. 所有线程获取内存使用情况(Runtime.getHeapUsage) + 8. 等待 10 秒后关闭 Allocation 录制,获取数据(HeapProfiler.stopTrackingHeapObjects) + 9. 销毁 worker 线程,对应的 debugger server 连接断开 + 10. 关闭主线程 debugger server 和 connect server 连接 +#!!================================================================ +""" +import sys +import time +from pathlib import Path + +root_path = Path(__file__).parent.parent.parent.parent +resource_path = root_path / 'resource' +sys.path.append(str(root_path / 'aw')) # add aw path to sys.path + +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from all_utils import CommonUtils, UiUtils +from cdp import heap_profiler +from implement_api import debugger_api, runtime_api, heap_profiler_api + + +class TestWorkerProfilerAllocation02(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + TestCase.__init__(self, self.TAG, controllers) + self.driver = UiDriver(self.device1) + self.ui_utils = UiUtils(self.driver) + self.common_utils = CommonUtils(self.driver) + self.id_generator = CommonUtils.message_id_generator() + self.config = { + 'start_mode': '-p dumpheap', + 'connect_server_port': 15706, + 'debugger_server_port': 15707, + 'bundle_name': 'com.example.multiWorker02', + 'hap_name': 'MultiWorker02.hap', + 'hap_path': str(resource_path / 'hap' / 'MultiWorker02.hap') + } + + def setup(self): + Step('1.下载应用') + self.driver.install_app(self.config['hap_path'], "-r") + Step('2.启动应用') + self.driver.start_app(package_name=self.config['bundle_name'], params=self.config['start_mode']) + self.config['pid'] = self.common_utils.get_pid(self.config['bundle_name']) + assert self.config['pid'] != 0, f'Failed to get pid of {self.config["bundle_name"]}' + Step('3.设置屏幕常亮') + self.ui_utils.keep_awake() + Step('4.端口映射,连接server') + self.common_utils.connect_server(self.config) + self.debugger_impl = debugger_api.DebuggerImpl(self.id_generator, self.config['websocket']) + self.runtime_impl = runtime_api.RuntimeImpl(self.id_generator, self.config['websocket']) + self.heap_profiler_impl = heap_profiler_api.HeapProfilerImpl(self.id_generator, self.config['websocket']) + + def process(self): + Step('5.执行测试用例') + websocket = self.config['websocket'] + taskpool = self.config['taskpool'] + taskpool.submit(websocket.main_task(taskpool, self.test, self.config['pid'])) + taskpool.await_taskpool() + taskpool.task_join() + if taskpool.task_exception: + raise taskpool.task_exception + + def teardown(self): + Step('6.关闭应用') + self.driver.stop_app(self.config['bundle_name']) + Step('7.卸载应用') + self.driver.uninstall_app(self.config['bundle_name']) + + async def test(self, websocket): + ################################################################################################################ + # main thread: connect the debugger server + ################################################################################################################ + main_thread = await self.debugger_impl.connect_to_debugger_server(self.config['pid'], True) + ################################################################################################################ + # main thread: Runtime.enable + ################################################################################################################ + await self.runtime_impl.send("Runtime.enable", main_thread) + ################################################################################################################ + # main thread: Runtime.getHeapUsage + ################################################################################################################ + await self.runtime_impl.send("Runtime.getHeapUsage", main_thread) + ################################################################################################################ + # main thread: HeapProfiler.startTrackingHeapObjects + ################################################################################################################ + params = heap_profiler.TrackingHeapObjectsParams(False) + await self.heap_profiler_impl.send("HeapProfiler.startTrackingHeapObjects", main_thread, params) + ################################################################################################################ + # main thread: Debugger.disable + ################################################################################################################ + await self.debugger_impl.send("Debugger.disable", main_thread) + ################################################################################################################ + # main thread: sleep 10 seconds + ################################################################################################################ + time.sleep(10) + ################################################################################################################ + # main thread: Runtime.getHeapUsage + ################################################################################################################ + await self.runtime_impl.send("Runtime.getHeapUsage", main_thread) + ################################################################################################################ + # main thread: HeapProfiler.stopTrackingHeapObjects + ################################################################################################################ + await self.heap_profiler_impl.send("HeapProfiler.stopTrackingHeapObjects", main_thread) + ################################################################################################################ + # main thread: click on the screen + ################################################################################################################ + self.ui_utils.click_on_middle() + ################################################################################################################ + # worker thread: connect the debugger server + ################################################################################################################ + worker_thread_1 = await self.debugger_impl.connect_to_debugger_server(self.config['pid'], False) + worker_thread_2 = await self.debugger_impl.connect_to_debugger_server(self.config['pid'], False) + ################################################################################################################ + # worker thread: Runtime.enable + ################################################################################################################ + await self.runtime_impl.send("Runtime.enable", worker_thread_1) + await self.runtime_impl.send("Runtime.enable", worker_thread_2) + ################################################################################################################ + # 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.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) + ################################################################################################################ + # worker thread: Debugger.disable + ################################################################################################################ + await self.debugger_impl.send("Debugger.disable", worker_thread_1) + await self.debugger_impl.send("Debugger.disable", worker_thread_2) + ################################################################################################################ + # worker 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 diff --git a/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerHeapSampling.json b/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerHeapSampling.json new file mode 100644 index 0000000000000000000000000000000000000000..d25626cba8b4cbddb052ec64bd801e812631d24c --- /dev/null +++ b/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerHeapSampling.json @@ -0,0 +1,15 @@ +{ + "description": "Config for TestWorkerProfilerHeapSampling", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "toolchain/profiler/TestWorkerProfilerHeapSampling.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/scenario_test/test_worker_profiler_heap_sampling.py b/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerHeapSampling.py similarity index 60% rename from test/autotest/scenario_test/test_worker_profiler_heap_sampling.py rename to test/autotest/testcases/toolchain/profiler/TestWorkerProfilerHeapSampling.py index 16b22fb146578d77d374014f6adbad32d25b6ec9..0fa77baebc064b78007ca0ee371897768221b7c1 100644 --- a/test/autotest/scenario_test/test_worker_profiler_heap_sampling.py +++ b/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerHeapSampling.py @@ -1,156 +1,167 @@ -#!/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.api import debugger_api, runtime_api, heap_profiler_api - - -@pytest.mark.heap_profiler -@pytest.mark.timeout(80) -class TestWorkerProfilerHeapSampling: - """ - 测试用例:多实例内存调优 HeapSampling 录制 - 测试步骤: - 1. 拉起应用,attach 主线程 - 2. 连接 connect server 和主线程 debugger server - 3. 连接 worker 线程 debugger server - 4. 所有线程使能 Runtime(Runtime.enable) - 5. 所有线程去使能 Debugger(Debugger.disable) - 6. 所有线程开启内存采样(HeapProfiler.startSampling) - 7. 等待 10 秒后,所有线程结束内存采样,获取数据(HeapProfiler.stopSampling) - 8. 销毁 worker 线程,对应的 debugger server 连接断开 - 9. 关闭主线程 debugger server 和 connect server 连接 - """ - - def setup_method(self): - logging.info('Start running TestWorkerProfilerHeapSampling: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_worker_profiler_heap_sampling.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('TestWorkerProfilerHeapSampling done') - - def test(self, test_suite_worker_02): - logging.info('Start running TestWorkerProfilerHeapSampling: test') - self.config = test_suite_worker_02 - 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: 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) - ################################################################################################################ - # main thread: HeapProfiler.startSampling - ################################################################################################################ - await self.heap_profiler_impl.send("HeapProfiler.startSampling", main_thread) - ################################################################################################################ - # worker thread: HeapProfiler.startSampling - ################################################################################################################ - await self.heap_profiler_impl.send("HeapProfiler.startSampling", worker_thread_1) - await self.heap_profiler_impl.send("HeapProfiler.startSampling", worker_thread_2) - ################################################################################################################ - # all thread: sleep 10 seconds - ################################################################################################################ - time.sleep(10) - ################################################################################################################ - # main thread: HeapProfiler.stopSampling - ################################################################################################################ - response = await self.heap_profiler_impl.send("HeapProfiler.stopSampling", main_thread) - assert response['result']['profile'] is not None - ################################################################################################################ - # worker thread: HeapProfiler.stopSampling - ################################################################################################################ - response = await self.heap_profiler_impl.send("HeapProfiler.stopSampling", worker_thread_1) - assert response['result']['profile'] is not None - response = await self.heap_profiler_impl.send("HeapProfiler.stopSampling", worker_thread_2) - assert response['result']['profile'] is not None - ################################################################################################################ - # 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') +#!/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. + +#================================================================== +#文 件 名: TestWorkerProfilerHeapSampling.py +#文件说明: 多实例内存调优 HeapSampling 录制 +#================================================================== +测试步骤: + 1. 拉起应用,attach 主线程 + 2. 连接 connect server 和主线程 debugger server + 3. 连接 worker 线程 debugger server + 4. 所有线程使能 Runtime(Runtime.enable) + 5. 所有线程去使能 Debugger(Debugger.disable) + 6. 所有线程开启内存采样(HeapProfiler.startSampling) + 7. 等待 10 秒后,所有线程结束内存采样,获取数据(HeapProfiler.stopSampling) + 8. 销毁 worker 线程,对应的 debugger server 连接断开 + 9. 关闭主线程 debugger server 和 connect server 连接 +#!!================================================================ +""" +import sys +import time +from pathlib import Path + +root_path = Path(__file__).parent.parent.parent.parent +resource_path = root_path / 'resource' +sys.path.append(str(root_path / 'aw')) # add aw path to sys.path + +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from all_utils import CommonUtils, UiUtils +from implement_api import debugger_api, runtime_api, heap_profiler_api + + +class TestWorkerProfilerHeapSampling(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + TestCase.__init__(self, self.TAG, controllers) + self.driver = UiDriver(self.device1) + self.ui_utils = UiUtils(self.driver) + self.common_utils = CommonUtils(self.driver) + self.id_generator = CommonUtils.message_id_generator() + self.config = { + 'start_mode': '', + 'connect_server_port': 15708, + 'debugger_server_port': 15709, + 'bundle_name': 'com.example.multiWorker02', + 'hap_name': 'MultiWorker02.hap', + 'hap_path': str(resource_path / 'hap' / 'MultiWorker02.hap') + } + + def setup(self): + Step('1.下载应用') + self.driver.install_app(self.config['hap_path'], "-r") + Step('2.启动应用') + self.driver.start_app(package_name=self.config['bundle_name'], params=self.config['start_mode']) + self.config['pid'] = self.common_utils.get_pid(self.config['bundle_name']) + assert self.config['pid'] != 0, f'Failed to get pid of {self.config["bundle_name"]}' + Step('3.设置屏幕常亮') + self.ui_utils.keep_awake() + Step('4.端口映射,连接server') + self.common_utils.connect_server(self.config) + self.debugger_impl = debugger_api.DebuggerImpl(self.id_generator, self.config['websocket']) + self.runtime_impl = runtime_api.RuntimeImpl(self.id_generator, self.config['websocket']) + self.heap_profiler_impl = heap_profiler_api.HeapProfilerImpl(self.id_generator, self.config['websocket']) + Step('5.attach调试应用') + self.common_utils.attach(self.config['bundle_name']) + + def process(self): + Step('6.执行测试用例') + websocket = self.config['websocket'] + taskpool = self.config['taskpool'] + taskpool.submit(websocket.main_task(taskpool, self.test, self.config['pid'])) + taskpool.await_taskpool() + taskpool.task_join() + if taskpool.task_exception: + raise taskpool.task_exception + + def teardown(self): + Step('7.关闭应用') + self.driver.stop_app(self.config['bundle_name']) + Step('8.卸载应用') + self.driver.uninstall_app(self.config['bundle_name']) + + async def test(self, websocket): + ################################################################################################################ + # main thread: connect the debugger server + ################################################################################################################ + main_thread = await self.debugger_impl.connect_to_debugger_server(self.config['pid'], True) + ################################################################################################################ + # main thread: Runtime.enable + ################################################################################################################ + await self.runtime_impl.send("Runtime.enable", main_thread) + ################################################################################################################ + # main thread: Debugger.disable + ################################################################################################################ + await self.debugger_impl.send("Debugger.disable", main_thread) + ################################################################################################################ + # main thread: HeapProfiler.startSampling + ################################################################################################################ + await self.heap_profiler_impl.send("HeapProfiler.startSampling", main_thread) + ################################################################################################################ + # all thread: sleep 10 seconds + ################################################################################################################ + time.sleep(10) + ################################################################################################################ + # main thread: HeapProfiler.stopSampling + ################################################################################################################ + response = await self.heap_profiler_impl.send("HeapProfiler.stopSampling", main_thread) + assert response['result']['profile'] is not None, f'Profile in result can not be None' + ################################################################################################################ + # main thread: click on the screen + ################################################################################################################ + self.ui_utils.click_on_middle() + ################################################################################################################ + # worker thread: connect the debugger server + ################################################################################################################ + worker_thread_1 = await self.debugger_impl.connect_to_debugger_server(self.config['pid'], False) + worker_thread_2 = await self.debugger_impl.connect_to_debugger_server(self.config['pid'], False) + ################################################################################################################ + # worker thread: Runtime.enable + ################################################################################################################ + await self.runtime_impl.send("Runtime.enable", worker_thread_1) + await self.runtime_impl.send("Runtime.enable", worker_thread_2) + ################################################################################################################ + # worker thread: Debugger.disable + ################################################################################################################ + await self.debugger_impl.send("Debugger.disable", worker_thread_1) + await self.debugger_impl.send("Debugger.disable", worker_thread_2) + ################################################################################################################ + # worker thread: HeapProfiler.startSampling + ################################################################################################################ + await self.heap_profiler_impl.send("HeapProfiler.startSampling", worker_thread_1) + await self.heap_profiler_impl.send("HeapProfiler.startSampling", worker_thread_2) + ################################################################################################################ + # worker thread: sleep 10 seconds + ################################################################################################################ + time.sleep(10) + ################################################################################################################ + # worker thread: HeapProfiler.stopSampling + ################################################################################################################ + response = await self.heap_profiler_impl.send("HeapProfiler.stopSampling", worker_thread_1) + assert response['result']['profile'] is not None, f'Profile in result can not be None' + response = await self.heap_profiler_impl.send("HeapProfiler.stopSampling", worker_thread_2) + assert response['result']['profile'] is not None, f'Profile in result can not be None' + ################################################################################################################ + # 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 diff --git a/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerLaunch.json b/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerLaunch.json new file mode 100644 index 0000000000000000000000000000000000000000..00a111eaf5145edf6d8feccb7eb0911caf91b560 --- /dev/null +++ b/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerLaunch.json @@ -0,0 +1,15 @@ +{ + "description": "Config for TestWorkerProfilerLaunch", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "toolchain/profiler/TestWorkerProfilerLaunch.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/scenario_test/test_worker_profiler_launch.py b/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerLaunch.py similarity index 58% rename from test/autotest/scenario_test/test_worker_profiler_launch.py rename to test/autotest/testcases/toolchain/profiler/TestWorkerProfilerLaunch.py index eab47f7f01b37bbbe3598895717a28dd33c67d4a..e873a874a018b788780dd32eee0921b47c28265e 100644 --- a/test/autotest/scenario_test/test_worker_profiler_launch.py +++ b/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerLaunch.py @@ -1,149 +1,159 @@ -#!/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 Utils -from aw import Application -from aw import profiler -from aw.api import debugger_api, runtime_api, profiler_api - - -@pytest.mark.cpu_profiler -@pytest.mark.timeout(80) -class TestWorkerProfilerLaunch: - """ - 测试用例:多实例 CPU 调优 Launch 录制 - 测试步骤: - 1. -p 模式启动应用 - 2. 连接 connect server 和主线程 debugger server - 3. 连接 worker 线程 debugger server - 4. worker 线程使能 Runtime(Runtime.enable) - 5. worker 线程设置采样间隔(Profiler.setSamplingInterval) - 6. worker 线程启动 CPU 调试(Profiler.start) - 7. worker 线程去使能 Debugger(Debugger.disable) - 8. 等待 10 秒后关闭 worker 线程 CPU 调优,获取 worker 线程调优数据(Profiler.stop) - 9. 销毁 worker 线程,对应的 debugger server 连接断开 - 10. 关闭主线程 CPU 调优,获取主线程调优数据(Profiler.stop) - 11. 关闭主线程 debugger server 和 connect server 连接 - """ - - def setup_method(self): - logging.info('Start running TestWorkerProfilerLaunch: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_worker_profiler_launch.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('TestWorkerProfilerLaunch done') - - def test(self, test_suite_worker_02_profile_jsperf): - logging.info('Start running TestWorkerProfilerLaunch: test') - self.config = test_suite_worker_02_profile_jsperf - 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.profiler_impl = profiler_api.ProfilerImpl(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}') - ################################################################################################################ - # 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}') - ################################################################################################################ - # worker thread: Runtime.enable - ################################################################################################################ - await self.runtime_impl.send("Runtime.enable", worker_thread_1) - await self.runtime_impl.send("Runtime.enable", worker_thread_2) - ################################################################################################################ - # worker thread: Profiler.setSamplingInterval - ################################################################################################################ - params = profiler.SamplingInterval(500) - await self.profiler_impl.send("Profiler.setSamplingInterval", worker_thread_1, params) - await self.profiler_impl.send("Profiler.setSamplingInterval", worker_thread_2, params) - ################################################################################################################ - # worker thread: Profiler.start - ################################################################################################################ - await self.profiler_impl.send("Profiler.start", worker_thread_1) - await self.profiler_impl.send("Profiler.start", worker_thread_2) - ################################################################################################################ - # 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) - ################################################################################################################ - # worker thread: Profiler.stop - ################################################################################################################ - await self.profiler_impl.send("Profiler.stop", worker_thread_1) - await self.profiler_impl.send("Profiler.stop", worker_thread_2) - ################################################################################################################ - # main thread: Profiler.stop - ################################################################################################################ - await self.profiler_impl.send("Profiler.stop", main_thread) - ################################################################################################################ - # 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') +#!/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. + +#================================================================== +#文 件 名: TestWorkerProfilerLaunch.py +#文件说明: 多实例 CPU 调优 Launch 录制 +#================================================================== +测试步骤: + 1. -p 模式启动应用 + 2. 连接 connect server 和主线程 debugger server + 3. 连接 worker 线程 debugger server + 4. worker 线程使能 Runtime(Runtime.enable) + 5. worker 线程设置采样间隔(Profiler.setSamplingInterval) + 6. worker 线程启动 CPU 调优(Profiler.start) + 7. worker 线程去使能 Debugger(Debugger.disable) + 8. 等待 10 秒后关闭 worker 线程 CPU 调优,获取 worker 线程调优数据(Profiler.stop) + 9. 销毁 worker 线程,对应的 debugger server 连接断开 + 10. 关闭主线程 CPU 调优,获取主线程调优数据(Profiler.stop) + 11. 关闭主线程 debugger server 和 connect server 连接 +#!!================================================================ +""" +import sys +import time +from pathlib import Path + +root_path = Path(__file__).parent.parent.parent.parent +resource_path = root_path / 'resource' +sys.path.append(str(root_path / 'aw')) # add aw path to sys.path + +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from all_utils import CommonUtils, UiUtils +from cdp import profiler +from implement_api import debugger_api, runtime_api, profiler_api + + +class TestWorkerProfilerLaunch(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + TestCase.__init__(self, self.TAG, controllers) + self.driver = UiDriver(self.device1) + self.ui_utils = UiUtils(self.driver) + self.common_utils = CommonUtils(self.driver) + self.id_generator = CommonUtils.message_id_generator() + self.config = { + 'start_mode': '-p "profile jsperf"', + 'connect_server_port': 15710, + 'debugger_server_port': 15711, + 'bundle_name': 'com.example.multiWorker02', + 'hap_name': 'MultiWorker02.hap', + 'hap_path': str(resource_path / 'hap' / 'MultiWorker02.hap') + } + + def setup(self): + Step('1.下载应用') + self.driver.install_app(self.config['hap_path'], "-r") + Step('2.启动应用') + self.driver.start_app(package_name=self.config['bundle_name'], params=self.config['start_mode']) + self.config['pid'] = self.common_utils.get_pid(self.config['bundle_name']) + assert self.config['pid'] != 0, f'Failed to get pid of {self.config["bundle_name"]}' + Step('3.设置屏幕常亮') + self.ui_utils.keep_awake() + Step('4.端口映射,连接server') + self.common_utils.connect_server(self.config) + self.debugger_impl = debugger_api.DebuggerImpl(self.id_generator, self.config['websocket']) + self.runtime_impl = runtime_api.RuntimeImpl(self.id_generator, self.config['websocket']) + self.profiler_impl = profiler_api.ProfilerImpl(self.id_generator, self.config['websocket']) + + def process(self): + Step('5.执行测试用例') + websocket = self.config['websocket'] + taskpool = self.config['taskpool'] + taskpool.submit(websocket.main_task(taskpool, self.test, self.config['pid'])) + taskpool.await_taskpool() + taskpool.task_join() + if taskpool.task_exception: + raise taskpool.task_exception + + def teardown(self): + Step('6.关闭应用') + self.driver.stop_app(self.config['bundle_name']) + Step('7.卸载应用') + self.driver.uninstall_app(self.config['bundle_name']) + + async def test(self, websocket): + ################################################################################################################ + # main thread: connect the debugger server + ################################################################################################################ + main_thread = await self.debugger_impl.connect_to_debugger_server(self.config['pid'], True) + ################################################################################################################ + # main thread: sleep 10 seconds + ################################################################################################################ + time.sleep(10) + ################################################################################################################ + # main thread: Profiler.stop + ################################################################################################################ + await self.profiler_impl.send("Profiler.stop", main_thread) + ################################################################################################################ + # main thread: click on the screen + ################################################################################################################ + self.ui_utils.click_on_middle() + ################################################################################################################ + # worker thread: connect the debugger server + ################################################################################################################ + worker_thread_1 = await self.debugger_impl.connect_to_debugger_server(self.config['pid'], False) + worker_thread_2 = await self.debugger_impl.connect_to_debugger_server(self.config['pid'], False) + ################################################################################################################ + # worker thread: Runtime.enable + ################################################################################################################ + await self.runtime_impl.send("Runtime.enable", worker_thread_1) + await self.runtime_impl.send("Runtime.enable", worker_thread_2) + ################################################################################################################ + # worker thread: Profiler.setSamplingInterval + ################################################################################################################ + params = profiler.SamplingInterval(500) + await self.profiler_impl.send("Profiler.setSamplingInterval", worker_thread_1, params) + await self.profiler_impl.send("Profiler.setSamplingInterval", worker_thread_2, params) + ################################################################################################################ + # worker thread: Profiler.start + ################################################################################################################ + await self.profiler_impl.send("Profiler.start", worker_thread_1) + await self.profiler_impl.send("Profiler.start", worker_thread_2) + ################################################################################################################ + # worker thread: Debugger.disable + ################################################################################################################ + await self.debugger_impl.send("Debugger.disable", worker_thread_1) + await self.debugger_impl.send("Debugger.disable", worker_thread_2) + ################################################################################################################ + # worker thread: sleep 10 seconds + ################################################################################################################ + time.sleep(10) + ################################################################################################################ + # worker thread: Profiler.stop + ################################################################################################################ + await self.profiler_impl.send("Profiler.stop", worker_thread_1) + await self.profiler_impl.send("Profiler.stop", 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 diff --git a/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerTime.json b/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerTime.json new file mode 100644 index 0000000000000000000000000000000000000000..ba97f315cda633ba300e91f1f08c097366a82d27 --- /dev/null +++ b/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerTime.json @@ -0,0 +1,15 @@ +{ + "description": "Config for TestWorkerProfilerTime", + "environment": [ + { + "type": "device", + "label": "phone" + } + ], + "driver": { + "type": "DeviceTest", + "py_file": [ + "toolchain/profiler/TestWorkerProfilerTime.py" + ] + } +} \ No newline at end of file diff --git a/test/autotest/scenario_test/test_worker_profiler_time.py b/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerTime.py similarity index 65% rename from test/autotest/scenario_test/test_worker_profiler_time.py rename to test/autotest/testcases/toolchain/profiler/TestWorkerProfilerTime.py index 0e98031b930323f28bdfc7ce38adb9010b8b9e60..0107053f990d76870439e16af2ee24b067ce7fc5 100644 --- a/test/autotest/scenario_test/test_worker_profiler_time.py +++ b/test/autotest/testcases/toolchain/profiler/TestWorkerProfilerTime.py @@ -1,164 +1,174 @@ -#!/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 Utils -from aw import Application -from aw import profiler -from aw.api import debugger_api, runtime_api, profiler_api - - -@pytest.mark.cpu_profiler -@pytest.mark.timeout(80) -class TestWorkerProfilerTime: - """ - 测试用例:多实例 CPU 调优 Time 录制 - 测试步骤: - 1. 连接 connect server 和主线程 debugger server - 2. 连接 worker 线程 debugger server - 3. 所有线程使能 Runtime(Runtime.enable) - 4. 所有线程设置采样间隔(Profiler.setSamplingInterval) - 5. 所有线程启动 CPU 调试(Profiler.start) - 6. 所有线程去使能 Debugger(Debugger.disable) - 7. 等待 10 秒后关闭 CPU 调优,获取调优数据(Profiler.stop) - 8. 销毁 worker 线程,对应的 debugger server 连接断开 - 9. 关闭主线程 debugger server 和 connect server 连接 - """ - - def setup_method(self): - logging.info('Start running TestWorkerProfilerTime: setup') - - self.log_path = rf'{os.path.dirname(__file__)}\..\log' - self.hilog_file_name = 'test_worker_profiler_time.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('TestWorkerProfilerTime done') - - def test(self, test_suite_worker_02): - logging.info('Start running TestWorkerProfilerTime: test') - self.config = test_suite_worker_02 - 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.profiler_impl = profiler_api.ProfilerImpl(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}') - ################################################################################################################ - # 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: Profiler.setSamplingInterval - ################################################################################################################ - params = profiler.SamplingInterval(500) - await self.profiler_impl.send("Profiler.setSamplingInterval", main_thread, params) - ################################################################################################################ - # worker thread: Profiler.setSamplingInterval - ################################################################################################################ - params = profiler.SamplingInterval(500) - await self.profiler_impl.send("Profiler.setSamplingInterval", worker_thread_1, params) - await self.profiler_impl.send("Profiler.setSamplingInterval", worker_thread_2, params) - ################################################################################################################ - # main thread: Profiler.start - ################################################################################################################ - await self.profiler_impl.send("Profiler.start", main_thread) - ################################################################################################################ - # worker thread: Profiler.start - ################################################################################################################ - await self.profiler_impl.send("Profiler.start", worker_thread_1) - await self.profiler_impl.send("Profiler.start", worker_thread_2) - ################################################################################################################ - # 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: Profiler.stop - ################################################################################################################ - await self.profiler_impl.send("Profiler.stop", main_thread) - ################################################################################################################ - # worker thread: Profiler.stop - ################################################################################################################ - await self.profiler_impl.send("Profiler.stop", worker_thread_1) - await self.profiler_impl.send("Profiler.stop", 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') +#!/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. + +#================================================================== +#文 件 名: TestWorkerProfilerTime.py +#文件说明: 多实例 CPU 调优 Time 录制 +#================================================================== +测试步骤: + 1. 连接 connect server 和主线程 debugger server + 2. 连接 worker 线程 debugger server + 3. 所有线程使能 Runtime(Runtime.enable) + 4. 所有线程设置采样间隔(Profiler.setSamplingInterval) + 5. 所有线程启动 CPU 调优(Profiler.start) + 6. 所有线程去使能 Debugger(Debugger.disable) + 7. 等待 10 秒后关闭 CPU 调优,获取调优数据(Profiler.stop) + 8. 销毁 worker 线程,对应的 debugger server 连接断开 + 9. 关闭主线程 debugger server 和 connect server 连接 +#!!================================================================ +""" +import sys +import time +from pathlib import Path + +root_path = Path(__file__).parent.parent.parent.parent +resource_path = root_path / 'resource' +sys.path.append(str(root_path / 'aw')) # add aw path to sys.path + +from devicetest.core.test_case import TestCase, Step +from hypium import UiDriver +from all_utils import CommonUtils, UiUtils +from cdp import profiler +from implement_api import debugger_api, runtime_api, profiler_api + + +class TestWorkerProfilerTime(TestCase): + def __init__(self, controllers): + self.TAG = self.__class__.__name__ + TestCase.__init__(self, self.TAG, controllers) + self.driver = UiDriver(self.device1) + self.ui_utils = UiUtils(self.driver) + self.common_utils = CommonUtils(self.driver) + self.id_generator = CommonUtils.message_id_generator() + self.config = { + 'start_mode': '', + 'connect_server_port': 15712, + 'debugger_server_port': 15713, + 'bundle_name': 'com.example.multiWorker02', + 'hap_name': 'MultiWorker02.hap', + 'hap_path': str(resource_path / 'hap' / 'MultiWorker02.hap') + } + + def setup(self): + Step('1.下载应用') + self.driver.install_app(self.config['hap_path'], "-r") + Step('2.启动应用') + self.driver.start_app(package_name=self.config['bundle_name'], params=self.config['start_mode']) + self.config['pid'] = self.common_utils.get_pid(self.config['bundle_name']) + assert self.config['pid'] != 0, f'Failed to get pid of {self.config["bundle_name"]}' + Step('3.设置屏幕常亮') + self.ui_utils.keep_awake() + Step('4.端口映射,连接server') + self.common_utils.connect_server(self.config) + self.debugger_impl = debugger_api.DebuggerImpl(self.id_generator, self.config['websocket']) + self.runtime_impl = runtime_api.RuntimeImpl(self.id_generator, self.config['websocket']) + self.profiler_impl = profiler_api.ProfilerImpl(self.id_generator, self.config['websocket']) + + def process(self): + Step('5.执行测试用例') + websocket = self.config['websocket'] + taskpool = self.config['taskpool'] + taskpool.submit(websocket.main_task(taskpool, self.test, self.config['pid'])) + taskpool.await_taskpool() + taskpool.task_join() + if taskpool.task_exception: + raise taskpool.task_exception + + def teardown(self): + Step('6.关闭应用') + self.driver.stop_app(self.config['bundle_name']) + Step('7.卸载应用') + self.driver.uninstall_app(self.config['bundle_name']) + + async def test(self, websocket): + ################################################################################################################ + # main thread: connect the debugger server + ################################################################################################################ + main_thread = await self.debugger_impl.connect_to_debugger_server(self.config['pid'], True) + ################################################################################################################ + # main thread: Runtime.enable + ################################################################################################################ + await self.runtime_impl.send("Runtime.enable", main_thread) + ################################################################################################################ + # main thread: Profiler.setSamplingInterval + ################################################################################################################ + params = profiler.SamplingInterval(500) + await self.profiler_impl.send("Profiler.setSamplingInterval", main_thread, params) + ################################################################################################################ + # main thread: Profiler.start + ################################################################################################################ + await self.profiler_impl.send("Profiler.start", main_thread) + ################################################################################################################ + # main thread: Debugger.disable + ################################################################################################################ + await self.debugger_impl.send("Debugger.disable", main_thread) + ################################################################################################################ + # main thread: sleep 10 seconds + ################################################################################################################ + time.sleep(10) + ################################################################################################################ + # main thread: Profiler.stop + ################################################################################################################ + await self.profiler_impl.send("Profiler.stop", main_thread) + ################################################################################################################ + # main thread: click on the screen + ################################################################################################################ + self.ui_utils.click_on_middle() + ################################################################################################################ + # worker thread: connect the debugger server + ################################################################################################################ + worker_thread_1 = await self.debugger_impl.connect_to_debugger_server(self.config['pid'], False) + worker_thread_2 = await self.debugger_impl.connect_to_debugger_server(self.config['pid'], False) + ################################################################################################################ + # worker thread: Runtime.enable + ################################################################################################################ + await self.runtime_impl.send("Runtime.enable", worker_thread_1) + await self.runtime_impl.send("Runtime.enable", worker_thread_2) + ################################################################################################################ + # worker thread: Profiler.setSamplingInterval + ################################################################################################################ + params = profiler.SamplingInterval(500) + await self.profiler_impl.send("Profiler.setSamplingInterval", worker_thread_1, params) + await self.profiler_impl.send("Profiler.setSamplingInterval", worker_thread_2, params) + ################################################################################################################ + # worker thread: Profiler.start + ################################################################################################################ + await self.profiler_impl.send("Profiler.start", worker_thread_1) + await self.profiler_impl.send("Profiler.start", worker_thread_2) + ################################################################################################################ + # worker thread: Debugger.disable + ################################################################################################################ + await self.debugger_impl.send("Debugger.disable", worker_thread_1) + await self.debugger_impl.send("Debugger.disable", worker_thread_2) + ################################################################################################################ + # worker thread: sleep 10 seconds + ################################################################################################################ + time.sleep(10) + ################################################################################################################ + # worker thread: Profiler.stop + ################################################################################################################ + await self.profiler_impl.send("Profiler.stop", worker_thread_1) + await self.profiler_impl.send("Profiler.stop", 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