Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ bazel-*
MODULE.bazel.lock

.ruff_cache

bazel-*
1 change: 1 addition & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
line-length = 120
12 changes: 12 additions & 0 deletions itf/plugins/base/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# *******************************************************************************
# Copyright (c) 2025 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************
88 changes: 88 additions & 0 deletions itf/plugins/base/base_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# *******************************************************************************
# Copyright (c) 2025 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************
import logging
import pytest

from itf.plugins.base.constants import TEST_CONFIG_KEY, TARGET_CONFIG_KEY
from itf.plugins.base.target.config import load_configuration, target_ecu_argparse
from itf.plugins.base.os.operating_system import OperatingSystem
from itf.plugins.utils import padder
from itf.plugins.xtf_common.bunch import Bunch


logger = logging.getLogger(__name__)


def pytest_addoption(parser):
parser.addoption(
"--target_config",
action="store",
default="",
help="Path to json file with target configurations.",
)
parser.addoption(
"--ecu",
action="store",
required=True,
nargs="?",
help="Target ECU for testing",
)
parser.addoption(
"--os",
action="store",
default=OperatingSystem.LINUX,
type=OperatingSystem.argparse,
choices=OperatingSystem,
nargs="?",
help="Operating System to run",
)
parser.addoption("--qemu", action="store_true", help="Run tests with QEMU image")
parser.addoption("--qvp", action="store_true", help="Run tests with QVP")
parser.addoption("--hw", action="store_true", help="Run tests against connected HW")


@pytest.hookimpl(hookwrapper=True, tryfirst=True)
def pytest_sessionstart(session):
logger.info("Starting session in base_plugin.py ...")
print(padder("live log sessionstart"))
session.stash[TEST_CONFIG_KEY] = __make_test_config(session.config)
session.stash[TARGET_CONFIG_KEY] = __make_target_config(session.stash[TEST_CONFIG_KEY])
session.ecu_name = session.stash[TEST_CONFIG_KEY].ecu.sut.ecu_name.lower()
yield


@pytest.fixture(scope="session")
def test_config_fixture(request):
return request.session.stash[TEST_CONFIG_KEY]


@pytest.fixture(scope="session")
def target_config_fixture(request):
target_config = request.session.stash[TARGET_CONFIG_KEY]
yield target_config


def __make_test_config(config):
load_configuration(config.getoption("target_config"))
return Bunch(
ecu=target_ecu_argparse(config.getoption("ecu")),
os=config.getoption("os"),
qemu=config.getoption("qemu"),
qvp=config.getoption("qvp"),
hw=config.getoption("hw"),
)


def __make_target_config(test_config):
target_config = test_config.ecu.sut
return target_config
17 changes: 17 additions & 0 deletions itf/plugins/base/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# *******************************************************************************
# Copyright (c) 2025 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************
import pytest
from itf.plugins.xtf_common.bunch import Bunch

TEST_CONFIG_KEY = pytest.StashKey[Bunch]()
TARGET_CONFIG_KEY = pytest.StashKey[Bunch]()
104 changes: 104 additions & 0 deletions itf/plugins/base/os/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# *******************************************************************************
# Copyright (c) 2025 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************
# pylint: disable=invalid-name
from itf.plugins.xtf_common.bunch import Bunch


DIAGNOSTICS_COMMON = {
"df_h": {
"description": "Disk usage",
"command": "df -h",
},
"ls_l_dev": {
"description": "List devices",
"command": "ls -l /dev/",
},
"netstat_r": {
"description": "Networking status - routing",
"command": "netstat -r",
},
}


DIAGNOSTICS_LINUX = {
"ps_aux": {
"description": "Processes - currently running",
"command": "ps aux",
},
"top_b_n_1": {
"description": "Processes - resources consumption",
"command": "top -b -n 1",
},
"journalctl": {
"description": "Query the systemd journal",
"command": "journalctl",
},
"netstat_tul": {
"description": "Networking status - TCP/UDP Listening Ports",
"command": "netstat -tul",
},
"netstat_xln": {
"description": "Networking status - active Unix domain sockets",
"command": "netstat -xln",
},
"ip_a": {
"description": "Networking status - interfaces",
"command": "ip a",
},
"iptables_L": {
"description": "Firewall rules",
"command": "iptables -S",
},
"systemd_analyze_plot": {
"description": "Systemd startup time plot",
"command": "systemd-analyze plot",
"extension": "svg",
},
}
DIAGNOSTICS_LINUX.update(DIAGNOSTICS_COMMON)


DIAGNOSTICS_QNX = {
"ps_A": {
"description": "Processes - currently running",
"command": "ps -A",
},
"top_i_1": {
"description": "Processes - resources consumption",
"command": "top -b -i 1",
},
"netstat": {
"description": "Networking status - active Unix domain, IPv4 and IPv6 sockets",
"command": "netstat",
},
}
DIAGNOSTICS_QNX.update(DIAGNOSTICS_COMMON)


def os_config(name, diagnostics, ssh_uses_ext_ip):
return Bunch(
name=name,
diagnostics=diagnostics,
ssh_uses_ext_ip=ssh_uses_ext_ip,
)


operating_system = Bunch(
linux=os_config("linux", DIAGNOSTICS_LINUX, False),
qnx=os_config("qnx", DIAGNOSTICS_QNX, False),
)


global_os_config = Bunch(
os=operating_system,
)
27 changes: 27 additions & 0 deletions itf/plugins/base/os/operating_system.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# *******************************************************************************
# Copyright (c) 2025 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************
from enum import Enum
from itf.plugins.base.os.config import global_os_config as os_config


class OperatingSystem(Enum):
LINUX = os_config.os.linux
QNX = os_config.os.qnx
UNSPECIFIED = {}

@staticmethod
def argparse(s):
try:
return OperatingSystem[s.upper()]
except KeyError:
return s
12 changes: 12 additions & 0 deletions itf/plugins/base/target/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# *******************************************************************************
# Copyright (c) 2025 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************
19 changes: 19 additions & 0 deletions itf/plugins/base/target/config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# *******************************************************************************
# Copyright (c) 2025 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************
from .config import load_configuration
from .config import target_ecu_argparse

from .config import ECUS
from .config import PERFORMANCE_PROCESSORS
from .config import SAFETY_PROCESSORS
from .config import OTHER_PROCESSORS
Loading