Revert "twister: Update path structure for tests"

This reverts commit 21eb27c5c0.

This change has been a source of much trouble and ends up preventing us
from tracking test results across tree. It uses the repo name as the
namespace, and that is not always the same and does not have to be
called 'zephyr', depending on where you are running and in which
environment.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2023-01-20 23:38:55 +00:00
commit a4b2d58d3f
6 changed files with 16 additions and 34 deletions

View file

@ -54,6 +54,5 @@ jobs:
ZEPHYR_BASE: ./ ZEPHYR_BASE: ./
ZEPHYR_TOOLCHAIN_VARIANT: zephyr ZEPHYR_TOOLCHAIN_VARIANT: zephyr
run: | run: |
west init -l . || true
echo "Run twister tests" echo "Run twister tests"
PYTHONPATH=./scripts/tests pytest ./scripts/tests/twister PYTHONPATH=./scripts/tests pytest ./scripts/tests/twister

View file

@ -26,19 +26,6 @@ ZEPHYR_BASE = os.getenv("ZEPHYR_BASE")
if not ZEPHYR_BASE: if not ZEPHYR_BASE:
sys.exit("$ZEPHYR_BASE environment variable undefined") sys.exit("$ZEPHYR_BASE environment variable undefined")
try:
subproc = subprocess.run(['west', 'topdir'], check = True, stdout=subprocess.PIPE)
if subproc.returncode == 0:
topdir = subproc.stdout.strip().decode()
logger.debug(f"Project's top directory: {topdir}")
except FileNotFoundError:
topdir = ZEPHYR_BASE
logger.warning(f"West is not installed. Using ZEPHYR_BASE {ZEPHYR_BASE} as project's top directory")
except subprocess.CalledProcessError as e:
topdir = ZEPHYR_BASE
logger.warning(e)
logger.warning(f"Using ZEPHYR_BASE {ZEPHYR_BASE} as project's top directory")
# Use this for internal comparisons; that's what canonicalization is # Use this for internal comparisons; that's what canonicalization is
# for. Don't use it when invoking other components of the build system # for. Don't use it when invoking other components of the build system
# to avoid confusing and hard to trace inconsistencies in error messages # to avoid confusing and hard to trace inconsistencies in error messages
@ -46,7 +33,7 @@ except subprocess.CalledProcessError as e:
# components directly. # components directly.
# Note "normalization" is different from canonicalization, see os.path. # Note "normalization" is different from canonicalization, see os.path.
canonical_zephyr_base = os.path.realpath(ZEPHYR_BASE) canonical_zephyr_base = os.path.realpath(ZEPHYR_BASE)
canonical_topdir = os.path.realpath(topdir)
def add_parse_arguments(parser = None): def add_parse_arguments(parser = None):
if parser is None: if parser is None:

View file

@ -12,7 +12,7 @@ import mmap
import glob import glob
from typing import List from typing import List
from twisterlib.mixins import DisablePyTestCollectionMixin from twisterlib.mixins import DisablePyTestCollectionMixin
from twisterlib.environment import canonical_topdir from twisterlib.environment import canonical_zephyr_base
from twisterlib.error import TwisterException, TwisterRuntimeError from twisterlib.error import TwisterException, TwisterRuntimeError
logger = logging.getLogger('twister') logger = logging.getLogger('twister')
@ -407,17 +407,13 @@ class TestSuite(DisablePyTestCollectionMixin):
def get_unique(testsuite_root, workdir, name): def get_unique(testsuite_root, workdir, name):
canonical_testsuite_root = os.path.realpath(testsuite_root) canonical_testsuite_root = os.path.realpath(testsuite_root)
relative_ts_root = os.path.relpath(canonical_testsuite_root, if Path(canonical_zephyr_base) in Path(canonical_testsuite_root).parents:
start=canonical_topdir) # This is in ZEPHYR_BASE, so include path in name for uniqueness
# Include path in name for name uniqueness. # FIXME: We should not depend on path of test for unique names.
# Replace all '..' with a single 'external' for external tests. relative_ts_root = os.path.relpath(canonical_testsuite_root,
# FIXME: We should not depend on path of test for unique names. start=canonical_zephyr_base)
is_external = Path(canonical_topdir) not in Path(canonical_testsuite_root).parents else:
if is_external: relative_ts_root = ""
relative_ts_parts = Path(relative_ts_root).parts
if ".." in relative_ts_parts:
relative_ts_parts = tuple(part for part in relative_ts_parts if part != "..")
relative_ts_root = os.path.join("external", *relative_ts_parts)
# workdir can be "." # workdir can be "."
unique = os.path.normpath(os.path.join(relative_ts_root, workdir, name)) unique = os.path.normpath(os.path.join(relative_ts_root, workdir, name))

View file

@ -33,7 +33,7 @@ def test_check_build_or_run(class_testplan, monkeypatch, all_testsuites_dict, pl
Scenario 2: Test if build_only is enabled when the OS is Windows""" Scenario 2: Test if build_only is enabled when the OS is Windows"""
class_testplan.testsuites = all_testsuites_dict class_testplan.testsuites = all_testsuites_dict
testsuite = class_testplan.testsuites.get('zephyr/scripts/tests/twister/test_data/testsuites/tests/test_a/test_a.check_1') testsuite = class_testplan.testsuites.get('scripts/tests/twister/test_data/testsuites/tests/test_a/test_a.check_1')
print(testsuite) print(testsuite)
class_testplan.platforms = platforms_list class_testplan.platforms = platforms_list
@ -69,7 +69,7 @@ def test_create_overlay(class_testplan, all_testsuites_dict, platforms_list, ena
"""Test correct content is written to testcase_extra.conf based on if conditions """Test correct content is written to testcase_extra.conf based on if conditions
TO DO: Add extra_configs to the input list""" TO DO: Add extra_configs to the input list"""
class_testplan.testsuites = all_testsuites_dict class_testplan.testsuites = all_testsuites_dict
testcase = class_testplan.testsuites.get('zephyr/scripts/tests/twister/test_data/testsuites/samples/test_app/sample_test.app') testcase = class_testplan.testsuites.get('scripts/tests/twister/test_data/testsuites/samples/test_app/sample_test.app')
class_testplan.platforms = platforms_list class_testplan.platforms = platforms_list
platform = class_testplan.get_platform("demo_board_2") platform = class_testplan.get_platform("demo_board_2")
@ -80,7 +80,7 @@ def test_create_overlay(class_testplan, all_testsuites_dict, platforms_list, ena
def test_calculate_sizes(class_testplan, all_testsuites_dict, platforms_list): def test_calculate_sizes(class_testplan, all_testsuites_dict, platforms_list):
""" Test Calculate sizes method for zephyr elf""" """ Test Calculate sizes method for zephyr elf"""
class_testplan.testsuites = all_testsuites_dict class_testplan.testsuites = all_testsuites_dict
testcase = class_testplan.testsuites.get('zephyr/scripts/tests/twister/test_data/testsuites/samples/test_app/sample_test.app') testcase = class_testplan.testsuites.get('scripts/tests/twister/test_data/testsuites/samples/test_app/sample_test.app')
class_testplan.platforms = platforms_list class_testplan.platforms = platforms_list
platform = class_testplan.get_platform("demo_board_2") platform = class_testplan.get_platform("demo_board_2")
testinstance = TestInstance(testcase, platform, class_testplan.env.outdir) testinstance = TestInstance(testcase, platform, class_testplan.env.outdir)

View file

@ -27,7 +27,7 @@ def test_testplan_add_testsuites(class_testplan):
class_testplan.TESTSUITE_FILENAME = 'test_data.yaml' class_testplan.TESTSUITE_FILENAME = 'test_data.yaml'
class_testplan.add_testsuites() class_testplan.add_testsuites()
tests_rel_dir = 'zephyr/scripts/tests/twister/test_data/testsuites/tests/' tests_rel_dir = 'scripts/tests/twister/test_data/testsuites/tests/'
expected_testsuites = ['test_b.check_1', expected_testsuites = ['test_b.check_1',
'test_b.check_2', 'test_b.check_2',
'test_c.check_1', 'test_c.check_1',

View file

@ -84,7 +84,7 @@ TESTDATA_3 = [
ZEPHYR_BASE, ZEPHYR_BASE,
ZEPHYR_BASE, ZEPHYR_BASE,
'test_a.check_1', 'test_a.check_1',
'zephyr/test_a.check_1' 'test_a.check_1'
), ),
( (
ZEPHYR_BASE, ZEPHYR_BASE,
@ -96,13 +96,13 @@ TESTDATA_3 = [
os.path.join(ZEPHYR_BASE, 'scripts/tests'), os.path.join(ZEPHYR_BASE, 'scripts/tests'),
os.path.join(ZEPHYR_BASE, 'scripts/tests'), os.path.join(ZEPHYR_BASE, 'scripts/tests'),
'test_b.check_1', 'test_b.check_1',
'zephyr/scripts/tests/test_b.check_1' 'scripts/tests/test_b.check_1'
), ),
( (
ZEPHYR_BASE, ZEPHYR_BASE,
ZEPHYR_BASE, ZEPHYR_BASE,
'test_a.check_1.check_2', 'test_a.check_1.check_2',
'zephyr/test_a.check_1.check_2' 'test_a.check_1.check_2'
), ),
( (
os.path.join(ZEPHYR_BASE, '..', 'module_A', 'samples', 'hello_world'), os.path.join(ZEPHYR_BASE, '..', 'module_A', 'samples', 'hello_world'),