Skip to content

test(fit): add score_time clock integration test - #300

Open
clanghans wants to merge 2 commits into
eclipse-score:mainfrom
etas-contrib:feature/score-time-integration-test
Open

clanghans wants to merge 2 commits into
eclipse-score:mainfrom
etas-contrib:feature/score-time-integration-test

Conversation

@clanghans

Copy link
Copy Markdown

What

Adds a feature integration test (FIT) for the score_time clock library.
score_time is already pinned in known_good.json (and the generated
bazel_common/score_modules_target_sw.MODULE.bazel), but so far it had no
integration test coverage. This adds one following the existing FIT pattern
(C++ scenario binary + pytest driver).

Scope

Three C++ scenarios exercise the public Clock<Tag> API and self-validate,
throwing (process exit 101) on failure:

  • time.system_clock_now — SystemClock::Now() tracks the host system clock
    within a generous tolerance (catches an epoch-zero stub / unlinked backend).
  • time.steady_clock_now — two SteadyClock::Now() readings are monotonic.
  • time.high_res_steady_clock_now — HighResSteadyClock::Now() is non-zero and
    monotonic.

Each scenario emits its reading as a structured JSON log line. The pytest FIT
case (tests/time/test_clock_now.py) drives each scenario and asserts the exit
code plus the emitted reading. score_time is C++ only, so the tests are
parametrized with version=["cpp"].

Deferred (not in this PR): VehicleTime (requires explicit Init()), and the
time_daemon / time_slave / ts_client processes (better suited to ITF/QEMU tests).

Files

  • feature_integration_tests/test_scenarios/cpp/src/scenarios/time/ — new scenarios + group mod.cpp
  • feature_integration_tests/test_scenarios/cpp/src/internals/time/clock_log.h — small JSON log helper
  • feature_integration_tests/test_scenarios/cpp/src/scenarios/mod.cpp — register the time group
  • feature_integration_tests/test_scenarios/cpp/BUILD — add the three @score_time clock deps
  • feature_integration_tests/test_cases/tests/time/test_clock_now.py — pytest FIT case

Verification

  • bazel build --config=linux-x86_64 //feature_integration_tests/test_scenarios/cpp:cpp_test_scenarios — builds with the score_time deps.
  • Ran each scenario binary directly — exit 0 with valid readings.
  • bazel test --config=linux-x86_64 //feature_integration_tests/test_cases:fit_cpp — all tests pass (6 new time tests + existing suite).
  • Python (ruff) and Starlark (buildifier) format checks pass.

@PiotrKorkus PiotrKorkus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good for basic smoke tests

did you consider any feature reqs? could you add the mapping?

I would suggest adding a scenario where we do a couple of ticks in a loop, assert all are not decreasing, then sleep for some known duration and compare again next tick.

pytestmark = pytest.mark.parametrize("version", ["cpp"], scope="class")


class ClockScenario(FitScenario):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant? should be possible to use FitScenario directly

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped the build_tools override — FitScenario.build_tools already resolves the parametrized version via request.getfixturevalue. ClockScenario is kept as a thin base only to provide test_config, which is abstract on Scenario and not implemented by FitScenario.

@anmittag

anmittag commented Oct 2, 2026

Copy link
Copy Markdown
Member

@clanghans any update on your PR, there are some findings....

@clanghans

Copy link
Copy Markdown
Author

Both addressed in 0b66ca82.

Feature req mapping: added @add_test_properties on each test class, mapping to the score_time feature requirements:

  • TestSystemClockNow → FR-9 (Absolute Time Base API)
  • TestHighResSteadyClockNow → FR-13 (High Precision Clock API)
  • TestSteadyClockNow, TestSteadyClockProgression → FR-14 (Monotonic Clock API)

Marked partially_verifies since each test covers one aspect (live reading / monotonicity / progression), not the full requirement.

Loop / sleep / compare scenario: added steady_clock_progression (C++) and TestSteadyClockProgression (Python). The scenario takes N readings (default 5), asserts the sequence is non-decreasing, sleeps a known duration (default 100 ms), takes a final reading, and asserts it does not precede the last. Python additionally checks the post-sleep gap is at least half the sleep duration (jitter tolerance). This covers the TC-FR14-001 "call Now() repeatedly, assert strictly increasing" case.

@clanghans

Copy link
Copy Markdown
Author

@anmittag Updated. The three findings from PiotrKorkus are addressed in 0b66ca82 — dropped the redundant ClockScenario.build_tools override, added feature-requirement mapping (FR-9 / FR-13 / FR-14), and added a steady-clock progression scenario that loops ticks, sleeps, and compares. Clock tests pass locally; the 6 UTF-8 persistency errors in test_combined_requirements.py are pre-existing on main (KVS init failure, unrelated to this PR).

Add a feature integration test for the score_time clock library, which was
already pinned in known_good.json but had no test coverage.

Three C++ scenarios exercise the public Clock API and self-validate:
- system_clock_now: reading tracks the host system clock within tolerance
- steady_clock_now: two readings are monotonic
- high_res_steady_clock_now: reading is non-zero and monotonic

A pytest FIT case drives each scenario and asserts the exit code plus the
emitted reading. Wire the scenarios into the root group and add the score_time
clock deps to the cpp_test_scenarios binary.
- Drop redundant ClockScenario.build_tools override; FitScenario already
  resolves the parametrized version. Keep version on test_config so it
  stays in the fixture dependency chain.
- Add @add_test_properties mapping to score_time feature requirements:
  FR-9 (SystemClock), FR-13 (HighResSteadyClock), FR-14 (SteadyClock).
- Add steady_clock_progression scenario and TestSteadyClockProgression:
  take N readings asserting non-decreasing, sleep a known duration, take
  a final reading and assert progression. Covers TC-FR14-001.
@clanghans
clanghans force-pushed the feature/score-time-integration-test branch from 0b66ca8 to c04f5c0 Compare October 4, 2026 20:05

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants