Skip to content

Commit 768b8bb

Browse files
nandojvenashif
authored andcommitted
scripts: west robot & simulation: Fix OOT
The current version of scipts do not consider OOT boards use cases and the tests with robot now are strict to only one robot file, which is not realistic for real environment. This address those issues and allow multiple testsuits at command line and lists at tests entries. It add another test parameter to allow configure robotframework options. Fixes: #74563 Signed-off-by: Gerson Fernando Budke <[email protected]>
1 parent 0825f24 commit 768b8bb

File tree

8 files changed

+78
-12
lines changed

8 files changed

+78
-12
lines changed

doc/develop/test/twister.rst

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -615,8 +615,11 @@ harness_config: <harness configuration options>
615615
If the scope is set to ``function``, DUT is launched for every test case
616616
in python script. For ``session`` scope, DUT is launched only once.
617617

618-
robot_test_path: <robot file path> (default empty)
619-
Specify a path to a file containing a Robot Framework test suite to be run.
618+
robot_testsuite: <robot file path> (default empty)
619+
Specify one or more paths to a file containing a Robot Framework test suite to be run.
620+
621+
robot_option: <robot option> (default empty)
622+
One or more options to be send to robotframework.
620623

621624
bsim_exe_name: <string>
622625
If provided, the executable filename when copying to BabbleSim's bin
@@ -673,7 +676,33 @@ harness_config: <harness configuration options>
673676
robot.example:
674677
harness: robot
675678
harness_config:
676-
robot_test_path: [robot file path]
679+
robot_testsuite: [robot file path]
680+
681+
It can be more than one test suite using a list.
682+
683+
.. code-block:: yaml
684+
685+
tests:
686+
robot.example:
687+
harness: robot
688+
harness_config:
689+
robot_testsuite:
690+
- [robot file path 1]
691+
- [robot file path 2]
692+
- [robot file path n]
693+
694+
One or more options can be passed to robotframework.
695+
696+
.. code-block:: yaml
697+
698+
tests:
699+
robot.example:
700+
harness: robot
701+
harness_config:
702+
robot_testsuite: [robot file path]
703+
robot_option:
704+
- --exclude tag
705+
- --stop-on-error
677706
678707
filter: <expression>
679708
Filter whether the test scenario should be run by evaluating an expression

samples/subsys/shell/shell_module/sample.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,4 @@ tests:
7575
sample.shell.shell_module.robot:
7676
harness: robot
7777
harness_config:
78-
robot_test_path: shell_module.robot
78+
robot_testsuite: shell_module.robot

scripts/pylib/twister/twisterlib/handlers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import threading
1919
import time
2020

21+
from pathlib import Path
2122
from queue import Queue, Empty
2223
from twisterlib.environment import ZEPHYR_BASE, strip_ansi_sequences
2324
from twisterlib.error import TwisterException
@@ -241,7 +242,11 @@ def _create_command(self, robot_test):
241242
# os.path.join cannot be used on a Mock object, so we are
242243
# explicitly checking the type
243244
if isinstance(self.instance.platform, Platform):
244-
resc = os.path.join(self.options.coverage_basedir, self.instance.platform.resc)
245+
for board_dir in self.options.board_root:
246+
path = os.path.join(Path(board_dir).parent, self.instance.platform.resc)
247+
if os.path.exists(path):
248+
resc = path
249+
break
245250
uart = self.instance.platform.uart
246251
command = ["renode-test",
247252
"--variable", "KEYWORDS:" + keywords,

scripts/pylib/twister/twisterlib/harness.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ def configure(self, instance):
160160

161161
config = instance.testsuite.harness_config
162162
if config:
163-
self.path = config.get('robot_test_path', None)
163+
self.path = config.get('robot_testsuite', None)
164+
self.option = config.get('robot_option', None)
164165

165166
def handle(self, line):
166167
''' Test cases that make use of this harness care about results given
@@ -176,7 +177,24 @@ def run_robot_test(self, command, handler):
176177
start_time = time.time()
177178
env = os.environ.copy()
178179

179-
command.append(os.path.join(handler.sourcedir, self.path))
180+
if self.option:
181+
if isinstance(self.option, list):
182+
for option in self.option:
183+
for v in str(option).split():
184+
command.append(f'{v}')
185+
else:
186+
for v in str(self.option).split():
187+
command.append(f'{v}')
188+
189+
if self.path is None:
190+
raise PytestHarnessException(f'The parameter robot_testsuite is mandatory')
191+
192+
if isinstance(self.path, list):
193+
for suite in self.path:
194+
command.append(os.path.join(handler.sourcedir, suite))
195+
else:
196+
command.append(os.path.join(handler.sourcedir, self.path))
197+
180198
with subprocess.Popen(command, stdout=subprocess.PIPE,
181199
stderr=subprocess.STDOUT, cwd=self.instance.build_dir, env=env) as renode_test_proc:
182200
out, _ = renode_test_proc.communicate()

scripts/schemas/twister/testsuite-schema.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,11 @@ schema;scenario-schema:
120120
required: false
121121
sequence:
122122
- type: str
123-
"robot_test_path":
124-
type: str
123+
"robot_testsuite":
124+
type: any
125+
required: false
126+
"robot_option":
127+
type: any
125128
required: false
126129
"record":
127130
type: map

scripts/tests/twister/test_harness.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ def test_robot_configure(tmp_path):
133133

134134
instance = TestInstance(testsuite=mock_testsuite, platform=mock_platform, outdir=outdir)
135135
instance.testsuite.harness_config = {
136-
'robot_test_path': '/path/to/robot/test'
136+
'robot_testsuite': '/path/to/robot/test',
137+
'robot_option': 'test_option'
137138
}
138139
robot_harness = Robot()
139140

@@ -143,6 +144,7 @@ def test_robot_configure(tmp_path):
143144
#Assert
144145
assert robot_harness.instance == instance
145146
assert robot_harness.path == '/path/to/robot/test'
147+
assert robot_harness.option == 'test_option'
146148

147149

148150
def test_robot_handle(tmp_path):
@@ -190,6 +192,7 @@ def test_robot_run_robot_test(tmp_path, caplog, exp_out, returncode, expected_st
190192
handler.log = "handler.log"
191193

192194
path = "path"
195+
option = "option"
193196

194197
mock_platform = mock.Mock()
195198
mock_platform.name = "mock_platform"
@@ -209,6 +212,7 @@ def test_robot_run_robot_test(tmp_path, caplog, exp_out, returncode, expected_st
209212

210213
robot = Robot()
211214
robot.path = path
215+
robot.option = option
212216
robot.instance = instance
213217
proc_mock = mock.Mock(
214218
returncode = returncode,

scripts/west_commands/runners/renode-robot.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def capabilities(cls):
2828
@classmethod
2929
def do_add_parser(cls, parser):
3030
parser.add_argument('--testsuite',
31+
metavar='SUITE',
32+
action='append',
3133
help='path to Robot test suite')
3234
parser.add_argument('--renode-robot-arg',
3335
metavar='ARG',
@@ -54,7 +56,8 @@ def run_test(self, **kwargs):
5456
for arg in self.renode_robot_arg:
5557
cmd.append(arg)
5658
if self.testsuite is not None:
57-
cmd.append(self.testsuite)
59+
for suite in self.testsuite:
60+
cmd.append(suite)
5861
else:
5962
self.logger.error("No Robot testsuite passed to renode-test! Use the `--testsuite` argument to provide one.")
6063
subprocess.run(cmd, check=True)

tests/drivers/console/line_splitting/testcase.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ common:
88
tests:
99
drivers.console.line_splitting:
1010
harness_config:
11-
robot_test_path: line_splitting.robot
11+
robot_testsuite: line_splitting.robot
12+
drivers.console.line_splitting.plus.some_option:
13+
harness_config:
14+
robot_testsuite: line_splitting.robot
15+
robot_option: --exclude some_flag

0 commit comments

Comments
 (0)