Skip to content
Open
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
25 changes: 25 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,28 @@ python.toolchain(
is_default = True,
python_version = PYTHON_VERSION,
)

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip", dev_dependency = True)

# To regenerate the lock file after editing requirements.txt:
# bazel run //score/time_daemon/tests/integration_tests:requirements.update
pip.parse(
hub_name = "pip_time_daemon_venv",
python_version = PYTHON_VERSION,
requirements_lock = "//score/time_daemon/tests/integration_tests:requirements.txt.lock",
)
use_repo(pip, "pip_time_daemon_venv")

bazel_dep(name = "rules_cc", version = "0.2.17", dev_dependency = True)

## Component Integration Test framework

bazel_dep(name = "score_test_scenarios", version = "0.3.0", dev_dependency = True)
git_override(
module_name = "score_test_scenarios",
commit = "a2f9cded3deb636f5dc800bf7a47131487119721", # tag v0.3.0
patch_cmds = [
"sed -i 's|deps = \\[\"@score_baselibs//score/json:json_parser\"\\]|deps = [\"@score_baselibs//score/json:json\", \"@score_baselibs//score/json:json_parser\"]|' test_scenarios_cpp/BUILD",
],
remote = "https://github.com/eclipse-score/testing_tools.git",
)
978 changes: 694 additions & 284 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions score/tests/patches/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# *******************************************************************************
# Copyright (c) 2026 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
# *******************************************************************************

exports_files(["score_test_scenarios_json_writer.patch"])
11 changes: 11 additions & 0 deletions score/tests/patches/score_test_scenarios_json_writer.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/test_scenarios_cpp/BUILD
+++ b/test_scenarios_cpp/BUILD
@@ -35,5 +35,8 @@
includes = ["include/"],
visibility = ["//visibility:public"],
- deps = ["@score_baselibs//score/json:json_parser"],
+ deps = [
+ "@score_baselibs//score/json:json",
+ "@score_baselibs//score/json:json_parser",
+ ],
)
5 changes: 4 additions & 1 deletion score/time_daemon/src/application/svt/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ load("@score_baselibs//score/language/safecpp:toolchain_features.bzl", "COMPILER
"svt_handler.h",
],
features = COMPILER_WARNING_FEATURES,
visibility = ["//score/time_daemon/src/application:__pkg__"],
visibility = [
"//score/time_daemon/src/application:__pkg__",
"//score/time_daemon/tests/test_scenarios/cpp:__pkg__",
],
deps = [
"//score/time_daemon/src/application:timebase_handler",
"//score/time_daemon/src/application/job_runner",
Expand Down
5 changes: 4 additions & 1 deletion score/time_daemon/src/ptp_machine/shm/details/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ cc_library(
],
features = COMPILER_WARNING_FEATURES,
tags = ["QM"],
visibility = ["//score/time_daemon:__subpackages__"],
visibility = [
"//score/tests/test_scenarios/cpp:__pkg__",
"//score/time_daemon:__subpackages__",
],
deps = [
"//score/time_daemon/src/common:logging_contexts",
"//score/time_daemon/src/common/data_types:ptp_time_info",
Expand Down
Empty file.
49 changes: 49 additions & 0 deletions score/time_daemon/tests/integration_tests/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# *******************************************************************************
# Copyright (c) 2026 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
# *******************************************************************************

load("@pip_time_daemon_venv//:requirements.bzl", "all_requirements")
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
load("@score_tooling//python_basics:defs.bzl", "score_py_pytest", "score_virtualenv")

# To regenerate requirements.txt.lock after editing requirements.txt, run:
# bazel run //score/time_daemon/tests/integration_tests:requirements.update
compile_pip_requirements(
name = "requirements",
srcs = [
"requirements.txt",
"@score_tooling//python_basics:requirements.txt",
],
requirements_txt = "requirements.txt.lock",
tags = ["manual"],
)

score_virtualenv(
name = "python_tc_venv",
reqs = all_requirements,
venv_name = ".python_tc_venv",
)

score_py_pytest(
name = "time_daemon_cit",
srcs = glob(["tests/**/*.py"]) + ["conftest.py"],
args = [
"--cpp-target-path=$(rootpath //score/time_daemon/tests/test_scenarios/cpp:test_scenarios)",
],
data = [
":python_tc_venv",
"//score/time_daemon/tests/test_scenarios/cpp:test_scenarios",
],
pytest_config = ":pytest.ini",
tags = ["integration"],
deps = all_requirements,
)
134 changes: 134 additions & 0 deletions score/time_daemon/tests/integration_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# *******************************************************************************
# Copyright (c) 2026 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 json
import os
from pathlib import Path

import pytest
from testing_utils import BazelTools

FAILED_CONFIGS = []


def pytest_addoption(parser):
parser.addoption(
"--traces",
choices=["none", "target", "all"],
default="none",
help=(
"Verbosity of traces in output. "
'"none" - show no traces, '
'"target" - show traces from test code, '
'"all" - show all traces.'
),
)
parser.addoption(
"--cpp-target-name",
type=str,
default="//score/time_daemon/tests/test_scenarios/cpp:test_scenarios",
help="C++ test scenario executable Bazel target.",
)
parser.addoption(
"--cpp-target-path",
type=Path,
help="Path to the pre-built C++ test scenario executable.",
)
parser.addoption(
"--build-scenarios",
action="store_true",
help="Build test scenario executables before running tests.",
)
parser.addoption(
"--build-scenarios-timeout",
type=float,
default=180.0,
help="Build command timeout in seconds. Default: %(default)s",
)
parser.addoption(
"--default-execution-timeout",
type=float,
default=10.0,
help="Default scenario execution timeout in seconds. Default: %(default)s",
)


@pytest.hookimpl(tryfirst=True)
def pytest_sessionstart(session):
try:
if session.config.getoption("--build-scenarios"):
build_timeout = session.config.getoption("--build-scenarios-timeout")
print("Building C++ test scenarios executable...")
bazel_tools = BazelTools(option_prefix="cpp", build_timeout=build_timeout)
cpp_target_name = session.config.getoption("--cpp-target-name")
bazel_tools.build(cpp_target_name, "--config=time-x86_64-linux")
except Exception as e:
pytest.exit(str(e), returncode=1)


def pytest_html_report_title(report):
report.title = "Time Daemon Component Integration Tests Report"


def pytest_html_results_table_header(cells):
cells.insert(1, "<th>Test Input</th>")
cells.insert(2, "<th>Description</th>")
cells.insert(3, "<th>Test Scenario Name</th>")
cells.insert(4, "<th>Test Scenario Command</th>")


def pytest_html_results_table_row(report, cells):
cells.insert(
1,
f'<td><pre style="white-space:pre-wrap;word-wrap:break-word">{json.dumps(report.input)}</pre></td>',
)
cells.insert(2, f"<td><pre>{report.description}</pre></td>")
cells.insert(3, f"<td><pre>{report.scenario}</pre></td>")
cells.insert(4, f"<td><pre>{report.command}</pre></td>")


@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
report = outcome.get_result()
report.description = str(item.function.__doc__)
report.scenario = item.funcargs.get("scenario_name", "")
report.input = item.funcargs.get("test_config", "")

command = []
for token in item.funcargs.get("command", ""):
if " " in token:
command.append(f"'{token}'")
else:
command.append(token)
report.command = " ".join(command)

if report.failed:
FAILED_CONFIGS.append(
{
"nodeid": report.nodeid,
"command": report.command,
}
)


def pytest_terminal_summary(terminalreporter):
if not FAILED_CONFIGS:
return
terminalreporter.write_sep("=", "Failed tests reproduction info")
terminalreporter.write_line(
"Run failed scenarios from the repo root working directory\n"
)
for entry in FAILED_CONFIGS:
terminalreporter.write_line(
f"{entry['nodeid']} | Run command:\n{entry['command']}\n"
)
22 changes: 22 additions & 0 deletions score/time_daemon/tests/integration_tests/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# *******************************************************************************
# Copyright (c) 2026 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
# *******************************************************************************
[pytest]
addopts = -v
testpaths = tests
pythonpath =
.
tests
junit_family = xunit1
filterwarnings =
ignore:record_property is incompatible with junit_family:pytest.PytestWarning
ignore:record_xml_attribute is an experimental feature:pytest.PytestExperimentalApiWarning
4 changes: 4 additions & 0 deletions score/time_daemon/tests/integration_tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
psutil
pytest-metadata
pytest-env
testing-utils @ git+https://github.com/eclipse-score/testing_tools.git@v0.3.0
Loading
Loading