Enhance the -s option of twister, used to point to a single scenario in a testsuite. - Now accept --scenario on the command line, --test still supported. - If no testsuite is provided, extract testsuite from scenario identifier and avoid parsing the whole tree if we only want to address one scenario in a testsuite. - If just the identifier of the scenario is provided to --test/--scenario option, try to find this as well, do not need the full path for that. Something like this is now possible: twister --scenario kernel.threads.init --list-tests twister -T <path> --scenario kernel.threads.init --list-tests twister -T <path>/kernel.threads.init --list-tests All should print the same output. Fixes #67307 Signed-off-by: Anas Nashif <anas.nashif@intel.com>
75 lines
2.3 KiB
Python
75 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
# Copyright (c) 2024 Intel Corporation
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
"""
|
|
Blackbox tests for twister's command line functions - simple does-error-out or not tests
|
|
"""
|
|
|
|
import importlib
|
|
import mock
|
|
import os
|
|
import pytest
|
|
import sys
|
|
|
|
from conftest import ZEPHYR_BASE, TEST_DATA, testsuite_filename_mock
|
|
from twisterlib.testplan import TestPlan
|
|
from twisterlib.error import TwisterRuntimeError
|
|
|
|
|
|
class TestError:
|
|
TESTDATA_1 = [
|
|
(
|
|
os.path.join(TEST_DATA, 'tests', 'dummy'),
|
|
os.path.join('scripts', 'tests', 'twister_blackbox', 'test_data', 'tests',
|
|
'dummy', 'agnostic', 'group1', 'subgroup1',
|
|
'dummy.agnostic.group1.subgroup1'),
|
|
SystemExit
|
|
),
|
|
(
|
|
None,
|
|
'dummy.agnostic.group1.subgroup1',
|
|
TwisterRuntimeError
|
|
),
|
|
(
|
|
os.path.join(TEST_DATA, 'tests', 'dummy'),
|
|
'dummy.agnostic.group1.subgroup1',
|
|
SystemExit
|
|
)
|
|
]
|
|
|
|
@classmethod
|
|
def setup_class(cls):
|
|
apath = os.path.join(ZEPHYR_BASE, 'scripts', 'twister')
|
|
cls.loader = importlib.machinery.SourceFileLoader('__main__', apath)
|
|
cls.spec = importlib.util.spec_from_loader(cls.loader.name, cls.loader)
|
|
cls.twister_module = importlib.util.module_from_spec(cls.spec)
|
|
|
|
@classmethod
|
|
def teardown_class(cls):
|
|
pass
|
|
|
|
@pytest.mark.parametrize(
|
|
'testroot, test, expected_exception',
|
|
TESTDATA_1,
|
|
ids=['valid', 'invalid', 'valid']
|
|
)
|
|
@mock.patch.object(TestPlan, 'TESTSUITE_FILENAME', testsuite_filename_mock)
|
|
def test_test(self, out_path, testroot, test, expected_exception):
|
|
test_platforms = ['qemu_x86', 'frdm_k64f']
|
|
args = []
|
|
if testroot:
|
|
args = ['-T', testroot]
|
|
args += ['-i', '--outdir', out_path, '--test', test, '-y'] + \
|
|
[val for pair in zip(
|
|
['-p'] * len(test_platforms), test_platforms
|
|
) for val in pair]
|
|
|
|
with mock.patch.object(sys, 'argv', [sys.argv[0]] + args), \
|
|
pytest.raises(expected_exception) as exc:
|
|
self.loader.exec_module(self.twister_module)
|
|
|
|
if expected_exception == SystemExit:
|
|
assert str(exc.value) == '0'
|
|
assert True
|