From 09a32437b3a2f741e8b8e41b15c60e10cb0bffa9 Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Thu, 3 Nov 2022 11:19:26 +0800 Subject: [PATCH] ci: migrate ttfw gdb_loadable_elf test to pytest --- .gitlab/ci/target-test.yml | 2 + .../system/gdb_loadable_elf/app_test.py | 74 ------------------- .../pytest_gdb_loadable_elf.py | 26 +++++++ 3 files changed, 28 insertions(+), 74 deletions(-) delete mode 100644 tools/test_apps/system/gdb_loadable_elf/app_test.py create mode 100644 tools/test_apps/system/gdb_loadable_elf/pytest_gdb_loadable_elf.py diff --git a/.gitlab/ci/target-test.yml b/.gitlab/ci/target-test.yml index 35652b3c95..9df8df2352 100644 --- a/.gitlab/ci/target-test.yml +++ b/.gitlab/ci/target-test.yml @@ -38,6 +38,7 @@ --known-failure-cases-file known_failure_cases/known_failure_cases.txt --parallel-count ${CI_NODE_TOTAL:-1} --parallel-index ${CI_NODE_INDEX:-1} + ${PYTEST_EXTRA_FLAGS} .pytest_examples_dir_template: extends: .pytest_template @@ -672,6 +673,7 @@ test_app_test_pytest_esp32_jtag: tags: [ esp32, test_jtag_arm] variables: SETUP_TOOLS: "1" # need gdb + PYTEST_EXTRA_FLAGS: "--log-cli-level DEBUG" test_app_test_pytest_esp32s2_generic: extends: diff --git a/tools/test_apps/system/gdb_loadable_elf/app_test.py b/tools/test_apps/system/gdb_loadable_elf/app_test.py deleted file mode 100644 index f740980220..0000000000 --- a/tools/test_apps/system/gdb_loadable_elf/app_test.py +++ /dev/null @@ -1,74 +0,0 @@ -from __future__ import unicode_literals - -import os -import threading -import time - -import debug_backend -import pexpect -import serial -import ttfw_idf -from tiny_test_fw import Utility - - -class SerialThread(object): - def run(self, log_path, exit_event): - with serial.Serial(os.getenv('ESPPORT', '/dev/ttyUSB1'), 115200) as ser, open(log_path, 'wb') as f: - while True: - f.write(ser.read(ser.in_waiting)) - if exit_event.is_set(): - break - time.sleep(1) - - def __init__(self, log_path): - self.exit_event = threading.Event() - self.t = threading.Thread(target=self.run, args=(log_path, self.exit_event,)) - self.t.start() - - def __enter__(self): - return self - - def __exit__(self, type, value, traceback): - self.exit_event.set() - self.t.join(60) - if self.t.is_alive(): - Utility.console_log('The pyserial thread is still alive', 'O') - - -@ttfw_idf.idf_custom_test(env_tag='test_jtag_arm', group='test-apps') -def test_app_loadable_elf(env, extra_data): - rel_project_path = os.path.join('tools', 'test_apps', 'system', 'gdb_loadable_elf') - app_files = ['gdb_loadable_elf.elf'] - target = 'esp32' - app = ttfw_idf.LoadableElfTestApp(rel_project_path, app_files, target=target) - idf_path = app.get_sdk_path() - proj_path = os.path.join(idf_path, rel_project_path) - elf_path = os.path.join(app.binary_path, 'gdb_loadable_elf.elf') - esp_log_path = os.path.join(proj_path, 'esp.txt') - - with SerialThread(esp_log_path): - openocd_log = os.path.join(proj_path, 'openocd.txt') - gdb_log = os.path.join(proj_path, 'gdb.txt') - gdb_init = os.path.join(proj_path, 'gdbinit_' + target) - gdb_dir = os.path.join(proj_path, 'main') - - with ttfw_idf.OCDBackend(openocd_log, app.target): - with ttfw_idf.GDBBackend(gdb_log, elf_path, app.target, gdb_init, gdb_dir) as p: - def wait_for_breakpoint(): - p.gdb.wait_target_state(debug_backend.TARGET_STATE_RUNNING) - stop_reason = p.gdb.wait_target_state(debug_backend.TARGET_STATE_STOPPED) - assert stop_reason == debug_backend.TARGET_STOP_REASON_BP, 'STOP reason: {}'.format(stop_reason) - - wait_for_breakpoint() - - p.gdb.add_bp('esp_restart') - p.gdb.exec_continue() - - wait_for_breakpoint() - - if pexpect.run('grep "Restarting now." {}'.format(esp_log_path), withexitstatus=True)[1]: - raise RuntimeError('Expected output from ESP was not received') - - -if __name__ == '__main__': - test_app_loadable_elf() diff --git a/tools/test_apps/system/gdb_loadable_elf/pytest_gdb_loadable_elf.py b/tools/test_apps/system/gdb_loadable_elf/pytest_gdb_loadable_elf.py new file mode 100644 index 0000000000..0447afd60a --- /dev/null +++ b/tools/test_apps/system/gdb_loadable_elf/pytest_gdb_loadable_elf.py @@ -0,0 +1,26 @@ +# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Unlicense OR CC0-1.0 + +import pytest +from pytest_embedded_idf import IdfDut + + +@pytest.mark.parametrize('offset', [ + pytest.param('0x40007d54', marks=[pytest.mark.esp32]), + # pytest.param('0x4000f6e2', marks=[pytest.mark.esp32s2]), + # pytest.param('0x40047654', marks=[pytest.mark.esp32c3]), +]) +@pytest.mark.parametrize('embedded_services, skip_autoflash, erase_all', [ + ('esp,idf,jtag', 'y', 'y'), +], indirect=True) +@pytest.mark.test_jtag_arm +def test_loadable_elf(dut: IdfDut, offset: str) -> None: + dut.gdb.write('mon reset halt') + dut.gdb.write(f'thb *{offset}') + assert 'Temporary breakpoint 1, 0x40007d54' in dut.gdb.write('c') + dut.gdb.write('load') + dut.gdb.write('tb app_main') + assert 'Thread 2 "main" hit Temporary breakpoint 2, app_main ()' in dut.gdb.write('c') + dut.gdb.write('tb esp_restart') + assert 'Thread 2 "main" hit Temporary breakpoint 3, esp_restart ()' in dut.gdb.write('c') + dut.expect_exact('Restarting now.')