feat(scheduler-sim-discrete-clock): remove the simulator speed argument and shadow copy (task 3.1)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Rongsong Shen 2026-09-29 05:19:34 +00:00
parent eb5f339541
commit aa2bb6d090
Signed by untrusted user: rshen
GPG key ID: 80533536B0EB651C
32 changed files with 72 additions and 129 deletions

View file

@ -4,16 +4,20 @@
*
* Observable under test:
* - xce_core_now() implements the two-anchor + speed formula (Req 5 AC 3)
* exactly, for all four documented operating modes (normal, discrete
* simulation, real-time simulation, fast/slow simulation), given fixed
* anchor values -- no sleep-based real-elapsed-time assertions. Where a
* mode's own definition makes the output track real wall-clock time
* (normal, real-time, fast/slow), the test brackets the result between
* two back-to-back CLOCK_MONOTONIC reads taken immediately before/after
* exactly, given fixed anchor values -- no sleep-based
* real-elapsed-time assertions. The product uses two settings of the
* speed atoms: 1/1 in normal mode and 0/1 (frozen) in simulation mode
* (scheduler-sim-discrete-clock: the simulator has no speed modes).
* Three further tests exercise the formula itself with an arbitrary
* virtual anchor and with ratios 1/1, N/1 and 1/N; they test the
* arithmetic, not any product mode. Where the ratio is non-zero the
* output tracks real wall-clock time, so the test brackets the result
* between two back-to-back CLOCK_MONOTONIC reads taken immediately
* before/after
* the call -- deterministic (time is monotonic, so the bracket always
* holds) and fast (nanoseconds of real work between the two reads), NOT
* the sleep-then-check-approximate-elapsed pattern this task forbids.
* Discrete-simulation (frozen, speed=0/1) collapses the bracket to an
* Simulation mode (frozen, speed=0/1) collapses the bracket to an
* exact equality since elapsed*0/den is always 0 regardless of when the
* test runs.
* - xce_core_tlog_format() (core_clock.c's registered tlog_format_func)
@ -161,12 +165,11 @@ static void test_xce_core_now_discrete_simulation_frozen_at_event_ts(void)
}
static void
test_xce_core_now_realtime_simulation_tracks_wall_clock_from_anchor(void)
test_xce_core_now_unit_ratio_tracks_wall_clock_from_virtual_anchor(void)
{
/* Simulation real-time (AC 3's table): virtual_clock_base=snapshot ts,
* real_clock_base=wall at load, speed=1/1 -- tracks wall clock from the
* virtual anchor: result is between [snapshot_ts, snapshot_ts +
* (after-before)]. */
/* Formula test: an arbitrary virtual_clock_base, real_clock_base=wall
* now, speed=1/1 -- the result advances with the wall clock from the
* virtual anchor: it lies in [anchor, anchor + (after-before)]. */
xce_sched_core_t core;
const uint64_t SNAPSHOT_TS = 500000000000ULL;
uint64_t before, result, after;
@ -182,10 +185,10 @@ test_xce_core_now_realtime_simulation_tracks_wall_clock_from_anchor(void)
TEST_ASSERT_TRUE(result <= SNAPSHOT_TS + (after - before));
}
static void test_xce_core_now_fast_simulation_scales_up_by_speed(void)
static void test_xce_core_now_ratio_above_one_scales_elapsed_up(void)
{
/* Simulation fast (AC 3's table): speed=N/1 -- runs N times faster than
* wall clock. Bracket scaled by N. */
/* Formula test: speed=N/1 -- elapsed wall time is multiplied by N.
* Bracket scaled by N. */
xce_sched_core_t core;
const uint64_t SNAPSHOT_TS = 1000ULL;
const uint64_t N = 1000ULL;
@ -202,11 +205,10 @@ static void test_xce_core_now_fast_simulation_scales_up_by_speed(void)
TEST_ASSERT_TRUE(result <= SNAPSHOT_TS + (after - before) * N);
}
static void test_xce_core_now_slow_simulation_scales_down_by_speed(void)
static void test_xce_core_now_ratio_below_one_scales_elapsed_down(void)
{
/* Simulation slow (AC 3's table): speed=1/N -- runs N times slower than
* wall clock. Bracket scaled down by N (+1 for integer-division
* rounding slack). */
/* Formula test: speed=1/N -- elapsed wall time is divided by N.
* Bracket scaled down by N (+1 for integer-division rounding slack). */
xce_sched_core_t core;
const uint64_t SNAPSHOT_TS = 1000ULL;
const uint64_t N = 1000ULL;
@ -494,9 +496,9 @@ int main(void)
RUN_TEST(test_xce_core_now_normal_mode_matches_wall_clock);
RUN_TEST(test_xce_core_now_discrete_simulation_frozen_at_event_ts);
RUN_TEST(
test_xce_core_now_realtime_simulation_tracks_wall_clock_from_anchor);
RUN_TEST(test_xce_core_now_fast_simulation_scales_up_by_speed);
RUN_TEST(test_xce_core_now_slow_simulation_scales_down_by_speed);
test_xce_core_now_unit_ratio_tracks_wall_clock_from_virtual_anchor);
RUN_TEST(test_xce_core_now_ratio_above_one_scales_elapsed_up);
RUN_TEST(test_xce_core_now_ratio_below_one_scales_elapsed_down);
RUN_TEST(test_xce_sched_core_init_seeds_normal_mode_defaults);
RUN_TEST(test_xce_core_set_wallclock_anchor_seeds_real_epoch_time);
RUN_TEST(test_xce_core_set_wallclock_anchor_null_core_is_a_safe_noop);