Skip to content

Commit

Permalink
scripts: twister: fixing compliance checks and minor issues
Browse files Browse the repository at this point in the history
Fixing minor compliance errors and issues popping up after rebase.
Fixing unit tests.

Signed-off-by: Artur Dobrynin <artur.dobrynin@nordicsemi.no>
  • Loading branch information
ardo-nordic committed Feb 17, 2025
1 parent e07b196 commit f747a95
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 112 deletions.
11 changes: 7 additions & 4 deletions scripts/pylib/twister/twisterlib/harness.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations

import glob
import json
import logging
import os
import platform
import random
import re
import shlex
import shutil
Expand All @@ -14,7 +16,6 @@
import threading
import time
import xml.etree.ElementTree as ET
import random
from collections import OrderedDict
from enum import Enum

Expand Down Expand Up @@ -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:
Expand All @@ -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]
Expand Down
7 changes: 4 additions & 3 deletions scripts/pylib/twister/twisterlib/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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})
Expand Down
5 changes: 3 additions & 2 deletions scripts/tests/twister/test_harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions scripts/tests/twister/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/bsim/bluetooth/host/att/read_fill_buf/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

This file was deleted.

10 changes: 8 additions & 2 deletions tests/bsim/bluetooth/host/gatt/ccc_store/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

This file was deleted.

17 changes: 14 additions & 3 deletions tests/bsim/bluetooth/host/security/ccc_update/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f747a95

Please sign in to comment.