Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

twister: pytest: Bluetooth: multi harness boards test against DuT #83641

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JingsaiLu
Copy link
Contributor

@JingsaiLu JingsaiLu commented Jan 7, 2025

Add one harness_devices pytest fixture,
Which will build and flash different harness apps into multi harness boards, then init all harness devices as dut for tests.
Add tests for central_ht and peripehral_ht apps with this feature.

Test on frdm_mcxw71 with command:
west twister -vvv --platform frdm_mcxw71 -T zephyr/samples/bluetooth/central_ht --device-testing --hardware-map dut_map.yml --pytest-args=--harness_device_map=harness_device_map.yml

dut_map.yml

zephyrproject>> cat dut_map.yml
- connected: true
  id: 001060217822
  platform: frdm_mcxw71
  product: J-Link
  runner: jlink
  serial: /dev/ttyACM0

harness_device_map.yml

zephyrproject>> cat harness_device_map.yml
- connected: true
  id: 001066591132
  platform: frdm_mcxw71
  product: J-Link
  runner: jlink
  serial: /dev/ttyACM2

Add one harness_devices pytest fixture,
Which will build and flash different harness apps into multi harness boards,
then init all harness devices as dut for tests.
Add tests for central_ht and peripehral_ht apps with this feature.

Signed-off-by: Jingsai Lu <[email protected]>
from twister_harness.helpers.domains_helper import ZEPHYR_BASE
sys.path.insert(0, os.path.join(ZEPHYR_BASE, 'scripts')) # import zephyr_module in environment.py
sys.path.insert(0, os.path.join(ZEPHYR_BASE, 'scripts', 'pylib', 'twister'))
from twisterlib.hardwaremap import HardwareMap
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not good, why fixture mixed with hardware map which supposed to be platform agnostic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi hake, thanks for these review and comments,

I put the harness devices configuration info in another yaml, and want to import and reuse twister HardwareMap class to load and parse this new yaml,

for the harness boards info, do you have any suggestion, where/which file to store/manage those info ?

all the boards in the current dut_map.yaml will be recognized as duts and scheduled for tests in parallels.

harness_device_yml = request.config.getoption('--harness_device_map')
harness_apps = request.config.getoption('--harness_apps')
logger.info(f'harness_device_yml:{harness_device_yml}')
logger.info(f'harness_apps:{harness_apps}')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update the twister doc to explain the usage of this harness

extra_configs:
- CONFIG_NXP_MONOLITHIC_NBU=n
harness_config:
pytest_dut_scope: session
pytest_args: ['--harness_apps=zephyr/samples/bluetooth/central_ht']
Copy link
Collaborator

@hakehuang hakehuang Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seeing from below code, the harness_apps is a list, so need define list like

pytest_args:
   harness_apps:
    - "zephyr/samples/bluetooth/central_ht"

by the way, why start from zephyr?

extra_config = ['-' + config for config in extra_config]
# build harness_app image for harness device
build_dir = f'./harness_{harness_hw.platform}_{os.path.basename(appname)}'
cmd = ['west', 'build', appname, '-b', harness_hw.platform, '--build-dir', build_dir] + extra_config
Copy link
Collaborator

@hakehuang hakehuang Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be update in CMakefile as dependency. refer to samples/subsys/ipc/openamp/remote

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks hake, will check how to do this with CMakefile system for the dependency board settings

Copy link
Collaborator

@hakehuang hakehuang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see this is a good way to implement in twister instead of implement in CMakefile system on dependency board settings

Comment on lines +1 to +26
# Copyright (c) 2025 NXP
#
# SPDX-License-Identifier: Apache-2.0

import logging

logger = logging.getLogger(__name__)


def test_os_boot(dut, harness_devices):
dut.readlines_until('Booting Zephyr OS build', timeout=5)
harness_devices[0].readlines_until('Booting Zephyr OS build', timeout=5)


def test_bluetooth_boot(dut, harness_devices):
dut.readlines_until('Advertising successfully started', timeout=5)
harness_devices[0].readlines_until('Scanning successfully started', timeout=5)


def test_bluetooth_connection(dut, harness_devices):
harness_devices[0].readlines_until('Connected', timeout=5)


def test_match_temp_value_over_ble(dut, harness_devices):
dut.readlines_until('Indication success', timeout=5)
harness_devices[0].readlines_until(r'Temperature \d{1,2}C', timeout=5)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the test case be running as part of PR CI, nightly or weekly on the upstream main branch? (if not, these test vectors can get stale when someone change the strings).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Bluetooth Host Bluetooth Host (excluding BR/EDR) area: Bluetooth area: Samples Samples area: Twister Twister
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants