Skip to content

Commit 962b473

Browse files
nashif57300
authored andcommitted
[nrf fromtree] twister: rework board handling
We now use hwmv2 to list boards instead of relying on twister specific config files. One yaml files (twister.yaml for now) will have all the data needed for all possible targets and variations of a board reusing most of the data where possible and variations can override the top level data. Twister keeps track of 'aliases' of boards and identifies that for example native_sim is the same as native_sim/native, so either names will be possible in both test yaml files or on the command line, however, the reporting will always use the full name, so no there is no confusion about what is being tested/built. Signed-off-by: Anas Nashif <[email protected]> (cherry picked from commit dfc7860)
1 parent 9d44fcf commit 962b473

File tree

8 files changed

+324
-235
lines changed

8 files changed

+324
-235
lines changed

boards/arm/fvp_base_revc_2xaemv8a/fvp_base_revc_2xaemv8a_fvp_base_revc_2xaemv8a_smp_ns.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (c) 2022 Arm Limited (or its affiliates). All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
identifier: fvp_base_revc_2xaemv8a//smp/ns
4+
identifier: fvp_base_revc_2xaemv8a/fvp_base_revc_2xaemv8a/smp/ns
55
name: FVP Emulation FVP_Base_RevC-2xAEMvA (SMP)
66
arch: arm64
77
type: sim

scripts/pylib/twister/twisterlib/config_parser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,14 @@ def __init__(self, filename, schema):
9393
self.common = {}
9494

9595
def load(self):
96-
self.data = scl.yaml_load_verify(self.filename, self.schema)
96+
data = scl.yaml_load_verify(self.filename, self.schema)
97+
self.data = data
9798

9899
if 'tests' in self.data:
99100
self.scenarios = self.data['tests']
100101
if 'common' in self.data:
101102
self.common = self.data['common']
103+
return data
102104

103105
def _cast_value(self, value, typestr):
104106
if isinstance(value, str):

scripts/pylib/twister/twisterlib/platform.py

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66

77
import os
88
import scl
9-
from twisterlib.config_parser import TwisterConfigParser
109
from twisterlib.environment import ZEPHYR_BASE
10+
import logging
11+
12+
logger = logging.getLogger('twister')
13+
logger.setLevel(logging.DEBUG)
1114

1215
class Platform:
1316
"""Class representing metadata for a particular platform
@@ -23,6 +26,7 @@ def __init__(self):
2326
"""
2427

2528
self.name = ""
29+
self.aliases = []
2630
self.normalized_name = ""
2731
# if sysbuild to be used by default on a given platform
2832
self.sysbuild = False
@@ -38,7 +42,7 @@ def __init__(self):
3842
self.flash = 512
3943
self.supported = set()
4044

41-
self.arch = ""
45+
self.arch = None
4246
self.vendor = ""
4347
self.tier = -1
4448
self.type = "na"
@@ -50,41 +54,58 @@ def __init__(self):
5054
self.filter_data = dict()
5155
self.uart = ""
5256
self.resc = ""
57+
self.qualifier = None
58+
59+
def load(self, board, target, aliases, data):
60+
"""Load the platform data from the board data and target data
61+
board: the board object as per the zephyr build system
62+
target: the target name of the board as per the zephyr build system
63+
aliases: list of aliases for the target
64+
data: the data from the twister.yaml file for the target
65+
"""
66+
self.name = target
67+
self.aliases = aliases
68+
69+
# Get data for various targets and use the main board data as a
70+
# defauly. Individual variant information will replace the default data
71+
# provded in the main twister configuration for this board.
72+
variants = data.get("variants", {})
73+
variant_data = {}
74+
for alias in aliases:
75+
variant_data = variants.get(alias, {})
76+
if variant_data:
77+
break
5378

54-
def load(self, platform_file):
55-
scp = TwisterConfigParser(platform_file, self.platform_schema)
56-
scp.load()
57-
data = scp.data
58-
59-
self.name = data['identifier']
6079
self.normalized_name = self.name.replace("/", "_")
61-
self.sysbuild = data.get("sysbuild", False)
62-
self.twister = data.get("twister", True)
80+
self.sysbuild = variant_data.get("sysbuild", data.get("sysbuild", self.sysbuild))
81+
self.twister = variant_data.get("twister", data.get("twister", self.twister))
82+
6383
# if no RAM size is specified by the board, take a default of 128K
64-
self.ram = data.get("ram", 128)
65-
testing = data.get("testing", {})
66-
self.timeout_multiplier = testing.get("timeout_multiplier", 1.0)
67-
self.ignore_tags = testing.get("ignore_tags", [])
68-
self.only_tags = testing.get("only_tags", [])
69-
self.default = testing.get("default", False)
84+
self.ram = variant_data.get("ram", data.get("ram", self.ram))
85+
# if no flash size is specified by the board, take a default of 512K
86+
self.flash = variant_data.get("flash", data.get("flash", self.flash))
87+
88+
testing = variant_data.get("testing", data.get("testing", {}))
89+
self.timeout_multiplier = testing.get("timeout_multiplier", self.timeout_multiplier)
90+
self.ignore_tags = testing.get("ignore_tags", self.ignore_tags)
91+
self.only_tags = testing.get("only_tags", self.only_tags)
92+
self.default = testing.get("default", self.default)
7093
self.binaries = testing.get("binaries", [])
7194
renode = testing.get("renode", {})
7295
self.uart = renode.get("uart", "")
7396
self.resc = renode.get("resc", "")
74-
# if no flash size is specified by the board, take a default of 512K
75-
self.flash = data.get("flash", 512)
7697
self.supported = set()
77-
for supp_feature in data.get("supported", []):
98+
for supp_feature in variant_data.get("supported", data.get("supported", [])):
7899
for item in supp_feature.split(":"):
79100
self.supported.add(item)
80101

81-
self.arch = data['arch']
82-
self.vendor = data.get('vendor', '')
83-
self.tier = data.get("tier", -1)
84-
self.type = data.get('type', "na")
85-
self.simulation = data.get('simulation', "na")
86-
self.simulation_exec = data.get('simulation_exec')
87-
self.supported_toolchains = data.get("toolchain", [])
102+
self.arch = variant_data.get('arch', data.get('arch', self.arch))
103+
self.vendor = board.vendor
104+
self.tier = variant_data.get("tier", data.get("tier", self.tier))
105+
self.type = variant_data.get('type', data.get('type', self.type))
106+
self.simulation = variant_data.get('simulation', data.get('simulation', self.simulation))
107+
self.simulation_exec = variant_data.get('simulation_exec', data.get('simulation_exec', self.simulation_exec))
108+
self.supported_toolchains = variant_data.get("toolchain", data.get("toolchain", []))
88109
if self.supported_toolchains is None:
89110
self.supported_toolchains = []
90111

@@ -111,7 +132,7 @@ def load(self, platform_file):
111132
if toolchain not in self.supported_toolchains:
112133
self.supported_toolchains.append(toolchain)
113134

114-
self.env = data.get("env", [])
135+
self.env = variant_data.get("env", data.get("env", []))
115136
self.env_satisfied = True
116137
for env in self.env:
117138
if not os.environ.get(env, None):

scripts/pylib/twister/twisterlib/testinstance.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,14 @@ def setup_handler(self, env: TwisterEnv):
241241
self.handler = handler
242242

243243
# Global testsuite parameters
244-
def check_runnable(self, enable_slow=False, filter='buildable', fixtures=[], hardware_map=None):
244+
def check_runnable(self,
245+
options,
246+
hardware_map=None):
247+
248+
enable_slow = options.enable_slow
249+
filter = options.filter
250+
fixtures = options.fixture
251+
device_testing = options.device_testing
245252

246253
if os.name == 'nt':
247254
# running on simulators is currently supported only for QEMU on Windows
@@ -264,8 +271,7 @@ def check_runnable(self, enable_slow=False, filter='buildable', fixtures=[], har
264271
target_ready = bool(self.testsuite.type == "unit" or \
265272
self.platform.type == "native" or \
266273
(self.platform.simulation in SUPPORTED_SIMS and \
267-
self.platform.simulation not in self.testsuite.simulation_exclude) or \
268-
filter == 'runnable')
274+
self.platform.simulation not in self.testsuite.simulation_exclude) or device_testing)
269275

270276
# check if test is runnable in pytest
271277
if self.testsuite.harness == 'pytest':
@@ -317,9 +323,10 @@ def create_overlay(self, platform, enable_asan=False, enable_ubsan=False, enable
317323
content = "\n".join(new_config_list)
318324

319325
if enable_coverage:
320-
if platform.name in coverage_platform:
321-
content = content + "\nCONFIG_COVERAGE=y"
322-
content = content + "\nCONFIG_COVERAGE_DUMP=y"
326+
for cp in coverage_platform:
327+
if cp in platform.aliases:
328+
content = content + "\nCONFIG_COVERAGE=y"
329+
content = content + "\nCONFIG_COVERAGE_DUMP=y"
323330

324331
if enable_asan:
325332
if platform.type == "native":

0 commit comments

Comments
 (0)