Skip to content

Conversation

amstokely
Copy link
Contributor

@amstokely amstokely commented Oct 1, 2025

This PR introduces user-defined active windows for recurring alarms in the MPAS timekeeping module. Previously, alarms could only be defined with an anchor time and a recurrence interval. Once the anchor was reached, the alarm would ring repeatedly until the end of the clock. There was no way to restrict alarms to a bounded time range.

Previous behavior

Alarms were defined only by anchor time and interval:

A ---------------- B ---------------------- E
^                 ^                        ^
Clock start    Alarm anchor              Clock stop

Once the anchor was reached, alarms rang every interval until the clock ended. There was no mechanism to disable alarms outside of a chosen window.

New behavior

With this PR, all alarms now have an active window. If the user does not explicitly provide a start or stop time, the window defaults to the clock start and stop times, so existing behavior is preserved. This allows the same logic to be applied consistently to both alarms with user-defined windows and alarms without them.

Timeline with user-defined window:

A                B          C            D                E
|----------------|----------|------------|----------------|
^                ^          ^            ^                ^
Clock start   Alarm anchor  Window     Window stop     Clock stop
                           start

Alarms do not ring before the window opens, ring normally inside it at the specified interval, and stop ringing after the window closes, even if the clock continues. Resets and direction changes interact correctly with these boundaries.

Internal structure

Several internal helpers were added to make the logic clearer and easier to maintain:

  • mpas_is_alarm_active checks whether the current clock time is inside an alarm’s active window.
  • mpas_prev_ring_in_window verifies whether the alarm’s previous ring time occurred strictly inside the window, using open-interval semantics (start, stop).
  • mpas_time_in_interval performs the low-level interval membership check, supporting both closed [start, end] and open (start, end) intervals.

These helpers are not tested directly; instead, their correctness is validated indirectly through behavioral tests of alarms. This ensures that the implementation can be refactored without breaking tests, as long as the observable alarm behavior remains consistent.

Tests

A new test fixture (alarm_fixture_t) and suite (test_window_alarm) validate alarm behavior across 16 scenarios. These cover cases before and after the anchor, ringing at the window boundaries, ringing inside the window, leaving the window, delayed anchor times, resets, and clock direction changes.

mpas_reset_clock_alarm is invoked in several cases to confirm that the previous ring time is updated correctly. It is called at both window boundaries and inside the active window to exercise different internal bound checks that could fail in one case but not the other.

The tests focus strictly on behavior: they verify only whether alarms ring when expected, not how that behavior is implemented. This design allows the internal code to evolve without destabilizing the suite. At the same time, the tests serve as executable documentation of the alarm ringing contract, which was previously implicit. They will make future development in MPAS timekeeping more efficient, reliable, and safe.

@amstokely amstokely marked this pull request as draft October 1, 2025 20:58
@amstokely amstokely force-pushed the framework/clock_alarm_active_window branch 2 times, most recently from 7d34528 to 1b12b02 Compare October 2, 2025 23:40
@amstokely amstokely force-pushed the framework/clock_alarm_active_window branch from 1b12b02 to cdc1d7c Compare October 3, 2025 17:29
This commit adds active windows to recurring alarms. If users do not
provide a start or stop time, they default to the clock start and stop,
so existing behavior is unchanged. New helpers simplify the logic and
are validated indirectly through behavior-level tests, allowing future
refactoring without breaking the suite. A new test fixture and 16-case
suite verify alarm behavior across boundaries, resets, anchors, and
direction changes, documenting the alarm ringing contract and ensuring
safe future development of MPAS timekeeping.
@amstokely amstokely force-pushed the framework/clock_alarm_active_window branch from cdc1d7c to 58b3e85 Compare October 3, 2025 17:59
@amstokely amstokely marked this pull request as ready for review October 3, 2025 18:04
@amstokely amstokely requested a review from mgduda October 3, 2025 18:22
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.

2 participants