-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pytest: gdbstub: Add GDB helper to Twister pytest plugin
Add GDB helper and fixture to Twister pytest plugin to reuse it for test cases where GDB execution is needed. Adjust GDB stub test to use the new helper class. Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
- Loading branch information
Showing
3 changed files
with
81 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
scripts/pylib/pytest-twister-harness/src/twister_harness/helpers/gdb.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright (c) 2023 Intel Corporation. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from __future__ import annotations | ||
|
||
import os | ||
import subprocess | ||
import sys | ||
import logging | ||
import shlex | ||
import re | ||
Check warning on line 12 in scripts/pylib/pytest-twister-harness/src/twister_harness/helpers/gdb.py GitHub Actions / Run compliance checks on patch series (PR)W0611
|
||
|
||
from twister_harness.device.device_adapter import DeviceAdapter | ||
|
||
ZEPHYR_BASE = os.getenv("ZEPHYR_BASE") | ||
sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts", "pylib", "twister")) | ||
from twisterlib.cmakecache import CMakeCache | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class GDBrunner: | ||
""" | ||
Helper class to run GDB process as a part of the test. | ||
""" | ||
|
||
def __init__(self, device: DeviceAdapter) -> None: | ||
build_dir = device.device_config.build_dir | ||
cmake_cache = CMakeCache.from_file(os.path.join(build_dir, 'CMakeCache.txt')) | ||
|
||
gdb_exec = cmake_cache.get('CMAKE_GDB', None) | ||
assert gdb_exec | ||
|
||
self.source_dir = cmake_cache.get('APPLICATION_SOURCE_DIR', None) | ||
assert self.source_dir | ||
|
||
self.build_image = cmake_cache.get('BYPRODUCT_KERNEL_ELF_NAME', None) | ||
assert self.build_image | ||
|
||
gdb_log_file = os.path.join(build_dir, 'gdb.log') | ||
|
||
self.command = [gdb_exec, '-batch', | ||
'-ex', f'set pagination off', | ||
'-ex', f'set trace-commands on', | ||
'-ex', f'set logging file {gdb_log_file}', | ||
'-ex', f'set logging enabled on' | ||
] | ||
# | ||
|
||
def run_script(self, target_remote: str, gdb_script:str, timeout:float | None = None) -> CompletedProcess: | ||
Check failure on line 51 in scripts/pylib/pytest-twister-harness/src/twister_harness/helpers/gdb.py GitHub Actions / Run compliance checks on patch series (PR)E0602
|
||
""" | ||
Run GDB process which executes a script connecting to remote target backend. | ||
""" | ||
cmd = self.command + [ | ||
'-ex', f'target remote {target_remote}', | ||
'-x', f'{self.source_dir}/{gdb_script}', | ||
self.build_image | ||
] | ||
logger.info(f'Run GDB: {shlex.join(cmd)}') | ||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=timeout) | ||
logger.info(f'GDB ends rc={result.returncode}') | ||
return result | ||
|
||
# GDBrunner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters