diff --git a/test/autotest/aw/api/debugger_api.py b/test/autotest/aw/api/debugger_api.py index 9ac16206afead4177c6284298e484c1c2d561777..3508439b63306b4230b615fce894756a17920f3a 100644 --- a/test/autotest/aw/api/debugger_api.py +++ b/test/autotest/aw/api/debugger_api.py @@ -79,15 +79,19 @@ class DebuggerImpl(ProtocolImpl): return response async def enable(self, message_id, connection, params): + response_list = [] response = await communicate_with_debugger_server(connection.instance_id, connection.send_msg_queue, connection.received_msg_queue, debugger.enable(), message_id) while response.startswith('{"method":"Debugger.scriptParsed"'): + response_list.append(response) response = await self.websocket.recv_msg_of_debugger_server(connection.instance_id, connection.received_msg_queue) response = json.loads(response) assert response == {"id": message_id, "result": {"debuggerId": "0", "protocols": Utils.get_custom_protocols()}} + response_list.append(response) + return response_list async def disable(self, message_id, connection, params): response = await communicate_with_debugger_server(connection.instance_id, diff --git a/test/autotest/resource/archive.json b/test/autotest/resource/archive.json index 493a6f15970991a8a0fed480f53ed5c1a5b5d46a..2235754ff7bbe014f76e0f63c99495cba1c3a531 100644 --- a/test/autotest/resource/archive.json +++ b/test/autotest/resource/archive.json @@ -76,5 +76,10 @@ "bundle name": "com.example.HotReloadPages01", "hqf name": [["HotReloadPages01.01.hqf"], ["HotReloadPages01.02.hqf"], ["HotReloadPages01.03.hqf"], ["HotReloadPages01.04.hqf"]] + }, + { + "application project": "Release_Debug_true", + "hap name": ["Release_Debug_true.hap"], + "bundle name": "com.example.release01" } ] \ No newline at end of file diff --git a/test/autotest/scenario_test/conftest.py b/test/autotest/scenario_test/conftest.py index 4d631a90b20dcdd31c4dd558632f7d75a93da224..c0fe846f89e942225b957df2e8e3816f0a96554e 100644 --- a/test/autotest/scenario_test/conftest.py +++ b/test/autotest/scenario_test/conftest.py @@ -25,6 +25,25 @@ import pytest from aw import Application, Fport, WebSocket, TaskPool, Utils +@pytest.fixture(scope='class') +def test_release_debug_true(): + logging.info('running release hap and attach') + config = { + 'start_mode': '-D', + 'connect_server_port': 15702, + 'debugger_server_port': 15703, + 'bundle_name': 'com.example.release01', + 'hap_name': 'Release_Debug_true.hap', + 'hap_path': rf'{os.path.dirname(__file__)}\..\resource\Release_Debug_true.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_01_debug(): logging.info('running main_instance_01 in debug mode') diff --git a/test/autotest/scenario_test/test_attach_release.py b/test/autotest/scenario_test/test_attach_release.py new file mode 100644 index 0000000000000000000000000000000000000000..9a3733352f54c8dcc24ac2b2a7d34263c1952535 --- /dev/null +++ b/test/autotest/scenario_test/test_attach_release.py @@ -0,0 +1,121 @@ +#!/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: + """ + 测试用例:Release应用 实例 attach 调试 + 测试步骤: + 1. 连接 connect server 和主线程 debugger server + 2. 所有线程使能 Runtime 和 Debugger + 3. 关闭所有线程 debugger server 和 connect server 连接 + 关键代码: + app.json5 + { + "app" : { + "debug": true + } + } + """ + + def setup_method(self): + logging.info('Start running TestAttachRelease: setup') + + self.log_path = rf'{os.path.dirname(__file__)}\..\log' + self.hilog_file_name = 'test_attach_release.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('TestAttachRelease done') + + def test(self, test_release_debug_true): + logging.info('Start running TestAttachRelease: test') + self.config = test_release_debug_true + 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}') + ################################################################################################################ + # main thread: Runtime.enable + ################################################################################################################ + await self.runtime_impl.send("Runtime.enable", main_thread) + ################################################################################################################ + # main thread: Debugger.enable, need two ets file scriptParsed success + ################################################################################################################ + response_list = await self.debugger_impl.send("Debugger.enable", main_thread) + if len(response_list) < 3: + raise Exception("Response List fewer than 3 elements, Got: {}".format(len(response_list))) + ################################################################################################################ + # main thread: Runtime.runIfWaitingForDebugger + ################################################################################################################ + await self.runtime_impl.send("Runtime.runIfWaitingForDebugger", 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