diff --git a/scripts/pylib/twister/twister/cmakecache.py b/scripts/pylib/twister/twisterlib/cmakecache.py similarity index 100% rename from scripts/pylib/twister/twister/cmakecache.py rename to scripts/pylib/twister/twisterlib/cmakecache.py diff --git a/scripts/pylib/twister/twister/config_parser.py b/scripts/pylib/twister/twisterlib/config_parser.py similarity index 99% rename from scripts/pylib/twister/twister/config_parser.py rename to scripts/pylib/twister/twisterlib/config_parser.py index 106fdb4f8b9..ae8a1abf8fa 100644 --- a/scripts/pylib/twister/twister/config_parser.py +++ b/scripts/pylib/twister/twisterlib/config_parser.py @@ -4,6 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 import scl +from twisterlib.error import ConfigurationError class TwisterConfigParser: """Class to read testsuite yaml files with semantic checking diff --git a/scripts/pylib/twister/twister/coverage.py b/scripts/pylib/twister/twisterlib/coverage.py similarity index 100% rename from scripts/pylib/twister/twister/coverage.py rename to scripts/pylib/twister/twisterlib/coverage.py diff --git a/scripts/pylib/twister/twister/enviornment.py b/scripts/pylib/twister/twisterlib/enviornment.py similarity index 99% rename from scripts/pylib/twister/twister/enviornment.py rename to scripts/pylib/twister/twisterlib/enviornment.py index ac82b8e9068..c56c2a4c63b 100644 --- a/scripts/pylib/twister/twister/enviornment.py +++ b/scripts/pylib/twister/twisterlib/enviornment.py @@ -17,7 +17,7 @@ import argparse logger = logging.getLogger('twister') logger.setLevel(logging.DEBUG) -from twister.error import TwisterRuntimeError +from twisterlib.error import TwisterRuntimeError ZEPHYR_BASE = os.getenv("ZEPHYR_BASE") if not ZEPHYR_BASE: @@ -627,7 +627,7 @@ structure in the main Zephyr tree: boards///""") sys.exit(1) if options.size: - from twister.size_calc import SizeCalculator + from twisterlib.size_calc import SizeCalculator for fn in options.size: sc = SizeCalculator(fn, []) sc.size_report() diff --git a/scripts/pylib/twister/twister/error.py b/scripts/pylib/twister/twisterlib/error.py similarity index 100% rename from scripts/pylib/twister/twister/error.py rename to scripts/pylib/twister/twisterlib/error.py diff --git a/scripts/pylib/twister/twister/handlers.py b/scripts/pylib/twister/twisterlib/handlers.py similarity index 99% rename from scripts/pylib/twister/twister/handlers.py rename to scripts/pylib/twister/twisterlib/handlers.py index ddfd933587f..28cdc8ac33c 100644 --- a/scripts/pylib/twister/twister/handlers.py +++ b/scripts/pylib/twister/twisterlib/handlers.py @@ -15,7 +15,8 @@ import shlex import subprocess import threading import select -from twister.enviornment import ZEPHYR_BASE +import re +from twisterlib.enviornment import ZEPHYR_BASE try: import serial diff --git a/scripts/pylib/twister/twister/hardwaremap.py b/scripts/pylib/twister/twisterlib/hardwaremap.py similarity index 99% rename from scripts/pylib/twister/twister/hardwaremap.py rename to scripts/pylib/twister/twisterlib/hardwaremap.py index 3e81d1ea611..53f7b0c0a73 100644 --- a/scripts/pylib/twister/twister/hardwaremap.py +++ b/scripts/pylib/twister/twisterlib/hardwaremap.py @@ -14,7 +14,7 @@ import scl import logging from pathlib import Path -from twister.enviornment import ZEPHYR_BASE +from twisterlib.enviornment import ZEPHYR_BASE try: # Use the C LibYAML parser if available, rather than the Python parser. @@ -153,7 +153,6 @@ class HardwareMap: if not self.options.device_testing and self.options.hardware_map: self.load(self.options.hardware_map) logger.info("Available devices:") - table = [] self.dump(connected_only=True) return 0 diff --git a/scripts/pylib/twister/twister/harness.py b/scripts/pylib/twister/twisterlib/harness.py similarity index 100% rename from scripts/pylib/twister/twister/harness.py rename to scripts/pylib/twister/twisterlib/harness.py diff --git a/scripts/pylib/twister/twister/mixins.py b/scripts/pylib/twister/twisterlib/mixins.py similarity index 99% rename from scripts/pylib/twister/twister/mixins.py rename to scripts/pylib/twister/twisterlib/mixins.py index a4b4935057c..d174edd0f45 100644 --- a/scripts/pylib/twister/twister/mixins.py +++ b/scripts/pylib/twister/twisterlib/mixins.py @@ -5,4 +5,3 @@ class DisablePyTestCollectionMixin(object): __test__ = False - diff --git a/scripts/pylib/twister/twister/platform.py b/scripts/pylib/twister/twisterlib/platform.py similarity index 96% rename from scripts/pylib/twister/twister/platform.py rename to scripts/pylib/twister/twisterlib/platform.py index 058c4c4880a..adda8b85045 100644 --- a/scripts/pylib/twister/twister/platform.py +++ b/scripts/pylib/twister/twisterlib/platform.py @@ -6,8 +6,8 @@ import os import scl -from twister.config_parser import TwisterConfigParser -from twister.enviornment import ZEPHYR_BASE +from twisterlib.config_parser import TwisterConfigParser +from twisterlib.enviornment import ZEPHYR_BASE class Platform: """Class representing metadata for a particular platform diff --git a/scripts/pylib/twister/twister/reports.py b/scripts/pylib/twister/twisterlib/reports.py similarity index 99% rename from scripts/pylib/twister/twister/reports.py rename to scripts/pylib/twister/twisterlib/reports.py index ab283242ce1..6c805ddb6ec 100644 --- a/scripts/pylib/twister/twister/reports.py +++ b/scripts/pylib/twister/twisterlib/reports.py @@ -497,4 +497,3 @@ class Reporting: else: filename = os.path.join(outdir,"{}.xml".format(platform)) self.xunit_report(json_file, filename, platform, full_report=True) - diff --git a/scripts/pylib/twister/twister/runner.py b/scripts/pylib/twister/twisterlib/runner.py similarity index 99% rename from scripts/pylib/twister/twister/runner.py rename to scripts/pylib/twister/twisterlib/runner.py index 1420ae912bc..f85b4a0ce79 100644 --- a/scripts/pylib/twister/twister/runner.py +++ b/scripts/pylib/twister/twisterlib/runner.py @@ -17,11 +17,8 @@ import traceback from colorama import Fore from multiprocessing import Lock, Process, Value from multiprocessing.managers import BaseManager - -from numpy import trace - -from twister.cmakecache import CMakeCache -from twister.enviornment import canonical_zephyr_base +from twisterlib.cmakecache import CMakeCache +from twisterlib.enviornment import canonical_zephyr_base logger = logging.getLogger('twister') logger.setLevel(logging.DEBUG) @@ -881,4 +878,3 @@ class TwisterRunner: logger.info("Execution interrupted") for p in processes: p.terminate() - diff --git a/scripts/pylib/twister/twister/size_calc.py b/scripts/pylib/twister/twisterlib/size_calc.py similarity index 99% rename from scripts/pylib/twister/twister/size_calc.py rename to scripts/pylib/twister/twisterlib/size_calc.py index b210ea21d12..c59ecf3381f 100644 --- a/scripts/pylib/twister/twister/size_calc.py +++ b/scripts/pylib/twister/twisterlib/size_calc.py @@ -5,7 +5,8 @@ # SPDX-License-Identifier: Apache-2.0 import subprocess -from twister.error import TwisterRuntimeError +import sys +from twisterlib.error import TwisterRuntimeError class SizeCalculator: @@ -224,4 +225,3 @@ class SizeCalculator: self.sections.append({"name": name, "load_addr": load_addr, "size": size, "virt_addr": virt_addr, "type": stype, "recognized": recognized}) - diff --git a/scripts/pylib/twister/twister/testinstance.py b/scripts/pylib/twister/twisterlib/testinstance.py similarity index 97% rename from scripts/pylib/twister/twister/testinstance.py rename to scripts/pylib/twister/twisterlib/testinstance.py index 5a145bf5a20..e947550033d 100644 --- a/scripts/pylib/twister/twister/testinstance.py +++ b/scripts/pylib/twister/twisterlib/testinstance.py @@ -7,12 +7,15 @@ import os import hashlib import random import logging -from twister.testsuite import TestCase -from twister.error import BuildError -from twister.handlers import BinaryHandler, QEMUHandler, DeviceHandler import shutil import glob +from twisterlib.testsuite import TestCase +from twisterlib.error import BuildError +from twisterlib.size_calc import SizeCalculator +from twisterlib.handlers import BinaryHandler, QEMUHandler, DeviceHandler + + logger = logging.getLogger('twister') logger.setLevel(logging.DEBUG) diff --git a/scripts/pylib/twister/twister/testplan.py b/scripts/pylib/twister/twisterlib/testplan.py similarity index 98% rename from scripts/pylib/twister/twister/testplan.py rename to scripts/pylib/twister/twisterlib/testplan.py index 7cd8fe3d2a0..74314a7238f 100755 --- a/scripts/pylib/twister/twister/testplan.py +++ b/scripts/pylib/twister/twisterlib/testplan.py @@ -10,13 +10,10 @@ import subprocess import glob import json import collections -from typing import List from collections import OrderedDict from itertools import islice import logging - - logger = logging.getLogger('twister') logger.setLevel(logging.DEBUG) @@ -25,23 +22,15 @@ try: except ImportError: print("Install the anytree module to use the --test-tree option") -from twister.testsuite import TestSuite, scan_testsuite_path -from twister.error import TwisterRuntimeError -from twister.platform import Platform -from twister.config_parser import TwisterConfigParser -from twister.testinstance import TestInstance +from twisterlib.testsuite import TestSuite, scan_testsuite_path +from twisterlib.error import TwisterRuntimeError +from twisterlib.platform import Platform +from twisterlib.config_parser import TwisterConfigParser +from twisterlib.testinstance import TestInstance from zephyr_module import west_projects, parse_modules -try: - # Use the C LibYAML parser if available, rather than the Python parser. - # It's much faster. - from yaml import CSafeLoader as SafeLoader - from yaml import CDumper as Dumper -except ImportError: - from yaml import SafeLoader, Dumper - ZEPHYR_BASE = os.getenv("ZEPHYR_BASE") if not ZEPHYR_BASE: sys.exit("$ZEPHYR_BASE environment variable undefined") @@ -51,8 +40,6 @@ sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts", "dts", "python-devicetree", "src")) from devicetree import edtlib # pylint: disable=unused-import -from twister.enviornment import TwisterEnv, canonical_zephyr_base - sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/")) import scl @@ -208,7 +195,7 @@ class TestPlan: s = self.options.subset try: subset, sets = (int(x) for x in s.split("/")) - except ValueError as e: + except ValueError: raise TwisterRuntimeError("Bad subset value.") if subset > sets: @@ -325,7 +312,7 @@ class TestPlan: if not area: area = Node(sec[1], parent=samples) - t = Node(test, parent=area) + Node(test, parent=area) else: sec = test.split(".") area = find(tests, lambda node: node.name == sec[0] and node.parent == tests) @@ -336,7 +323,7 @@ class TestPlan: subarea = find(area, lambda node: node.name == sec[1] and node.parent == area) if not subarea: subarea = Node(sec[1], parent=area) - t = Node(test, parent=subarea) + Node(test, parent=subarea) for pre, _, node in RenderTree(testsuite): print("%s%s" % (pre, node.name)) @@ -355,14 +342,13 @@ class TestPlan: def report_excluded_tests(self): all_tests = self.get_all_tests() to_be_run = set() - for i, p in self.instances.items(): + for _, p in self.instances.items(): to_be_run.update(p.testsuite.cases) if all_tests - to_be_run: print("Tests that never build or run:") for not_run in all_tests - to_be_run: print("- {}".format(not_run)) - return def report_platform_tests(self, platforms=[]): if len(platforms) > 1: @@ -378,8 +364,6 @@ class TestPlan: count += 1 print(f"Tests found: {count}") - return - def get_platform_instances(self, platform): filtered_dict = {k:v for k,v in self.instances.items() if k.startswith(platform + os.sep)} return filtered_dict diff --git a/scripts/pylib/twister/twister/testsuite.py b/scripts/pylib/twister/twisterlib/testsuite.py similarity index 98% rename from scripts/pylib/twister/twister/testsuite.py rename to scripts/pylib/twister/twisterlib/testsuite.py index 08984312c2b..6f975017053 100644 --- a/scripts/pylib/twister/twister/testsuite.py +++ b/scripts/pylib/twister/twisterlib/testsuite.py @@ -4,7 +4,6 @@ # SPDX-License-Identifier: Apache-2.0 import os -import sys from pathlib import Path import re import logging @@ -12,9 +11,9 @@ import contextlib import mmap import glob from typing import List -from twister.mixins import DisablePyTestCollectionMixin -from twister.enviornment import canonical_zephyr_base -from twister.error import TwisterException, TwisterRuntimeError +from twisterlib.mixins import DisablePyTestCollectionMixin +from twisterlib.enviornment import canonical_zephyr_base +from twisterlib.error import TwisterException, TwisterRuntimeError logger = logging.getLogger('twister') logger.setLevel(logging.DEBUG) @@ -422,4 +421,3 @@ Tests should reference the category and subsystem with a dot as a separator. """ ) return unique - diff --git a/scripts/tests/twister/conftest.py b/scripts/tests/twister/conftest.py index 2576c146192..8ee351206f2 100644 --- a/scripts/tests/twister/conftest.py +++ b/scripts/tests/twister/conftest.py @@ -12,9 +12,9 @@ import pytest ZEPHYR_BASE = os.getenv("ZEPHYR_BASE") sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister")) sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts")) -from twister.testplan import TestPlan -from twister.testinstance import TestInstance -from twister.enviornment import TwisterEnv, parse_arguments +from twisterlib.testplan import TestPlan +from twisterlib.testinstance import TestInstance +from twisterlib.enviornment import TwisterEnv, parse_arguments def new_get_toolchain(*args, **kwargs): return 'zephyr' diff --git a/scripts/tests/twister/test_testinstance.py b/scripts/tests/twister/test_testinstance.py index c0315dde5b4..1bfc251ff8c 100644 --- a/scripts/tests/twister/test_testinstance.py +++ b/scripts/tests/twister/test_testinstance.py @@ -13,9 +13,9 @@ import pytest ZEPHYR_BASE = os.getenv("ZEPHYR_BASE") sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister")) -from twister.testinstance import TestInstance -from twister.error import BuildError, TwisterException -from twister.testsuite import TestSuite +from twisterlib.testinstance import TestInstance +from twisterlib.error import BuildError, TwisterException +from twisterlib.testsuite import TestSuite TESTDATA_1 = [ diff --git a/scripts/tests/twister/test_testplan_class.py b/scripts/tests/twister/test_testplan_class.py index 0b3038dfeb7..e98020610fc 100644 --- a/scripts/tests/twister/test_testplan_class.py +++ b/scripts/tests/twister/test_testplan_class.py @@ -13,10 +13,10 @@ import pytest ZEPHYR_BASE = os.getenv("ZEPHYR_BASE") sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister")) -from twister.testplan import TestPlan -from twister.testinstance import TestInstance -from twister.testsuite import TestSuite -from twister.platform import Platform +from twisterlib.testplan import TestPlan +from twisterlib.testinstance import TestInstance +from twisterlib.testsuite import TestSuite +from twisterlib.platform import Platform def test_testplan_add_testsuites(class_testplan): @@ -255,4 +255,3 @@ def test_add_instances(test_data, class_env, all_testsuites_dict, platforms_list [platform.name + '/' + s for s in list(all_testsuites_dict.keys())] assert all(isinstance(n, TestInstance) for n in list(plan.instances.values())) assert list(plan.instances.values()) == instance_list - diff --git a/scripts/tests/twister/test_testsuite.py b/scripts/tests/twister/test_testsuite.py index b64cbd92e64..aea931ae0d7 100644 --- a/scripts/tests/twister/test_testsuite.py +++ b/scripts/tests/twister/test_testsuite.py @@ -2,7 +2,6 @@ # Copyright (c) 2020 Intel Corporation # # SPDX-License-Identifier: Apache-2.0 -# pylint: disable=line-too-long """ Tests for testinstance class """ @@ -14,7 +13,7 @@ import pytest ZEPHYR_BASE = os.getenv("ZEPHYR_BASE") sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister")) -from twister.testsuite import scan_file, ScanPathResult +from twisterlib.testsuite import scan_file, ScanPathResult TESTDATA_5 = [ ("testsuites/tests/test_ztest.c", @@ -59,4 +58,3 @@ def test_scan_file(test_data, test_file, class_env, expected: ScanPathResult): result: ScanPathResult = scan_file(os.path.join(test_data, test_file)) assert result == expected - diff --git a/scripts/tests/twister/test_twister.py b/scripts/tests/twister/test_twister.py index a6329e985c0..89c0dda4094 100644 --- a/scripts/tests/twister/test_twister.py +++ b/scripts/tests/twister/test_twister.py @@ -14,7 +14,7 @@ ZEPHYR_BASE = os.getenv("ZEPHYR_BASE") sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister")) import scl -from twister.testplan import TwisterConfigParser +from twisterlib.testplan import TwisterConfigParser def test_yamlload(): """ Test to check if loading the non-existent files raises the errors """ diff --git a/scripts/twister b/scripts/twister index 7472b6ffbba..68daaa0fd82 100755 --- a/scripts/twister +++ b/scripts/twister @@ -187,20 +187,14 @@ if not ZEPHYR_BASE: print(f'ZEPHYR_BASE unset, using "{ZEPHYR_BASE}"') +sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister/")) -try: - from tabulate import tabulate -except ImportError: - print("Install tabulate python module with pip to use --device-testing option.") - -sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts/pylib/twister")) - -from twister.testplan import TestPlan -from twister.enviornment import TwisterEnv, parse_arguments -from twister.reports import Reporting -from twister.hardwaremap import HardwareMap -from twister.coverage import run_coverage -from twister.runner import TwisterRunner +from twisterlib.testplan import TestPlan +from twisterlib.enviornment import TwisterEnv, parse_arguments +from twisterlib.reports import Reporting +from twisterlib.hardwaremap import HardwareMap +from twisterlib.coverage import run_coverage +from twisterlib.runner import TwisterRunner logger = logging.getLogger('twister') logger.setLevel(logging.DEBUG)