From f747a955c124a5e67f3ec3ed92bb868c5759575d Mon Sep 17 00:00:00 2001 From: Artur Dobrynin Date: Wed, 12 Feb 2025 14:43:23 +0100 Subject: [PATCH] scripts: twister: fixing compliance checks and minor issues Fixing minor compliance errors and issues popping up after rebase. Fixing unit tests. Signed-off-by: Artur Dobrynin --- scripts/pylib/twister/twisterlib/harness.py | 11 ++-- scripts/pylib/twister/twisterlib/runner.py | 7 +-- scripts/tests/twister/test_harness.py | 5 +- scripts/tests/twister/test_runner.py | 4 +- .../host/att/read_fill_buf/testcase.yaml | 4 +- .../test_scripts/ccc_store_no_long_wq.sh | 41 -------------- .../host/gatt/ccc_store/testcase.yaml | 10 +++- .../test_scripts/ccc_update_no_long_wq.sh | 53 ------------------- .../host/security/ccc_update/testcase.yaml | 17 ++++-- 9 files changed, 40 insertions(+), 112 deletions(-) delete mode 100755 tests/bsim/bluetooth/host/gatt/ccc_store/test_scripts/ccc_store_no_long_wq.sh delete mode 100755 tests/bsim/bluetooth/host/security/ccc_update/test_scripts/ccc_update_no_long_wq.sh diff --git a/scripts/pylib/twister/twisterlib/harness.py b/scripts/pylib/twister/twisterlib/harness.py index af56251b98f6..55d380a04963 100644 --- a/scripts/pylib/twister/twisterlib/harness.py +++ b/scripts/pylib/twister/twisterlib/harness.py @@ -1,4 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 + from __future__ import annotations import glob @@ -6,6 +7,7 @@ import logging import os import platform +import random import re import shlex import shutil @@ -14,7 +16,6 @@ import threading import time import xml.etree.ElementTree as ET -import random from collections import OrderedDict from enum import Enum @@ -974,6 +975,9 @@ def _get_exe_path(self, index): return self._exe_paths[index if index < len(self._exe_paths) else 0] def configure(self, instance): + def replacer(exe_name): + return exe_name.replace(os.path.sep, '_').replace('.', '_').replace('@', '_') + super().configure(instance) if not self._bsim_out_path: @@ -982,11 +986,10 @@ def configure(self, instance): exe_names = [] for exe_name in self.instance.testsuite.harness_config.get('bsim_exe_name', []): new_exe_name = f'bs_{self.instance.platform.name}_{exe_name}' - exe_names.append( - new_exe_name.replace(os.path.sep, '_').replace('.', '_').replace('@', '_')) + exe_names.append(replacer(new_exe_name)) if not exe_names: - exe_names = [f'bs_{self.instance.name}'] + exe_names = [f'bs_{replacer(self.instance.name)}'] self._exe_paths = \ [os.path.join(self._bsim_out_path, exe_name) for exe_name in exe_names] diff --git a/scripts/pylib/twister/twisterlib/runner.py b/scripts/pylib/twister/twisterlib/runner.py index f61b16b53a24..21c6e931d9e6 100644 --- a/scripts/pylib/twister/twisterlib/runner.py +++ b/scripts/pylib/twister/twisterlib/runner.py @@ -44,7 +44,7 @@ from domains import Domains from twisterlib.coverage import run_coverage_instance from twisterlib.environment import TwisterEnv -from twisterlib.harness import Ctest, HarnessImporter, Pytest, Bsim +from twisterlib.harness import Bsim, Ctest, HarnessImporter, Pytest from twisterlib.log_helper import log_command from twisterlib.platform import Platform from twisterlib.testinstance import TestInstance @@ -1792,7 +1792,7 @@ def run(self): harness.bsim_run(instance.handler.get_test_timeout()) else: instance.status = TwisterStatus.ERROR - instance.reason = str("BSIM not ready") + instance.reason = "BSIM not ready" logger.error(instance.reason) else: instance.handler.handle(harness) @@ -1988,7 +1988,8 @@ def add_tasks_to_queue( expr_parser.reserved.keys() ) - if test_only or instance.testsuite.no_build and instance.run: + if (test_only and instance.run) or\ + (instance.testsuite.no_build and instance.testsuite.harness == 'bsim'): task_list.append({"op": "run", "test": instance}) elif instance.filter_stages and "full" not in instance.filter_stages: task_list.append({"op": "filter", "test": instance}) diff --git a/scripts/tests/twister/test_harness.py b/scripts/tests/twister/test_harness.py index d5b01cef9f8e..797823017dae 100644 --- a/scripts/tests/twister/test_harness.py +++ b/scripts/tests/twister/test_harness.py @@ -1211,6 +1211,8 @@ def test_gtest_repeated_run(gtest): def test_bsim_build(monkeypatch, tmp_path): + monkeypatch.setenv("BSIM_OUT_PATH", str(tmp_path)) + mocked_instance = mock.Mock() build_dir = tmp_path / "build_dir" os.makedirs(build_dir) @@ -1219,9 +1221,8 @@ def test_bsim_build(monkeypatch, tmp_path): mocked_instance.testsuite.harness_config = {} harness = Bsim() - harness.instance = mocked_instance + harness.configure(mocked_instance) - monkeypatch.setenv("BSIM_OUT_PATH", str(tmp_path)) os.makedirs(os.path.join(tmp_path, "bin"), exist_ok=True) zephyr_exe_path = os.path.join(build_dir, "zephyr", "zephyr.exe") os.makedirs(os.path.dirname(zephyr_exe_path), exist_ok=True) diff --git a/scripts/tests/twister/test_runner.py b/scripts/tests/twister/test_runner.py index 63894e14aedd..49a15944292f 100644 --- a/scripts/tests/twister/test_runner.py +++ b/scripts/tests/twister/test_runner.py @@ -2320,8 +2320,8 @@ def test_projectbuilder_run( pytest_mock = mock.Mock(spec=Pytest) harness_mock = mock.Mock() - def mock_harness(name): - if name == 'Pytest': + def mock_harness(inst): + if instance_mock.testsuite.harness == 'pytest': return pytest_mock else: return harness_mock diff --git a/tests/bsim/bluetooth/host/att/read_fill_buf/testcase.yaml b/tests/bsim/bluetooth/host/att/read_fill_buf/testcase.yaml index 5455c9f788ae..b26a4185cdf5 100644 --- a/tests/bsim/bluetooth/host/att/read_fill_buf/testcase.yaml +++ b/tests/bsim/bluetooth/host/att/read_fill_buf/testcase.yaml @@ -14,7 +14,7 @@ tests: bsim_verbosity: 2 bsim_sim_length: 60e6 bsim_test_ids: - - the_test - - the_test + - cli + - srv bsim_options: - -RealEncryption=1 diff --git a/tests/bsim/bluetooth/host/gatt/ccc_store/test_scripts/ccc_store_no_long_wq.sh b/tests/bsim/bluetooth/host/gatt/ccc_store/test_scripts/ccc_store_no_long_wq.sh deleted file mode 100755 index cad38e56e524..000000000000 --- a/tests/bsim/bluetooth/host/gatt/ccc_store/test_scripts/ccc_store_no_long_wq.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/env bash -# Copyright 2025 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -source ${ZEPHYR_BASE}/tests/bsim/sh_common.source - -test_exe="bs_${BOARD_TS}_$(guess_test_long_name)_overlay-no_long_wq_conf" -simulation_id="ccc_store_no_long_wq" -verbosity_level=2 -EXECUTE_TIMEOUT=60 - -cd ${BSIM_OUT_PATH}/bin - -if [ "${1}" != 'debug0' ]; then - Execute "./${test_exe}" \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central \ - -flash="${simulation_id}_client.log.bin" -flash_rm -RealEncryption=1 -argstest 10 -fi - -if [ "${1}" != 'debug1' ]; then - Execute "./${test_exe}" \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral \ - -flash="${simulation_id}_server.log.bin" -flash_rm -RealEncryption=1 -argstest 10 -fi - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=2 -sim_length=60e6 - -if [ "${1}" == 'debug0' ]; then - gdb --args "./${test_exe}" \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central \ - -flash="${simulation_id}_client.log.bin" -flash_rm -RealEncryption=1 -argstest 10 -fi - -if [ "${1}" == 'debug1' ]; then - gdb --args "./${test_exe}" \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=peripheral \ - -flash="${simulation_id}_server.log.bin" -flash_rm -RealEncryption=1 -argstest 10 -fi - -wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/gatt/ccc_store/testcase.yaml b/tests/bsim/bluetooth/host/gatt/ccc_store/testcase.yaml index d5d6f3ea2d8d..6862080c52ec 100644 --- a/tests/bsim/bluetooth/host/gatt/ccc_store/testcase.yaml +++ b/tests/bsim/bluetooth/host/gatt/ccc_store/testcase.yaml @@ -24,7 +24,7 @@ tests: - '["-flash=ccc_store_client.log.bin", "-flash=ccc_store_server.log.bin"]' - -argstest - '10' - bluetooth.host.gatt.ccc_no_store_on_write: + bluetooth.host.gatt.ccc_store_no_store_on_write: harness_config: bsim_exe_name: - tests_bsim_bluetooth_host_gatt_ccc_store_overlay-no_store_on_write_conf @@ -37,6 +37,12 @@ tests: EXTRA_CONF_FILE=overlay-no_store_on_write.conf bluetooth.host.gatt.ccc_store_no_long_wq: harness_config: - bsim_exe_name: tests_bsim_bluetooth_host_gatt_ccc_store_overlay-no_long_wq_conf + bsim_exe_name: + - tests_bsim_bluetooth_host_gatt_ccc_store_overlay-no_long_wq_conf + bsim_options: + - '["-flash=ccc_store_no_long_wq_client.log.bin", + "-flash=ccc_store_no_long_wq_server.log.bin"]' + - -argstest + - '10' extra_args: EXTRA_CONF_FILE=overlay-no_long_wq.conf diff --git a/tests/bsim/bluetooth/host/security/ccc_update/test_scripts/ccc_update_no_long_wq.sh b/tests/bsim/bluetooth/host/security/ccc_update/test_scripts/ccc_update_no_long_wq.sh deleted file mode 100755 index 425494e42949..000000000000 --- a/tests/bsim/bluetooth/host/security/ccc_update/test_scripts/ccc_update_no_long_wq.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env bash -# Copyright 2025 Nordic Semiconductor ASA -# SPDX-License-Identifier: Apache-2.0 - -source ${ZEPHYR_BASE}/tests/bsim/sh_common.source - -test_name='ccc_update' -test_exe="bs_${BOARD_TS}_tests_bsim_bluetooth_host_security_${test_name}_overlay-no_long_wq_conf" -simulation_id="${test_name}_no_long_wq" -verbosity_level=2 - -cd ${BSIM_OUT_PATH}/bin - -if [ "${1}" != 'debug0' ]; then - Execute "./${test_exe}" \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central \ - -flash="${simulation_id}_client.log.bin" -flash_rm -RealEncryption=1 -fi - -if [ "${1}" != 'debug1' ]; then - Execute "./${test_exe}" \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=bad_central \ - -flash="${simulation_id}_bad_client.log.bin" -flash_rm -RealEncryption=1 -fi - -if [ "${1}" != 'debug2' ]; then - Execute "./${test_exe}" \ - -v=${verbosity_level} -s=${simulation_id} -d=2 -testid=peripheral \ - -flash="${simulation_id}_server.log.bin" -flash_rm -RealEncryption=1 -fi - -Execute ./bs_2G4_phy_v1 -v=${verbosity_level} -s=${simulation_id} \ - -D=3 -sim_length=60e6 - -if [ "${1}" == 'debug0' ]; then - gdb --args "./${test_exe}" \ - -v=${verbosity_level} -s=${simulation_id} -d=0 -testid=central \ - -flash="${simulation_id}_client.log.bin" -flash_rm -RealEncryption=1 -fi - -if [ "${1}" == 'debug1' ]; then - gdb --args "./${test_exe}" \ - -v=${verbosity_level} -s=${simulation_id} -d=1 -testid=bad_central \ - -flash="${simulation_id}_bad_client.log.bin" -flash_rm -RealEncryption=1 -fi - -if [ "${1}" == 'debug2' ]; then - gdb --args "./${test_exe}" \ - -v=${verbosity_level} -s=${simulation_id} -d=2 -testid=peripheral \ - -flash="${simulation_id}_server.log.bin" -flash_rm -RealEncryption=1 -fi - -wait_for_background_jobs diff --git a/tests/bsim/bluetooth/host/security/ccc_update/testcase.yaml b/tests/bsim/bluetooth/host/security/ccc_update/testcase.yaml index 1732e1bef9cc..718cd26bd532 100644 --- a/tests/bsim/bluetooth/host/security/ccc_update/testcase.yaml +++ b/tests/bsim/bluetooth/host/security/ccc_update/testcase.yaml @@ -15,21 +15,32 @@ common: bsim_options: - -RealEncryption=1 - -flash_rm - - "['-flash=ccc_update_client.log.bin', '-flash=ccc_update_bad_client.log.bin', - '-flash=ccc_update_server.log.bin']" tests: bluetooth.host.security.ccc_update: harness_config: bsim_exe_name: - tests_bsim_bluetooth_host_security_ccc_update_prj_conf + bsim_options: + - "['-flash=ccc_update_client.log.bin', '-flash=ccc_update_bad_client.log.bin', + '-flash=ccc_update_server.log.bin']" + bluetooth.host.security.ccc_update_no_lazy_load: harness_config: bsim_exe_name: - tests_bsim_bluetooth_host_security_ccc_update_overlay-no_lazy_load_conf + bsim_options: + - "['-flash=ccc_update_no_lazy_load_client.log.bin', + '-flash=ccc_update_no_lazy_load_bad_client.log.bin', + '-flash=ccc_update_no_lazy_load_server.log.bin']" extra_args: EXTRA_CONF_FILE=overlay-no_lazy_load.conf bluetooth.host.security.ccc_update_no_long_wq: harness_config: - bsim_exe_name: tests_bsim_bluetooth_host_security_ccc_update_overlay-no_long_wq_conf + bsim_exe_name: + - tests_bsim_bluetooth_host_security_ccc_update_overlay-no_long_wq_conf + bsim_options: + - "['-flash=ccc_update_no_long_wq_client.log.bin', + '-flash=ccc_update_no_long_wq_bad_client.log.bin', + '-flash=ccc_update_no_long_wq_server.log.bin']" extra_args: EXTRA_CONF_FILE=overlay-no_long_wq.conf