diff --git a/test/autotest/aw/api/debugger_api.py b/test/autotest/aw/api/debugger_api.py new file mode 100644 index 0000000000000000000000000000000000000000..abbb3df6b13bdf7d481f8962c8a2c7bf16b6703b --- /dev/null +++ b/test/autotest/aw/api/debugger_api.py @@ -0,0 +1,132 @@ +#!/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: Python Debugger Domain Interfaces. +""" + +import json +import logging + +from aw import communicate_with_debugger_server +from aw import Utils +from aw.cdp import debugger +from aw.types import ThreadConnectionInfo + + +async def connect_to_debugger_server(websocket, pid, is_main=True): + if is_main: + send_msg = {"type": "connected"} + await websocket.send_msg_to_connect_server(send_msg) + response = await websocket.recv_msg_of_connect_server() + response = json.loads(response) + assert response['type'] == 'addInstance' + assert response['instanceId'] == 0, logging.error('Instance id of the main thread is not equal to 0') + assert response['tid'] == pid + else: + response = await websocket.recv_msg_of_connect_server() + response = json.loads(response) + assert response['type'] == 'addInstance' + assert response['instanceId'] != 0 + assert response['tid'] != pid + assert 'workerThread_' in response['name'] + instance_id = await websocket.get_instance() + send_queue = websocket.to_send_msg_queues[instance_id] + received_queue = websocket.received_msg_queues[instance_id] + connection_info = ThreadConnectionInfo(instance_id, send_queue, received_queue) + return connection_info + + +async def destroy_instance(websocket): + response = await websocket.recv_msg_of_connect_server() + response = json.loads(response) + return response + + +async def enable(message_id, websocket, connection_info): + response = await communicate_with_debugger_server(connection_info.instance_id, + connection_info.send_msg_queue, + connection_info.received_msg_queue, + debugger.enable(), message_id) + while response.startswith('{"method":"Debugger.scriptParsed"'): + response = await websocket.recv_msg_of_debugger_server(connection_info.instance_id, + connection_info.received_msg_queue) + assert json.loads(response) == {"id": message_id, "result": {"debuggerId": "0", + "protocols": Utils.get_custom_protocols()}} + + +async def disable(message_id, websocket, connection_info): + response = await communicate_with_debugger_server(connection_info.instance_id, + connection_info.send_msg_queue, + connection_info.received_msg_queue, + debugger.disable(), message_id) + assert json.loads(response) == {"method": "Debugger.resumed", "params": {}} + response = await websocket.recv_msg_of_debugger_server(connection_info.instance_id, + connection_info.received_msg_queue) + assert json.loads(response) == {"id": message_id, "result": {}} + + +async def script_parsed(websocket, connection_info): + response = await websocket.recv_msg_of_debugger_server(connection_info.instance_id, + connection_info.received_msg_queue) + response = json.loads(response) + return response + + +async def paused(websocket, connection_info): + response = await websocket.recv_msg_of_debugger_server(connection_info.instance_id, + connection_info.received_msg_queue) + response = json.loads(response) + return response + + +async def resume(message_id, websocket, connection_info): + response = await communicate_with_debugger_server(connection_info.instance_id, + connection_info.send_msg_queue, + connection_info.received_msg_queue, + debugger.resume(), message_id) + assert json.loads(response) == {"method": "Debugger.resumed", "params": {}} + response = await websocket.recv_msg_of_debugger_server(connection_info.instance_id, + connection_info.received_msg_queue) + assert json.loads(response) == {"id": message_id, "result": {}} + + +async def remove_breakpoints_by_url(message_id, url, connection_info): + response = await communicate_with_debugger_server(connection_info.instance_id, + connection_info.send_msg_queue, + connection_info.received_msg_queue, + debugger.remove_breakpoints_by_url(url), message_id) + assert json.loads(response) == {"id": message_id, "result": {}} + + +async def get_possible_and_set_breakpoints_by_url(message_id, locations, connection_info): + response = await communicate_with_debugger_server(connection_info.instance_id, + connection_info.send_msg_queue, + connection_info.received_msg_queue, + debugger.get_possible_and_set_breakpoint_by_url(locations), + message_id) + response = json.loads(response) + return response + + +async def step_over(message_id, websocket, connection_info): + response = await communicate_with_debugger_server(connection_info.instance_id, + connection_info.send_msg_queue, + connection_info.received_msg_queue, + debugger.step_over(), message_id) + assert json.loads(response) == {"method": "Debugger.resumed", "params": {}} + response = await websocket.recv_msg_of_debugger_server(connection_info.instance_id, + connection_info.received_msg_queue) + assert json.loads(response) == {"id": message_id, "result": {}} diff --git a/test/autotest/aw/api/runtime_api.py b/test/autotest/aw/api/runtime_api.py new file mode 100644 index 0000000000000000000000000000000000000000..809b537d619854a6442c7f7bbcac1bf14256628f --- /dev/null +++ b/test/autotest/aw/api/runtime_api.py @@ -0,0 +1,53 @@ +#!/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: Python Runtime Domain Interfaces. +""" + +import json + +from aw import communicate_with_debugger_server +from aw.cdp import runtime + + +async def enable(message_id, connection_info): + response = await communicate_with_debugger_server(connection_info.instance_id, + connection_info.send_msg_queue, + connection_info.received_msg_queue, + runtime.enable(), message_id) + assert json.loads(response) == {"id": message_id, "result": {"protocols":[]}} + + +async def run_if_waiting_for_debugger(message_id, connection_info): + response = await communicate_with_debugger_server(connection_info.instance_id, + connection_info.send_msg_queue, + connection_info.received_msg_queue, + runtime.run_if_waiting_for_debugger(), message_id) + assert json.loads(response) == {"id": message_id, "result": {}} + + +async def get_properties(message_id, connection_info, object_id, own_properties=True, accessor_properties_only=False, + generate_preview=True): + response = await communicate_with_debugger_server(connection_info.instance_id, + connection_info.send_msg_queue, + connection_info.received_msg_queue, + runtime.get_properties(object_id=object_id, + own_properties=own_properties, + accessor_properties_only=accessor_properties_only, + generate_preview=generate_preview), + message_id) + response = json.loads(response) + return response diff --git a/test/autotest/aw/types.py b/test/autotest/aw/types.py new file mode 100644 index 0000000000000000000000000000000000000000..9bca69561e7e99b976036613a1a5b7fd993e9e93 --- /dev/null +++ b/test/autotest/aw/types.py @@ -0,0 +1,28 @@ +#!/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: Data Transferring Classes. +""" + +import asyncio +from dataclasses import dataclass + + +@dataclass(init=True) +class ThreadConnectionInfo: + instance_id: int # Instance id + send_msg_queue: asyncio.Queue # Message send queue + received_msg_queue: asyncio.Queue # Message receive queue diff --git a/test/autotest/scenario_test/test_debug_01.py b/test/autotest/scenario_test/test_debug_01.py index 94322b2db136a6514fd9e089a3419845ecc67ac7..a0e347ebd108c97c7accf817c8bfbc8e837da9f6 100644 --- a/test/autotest/scenario_test/test_debug_01.py +++ b/test/autotest/scenario_test/test_debug_01.py @@ -17,7 +17,6 @@ limitations under the License. Description: Scenario test case. """ -import json import logging import os import time @@ -26,8 +25,8 @@ import pytest from aw import Application from aw import Utils -from aw import communicate_with_debugger_server -from aw import debugger, runtime +from aw import debugger +from aw.api import debugger_api, runtime_api @pytest.mark.debug @@ -94,61 +93,34 @@ class TestDebug01: ################################################################################################################ # main thread: connect the debugger server ################################################################################################################ - send_msg = {"type": "connected"} - await websocket.send_msg_to_connect_server(send_msg) - response = await websocket.recv_msg_of_connect_server() - response = json.loads(response) - assert response['type'] == 'addInstance' - assert response['instanceId'] == 0, logging.error('instance id of the main thread not equal to 0') - assert response['tid'] == self.config['pid'] - main_thread_instance_id = await websocket.get_instance() - main_thread_to_send_queue = websocket.to_send_msg_queues[main_thread_instance_id] - main_thread_received_queue = websocket.received_msg_queues[main_thread_instance_id] - logging.info(f'Connect to the debugger server of instance: {main_thread_instance_id}') + connection_info = await debugger_api.connect_to_debugger_server(websocket, self.config['pid'], True) + logging.info(f'Connect to the debugger server of instance: {connection_info.instance_id}') ################################################################################################################ # main thread: runtime.enable ################################################################################################################ message_id = next(self.id_generator) - response = await communicate_with_debugger_server(main_thread_instance_id, - main_thread_to_send_queue, - main_thread_received_queue, - runtime.enable(), message_id) - assert json.loads(response) == {"id": message_id, "result": {"protocols": []}} - + await runtime_api.enable(message_id, connection_info) ################################################################################################################ # main thread: debugger.enable ################################################################################################################ message_id = next(self.id_generator) - response = await communicate_with_debugger_server(main_thread_instance_id, - main_thread_to_send_queue, - main_thread_received_queue, - debugger.enable(), message_id) - assert json.loads(response) == {"id": message_id, "result": {"debuggerId": "0", - "protocols": Utils.get_custom_protocols()}} + await debugger_api.enable(message_id, websocket, connection_info) ################################################################################################################ # main thread: runtime.run_if_waiting_for_debugger ################################################################################################################ message_id = next(self.id_generator) - response = await communicate_with_debugger_server(main_thread_instance_id, - main_thread_to_send_queue, - main_thread_received_queue, - runtime.run_if_waiting_for_debugger(), message_id) - assert json.loads(response) == {"id": message_id, "result": {}} + await runtime_api.run_if_waiting_for_debugger(message_id, connection_info) ################################################################################################################ # main thread: Debugger.scriptParsed ################################################################################################################ - response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id, - main_thread_received_queue) - response = json.loads(response) + response = await debugger_api.script_parsed(websocket, connection_info) assert response['method'] == 'Debugger.scriptParsed' assert response['params']['url'] == 'entry|entry|1.0.0|src/main/ets/entryability/EntryAbility.ts' assert response['params']['endLine'] == 0 ################################################################################################################ # main thread: Debugger.paused ################################################################################################################ - response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id, - main_thread_received_queue) - response = json.loads(response) + response = await debugger_api.paused(websocket, connection_info) assert response['method'] == 'Debugger.paused' assert (response['params']['callFrames'][0]['url'] == 'entry|entry|1.0.0|src/main/ets/entryability/EntryAbility.ts') @@ -157,29 +129,18 @@ class TestDebug01: # main thread: Debugger.resume ################################################################################################################ message_id = next(self.id_generator) - response = await communicate_with_debugger_server(main_thread_instance_id, - main_thread_to_send_queue, - main_thread_received_queue, - debugger.resume(), message_id) - assert json.loads(response) == {"method": "Debugger.resumed", "params": {}} - response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id, - main_thread_received_queue) - assert json.loads(response) == {"id": message_id, "result": {}} + await debugger_api.resume(message_id, websocket, connection_info) ################################################################################################################ # main thread: Debugger.scriptParsed ################################################################################################################ - response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id, - main_thread_received_queue) - response = json.loads(response) + response = await debugger_api.script_parsed(websocket, connection_info) assert response['method'] == 'Debugger.scriptParsed' assert response['params']['url'] == 'entry|entry|1.0.0|src/main/ets/pages/Index.ts' assert response['params']['endLine'] == 0 ################################################################################################################ # main thread: Debugger.paused ################################################################################################################ - response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id, - main_thread_received_queue) - response = json.loads(response) + response = await debugger_api.paused(websocket, connection_info) assert response['method'] == 'Debugger.paused' assert response['params']['callFrames'][0]['url'] == 'entry|entry|1.0.0|src/main/ets/pages/Index.ts' assert response['params']['reason'] == 'Break on start' @@ -188,23 +149,14 @@ class TestDebug01: ################################################################################################################ url = 'entry|entry|1.0.0|src/main/ets/pages/Index.ts' message_id = next(self.id_generator) - response = await communicate_with_debugger_server(main_thread_instance_id, - main_thread_to_send_queue, - main_thread_received_queue, - debugger.remove_breakpoints_by_url(url), message_id) - assert json.loads(response) == {"id": message_id, "result": {}} + await debugger_api.remove_breakpoints_by_url(message_id, url, connection_info) ################################################################################################################ # main thread: Debugger.getPossibleAndSetBreakpointByUrl ################################################################################################################ message_id = next(self.id_generator) locations = [debugger.BreakLocationUrl(url='entry|entry|1.0.0|src/main/ets/pages/Index.ts', line_number=22), debugger.BreakLocationUrl(url='entry|entry|1.0.0|src/main/ets/pages/Index.ts', line_number=26)] - response = await communicate_with_debugger_server(main_thread_instance_id, - main_thread_to_send_queue, - main_thread_received_queue, - debugger.get_possible_and_set_breakpoint_by_url(locations), - message_id) - response = json.loads(response) + response = await debugger_api.get_possible_and_set_breakpoints_by_url(message_id, locations, connection_info) assert response['id'] == message_id assert response['result']['locations'][0]['id'] == 'id:22:0:entry|entry|1.0.0|src/main/ets/pages/Index.ts' assert response['result']['locations'][1]['id'] == 'id:26:0:entry|entry|1.0.0|src/main/ets/pages/Index.ts' @@ -212,48 +164,24 @@ class TestDebug01: # main thread: Debugger.resume ################################################################################################################ message_id = next(self.id_generator) - response = await communicate_with_debugger_server(main_thread_instance_id, - main_thread_to_send_queue, - main_thread_received_queue, - debugger.resume(), message_id) - assert json.loads(response) == {"method": "Debugger.resumed", "params": {}} - response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id, main_thread_received_queue) - assert json.loads(response) == {"id": message_id, "result": {}} + await debugger_api.resume(message_id, websocket, connection_info) ################################################################################################################ # main thread: Debugger.paused, hit breakpoint ################################################################################################################ - response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id, - main_thread_received_queue) - response = json.loads(response) + response = await debugger_api.paused(websocket, connection_info) assert response['method'] == 'Debugger.paused' assert response['params']['callFrames'][0]['url'] == 'entry|entry|1.0.0|src/main/ets/pages/Index.ts' assert response['params']['hitBreakpoints'] == ["id:22:4:entry|entry|1.0.0|src/main/ets/pages/Index.ts"] ################################################################################################################ # worker thread: connect the debugger server ################################################################################################################ - response = await websocket.recv_msg_of_connect_server() - response = json.loads(response) - assert response['type'] == 'addInstance' - assert response['instanceId'] != 0 - assert response['tid'] != self.config['pid'] - assert 'workerThread_' in response['name'] - worker_instance_id = await websocket.get_instance() - worker_thread_to_send_queue = websocket.to_send_msg_queues[worker_instance_id] - worker_thread_received_queue = websocket.received_msg_queues[worker_instance_id] - logging.info(f'Connect to the debugger server of instance: {worker_instance_id}') + connection_info_worker = await debugger_api.connect_to_debugger_server(websocket, self.config['pid'], False) + logging.info(f'Connect to the debugger server of instance: {connection_info_worker.instance_id}') ################################################################################################################ # main thread: Runtime.getProperties. ################################################################################################################ message_id = next(self.id_generator) - response = await communicate_with_debugger_server(main_thread_instance_id, - main_thread_to_send_queue, - main_thread_received_queue, - runtime.get_properties(object_id='0', - own_properties=True, - accessor_properties_only=False, - generate_preview=True), - message_id) - response = json.loads(response) + response = await runtime_api.get_properties(message_id, connection_info, '0') assert response['id'] == message_id assert response['result']['result'][0]['name'] == 'newWorker' assert response['result']['result'][0]['value']['type'] == 'function' @@ -261,43 +189,28 @@ class TestDebug01: # worker thread: runtime.enable ################################################################################################################ message_id = next(self.id_generator) - response = await communicate_with_debugger_server(worker_instance_id, - worker_thread_to_send_queue, - worker_thread_received_queue, - runtime.enable(), message_id) - assert json.loads(response) == {"id": message_id, "result": {"protocols": []}} + await runtime_api.enable(message_id, connection_info_worker) ################################################################################################################ # worker thread: debugger.enable ################################################################################################################ message_id = next(self.id_generator) - response = await communicate_with_debugger_server(worker_instance_id, - worker_thread_to_send_queue, - worker_thread_received_queue, - debugger.enable(), message_id) - assert json.loads(response) == {"id": message_id, "result": {"debuggerId": "0", - "protocols": Utils.get_custom_protocols()}} + await debugger_api.enable(message_id, websocket, connection_info_worker) ################################################################################################################ # worker thread: runtime.run_if_waiting_for_debugger ################################################################################################################ message_id = next(self.id_generator) - response = await communicate_with_debugger_server(worker_instance_id, - worker_thread_to_send_queue, - worker_thread_received_queue, - runtime.run_if_waiting_for_debugger(), message_id) - assert json.loads(response) == {"id": message_id, "result": {}} + await runtime_api.run_if_waiting_for_debugger(message_id, connection_info_worker) ################################################################################################################ # worker thread: Debugger.scriptParsed ################################################################################################################ - response = await websocket.recv_msg_of_debugger_server(worker_instance_id, worker_thread_received_queue) - response = json.loads(response) + response = await debugger_api.script_parsed(websocket, connection_info_worker) assert response['method'] == 'Debugger.scriptParsed' assert response['params']['url'] == 'entry|entry|1.0.0|src/main/ets/workers/Worker.ts' assert response['params']['endLine'] == 0 ################################################################################################################ # worker thread: Debugger.paused ################################################################################################################ - response = await websocket.recv_msg_of_debugger_server(worker_instance_id, worker_thread_received_queue) - response = json.loads(response) + response = await debugger_api.paused(websocket, connection_info_worker) assert response['method'] == 'Debugger.paused' assert response['params']['callFrames'][0]['url'] == 'entry|entry|1.0.0|src/main/ets/workers/Worker.ts' assert response['params']['reason'] == 'Break on start' @@ -306,23 +219,15 @@ class TestDebug01: ################################################################################################################ url = 'entry|entry|1.0.0|src/main/ets/workers/Worker.ts' message_id = next(self.id_generator) - response = await communicate_with_debugger_server(worker_instance_id, - worker_thread_to_send_queue, - worker_thread_received_queue, - debugger.remove_breakpoints_by_url(url), message_id) - assert json.loads(response) == {"id": message_id, "result": {}} + await debugger_api.remove_breakpoints_by_url(message_id, url, connection_info_worker) ################################################################################################################ # worker thread: Debugger.getPossibleAndSetBreakpointByUrl ################################################################################################################ message_id = next(self.id_generator) locations = [debugger.BreakLocationUrl(url='entry|entry|1.0.0|src/main/ets/workers/Worker.ts', line_number=17), debugger.BreakLocationUrl(url='entry|entry|1.0.0|src/main/ets/workers/Worker.ts', line_number=20)] - response = await communicate_with_debugger_server(worker_instance_id, - worker_thread_to_send_queue, - worker_thread_received_queue, - debugger.get_possible_and_set_breakpoint_by_url(locations), - message_id) - response = json.loads(response) + response = await debugger_api.get_possible_and_set_breakpoints_by_url(message_id, locations, + connection_info_worker) assert response['id'] == message_id assert response['result']['locations'][0]['id'] == 'id:17:0:entry|entry|1.0.0|src/main/ets/workers/Worker.ts' assert response['result']['locations'][1]['id'] == 'id:20:0:entry|entry|1.0.0|src/main/ets/workers/Worker.ts' @@ -330,34 +235,20 @@ class TestDebug01: # worker thread: Debugger.resume ################################################################################################################ message_id = next(self.id_generator) - response = await communicate_with_debugger_server(worker_instance_id, - worker_thread_to_send_queue, - worker_thread_received_queue, - debugger.resume(), message_id) - assert json.loads(response) == {"method": "Debugger.resumed", "params": {}} - response = await websocket.recv_msg_of_debugger_server(worker_instance_id, worker_thread_received_queue) - assert json.loads(response) == {"id": message_id, "result": {}} + await debugger_api.resume(message_id, websocket, connection_info_worker) ################################################################################################################ # main thread: step over ################################################################################################################ message_id = next(self.id_generator) - response = await communicate_with_debugger_server(main_thread_instance_id, - main_thread_to_send_queue, - main_thread_received_queue, - debugger.step_over(), message_id) - assert json.loads(response) == {"method": "Debugger.resumed", "params": {}} - response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id, main_thread_received_queue) - assert json.loads(response) == {"id": message_id, "result": {}} + await debugger_api.step_over(message_id, websocket, connection_info) # main thread: Debugger.paused - response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id, main_thread_received_queue) - response = json.loads(response) + response = await debugger_api.paused(websocket, connection_info) assert response['method'] == 'Debugger.paused' assert response['params']['callFrames'][0]['url'] == 'entry|entry|1.0.0|src/main/ets/pages/Index.ts' assert response['params']['reason'] == 'other' assert response['params']['hitBreakpoints'] == [] # worker thread: Debugger.paused - response = await websocket.recv_msg_of_debugger_server(worker_instance_id, worker_thread_received_queue) - response = json.loads(response) + response = await debugger_api.paused(websocket, connection_info_worker) assert response['method'] == 'Debugger.paused' assert response['params']['callFrames'][0]['url'] == 'entry|entry|1.0.0|src/main/ets/workers/Worker.ts' assert response['params']['reason'] == 'other' @@ -366,16 +257,9 @@ class TestDebug01: # worker thread: step over ################################################################################################################ message_id = next(self.id_generator) - response = await communicate_with_debugger_server(worker_instance_id, - worker_thread_to_send_queue, - worker_thread_received_queue, - debugger.step_over(), message_id) - assert json.loads(response) == {"method": "Debugger.resumed", "params": {}} - response = await websocket.recv_msg_of_debugger_server(worker_instance_id, worker_thread_received_queue) - assert json.loads(response) == {"id": message_id, "result": {}} + await debugger_api.step_over(message_id, websocket, connection_info_worker) # worker thread: Debugger.paused - response = await websocket.recv_msg_of_debugger_server(worker_instance_id, worker_thread_received_queue) - response = json.loads(response) + response = await debugger_api.paused(websocket, connection_info_worker) assert response['method'] == 'Debugger.paused' assert response['params']['callFrames'][0]['url'] == 'entry|entry|1.0.0|src/main/ets/workers/Worker.ts' assert response['params']['reason'] == 'other' @@ -384,15 +268,7 @@ class TestDebug01: # worker thread: Runtime.getProperties. ################################################################################################################ message_id = next(self.id_generator) - response = await communicate_with_debugger_server(worker_instance_id, - worker_thread_to_send_queue, - worker_thread_received_queue, - runtime.get_properties(object_id='0', - own_properties=True, - accessor_properties_only=False, - generate_preview=True), - message_id) - response = json.loads(response) + response = await runtime_api.get_properties(message_id, connection_info_worker, '0') assert response['id'] == message_id assert response['result']['result'][0]['name'] == '' assert response['result']['result'][0]['value']['type'] == 'function' @@ -404,16 +280,9 @@ class TestDebug01: # main thread: step over ################################################################################################################ message_id = next(self.id_generator) - response = await communicate_with_debugger_server(main_thread_instance_id, - main_thread_to_send_queue, - main_thread_received_queue, - debugger.step_over(), message_id) - assert json.loads(response) == {"method": "Debugger.resumed", "params": {}} - response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id, main_thread_received_queue) - assert json.loads(response) == {"id": message_id, "result": {}} + await debugger_api.step_over(message_id, websocket, connection_info) # main thread: Debugger.paused - response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id, main_thread_received_queue) - response = json.loads(response) + response = await debugger_api.paused(websocket, connection_info) assert response['method'] == 'Debugger.paused' assert response['params']['callFrames'][0]['location']['lineNumber'] == 25 assert response['params']['callFrames'][0]['url'] == 'entry|entry|1.0.0|src/main/ets/pages/Index.ts' @@ -424,16 +293,9 @@ class TestDebug01: # main thread: Debugger.resume ################################################################################################################ message_id = next(self.id_generator) - response = await communicate_with_debugger_server(main_thread_instance_id, - main_thread_to_send_queue, - main_thread_received_queue, - debugger.resume(), message_id) - assert json.loads(response) == {"method": "Debugger.resumed", "params": {}} - response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id, main_thread_received_queue) - assert json.loads(response) == {"id": message_id, "result": {}} + await debugger_api.resume(message_id, websocket, connection_info) # main thread: Debugger.paused - response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id, main_thread_received_queue) - response = json.loads(response) + response = await debugger_api.paused(websocket, connection_info) assert response['method'] == 'Debugger.paused' assert response['params']['callFrames'][0]['location']['lineNumber'] == 26 assert response['params']['callFrames'][0]['url'] == 'entry|entry|1.0.0|src/main/ets/pages/Index.ts' @@ -443,16 +305,9 @@ class TestDebug01: # main thread: step over ################################################################################################################ message_id = next(self.id_generator) - response = await communicate_with_debugger_server(main_thread_instance_id, - main_thread_to_send_queue, - main_thread_received_queue, - debugger.step_over(), message_id) - assert json.loads(response) == {"method": "Debugger.resumed", "params": {}} - response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id, main_thread_received_queue) - assert json.loads(response) == {"id": message_id, "result": {}} + await debugger_api.step_over(message_id, websocket, connection_info) # main thread: Debugger.paused - response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id, main_thread_received_queue) - response = json.loads(response) + response = await debugger_api.paused(websocket, connection_info) assert response['method'] == 'Debugger.paused' assert response['params']['callFrames'][0]['location']['lineNumber'] == 27 assert response['params']['callFrames'][0]['url'] == 'entry|entry|1.0.0|src/main/ets/pages/Index.ts' @@ -462,45 +317,27 @@ class TestDebug01: # main thread: Debugger.resume ################################################################################################################ message_id = next(self.id_generator) - response = await communicate_with_debugger_server(main_thread_instance_id, - main_thread_to_send_queue, - main_thread_received_queue, - debugger.resume(), message_id) - assert json.loads(response) == {"method": "Debugger.resumed", "params": {}} - response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id, main_thread_received_queue) - assert json.loads(response) == {"id": message_id, "result": {}} + await debugger_api.resume(message_id, websocket, connection_info) ################################################################################################################ # worker thread: Debugger.disable ################################################################################################################ message_id = next(self.id_generator) - response = await communicate_with_debugger_server(worker_instance_id, - worker_thread_to_send_queue, - worker_thread_received_queue, - debugger.disable(), message_id) - assert json.loads(response) == {"method": "Debugger.resumed", "params": {}} - response = await websocket.recv_msg_of_debugger_server(worker_instance_id, worker_thread_received_queue) - assert json.loads(response) == {"id": message_id, "result": {}} + await debugger_api.disable(message_id, websocket, connection_info_worker) ################################################################################################################ # worker thread: destroy instance ################################################################################################################ - response = await websocket.recv_msg_of_connect_server() - response = json.loads(response) + response = await debugger_api.destroy_instance(websocket) assert response['type'] == 'destroyInstance' - assert response['instanceId'] == worker_instance_id + assert response['instanceId'] == connection_info_worker.instance_id ################################################################################################################ # main thread: Debugger.disable ################################################################################################################ message_id = next(self.id_generator) - response = await communicate_with_debugger_server(main_thread_instance_id, - main_thread_to_send_queue, - main_thread_received_queue, - debugger.disable(), message_id) - assert json.loads(response) == {"method": "Debugger.resumed", "params": {}} - response = await websocket.recv_msg_of_debugger_server(main_thread_instance_id, main_thread_received_queue) - assert json.loads(response) == {"id": message_id, "result": {}} + await debugger_api.disable(message_id, websocket, connection_info) ################################################################################################################ # close the websocket connections ################################################################################################################ - await websocket.send_msg_to_debugger_server(main_thread_instance_id, main_thread_to_send_queue, 'close') + await websocket.send_msg_to_debugger_server(connection_info.instance_id, connection_info.send_msg_queue, + 'close') await websocket.send_msg_to_connect_server('close') ################################################################################################################