feat(scheduler-core): implement REPL snapshot capture and simulation parameter commands (task 12.3)

Adds `snapshot [FILE]` and `set speed|output|verify ...`/`info config`
(Req 5 AC 22 "Snapshots"/"Simulation parameters") to the interactive
simulation REPL.

`snapshot` reuses sim_record.c's existing sim_record_write_header_and_
snapshot() (task 11.5) rather than reimplementing capnp encoding, so
the produced file is genuinely loadable via a fresh --sim invocation
-- the task's own Observable. `set speed`/`set output`/`set verify`
mutate fields sim_loop.c and core_clock.c already read fresh on every
event/session, so no new hook points were needed and sim_loop.c stays
untouched at exactly 800/800 lines (this project's hard per-file cap).

New repl_params.c is a fourth sibling in the repl.c/repl_break.c/
repl_info.c split (task 12.2's precedent) -- neither existing file had
headroom left under the 800-line cap for this task's own logic.

Scheduler suite: 36/36 clean (was 35/35). Review independently
reproduced the RED-phase probe and additionally verified the
snapshot round-trip Observable is non-vacuous.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JPPXeKSUXUqcqvzNXY1rzJ
This commit is contained in:
Rongsong Shen 2026-08-07 10:25:32 +00:00
parent 2fecea3592
commit 2329dbf2a8
Signed by: rshen
SSH key fingerprint: SHA256:8Vf2pZ3h6rJa7EhGK+WaAQ9Mta/apZvteW6g9U/WKKk
18 changed files with 2755 additions and 110 deletions

View file

@ -21,6 +21,7 @@ scheduler_srcs = [
'src/repl.c',
'src/repl_break.c',
'src/repl_info.c',
'src/repl_params.c',
'src/schedobj.c',
'src/plugin.c',
'src/resource.c',
@ -80,23 +81,24 @@ sched_core_isolation_lib = static_library(
# Task 11.3 (scheduler-core spec, Req 5 AC 17): isolated compile target for
# the simulation driver's own files, consumed by
# testsuite/test_sim_isolation.c to prove at build time that
# sim.c/sim_loop.c/sim_record.c/repl.c/repl_break.c/repl_info.c reference
# zero controller-facing symbols (client/netio/xceapi/delay/idgen). All
# files are compiled together into ONE archive -- task 11.2 added
# sim_loop.c as a sibling file to task 11.1's sim.c, task 11.5 added
# sim_record.c as a third, task 12.1 added repl.c as a fourth, and task
# 12.2 adds repl_break.c/repl_info.c as a fifth/sixth (task 12.2's own
# 800-line-cap split of repl.c's breakpoint/state-inspection logic --
# sim.c/sim_loop.c/sim_record.c/repl.c/repl_break.c/repl_info.c/
# repl_params.c reference zero controller-facing symbols (client/netio/
# xceapi/delay/idgen). All files are compiled together into ONE archive --
# task 11.2 added sim_loop.c as a sibling file to task 11.1's sim.c, task
# 11.5 added sim_record.c as a third, task 12.1 added repl.c as a fourth,
# task 12.2 added repl_break.c/repl_info.c as a fifth/sixth (task 12.2's
# own 800-line-cap split of repl.c's breakpoint/state-inspection logic --
# repl_internal.h's own "Why a split at all" section has the full
# rationale); covering only a subset of them would repeat core.c's own
# siblings' (core_events.c/core_session.c/core_clock.c)
# never-mechanically-covered gap for the sim driver. Same "compiling to an
# object is enough, no real linking needed" rationale as
# rationale), and task 12.3 adds repl_params.c as a seventh (the same
# split, extended again for `snapshot`/`set`); covering only a subset of
# them would repeat core.c's own siblings' (core_events.c/core_session.c/
# core_clock.c) never-mechanically-covered gap for the sim driver. Same
# "compiling to an object is enough, no real linking needed" rationale as
# sched_core_isolation_lib above.
sched_sim_isolation_lib = static_library(
'sched_sim_isolation',
['src/sim.c', 'src/sim_loop.c', 'src/sim_record.c', 'src/repl.c',
'src/repl_break.c', 'src/repl_info.c'],
'src/repl_break.c', 'src/repl_info.c', 'src/repl_params.c'],
include_directories: incdir,
dependencies: scheduler_deps,
install: false)

View file

@ -20,11 +20,13 @@
* This file's own scope: `step [N]`/`continue`/`quit`/`help`, the
* pre-replay pause, the blocking interaction model, and repl_dispatch()'s
* command table (which now also hands off to repl_break.c's `break`/
* `delete` and repl_info.c's `info` -- task 12.2, Req 5 AC 22
* "Breakpoints"/"State inspection"). Breakpoint matching/storage and state-
* inspection dumps are NOT in this file -- task 12.2's full scope did not
* fit in one file under this project's 800-line cap, so it is split across
* repl.c (this file)/repl_break.c/repl_info.c, sharing private state via
* `delete`, repl_info.c's `info` -- task 12.2, Req 5 AC 22
* "Breakpoints"/"State inspection" -- and repl_params.c's `snapshot`/`set`
* -- task 12.3, Req 5 AC 22 "Snapshots"/"Simulation parameters"). Breakpoint
* matching/storage, state-inspection dumps, and snapshot/parameter commands
* are NOT in this file -- their combined scope does not fit in one file
* under this project's 800-line cap, so it is split across repl.c (this
* file)/repl_break.c/repl_info.c/repl_params.c, sharing private state via
* repl_internal.h -- see that header's own "Why a split at all" section for
* the full rationale, matching the precedent snapshot.c/snapshot_wire.c/
* snapshot_load.c (task 8.1) already established for the identical
@ -186,10 +188,8 @@ static void repl_print_banner(const xce_sched_sim_driver_t* sim)
/*
* repl_print_help - Req 5 AC 22's "help" command: "Print available commands
* with one-line descriptions." Covers execution control (task 12.1),
* breakpoints, and state inspection (task 12.2) -- AC 22's remaining rows
* (`snapshot`, `set`/`info config`) are task 12.3's job and stay unlisted
* until implemented, matching task 12.1's own "don't over-build entries for
* commands that don't exist yet" convention.
* breakpoints and state inspection (task 12.2), and snapshot capture plus
* simulation parameters (task 12.3) -- every AC 22 command is now listed.
*/
static void repl_print_help(void)
{
@ -207,6 +207,14 @@ static void repl_print_help(void)
printf(" info worker <name>|all Dump worker(s).\n");
printf(" info resource <name>|all Dump resource(s).\n");
printf(" info summary Quick overview.\n");
printf(" snapshot [FILE] Write a standalone "
"snapshot.\n");
printf(" set speed <N> Set simulation speed.\n");
printf(" set output <FILE>|off Start/stop writing "
"decisions.\n");
printf(" set verify on|off Toggle decision "
"verification.\n");
printf(" info config Show sim parameters.\n");
}
/*
@ -293,8 +301,9 @@ static bool repl_cmd_step(xce_sched_sim_driver_t* sim, const char* line)
* unrecognized command, or a `step` parse error). `quit` never returns from
* repl_cmd_quit() -- its own return value below is unreachable, kept only
* so every branch has a well-typed value. `break`/`delete`/`info` are
* implemented in repl_break.c/repl_info.c (repl_internal.h's own extern
* declarations) -- this file only routes to them.
* implemented in repl_break.c/repl_info.c, and `snapshot`/`set` in
* repl_params.c (repl_internal.h's own extern declarations) -- this file
* only routes to them.
*/
static bool repl_dispatch(xce_sched_sim_driver_t* sim, const char* line)
{
@ -328,6 +337,12 @@ static bool repl_dispatch(xce_sched_sim_driver_t* sim, const char* line)
if (strcmp(cmd, "info") == 0) {
return repl_cmd_info(sim, line);
}
if (strcmp(cmd, "snapshot") == 0) {
return repl_cmd_snapshot(sim, line);
}
if (strcmp(cmd, "set") == 0) {
return repl_cmd_set(sim, line);
}
printf("[sim] unknown command: '%s' (type 'help' for a list)\n", cmd);

View file

@ -9,14 +9,18 @@
/*
* repl_info.c - state inspection (scheduler-core spec, task 12.2, Req 5 AC
* 22 "State inspection"). Sibling of repl.c/repl_break.c -- see
* repl_internal.h's own "Why a split at all" section for the full
* rationale behind this three-file layout.
* 22 "State inspection"; `info config` added by task 12.3, Req 5 AC 22
* "Simulation parameters"). Sibling of repl.c/repl_break.c/repl_params.c --
* see repl_internal.h's own "Why a split at all" section for the full
* rationale behind this four-file layout.
*
* Owns: `info session`/`info job`/`info queue`/`info worker`/
* `info resource`/`info summary`/`info break`, and the `repl_cmd_info()`
* dispatcher repl.c's repl_dispatch() hands off to (repl_internal.h's own
* extern declaration).
* `info resource`/`info summary`/`info break`/`info config`, and the
* `repl_cmd_info()` dispatcher repl.c's repl_dispatch() hands off to
* (repl_internal.h's own extern declaration). `info config` is the
* read-only counterpart to repl_params.c's `set speed`/`set output`/
* `set verify` -- grouped here with every other `info` dump rather than in
* repl_params.c, per this file's own domain-ownership scope.
*
* Every dump below reads core->jobs/queues/workers/resmgr the SAME way
* repl.c's own repl_count_jobs() and snapshot.c's
@ -586,6 +590,43 @@ static void repl_info_session(xce_sched_sim_driver_t* sim)
}
}
/*
* repl_info_config - AC 22's "info config": "Show current sim parameters:
* speed=N, output=<path or \"off\">, verify=on|off, events_processed=N,
* current_ts=<logical_time>, sessions=N." Read-only counterpart to
* repl_params.c's `set speed`/`set output`/`set verify` (task 12.3) --
* reads sim->sim_speed_num (the driver-level shadow copy sim.h's own doc
* comment says exists precisely "for the REPL/diagnostics to read without
* reaching into core", kept in sync with the real core.speed_num/speed_den
* atomics by every `set speed` call, repl_params.c's repl_set_speed()),
* sim->record_file/rs->output_path (repl_params.c's own output_path field
* doc comment explains the "path unknown" fallback for a --sim-output
* stream this REPL session never itself opened), sim->verify, and the SAME
* rs->event_index/rs->session_count `info session` already reports
* (repl_info_session() above).
*/
static void repl_info_config(xce_sched_sim_driver_t* sim)
{
xce_sched_repl_state_t* rs = sim->repl_state;
const char* output_desc;
if (sim->record_file == NULL) {
output_desc = "off";
} else if ((rs != NULL) && (rs->output_path != NULL)) {
output_desc = rs->output_path;
} else {
output_desc = "(active, path unknown)";
}
printf("[sim] config: speed=%llu output=%s verify=%s "
"events_processed=%llu current_ts=%llu sessions=%llu\n",
(unsigned long long)sim->sim_speed_num, output_desc,
sim->verify ? "on" : "off",
(unsigned long long)((rs != NULL) ? rs->event_index : 0),
(unsigned long long)xce_core_now(&(sim->core)),
(unsigned long long)((rs != NULL) ? rs->session_count : 0));
}
/* repl_info_break - AC 22's "info break": "List all breakpoints with their
* IDs, event types, and filters." */
static void repl_info_break(xce_sched_sim_driver_t* sim)
@ -612,8 +653,8 @@ static void repl_info_break(xce_sched_sim_driver_t* sim)
/*
* repl_cmd_info - Req 5 AC 22's "info ..." family: dispatches on the second
* token to repl_info_break()/repl_info_session()/repl_info_job()/
* repl_info_queue()/repl_info_worker()/repl_info_resource()/
* token to repl_info_break()/repl_info_session()/repl_info_config()/
* repl_info_job()/repl_info_queue()/repl_info_worker()/repl_info_resource()/
* repl_info_summary() (all above). No `info` subcommand ever hands control
* back to the driver loop -- inspecting state is never a reason to advance
* the simulation. repl.c's repl_dispatch() calls this (repl_internal.h's
@ -625,8 +666,8 @@ bool repl_cmd_info(xce_sched_sim_driver_t* sim, const char* line)
int ntok = repl_split_tokens(line, tokens, XCE_REPL_MAX_TOKENS);
if (ntok < 2) {
printf("[sim] info: usage: info "
"<break|session|job|queue|worker|resource|summary> [arg]\n");
printf("[sim] info: usage: info <break|session|config|job|queue|"
"worker|resource|summary> [arg]\n");
return false;
}
@ -634,6 +675,8 @@ bool repl_cmd_info(xce_sched_sim_driver_t* sim, const char* line)
repl_info_break(sim);
} else if (strcmp(tokens[1], "session") == 0) {
repl_info_session(sim);
} else if (strcmp(tokens[1], "config") == 0) {
repl_info_config(sim);
} else if (strcmp(tokens[1], "summary") == 0) {
repl_info_summary(sim);
} else if (strcmp(tokens[1], "job") == 0) {

View file

@ -20,31 +20,45 @@
* fit in one file under this project's 800-line-per-file cap
* (CLAUDE.md/coding-style.md). Split along the same domain boundaries
* task 8.1 already used for snapshot.c/snapshot_wire.c/snapshot_load.c
* (that file's own "Three-file split" header section is the precedent):
* (that file's own "Three-file split" header section is the precedent).
* Task 12.3 (snapshot capture + `set speed`/`set output`/`set verify`)
* adds a FOURTH file, repl_params.c, for the identical reason: neither
* repl_break.c nor repl_info.c had enough remaining headroom under the
* 800-line cap to absorb this task's own real chunk of new logic (both
* were already within ~130-160 lines of the cap after task 12.2):
*
* - repl.c: the command loop itself (readline()/dispatch), execution
* control (`step`/`continue`/`quit`/`help`), and the two task-12.1
* driver-facing entry points (xce_repl_start()/
* xce_repl_post_session_check()). Unchanged in scope from task 12.1
* except for three new repl_dispatch() branches that hand off to the
* other two files.
* except for repl_dispatch() branches that hand off to the other
* sibling files (task 12.2's `break`/`delete`/`info`, task 12.3's
* `snapshot`/`set`).
* - repl_break.c: breakpoint kind/filter matching, the breakpoint list
* (create/list/delete), and the three task-12.2 driver-facing hooks
* (xce_repl_on_event()/xce_repl_on_begin_round()/xce_repl_on_decision(),
* declared in repl.h, implemented here since they are breakpoint-domain
* logic through and through).
* - repl_info.c: the `info job`/`queue`/`worker`/`resource`/`summary`/
* `session`/`break` state-inspection dumps.
* `session`/`break`/`config` state-inspection dumps (`info config` is
* task 12.3's own read-only counterpart to repl_params.c's `set`
* commands -- grouped here, not in repl_params.c, since it belongs
* domain-wise with every other `info` dump, matching this file's own
* "Owns" doc comment).
* - repl_params.c (task 12.3): the `snapshot [FILE]` and `set
* speed|output|verify ...` command handlers -- mutating the simulation
* parameters `info config` (repl_info.c) reports.
*
* `struct xce_sched_repl_state_s` (the full definition of sim.h's opaque
* forward declaration) moves here from repl.c for the same reason:
* repl_break.c's breakpoint list and repl_info.c's `info session`/
* `info break` both need direct field access, not just the opaque pointer
* sim_loop.c gets via sim.h. This does NOT weaken the "opaque outside the
* owning module" property that struct always had -- repl_internal.h is
* never included outside src/scheduler/src/repl*.c, so sim_loop.c and
* every other production consumer still see only the pointer (via sim.h),
* exactly as before this split.
* repl_break.c's breakpoint list, repl_info.c's `info session`/`info
* break`/`info config`, and repl_params.c's `set output` bookkeeping all
* need direct field access, not just the opaque pointer sim_loop.c gets via
* sim.h. This does NOT weaken the "opaque outside the owning module"
* property that struct always had -- repl_internal.h is never included
* outside src/scheduler/src/repl*.c, so sim_loop.c and every other
* production consumer still see only the pointer (via sim.h), exactly as
* before this split.
*/
typedef enum {
@ -132,6 +146,32 @@ struct xce_sched_repl_state_s {
int last_n_dispatch;
int last_n_pend;
int last_n_preempt;
/*
* Task 12.3 fields (`set output`/`info config`, Req 5 AC 22
* "Simulation parameters") -- see repl_params.c's
* repl_set_output_file()/repl_set_output_off() for the full field
* contracts.
*/
char* output_path; /* strdup'd path of the output file
* THIS REPL session opened via `set
* output FILE`; NULL when off, OR
* when sim->record_file is active
* but was opened via --sim-output
* before any `set output` command
* ran this session (repl_params.c's
* own doc comment has the full
* "path unknown" rationale). Freed
* and reset to NULL only by
* repl_params.c (`set output off`,
* or a subsequent `set output
* FILE` replacing it). */
uint64_t output_start_event_index; /* event_index snapshot taken when
* `set output FILE` opened the
* file -- `set output off`
* subtracts this from the CURRENT
* event_index to report "N events
* written". Meaningless while
* output_path == NULL. */
};
/* repl_split_tokens/XCE_REPL_MAX_TOKENS/XCE_REPL_TOKEN_LEN (repl.c) -
@ -159,4 +199,12 @@ extern bool repl_cmd_break(xce_sched_sim_driver_t* sim, const char* line);
extern bool repl_cmd_delete(xce_sched_sim_driver_t* sim, const char* line);
extern bool repl_cmd_info(xce_sched_sim_driver_t* sim, const char* line);
/* repl_cmd_snapshot/repl_cmd_set (repl_params.c, task 12.3) -- the two
* task-12.3 command handlers repl.c's repl_dispatch() hands off to. Same
* "returns false, re-prompt" contract every other repl_cmd_* above already
* follows -- neither taking a snapshot nor changing a parameter is ever a
* reason to hand control back to the driver loop. */
extern bool repl_cmd_snapshot(xce_sched_sim_driver_t* sim, const char* line);
extern bool repl_cmd_set(xce_sched_sim_driver_t* sim, const char* line);
#endif

View file

@ -0,0 +1,378 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "repl.h"
#include "repl_internal.h"
#include "utils.h"
/*
* repl_params.c - snapshot capture and simulation parameter commands
* (scheduler-core spec, task 12.3, Req 5 AC 22 "Snapshots" + "Simulation
* parameters"). Fourth sibling in the repl.c/repl_break.c/repl_info.c
* family -- see repl_internal.h's own "Why a split at all" section for the
* full rationale: this task's own real chunk of new logic (`snapshot` plus
* three `set` sub-commands) does not fit into either repl_break.c or
* repl_info.c's remaining headroom under this project's 800-line cap (both
* were already within ~130-160 lines of the cap after task 12.2), so it
* gets its own file, matching task 12.2's own precedent for the identical
* problem.
*
* Owns: the `snapshot [FILE]` and `set speed|output|verify ...` command
* handlers (repl_cmd_snapshot()/repl_cmd_set(), repl_internal.h's own
* extern declarations; repl.c's repl_dispatch() hands off to both). `info
* config` -- the read-only counterpart that reports the SAME parameters
* this file's `set` command mutates -- lives in repl_info.c instead,
* alongside every other `info` subcommand (that file's own "Owns" doc
* comment), not here.
*
* Boundary (Req 5 AC 17): same as repl.c/repl_break.c/repl_info.c -- only
* xce_sched_sim_driver_t/xce_sched_core_t (via repl.h/repl_internal.h ->
* sim.h -> core.h) plus stdio/string.h/stdlib.h/errno.h.
*
* Reuse, not reimplementation (this task's own explicit instruction): both
* `snapshot` and `set output`'s file-open path write the SAME
* ReplayHeader+SnapshotEntry preamble sim_loop.c's own --sim-output startup
* path writes, via sim_record_write_header_and_snapshot() (sim_record.c,
* task 11.5) -- redeclared here via a local `extern`, the SAME "extern
* declared where consumed" idiom sim_loop.c/sim_record.c themselves already
* use for write_capnp_message()/write_snapshot_entry() (see sim_record.c's
* own file header comment for the precedent this follows). Neither command
* hand-rolls capnp encoding.
*
* `set speed`'s atomic_store_explicit()/memory_order_release calls need no
* `#include <stdatomic.h>` of their own -- core.h (pulled in transitively
* via repl.h -> sim.h -> core.h) already includes it, the SAME reason
* sim.c's own sim_set_virtual_clock() (the function this file's
* repl_set_speed() mirrors) needs no direct include either.
*/
extern int sim_record_write_header_and_snapshot(FILE* f, xce_sched_core_t* core,
uint64_t snapshot_ts);
/* ------------------------------------------------------------------------
* snapshot [FILE]
* ---------------------------------------------------------------------- */
/* XCE_REPL_SNAPSHOT_AUTO_BASENAME - see repl_snapshot_default_path()'s own
* doc comment for why this is a fixed, documented stand-in for the real
* replay basename AC 22's auto-naming rule asks for. */
#define XCE_REPL_SNAPSHOT_AUTO_BASENAME "sim"
/*
* repl_snapshot_default_path - AC 22's `snapshot [FILE]` auto-naming rule:
* "<replay_basename>-snap-<event_index>.replay" when FILE is omitted.
*
* Deviation note (this task's own "your judgment, document the deviation"
* allowance -- the same discipline repl.c's repl_count_jobs() doc comment
* already establishes for an identical AC-22-pseudocode gap):
* xce_sched_sim_driver_t (sim.h) retains no string form of the replay
* file's own path -- only a bare FILE* (`replay_file`), opened once at
* startup and never named again; sched_sim_driver_start()'s own `args`
* (which DOES carry `replay_path`) is a local, non-retained parameter, gone
* by the time any REPL command runs. Adding a retained path field to
* xce_sched_sim_driver_t purely to serve this one auto-naming convenience
* was judged not worth the wider blast radius (a sim.h/sim.c change
* touching two OTHER tasks' files, for a fallback branch of a debugging
* convenience) -- instead this uses a fixed, documented basename ("sim")
* in place of the unavailable real one. `event_index` still makes the
* generated name unique across repeated `snapshot` calls in one session
* (never collides); an operator who cares about the base filename can
* always pass one explicitly.
*/
static void repl_snapshot_default_path(xce_sched_sim_driver_t* sim, char* out,
size_t out_sz)
{
uint64_t event_index
= (sim->repl_state != NULL) ? sim->repl_state->event_index : 0;
snprintf(out, out_sz, "%s-snap-%llu.replay", XCE_REPL_SNAPSHOT_AUTO_BASENAME,
(unsigned long long)event_index);
}
/*
* repl_cmd_snapshot - Req 5 AC 22's "snapshot [FILE]": "Write a full
* save_snapshot() to FILE as a standalone .replay file (contains
* ReplayHeader + SnapshotEntry) ... The operator can restart simulation
* from this snapshot via --sim <snapshot_file> --sim-start-ts
* <time_at_snapshot>." Uses `xce_core_now(&sim->core)` -- the CURRENT
* simulation position -- as both the ReplayHeader's recording_start_ts and
* the SnapshotEntry's own ts (sim_record_write_header_and_snapshot()'s
* `snapshot_ts` parameter), so a `--sim-start-ts <that same value>` reload
* lands on exactly this SnapshotEntry (AC 13's own "most recent
* SnapshotEntry with ts <= sim_start_ts" selection rule, satisfied
* trivially since this file's sole SnapshotEntry is the only candidate).
* Deliberately NOT `sim->snapshot_ts` (the ORIGINAL load-time value, sim.h's
* own task 11.5 field) -- AC 22's own wording is "at the current simulation
* position", which has moved on since load if any session has already run.
*
* fopen()s the target path directly -- no sched_validate_record_filename()
* TOCTOU hardening, unlike recording.c's sched_record_start(): that
* hardening exists to protect a LIVE production daemon's --record-dir
* against an adversarial symlink/hardlink swap, and needs an
* xce_scheduler_t pointer plus a record_dir this file family deliberately
* never has (Req 5 AC 17). This REPL command is a trusted operator typing
* a path at an interactive debugging prompt -- the same trust boundary
* sim.c's own --sim-output/--sim-alt-events fopen() calls
* (sched_sim_driver_start(), sim.c) already accept without TOCTOU
* hardening of their own.
*
* Always returns false -- taking a snapshot is never a reason to hand
* control back to the driver loop.
*/
bool repl_cmd_snapshot(xce_sched_sim_driver_t* sim, const char* line)
{
char tokens[XCE_REPL_MAX_TOKENS][XCE_REPL_TOKEN_LEN];
int ntok = repl_split_tokens(line, tokens, XCE_REPL_MAX_TOKENS);
char auto_path[XCE_REPL_TOKEN_LEN + 32];
const char* path;
FILE* f;
uint64_t ts;
int rc;
if (ntok >= 2) {
path = tokens[1];
} else {
repl_snapshot_default_path(sim, auto_path, sizeof(auto_path));
path = auto_path;
}
f = fopen(path, "w");
if (f == NULL) {
printf("[sim] snapshot: failed to open '%s': %s\n", path,
strerror(errno));
return false;
}
ts = xce_core_now(&(sim->core));
rc = sim_record_write_header_and_snapshot(f, &(sim->core), ts);
fflush(f);
fclose(f);
if (rc < 0) {
printf("[sim] snapshot: failed writing to '%s': rc=%d\n", path, rc);
return false;
}
printf("[sim] snapshot written: %s (ts=%llu)\n", path,
(unsigned long long)ts);
return false;
}
/* ------------------------------------------------------------------------
* set speed|output|verify ...
* ---------------------------------------------------------------------- */
/*
* repl_set_speed - AC 22's "set speed <N>": mutates BOTH
* sim->sim_speed_num/sim_speed_den (the driver-level shadow copy sim.h's
* own doc comment says exists "for the REPL/diagnostics to read without
* reaching into `core`" -- `info config`'s own speed= field, repl_info.c,
* reads these) AND sim->core.speed_num/speed_den -- the atomic pair
* core_clock.c's xce_core_now() actually consults, FRESH, on every single
* call (no caching) -- via the SAME two atomic_store_explicit() calls
* sim_set_virtual_clock() (sim.c, Req 5 AC 13 Step 4) already performs at
* startup for the identical pair. Mutating only the shadow copy would leave
* `info config` and reality disagreeing forever; sim_loop.c needs no new
* call site for this to take effect -- xce_core_now() is already called
* throughout its event loop on every iteration, so the very next call
* observes the new speed.
*
* `N` = 0 (freeze / "as-fast-as-possible", AC 22's own table wording) is
* accepted here, unlike `step`'s N (repl_cmd_step(), repl.c), which
* rejects N<=0 -- speed=0 is a legitimate, documented mode (core.h's own
* speed_num/speed_den field doc comment: "discrete-simulation freezes via
* speed_num=0"), not a user error.
*
* Deliberately does NOT re-anchor virtual_clock_base/real_clock_base:
* those are only ever re-anchored by sim_advance_virtual_clock()
* (sim_loop.c) at each event/session-boundary jump, and the REPL only ever
* regains control AT one of those jump points (the pre-replay pause, a
* post-session pause, or a breakpoint hit) -- so leaving them untouched
* here introduces no discontinuity in xce_core_now()'s reported value.
*/
static bool repl_set_speed(xce_sched_sim_driver_t* sim, const char* value)
{
char* endptr;
uint64_t n;
if (value[0] == '\0') {
printf("[sim] set speed: usage: set speed <N>\n");
return false;
}
n = strtoull(value, &endptr, 10);
if (*endptr != '\0') {
printf("[sim] set speed: '%s' is not a valid non-negative integer\n",
value);
return false;
}
atomic_store_explicit(&(sim->core.speed_num), n, memory_order_release);
atomic_store_explicit(&(sim->core.speed_den), 1, memory_order_release);
sim->sim_speed_num = n;
sim->sim_speed_den = 1;
printf("[sim] speed set to %llu\n", (unsigned long long)n);
return false;
}
/*
* repl_set_output_off - AC 22's "set output off": "Close the current
* output file. info config confirms the path and event count at close
* time." Read here as: the confirmation IS this function's own printed
* line, given at the moment of closing -- not a new obligation for a
* SUBSEQUENT `info config` call to remember a now-closed stream's history
* (which would need its own separate tracking for no real benefit; `info
* config` legitimately reports output=off afterward, per the table's own
* literal format).
*
* "event count" is rs->event_index's delta since this output file was
* opened (rs->output_start_event_index, set by repl_set_output_file()
* below) -- an honest, REPL-visible proxy: sim_loop.c's actual per-event
* write happens inside its own loop
* (sim_process_replay_event_message()/sched_record_session_add_decision()),
* never observed directly by this file; event_index already increments in
* exact lockstep with every event write while sim->record_file stays
* non-NULL (xce_repl_on_event(), repl_break.c), so the delta is exact FOR
* an output file this REPL command itself opened. If --sim-output was
* already active at startup (CLI flag, before this session ever ran `set
* output`), rs->output_path is NULL (repl_set_output_file() is the only
* place that ever sets it) -- reported honestly below as unavailable, not
* fabricated.
*/
static bool repl_set_output_off(xce_sched_sim_driver_t* sim)
{
xce_sched_repl_state_t* rs = sim->repl_state;
if (sim->record_file == NULL) {
printf("[sim] set output: already off\n");
return false;
}
fflush(sim->record_file);
fclose(sim->record_file);
sim->record_file = NULL;
if ((rs != NULL) && (rs->output_path != NULL)) {
uint64_t n = rs->event_index - rs->output_start_event_index;
printf("[sim] output stopped: %s (%llu event(s) written)\n",
rs->output_path, (unsigned long long)n);
free(rs->output_path);
rs->output_path = NULL;
} else {
printf("[sim] output stopped (path/count unavailable -- was opened "
"via --sim-output before this REPL session set one)\n");
}
return false;
}
/*
* repl_set_output_file - AC 22's "set output <FILE>": "Start writing
* simulation decisions to FILE in the same .replay capnp stream format as
* --sim-output. Opens ReplayHeader+SnapshotEntry at the current position if
* the file is new." "The current position" is `xce_core_now(&sim->core)` at
* the moment this command runs -- the same "current simulation position"
* reading repl_cmd_snapshot() above uses, for the identical reason (AC 22's
* own wording, not the original load-time `sim->snapshot_ts`).
*
* If sim->record_file is already active (either a prior `set output FILE`
* this session, or --sim-output from the CLI), it is flushed and closed
* first: AC 22's table does not literally describe re-running `set output`
* while already active, but silently leaking the old FILE* or interleaving
* writes into two files at once would both be worse than the documented
* "switch cleanly" behavior implemented here.
*/
static bool repl_set_output_file(xce_sched_sim_driver_t* sim, const char* path)
{
xce_sched_repl_state_t* rs = sim->repl_state;
FILE* f;
uint64_t ts;
int rc;
if (sim->record_file != NULL) {
fflush(sim->record_file);
fclose(sim->record_file);
sim->record_file = NULL;
if ((rs != NULL) && (rs->output_path != NULL)) {
free(rs->output_path);
rs->output_path = NULL;
}
}
f = fopen(path, "w");
if (f == NULL) {
printf("[sim] set output: failed to open '%s': %s\n", path,
strerror(errno));
return false;
}
ts = xce_core_now(&(sim->core));
rc = sim_record_write_header_and_snapshot(f, &(sim->core), ts);
if (rc < 0) {
printf("[sim] set output: failed writing header/snapshot to '%s': "
"rc=%d\n",
path, rc);
fclose(f);
return false;
}
sim->record_file = f;
if (rs != NULL) {
rs->output_path = strdup(path);
rs->output_start_event_index = rs->event_index;
}
printf("[sim] output started: %s\n", path);
return false;
}
/*
* repl_cmd_set - Req 5 AC 22's "set ..." family: "set speed <N>" /
* "set output <FILE>|off" / "set verify on|off". `line` re-tokenized via
* repl_split_tokens() (repl.c), same as break/delete/info.
*/
bool repl_cmd_set(xce_sched_sim_driver_t* sim, const char* line)
{
char tokens[XCE_REPL_MAX_TOKENS][XCE_REPL_TOKEN_LEN];
int ntok = repl_split_tokens(line, tokens, XCE_REPL_MAX_TOKENS);
if (ntok < 3) {
printf("[sim] set: usage: set speed <N> | set output <FILE>|off | "
"set verify on|off\n");
return false;
}
if (strcmp(tokens[1], "speed") == 0) {
return repl_set_speed(sim, tokens[2]);
}
if (strcmp(tokens[1], "output") == 0) {
if (strcmp(tokens[2], "off") == 0) {
return repl_set_output_off(sim);
}
return repl_set_output_file(sim, tokens[2]);
}
if (strcmp(tokens[1], "verify") == 0) {
if (strcmp(tokens[2], "on") == 0) {
sim->verify = true;
} else if (strcmp(tokens[2], "off") == 0) {
sim->verify = false;
} else {
printf("[sim] set verify: usage: set verify on|off\n");
return false;
}
printf("[sim] verify set to %s\n", sim->verify ? "on" : "off");
return false;
}
printf("[sim] set: unrecognized parameter '%s'\n", tokens[1]);
return false;
}

View file

@ -560,6 +560,9 @@ sched_sim_isolation_test = executable(
'-DXCE_SIM_REPL_INTERNAL_H_PATH="'
+ (meson.current_source_dir() / '..' / 'src' / 'repl_internal.h')
+ '"',
'-DXCE_SIM_REPL_PARAMS_C_PATH="'
+ (meson.current_source_dir() / '..' / 'src' / 'repl_params.c')
+ '"',
'-DXCE_SIM_LIB_PATH="'
+ sched_sim_isolation_lib.full_path()
+ '"'],
@ -708,6 +711,31 @@ sched_repl_breakpoints_inspection_test = executable(
dependencies: [scheduler_test_deps, libedit_dep],
install: false)
# Contract test for the interactive simulation REPL's snapshot-capture and
# simulation-parameter command slice (scheduler-core spec, task 12.3, Req 5
# AC 22 "Snapshots"/"Simulation parameters"): `snapshot [FILE]` writes a
# standalone .replay file a FRESH sched_sim_driver_start() can load, landing
# on the exact position the snapshot was taken at (the task's own central
# Observable, proved end to end via a forked child + a second, real
# sched_sim_driver_start() call in the parent); `set speed`/`set output`/
# `set verify` mutate the parameters `info config` reports. Same white-box
# #include pattern as sched_repl_breakpoints_inspection_test above (core.c,
# core_clock.c, core_events.c, core_session.c, decision.c, plugin.c,
# plugins/builtin_fcfs.c, recording.c, recording_session.c, sim.c,
# sim_loop.c, sim_record.c, sim_verify.c,
# snapshot.c/snapshot_wire.c/snapshot_load.c, repl.c, repl_break.c,
# repl_info.c) PLUS the new ../src/repl_params.c under test. Split into its
# own file rather than appended to test_repl_breakpoints_inspection.c --
# that file was already over 1000 lines after task 12.2, and this task's
# own fixture/assertion surface (a fork+reload round-trip plus five
# further unit-level command tests) does not belong crammed into it.
sched_repl_snapshot_params_test = executable(
'sched_repl_snapshot_params_test',
['test_repl_snapshot_params.c'],
include_directories:[incdir],
dependencies: [scheduler_test_deps, libedit_dep],
install: false)
# Register as meson tests so `meson test --suite scheduler` runs them all.
# detect_leaks=0 matches the suite convention (fixtures are not torn down).
test('scheduler test', scheduler_test, suite: 'scheduler',
@ -804,3 +832,6 @@ test('scheduler repl execution control test',
test('scheduler repl breakpoints inspection test',
sched_repl_breakpoints_inspection_test, suite: 'scheduler',
env: ['ASAN_OPTIONS=detect_leaks=0'])
test('scheduler repl snapshot params test',
sched_repl_snapshot_params_test, suite: 'scheduler',
env: ['ASAN_OPTIONS=detect_leaks=0'])

View file

@ -81,6 +81,7 @@
#include "../src/repl.c"
#include "../src/repl_break.c"
#include "../src/repl_info.c"
#include "../src/repl_params.c"
#include "../src/sim.c"
#include "../src/sim_loop.c"
#include "../src/sim_record.c"

View file

@ -96,6 +96,7 @@
#include "../src/repl.c"
#include "../src/repl_break.c"
#include "../src/repl_info.c"
#include "../src/repl_params.c"
#include "../src/sim.c"
#include "../src/sim_loop.c"
#include "../src/sim_record.c"

View file

@ -0,0 +1,845 @@
/*
* test_repl_snapshot_params.c - contract test for the interactive
* simulation REPL's snapshot-capture and simulation-parameter command slice
* (scheduler-core spec, task 12.3, Req 5 AC 22 "Snapshots"/"Simulation
* parameters").
*
* Observable under test (task 12.3's own text): "a snapshot command
* produces a file that the simulation driver can later load via a fresh
* `--sim` invocation starting from that exact position." Proved end to end
* (test_snapshot_written_file_is_loadable_by_fresh_sim_start below): a
* forked child drives a REAL sched_sim_driver_run() against a real
* fixture, issues `step 1` then `snapshot <path>` then `quit`, and the
* PARENT then calls the real sched_sim_driver_start() a SECOND time
* against the file the child wrote, asserting it succeeds and that the
* reloaded core state (snapshot_ts, the pushed job) matches what the
* child's session actually produced.
*
* The remaining tests cover `set speed`/`set output`/`set verify`/
* `info config` and the auto-generated `snapshot` filename, at the same
* "unit-level precision where possible, integration-level proof for the
* one Observable that needs it" split test_repl_execution_control.c's own
* header comment establishes.
*
* Fixture strategy and white-box #include set: identical to
* test_repl_execution_control.c/test_repl_breakpoints_inspection.c (see
* either file's own header comment) PLUS the new ../src/repl_params.c
* under test (task 12.3's own file, repl_internal.h's "Why a split at
* all" section).
*/
#include <errno.h>
#include <limits.h>
#include <stdatomic.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
#include <unity/unity.h>
#include "controller.capnp.h"
#include "kvmgr.h"
#include "scheduler.h"
#include "xstring.h"
/* Pull in the real functions under test into this TU (white-box #include,
* same convention as test_repl_execution_control.c/
* test_repl_breakpoints_inspection.c). */
#include "../src/core.c"
#include "../src/core_clock.c"
#include "../src/core_events.c"
#include "../src/core_session.c"
#include "../src/decision.c"
#include "../src/plugin.c"
#include "../src/plugins/builtin_fcfs.c"
#include "../src/recording.c"
#include "../src/recording_session.c"
#include "../src/repl.c"
#include "../src/repl_break.c"
#include "../src/repl_info.c"
#include "../src/repl_params.c"
#include "../src/sim.c"
#include "../src/sim_loop.c"
#include "../src/sim_record.c"
#include "../src/sim_verify.c"
#include "../src/snapshot.c"
#include "../src/snapshot_load.c"
#include "../src/snapshot_wire.c"
void kill_sched_job(void* arg) { (void)arg; }
void kill_sched_queue(void* arg) { (void)arg; }
void kill_sched_worker(void* arg) { (void)arg; }
void kill_sched_user(void* arg) { (void)arg; }
void kill_sched_project(void* arg) { (void)arg; }
void kill_sched_resval(xce_val_t* val) { (void)val; }
void sched_worker_release_host_ctx(xce_sched_worker_t* w) { (void)w; }
int sched_fill_limit_requests(xce_scheduler_t* sched, xvec_idval_t* vec,
xlist_t* limits)
{
(void)sched;
(void)vec;
(void)limits;
return 0;
}
/* Real reimplementation of schedobj.c's sched_resolve_job_picker -- same
* copy every sim-family white-box test carries (schedobj.c is not linked
* here: it would need plugin_register(), which requires a genuine
* xce_scheduler_t* neither this file's fixtures nor sim_loop.c's own
* core-scoped registration path have, Req 5 AC 17). */
int sched_resolve_job_picker(xce_sched_core_t* core, xce_sched_plugin_t** out)
{
xce_sched_plugin_t* plugin = NULL;
int rc = 0;
if ((core == NULL) || (out == NULL)) {
return -EINVAL;
}
*out = NULL;
if (core->job_pick_plugin == NULL) {
return -EINVAL;
}
lock(core->plugins, RTTI_LOCK_READ);
rc = key_find(core->plugins, core->job_pick_plugin, (void**)&plugin);
unlock(core->plugins);
if (rc <= 0) {
return (rc < 0) ? rc : -ENOENT;
}
if ((plugin == NULL) || (plugin->picker_iface == NULL)
|| (plugin->picker_iface->next_job == NULL)
|| (plugin->picker_iface->begin_session == NULL)
|| (plugin->picker_iface->end_session == NULL)
|| (plugin->picker_iface->on_dispatch == NULL)
|| (plugin->picker_iface->on_pend == NULL)) {
return -EINVAL;
}
*out = plugin;
return 0;
}
void setUp(void) { return; }
void tearDown(void) { return; }
/* ---------------------------------------------------------------------- */
/* Fixture helpers -- same techniques test_repl_execution_control.c/ */
/* test_repl_breakpoints_inspection.c already establish. */
/* ---------------------------------------------------------------------- */
static void make_tmp_dir(char* out, size_t out_len, const char* suffix)
{
char tmpl[PATH_MAX];
snprintf(tmpl, sizeof(tmpl), "/tmp/sched_replparams%s_XXXXXX", suffix);
TEST_ASSERT_NOT_NULL(mkdtemp(tmpl));
TEST_ASSERT_TRUE(strlen(tmpl) < out_len);
strcpy(out, tmpl);
}
static void build_fixture_scheduler(xce_scheduler_t* sched, char* record_dir)
{
int rc;
memset(sched, 0, sizeof(*sched));
mylock_init(&(sched->record_lock));
rc = xce_sched_core_init(&(sched->core));
TEST_ASSERT_EQUAL_INT(0, rc);
sched->core.job_pick_plugin = (char*)"builtin_fcfs";
sched->record_dir = record_dir;
}
static FILE* write_header_and_snapshot(char* out_path, size_t out_path_len,
const char* suffix)
{
char record_dir[PATH_MAX];
xce_scheduler_t sched;
int rc;
make_tmp_dir(record_dir, sizeof(record_dir), suffix);
build_fixture_scheduler(&sched, record_dir);
rc = sched_record_start(&sched, "fixture.replay");
TEST_ASSERT_EQUAL_INT(0, rc);
TEST_ASSERT_TRUE(strlen(sched.record_file_path) < out_path_len);
strcpy(out_path, sched.record_file_path);
return sched.record_file;
}
static void append_queue_update_event(FILE* f, uint64_t ts,
const char* queue_name)
{
xce_queue_t queue;
replay_event_t src;
struct capn c;
struct capn_segment* cs;
ReplayEvent_ptr p;
memset(&queue, 0, sizeof(queue));
queue.queue = (char*)queue_name;
queue.status = QUEUE_STAT_OPEN;
queue.priority = 1;
memset(&src, 0, sizeof(src));
src.ts = ts;
src.body_which = ReplayEvent_body_queueUpdate;
src.body.queue_update = &queue;
capn_init_malloc(&c);
cs = capn_root(&c).seg;
encode_ReplayEvent_ptr(cs, &p, &src);
capn_setp(capn_root(&c), 0, p.p);
TEST_ASSERT_EQUAL_INT(0, write_capnp_message(f, &c));
capn_free(&c);
}
static void append_jobs_push_event(FILE* f, uint64_t ts, uint64_t jobid,
const char* queue_name)
{
job_submit_data_t submit;
xce_job_t job;
xce_job_t* jobs[1];
xce_jobs_data_t jobs_data;
replay_event_t src;
struct capn c;
struct capn_segment* cs;
ReplayEvent_ptr p;
memset(&submit, 0, sizeof(submit));
submit.queue = (char*)queue_name;
submit.user = (char*)"alice";
submit.mintasks = 1;
submit.maxtasks = 1;
memset(&job, 0, sizeof(job));
job.jobid = jobid;
job.state = JOB_STAT_PEND;
job.submit = &submit;
jobs[0] = &job;
memset(&jobs_data, 0, sizeof(jobs_data));
jobs_data.n_total = 1;
jobs_data.count = 1;
jobs_data.jobs = jobs;
memset(&src, 0, sizeof(src));
src.ts = ts;
src.body_which = ReplayEvent_body_jobsPush;
src.body.jobs_push = &jobs_data;
capn_init_malloc(&c);
cs = capn_root(&c).seg;
encode_ReplayEvent_ptr(cs, &p, &src);
capn_setp(capn_root(&c), 0, p.p);
TEST_ASSERT_EQUAL_INT(0, write_capnp_message(f, &c));
capn_free(&c);
}
static void append_replay_session(FILE* f, uint64_t begin_round)
{
struct capn c;
struct capn_segment* cs;
ReplaySession_ptr sp;
capn_init_malloc(&c);
cs = capn_root(&c).seg;
sp = new_ReplaySession(cs);
ReplaySession_set_beginRound(sp, begin_round);
capn_setp(capn_root(&c), 0, sp.p);
TEST_ASSERT_EQUAL_INT(0, write_capnp_message(f, &c));
capn_free(&c);
}
static void append_end_of_stream_marker(FILE* f)
{
replay_event_t src;
struct capn c;
struct capn_segment* cs;
ReplayEvent_ptr p;
memset(&src, 0, sizeof(src));
src.body_which = ReplayEvent_body_endSession;
capn_init_malloc(&c);
cs = capn_root(&c).seg;
encode_ReplayEvent_ptr(cs, &p, &src);
capn_setp(capn_root(&c), 0, p.p);
TEST_ASSERT_EQUAL_INT(0, write_capnp_message(f, &c));
capn_free(&c);
}
static void write_text_file(const char* path, const char* content)
{
FILE* f = fopen(path, "w");
TEST_ASSERT_NOT_NULL(f);
TEST_ASSERT_TRUE(fputs(content, f) >= 0);
fclose(f);
}
static char* read_whole_file(const char* path)
{
FILE* f = fopen(path, "rb");
long len;
char* buf;
TEST_ASSERT_NOT_NULL(f);
TEST_ASSERT_EQUAL_INT(0, fseek(f, 0, SEEK_END));
len = ftell(f);
TEST_ASSERT_TRUE(len >= 0);
rewind(f);
buf = (char*)malloc((size_t)len + 1);
TEST_ASSERT_NOT_NULL(buf);
if (len > 0) {
TEST_ASSERT_EQUAL_INT((int)len, (int)fread(buf, 1, (size_t)len, f));
}
buf[len] = '\0';
fclose(f);
return buf;
}
/* Same dup()/dup2()-around-STDOUT_FILENO capture technique
* test_repl_execution_control.c's own capture_stdout_around() establishes. */
static char* capture_stdout_around(void (*fn)(void))
{
char tmp[] = "/tmp/xce_replparams_stdoutcap_XXXXXX";
int fd = mkstemp(tmp);
int saved_stdout;
off_t len;
char* buf;
TEST_ASSERT_TRUE_MESSAGE(fd >= 0, "mkstemp for stdout capture must "
"succeed");
fflush(stdout);
saved_stdout = dup(STDOUT_FILENO);
TEST_ASSERT_TRUE_MESSAGE(saved_stdout >= 0, "dup(STDOUT_FILENO) must "
"succeed");
TEST_ASSERT_TRUE_MESSAGE(dup2(fd, STDOUT_FILENO) >= 0,
"dup2 redirect of STDOUT_FILENO must succeed");
fn();
fflush(stdout);
dup2(saved_stdout, STDOUT_FILENO);
close(saved_stdout);
len = lseek(fd, 0, SEEK_CUR);
TEST_ASSERT_TRUE(len >= 0);
buf = (char*)calloc(1, (size_t)len + 1);
TEST_ASSERT_NOT_NULL(buf);
TEST_ASSERT_TRUE(lseek(fd, 0, SEEK_SET) == 0);
if (len > 0) {
ssize_t nread = read(fd, buf, (size_t)len);
TEST_ASSERT_TRUE(nread == len);
}
close(fd);
unlink(tmp);
return buf;
}
static bool file_exists_nonempty(const char* path)
{
FILE* f = fopen(path, "rb");
long len;
if (f == NULL) {
return false;
}
if (fseek(f, 0, SEEK_END) != 0) {
fclose(f);
return false;
}
len = ftell(f);
fclose(f);
return len > 0;
}
/* ---------------------------------------------------------------------- */
/* Test: `snapshot <FILE>` writes a standalone .replay file a FRESH */
/* sched_sim_driver_start() can load, landing on the exact position the */
/* snapshot was taken at -- the task's own central Observable. */
/* ---------------------------------------------------------------------- */
static void child_step_snapshot_quit(const char* replay_path,
const char* script_path,
const char* capture_path,
const char* output_dir)
{
xce_sched_sim_driver_t sim;
sched_sim_args_t args;
if (chdir(output_dir) != 0) {
_exit(119);
}
if (freopen(script_path, "r", stdin) == NULL) {
_exit(120);
}
if (freopen(capture_path, "w", stdout) == NULL) {
_exit(121);
}
memset(&sim, 0, sizeof(sim));
memset(&args, 0, sizeof(args));
args.replay_path = replay_path;
args.sim_start_ts = SCHED_SIM_START_TS_LATEST;
args.sim_speed = 0; /* frozen virtual clock -- deterministic ts */
args.interactive = true;
(void)sched_sim_driver_run(&sim, &args);
/* Unreachable in a correct implementation -- "quit" must have called
* exit(0) already. */
fflush(stdout);
_exit(111);
}
static void test_snapshot_written_file_is_loadable_by_fresh_sim_start(void)
{
char replay_path[PATH_MAX];
char output_dir[PATH_MAX];
char aux_dir[PATH_MAX];
char script_path[PATH_MAX];
char capture_path[PATH_MAX];
char snap_path[PATH_MAX];
FILE* f;
pid_t pid;
int status;
char* captured;
xce_sched_sim_driver_t sim2;
sched_sim_args_t args2;
int rc;
xce_sched_job_t* job;
f = write_header_and_snapshot(replay_path, sizeof(replay_path),
"_snapload");
TEST_ASSERT_NOT_NULL(f);
append_queue_update_event(f, 1000ULL, "normal");
append_jobs_push_event(f, 1500ULL, 555ULL, "normal");
append_replay_session(f, 2000ULL); /* session boundary #1 -- `step 1`
* pauses here, frozen at ts=2000 */
append_jobs_push_event(f, 2500ULL, 999ULL, "normal");
append_replay_session(f, 3000ULL); /* must NEVER be reached */
append_end_of_stream_marker(f);
fclose(f);
make_tmp_dir(output_dir, sizeof(output_dir), "_snaploadout");
make_tmp_dir(aux_dir, sizeof(aux_dir), "_snaploadaux");
snprintf(script_path, sizeof(script_path), "%s/script.txt", aux_dir);
snprintf(capture_path, sizeof(capture_path), "%s/capture.out", aux_dir);
write_text_file(script_path, "step 1\nsnapshot snap_out.replay\nquit\n");
pid = fork();
TEST_ASSERT_TRUE_MESSAGE(pid >= 0, "fork() must succeed");
if (pid == 0) {
child_step_snapshot_quit(replay_path, script_path, capture_path,
output_dir);
_exit(112); /* unreachable */
}
TEST_ASSERT_EQUAL_INT_MESSAGE(pid, waitpid(pid, &status, 0),
"waitpid must reap the REPL child");
TEST_ASSERT_TRUE_MESSAGE(WIFEXITED(status),
"the REPL child must exit normally via quit's "
"exit(0)");
TEST_ASSERT_EQUAL_INT_MESSAGE(0, WEXITSTATUS(status),
"quit's exit(0) is the only correct exit "
"path");
captured = read_whole_file(capture_path);
TEST_ASSERT_NOT_NULL_MESSAGE(strstr(captured, "snapshot written"),
"the snapshot command must print a "
"confirmation line");
free(captured);
snprintf(snap_path, sizeof(snap_path), "%s/snap_out.replay", output_dir);
TEST_ASSERT_TRUE_MESSAGE(file_exists_nonempty(snap_path),
"the snapshot command must have created a "
"non-empty file at the requested path");
/* The central Observable: a FRESH sched_sim_driver_start() against the
* snapshot the REPL just wrote must succeed and land exactly where the
* `snapshot` command was issued -- after session 1, NOT session 2. */
memset(&sim2, 0, sizeof(sim2));
memset(&args2, 0, sizeof(args2));
args2.replay_path = snap_path;
args2.sim_start_ts = SCHED_SIM_START_TS_LATEST;
rc = sched_sim_driver_start(&sim2, &args2);
TEST_ASSERT_EQUAL_INT_MESSAGE(0, rc,
"a fresh --sim invocation must load the "
"REPL-written snapshot successfully");
TEST_ASSERT_EQUAL_UINT64_MESSAGE(2000ULL, sim2.snapshot_ts,
"the reloaded snapshot's ts must be "
"exactly the simulation position at "
"the moment `snapshot` was issued "
"(session 1's begin_round, frozen "
"clock)");
job = sched_get_job(&(sim2.core), 555ULL);
TEST_ASSERT_NOT_NULL_MESSAGE(job, "job 555 (pushed before session 1) "
"must be present in the reloaded "
"snapshot's state");
TEST_ASSERT_NULL_MESSAGE(sched_get_job(&(sim2.core), 999ULL),
"job 999 (pushed AFTER session 1, never "
"reached) must NOT be present -- proves the "
"snapshot captured the position at `snapshot` "
"time, not the whole file");
printf("test_snapshot_written_file_is_loadable_by_fresh_sim_start: "
"PASS\n");
}
/* ---------------------------------------------------------------------- */
/* Test: `snapshot` with no FILE argument auto-generates a name using the */
/* REPL's own event_index position counter. */
/* ---------------------------------------------------------------------- */
static void child_step_snapshot_noarg_quit(const char* replay_path,
const char* script_path,
const char* capture_path,
const char* output_dir)
{
xce_sched_sim_driver_t sim;
sched_sim_args_t args;
if (chdir(output_dir) != 0) {
_exit(119);
}
if (freopen(script_path, "r", stdin) == NULL) {
_exit(120);
}
if (freopen(capture_path, "w", stdout) == NULL) {
_exit(121);
}
memset(&sim, 0, sizeof(sim));
memset(&args, 0, sizeof(args));
args.replay_path = replay_path;
args.sim_start_ts = SCHED_SIM_START_TS_LATEST;
args.sim_speed = 0;
args.interactive = true;
(void)sched_sim_driver_run(&sim, &args);
fflush(stdout);
_exit(111);
}
static void test_snapshot_auto_generates_filename_from_event_index(void)
{
char replay_path[PATH_MAX];
char output_dir[PATH_MAX];
char aux_dir[PATH_MAX];
char script_path[PATH_MAX];
char capture_path[PATH_MAX];
char expect_path[PATH_MAX];
FILE* f;
pid_t pid;
int status;
f = write_header_and_snapshot(replay_path, sizeof(replay_path),
"_snapauto");
TEST_ASSERT_NOT_NULL(f);
/* Two translatable events (QUEUE_UPDATE, JOBS_PUSH) before the one
* session boundary -- event_index == 2 by the time `step 1` re-pauses. */
append_queue_update_event(f, 1000ULL, "normal");
append_jobs_push_event(f, 1500ULL, 777ULL, "normal");
append_replay_session(f, 2000ULL);
append_end_of_stream_marker(f);
fclose(f);
make_tmp_dir(output_dir, sizeof(output_dir), "_snapautoout");
make_tmp_dir(aux_dir, sizeof(aux_dir), "_snapautoaux");
snprintf(script_path, sizeof(script_path), "%s/script.txt", aux_dir);
snprintf(capture_path, sizeof(capture_path), "%s/capture.out", aux_dir);
write_text_file(script_path, "step 1\nsnapshot\nquit\n");
pid = fork();
TEST_ASSERT_TRUE_MESSAGE(pid >= 0, "fork() must succeed");
if (pid == 0) {
child_step_snapshot_noarg_quit(replay_path, script_path,
capture_path, output_dir);
_exit(112);
}
TEST_ASSERT_EQUAL_INT_MESSAGE(pid, waitpid(pid, &status, 0),
"waitpid must reap the REPL child");
TEST_ASSERT_TRUE_MESSAGE(WIFEXITED(status),
"the REPL child must exit normally via quit's "
"exit(0)");
TEST_ASSERT_EQUAL_INT_MESSAGE(0, WEXITSTATUS(status),
"quit's exit(0) is the only correct exit "
"path");
snprintf(expect_path, sizeof(expect_path), "%s/sim-snap-2.replay",
output_dir);
TEST_ASSERT_TRUE_MESSAGE(file_exists_nonempty(expect_path),
"an omitted FILE argument must auto-generate "
"'sim-snap-<event_index>.replay' in the "
"current directory");
printf("test_snapshot_auto_generates_filename_from_event_index: "
"PASS\n");
}
/* ---------------------------------------------------------------------- */
/* Test: `set speed <N>` mutates BOTH the driver-level shadow copy AND the */
/* atomic core.speed_num/speed_den pair xce_core_now() actually reads. */
/* ---------------------------------------------------------------------- */
static void test_set_speed_updates_shadow_and_core_atomics(void)
{
xce_sched_sim_driver_t sim;
bool handled;
memset(&sim, 0, sizeof(sim));
handled = repl_cmd_set(&sim, "set speed 7");
TEST_ASSERT_FALSE_MESSAGE(handled, "`set` never hands control back");
TEST_ASSERT_EQUAL_UINT64(7ULL, sim.sim_speed_num);
TEST_ASSERT_EQUAL_UINT64(1ULL, sim.sim_speed_den);
TEST_ASSERT_EQUAL_UINT64(
7ULL, atomic_load_explicit(&(sim.core.speed_num), memory_order_acquire));
TEST_ASSERT_EQUAL_UINT64(
1ULL, atomic_load_explicit(&(sim.core.speed_den), memory_order_acquire));
/* speed=0 (freeze / as-fast-as-possible) is a legitimate value, unlike
* `step`'s N (which rejects <= 0). */
handled = repl_cmd_set(&sim, "set speed 0");
TEST_ASSERT_FALSE(handled);
TEST_ASSERT_EQUAL_UINT64(0ULL, sim.sim_speed_num);
TEST_ASSERT_EQUAL_UINT64(
0ULL, atomic_load_explicit(&(sim.core.speed_num), memory_order_acquire));
/* Malformed input must be rejected AND leave state unchanged. */
handled = repl_cmd_set(&sim, "set speed abc");
TEST_ASSERT_FALSE(handled);
TEST_ASSERT_EQUAL_UINT64_MESSAGE(0ULL, sim.sim_speed_num,
"a malformed `set speed` argument must "
"not change the current speed");
printf("test_set_speed_updates_shadow_and_core_atomics: PASS\n");
}
/* ---------------------------------------------------------------------- */
/* Test: `set verify on|off` toggles sim->verify, the exact flag */
/* sim_loop.c's own decision-verification branch already reads fresh. */
/* ---------------------------------------------------------------------- */
static void test_set_verify_toggles_flag(void)
{
xce_sched_sim_driver_t sim;
bool handled;
memset(&sim, 0, sizeof(sim));
TEST_ASSERT_FALSE(sim.verify);
handled = repl_cmd_set(&sim, "set verify on");
TEST_ASSERT_FALSE(handled);
TEST_ASSERT_TRUE(sim.verify);
handled = repl_cmd_set(&sim, "set verify off");
TEST_ASSERT_FALSE(handled);
TEST_ASSERT_FALSE(sim.verify);
/* Malformed value leaves the flag unchanged. */
handled = repl_cmd_set(&sim, "set verify maybe");
TEST_ASSERT_FALSE(handled);
TEST_ASSERT_FALSE_MESSAGE(sim.verify, "a malformed `set verify` "
"argument must not change the "
"current flag");
printf("test_set_verify_toggles_flag: PASS\n");
}
/* ---------------------------------------------------------------------- */
/* Test: `set output <FILE>` opens the file, writes a real */
/* ReplayHeader+SnapshotEntry preamble (reusing sim_record.c's own writer, */
/* not hand-rolled), and `set output off` closes it cleanly. */
/* ---------------------------------------------------------------------- */
static void test_set_output_opens_writes_preamble_and_off_closes(void)
{
xce_sched_sim_driver_t sim;
char tmp_dir[PATH_MAX];
char out_path[PATH_MAX];
char cmd[PATH_MAX + 32];
bool handled;
FILE* check;
struct capn c;
capn_ptr root;
memset(&sim, 0, sizeof(sim));
TEST_ASSERT_EQUAL_INT(0, xce_sched_core_init(&(sim.core)));
sim.repl_state = repl_state_ensure(&sim);
TEST_ASSERT_NOT_NULL(sim.repl_state);
make_tmp_dir(tmp_dir, sizeof(tmp_dir), "_setoutput");
snprintf(out_path, sizeof(out_path), "%s/out.replay", tmp_dir);
snprintf(cmd, sizeof(cmd), "set output %s", out_path);
handled = repl_cmd_set(&sim, cmd);
TEST_ASSERT_FALSE(handled);
TEST_ASSERT_NOT_NULL_MESSAGE(sim.record_file,
"`set output FILE` must open sim->record_file");
TEST_ASSERT_NOT_NULL(sim.repl_state->output_path);
TEST_ASSERT_EQUAL_STRING(out_path, sim.repl_state->output_path);
/* Flush so the reader below sees the two messages already written. */
fflush(sim.record_file);
check = fopen(out_path, "rb");
TEST_ASSERT_NOT_NULL_MESSAGE(check, "the opened output file must exist "
"on disk");
TEST_ASSERT_EQUAL_INT_MESSAGE(0, capn_init_fp(&c, check, 0),
"first message must be readable capnp");
TEST_ASSERT_TRUE_MESSAGE(
msg_root_has_shape(&c, &root, ReplayHeader_word_count,
ReplayHeader_pointer_count),
"first message must be a ReplayHeader");
capn_free(&c);
TEST_ASSERT_EQUAL_INT_MESSAGE(0, capn_init_fp(&c, check, 0),
"second message must be readable capnp");
TEST_ASSERT_TRUE_MESSAGE(
msg_root_has_shape(&c, &root, SnapshotEntry_word_count,
SnapshotEntry_pointer_count),
"second message must be a SnapshotEntry");
capn_free(&c);
fclose(check);
handled = repl_cmd_set(&sim, "set output off");
TEST_ASSERT_FALSE(handled);
TEST_ASSERT_NULL_MESSAGE(sim.record_file, "`set output off` must close "
"sim->record_file");
TEST_ASSERT_NULL_MESSAGE(sim.repl_state->output_path,
"`set output off` must clear the tracked path");
/* A second `off` while already off must be a harmless no-op. */
handled = repl_cmd_set(&sim, "set output off");
TEST_ASSERT_FALSE(handled);
TEST_ASSERT_NULL(sim.record_file);
printf("test_set_output_opens_writes_preamble_and_off_closes: PASS\n");
}
/* ---------------------------------------------------------------------- */
/* Test: `info config` reports speed/output/verify/events_processed/ */
/* current_ts/sessions, both while output is off and while it is active */
/* with a known path. */
/* ---------------------------------------------------------------------- */
static xce_sched_sim_driver_t g_cfg_sim;
static void run_info_config(void) { repl_cmd_info(&g_cfg_sim, "info config"); }
static void test_info_config_reports_current_parameters(void)
{
char* captured;
char tmp_dir[PATH_MAX];
char out_path[PATH_MAX];
FILE* real_out;
memset(&g_cfg_sim, 0, sizeof(g_cfg_sim));
g_cfg_sim.repl_state = repl_state_ensure(&g_cfg_sim);
TEST_ASSERT_NOT_NULL(g_cfg_sim.repl_state);
g_cfg_sim.sim_speed_num = 3;
g_cfg_sim.sim_speed_den = 1;
g_cfg_sim.verify = true;
g_cfg_sim.repl_state->event_index = 7;
g_cfg_sim.repl_state->session_count = 2;
g_cfg_sim.record_file = NULL;
captured = capture_stdout_around(run_info_config);
TEST_ASSERT_NOT_NULL(strstr(captured, "speed=3"));
TEST_ASSERT_NOT_NULL(strstr(captured, "output=off"));
TEST_ASSERT_NOT_NULL(strstr(captured, "verify=on"));
TEST_ASSERT_NOT_NULL(strstr(captured, "events_processed=7"));
TEST_ASSERT_NOT_NULL(strstr(captured, "sessions=2"));
TEST_ASSERT_NOT_NULL(strstr(captured, "current_ts="));
free(captured);
/* Now with an active, known output path. */
make_tmp_dir(tmp_dir, sizeof(tmp_dir), "_infocfg");
snprintf(out_path, sizeof(out_path), "%s/active.replay", tmp_dir);
real_out = fopen(out_path, "w");
TEST_ASSERT_NOT_NULL(real_out);
g_cfg_sim.record_file = real_out;
g_cfg_sim.repl_state->output_path = strdup(out_path);
captured = capture_stdout_around(run_info_config);
TEST_ASSERT_NOT_NULL_MESSAGE(strstr(captured, out_path),
"info config must report the active "
"output path when known");
free(captured);
fclose(real_out);
free(g_cfg_sim.repl_state->output_path);
printf("test_info_config_reports_current_parameters: PASS\n");
}
/* ---------------------------------------------------------------------- */
/* Test: repl_print_help() lists the task 12.3 commands. */
/* ---------------------------------------------------------------------- */
static void run_print_help(void) { repl_print_help(); }
static void test_help_lists_snapshot_and_set_commands(void)
{
char* captured = capture_stdout_around(run_print_help);
TEST_ASSERT_NOT_NULL(strstr(captured, "snapshot"));
TEST_ASSERT_NOT_NULL(strstr(captured, "set speed"));
TEST_ASSERT_NOT_NULL(strstr(captured, "set output"));
TEST_ASSERT_NOT_NULL(strstr(captured, "set verify"));
TEST_ASSERT_NOT_NULL(strstr(captured, "info config"));
free(captured);
printf("test_help_lists_snapshot_and_set_commands: PASS\n");
}
int main(void)
{
UNITY_BEGIN();
RUN_TEST(test_snapshot_written_file_is_loadable_by_fresh_sim_start);
RUN_TEST(test_snapshot_auto_generates_filename_from_event_index);
RUN_TEST(test_set_speed_updates_shadow_and_core_atomics);
RUN_TEST(test_set_verify_toggles_flag);
RUN_TEST(test_set_output_opens_writes_preamble_and_off_closes);
RUN_TEST(test_info_config_reports_current_parameters);
RUN_TEST(test_help_lists_snapshot_and_set_commands);
return UNITY_END();
}

View file

@ -89,6 +89,7 @@
#include "../src/repl.c"
#include "../src/repl_break.c"
#include "../src/repl_info.c"
#include "../src/repl_params.c"
#include "../src/sim.c"
#include "../src/sim_loop.c"
#include "../src/sim_record.c"

View file

@ -158,6 +158,7 @@
#include "../src/repl.c"
#include "../src/repl_break.c"
#include "../src/repl_info.c"
#include "../src/repl_params.c"
#include "../src/sim.c"
#include "../src/sim_loop.c"
#include "../src/sim_record.c"

View file

@ -104,6 +104,7 @@
#include "../src/repl.c"
#include "../src/repl_break.c"
#include "../src/repl_info.c"
#include "../src/repl_params.c"
#include "../src/sim.c"
#include "../src/sim_loop.c"
#include "../src/sim_record.c"

View file

@ -5,22 +5,24 @@
* from the simulation driver's compiled object" -- plus the AC's own
* "confirmed by the struct definition itself, not runtime checks alone"
* clause. Scope: sim.h + sim.c + sim_loop.c + sim_record.c + repl.c/repl.h/
* repl_break.c/repl_info.c/repl_internal.h together (task 11.1 + task
* 11.2's sibling file + task 11.5's sibling file, the --sim-output writer +
* task 12.1's REPL files + task 12.2's own repl_break.c/repl_info.c/
* repl_internal.h, its 800-line-cap split of repl.c -- see repl_internal.h's
* own "Why a split at all" section) -- NOT a re-audit of core.c (task 4.1's
* own territory, test_core_isolation.c) and NOT plugin.c/builtin_fcfs.c
* (shared normal-mode infra, out of this task's boundary). sim_verify.c
* (task 11.4) is likewise out of scope here -- it is never compiled into
* repl_break.c/repl_info.c/repl_internal.h/repl_params.c together (task
* 11.1 + task 11.2's sibling file + task 11.5's sibling file, the
* --sim-output writer + task 12.1's REPL files + task 12.2's own
* repl_break.c/repl_info.c/repl_internal.h + task 12.3's own repl_params.c,
* each an 800-line-cap split of repl.c -- see repl_internal.h's own "Why a
* split at all" section) -- NOT a re-audit of core.c (task 4.1's own
* territory, test_core_isolation.c) and NOT plugin.c/builtin_fcfs.c (shared
* normal-mode infra, out of this task's boundary). sim_verify.c (task 11.4)
* is likewise out of scope here -- it is never compiled into
* sched_sim_isolation_lib below and carries no isolation-sensitive logic of
* its own (pure struct comparison, no I/O); extending this guard to it was
* not part of task 11.4's own text and is left as-is. repl.c/repl.h were
* added per task 12.1's own text (extending this exact 3-file precedent to
* a 5-file one); repl_break.c/repl_info.c/repl_internal.h extend it again
* (task 12.2, to an 8-file one) -- all touch xce_sched_sim_driver_t
* directly or read/write stdin/stdout, the same category of driver-level
* code this guard already covers.
* a 5-file one); repl_break.c/repl_info.c/repl_internal.h extended it again
* (task 12.2, to an 8-file one); repl_params.c extends it once more (task
* 12.3, to a 9-file one) -- all touch xce_sched_sim_driver_t directly or
* read/write stdin/stdout, the same category of driver-level code this
* guard already covers.
*
* Three layers, extending test_core_isolation.c's two-layer pattern (same
* genre: source-text scans of the real, current on-disk files, not a frozen
@ -112,9 +114,13 @@
#error \
"XCE_SIM_REPL_INTERNAL_H_PATH must be defined by meson.build to repl_internal.h's absolute path"
#endif
#ifndef XCE_SIM_REPL_PARAMS_C_PATH
#error \
"XCE_SIM_REPL_PARAMS_C_PATH must be defined by meson.build to repl_params.c's absolute path"
#endif
#ifndef XCE_SIM_LIB_PATH
#error \
"XCE_SIM_LIB_PATH must be defined by meson.build to the absolute path of sim.c+sim_loop.c+sim_record.c+repl.c+repl_break.c+repl_info.c's isolated static_library() archive"
"XCE_SIM_LIB_PATH must be defined by meson.build to the absolute path of sim.c+sim_loop.c+sim_record.c+repl.c+repl_break.c+repl_info.c+repl_params.c's isolated static_library() archive"
#endif
/* Forbidden headers (design.md "Allowed Dependencies", same list
@ -384,15 +390,16 @@ void tearDown(void) { return; }
* failure mode this whole test exists to avoid). */
static void test_sim_source_paths_are_readable(void)
{
char* h = read_whole_file(XCE_SIM_H_PATH);
char* c = read_whole_file(XCE_SIM_C_PATH);
char* loop = read_whole_file(XCE_SIM_LOOP_C_PATH);
char* record = read_whole_file(XCE_SIM_RECORD_C_PATH);
char* repl_c = read_whole_file(XCE_SIM_REPL_C_PATH);
char* repl_h = read_whole_file(XCE_SIM_REPL_H_PATH);
char* repl_break_c = read_whole_file(XCE_SIM_REPL_BREAK_C_PATH);
char* repl_info_c = read_whole_file(XCE_SIM_REPL_INFO_C_PATH);
char* repl_int_h = read_whole_file(XCE_SIM_REPL_INTERNAL_H_PATH);
char* h = read_whole_file(XCE_SIM_H_PATH);
char* c = read_whole_file(XCE_SIM_C_PATH);
char* loop = read_whole_file(XCE_SIM_LOOP_C_PATH);
char* record = read_whole_file(XCE_SIM_RECORD_C_PATH);
char* repl_c = read_whole_file(XCE_SIM_REPL_C_PATH);
char* repl_h = read_whole_file(XCE_SIM_REPL_H_PATH);
char* repl_break_c = read_whole_file(XCE_SIM_REPL_BREAK_C_PATH);
char* repl_info_c = read_whole_file(XCE_SIM_REPL_INFO_C_PATH);
char* repl_int_h = read_whole_file(XCE_SIM_REPL_INTERNAL_H_PATH);
char* repl_params_c = read_whole_file(XCE_SIM_REPL_PARAMS_C_PATH);
TEST_ASSERT_NOT_NULL_MESSAGE(h, XCE_SIM_H_PATH);
TEST_ASSERT_NOT_NULL_MESSAGE(c, XCE_SIM_C_PATH);
@ -403,6 +410,7 @@ static void test_sim_source_paths_are_readable(void)
TEST_ASSERT_NOT_NULL_MESSAGE(repl_break_c, XCE_SIM_REPL_BREAK_C_PATH);
TEST_ASSERT_NOT_NULL_MESSAGE(repl_info_c, XCE_SIM_REPL_INFO_C_PATH);
TEST_ASSERT_NOT_NULL_MESSAGE(repl_int_h, XCE_SIM_REPL_INTERNAL_H_PATH);
TEST_ASSERT_NOT_NULL_MESSAGE(repl_params_c, XCE_SIM_REPL_PARAMS_C_PATH);
free(h);
free(c);
@ -413,19 +421,21 @@ static void test_sim_source_paths_are_readable(void)
free(repl_break_c);
free(repl_info_c);
free(repl_int_h);
free(repl_params_c);
}
static void test_sim_never_includes_forbidden_headers(void)
{
char* h_raw = read_whole_file(XCE_SIM_H_PATH);
char* c_raw = read_whole_file(XCE_SIM_C_PATH);
char* loop_raw = read_whole_file(XCE_SIM_LOOP_C_PATH);
char* record_raw = read_whole_file(XCE_SIM_RECORD_C_PATH);
char* repl_c_raw = read_whole_file(XCE_SIM_REPL_C_PATH);
char* repl_h_raw = read_whole_file(XCE_SIM_REPL_H_PATH);
char* repl_break_c_raw = read_whole_file(XCE_SIM_REPL_BREAK_C_PATH);
char* repl_info_c_raw = read_whole_file(XCE_SIM_REPL_INFO_C_PATH);
char* repl_int_h_raw = read_whole_file(XCE_SIM_REPL_INTERNAL_H_PATH);
char* h_raw = read_whole_file(XCE_SIM_H_PATH);
char* c_raw = read_whole_file(XCE_SIM_C_PATH);
char* loop_raw = read_whole_file(XCE_SIM_LOOP_C_PATH);
char* record_raw = read_whole_file(XCE_SIM_RECORD_C_PATH);
char* repl_c_raw = read_whole_file(XCE_SIM_REPL_C_PATH);
char* repl_h_raw = read_whole_file(XCE_SIM_REPL_H_PATH);
char* repl_break_c_raw = read_whole_file(XCE_SIM_REPL_BREAK_C_PATH);
char* repl_info_c_raw = read_whole_file(XCE_SIM_REPL_INFO_C_PATH);
char* repl_int_h_raw = read_whole_file(XCE_SIM_REPL_INTERNAL_H_PATH);
char* repl_params_c_raw = read_whole_file(XCE_SIM_REPL_PARAMS_C_PATH);
char* h;
char* c;
char* loop;
@ -435,6 +445,7 @@ static void test_sim_never_includes_forbidden_headers(void)
char* repl_break_c;
char* repl_info_c;
char* repl_int_h;
char* repl_params_c;
TEST_ASSERT_NOT_NULL(h_raw);
TEST_ASSERT_NOT_NULL(c_raw);
@ -445,16 +456,18 @@ static void test_sim_never_includes_forbidden_headers(void)
TEST_ASSERT_NOT_NULL(repl_break_c_raw);
TEST_ASSERT_NOT_NULL(repl_info_c_raw);
TEST_ASSERT_NOT_NULL(repl_int_h_raw);
TEST_ASSERT_NOT_NULL(repl_params_c_raw);
h = strip_c_comments(h_raw);
c = strip_c_comments(c_raw);
loop = strip_c_comments(loop_raw);
record = strip_c_comments(record_raw);
repl_c = strip_c_comments(repl_c_raw);
repl_h = strip_c_comments(repl_h_raw);
repl_break_c = strip_c_comments(repl_break_c_raw);
repl_info_c = strip_c_comments(repl_info_c_raw);
repl_int_h = strip_c_comments(repl_int_h_raw);
h = strip_c_comments(h_raw);
c = strip_c_comments(c_raw);
loop = strip_c_comments(loop_raw);
record = strip_c_comments(record_raw);
repl_c = strip_c_comments(repl_c_raw);
repl_h = strip_c_comments(repl_h_raw);
repl_break_c = strip_c_comments(repl_break_c_raw);
repl_info_c = strip_c_comments(repl_info_c_raw);
repl_int_h = strip_c_comments(repl_int_h_raw);
repl_params_c = strip_c_comments(repl_params_c_raw);
TEST_ASSERT_NOT_NULL(h);
TEST_ASSERT_NOT_NULL(c);
TEST_ASSERT_NOT_NULL(loop);
@ -464,6 +477,7 @@ static void test_sim_never_includes_forbidden_headers(void)
TEST_ASSERT_NOT_NULL(repl_break_c);
TEST_ASSERT_NOT_NULL(repl_info_c);
TEST_ASSERT_NOT_NULL(repl_int_h);
TEST_ASSERT_NOT_NULL(repl_params_c);
assert_no_forbidden_includes(h, "sim.h");
assert_no_forbidden_includes(c, "sim.c");
@ -474,6 +488,7 @@ static void test_sim_never_includes_forbidden_headers(void)
assert_no_forbidden_includes(repl_break_c, "repl_break.c");
assert_no_forbidden_includes(repl_info_c, "repl_info.c");
assert_no_forbidden_includes(repl_int_h, "repl_internal.h");
assert_no_forbidden_includes(repl_params_c, "repl_params.c");
free(h_raw);
free(c_raw);
@ -484,6 +499,7 @@ static void test_sim_never_includes_forbidden_headers(void)
free(repl_break_c_raw);
free(repl_info_c_raw);
free(repl_int_h_raw);
free(repl_params_c_raw);
free(h);
free(c);
free(loop);
@ -493,19 +509,21 @@ static void test_sim_never_includes_forbidden_headers(void)
free(repl_break_c);
free(repl_info_c);
free(repl_int_h);
free(repl_params_c);
}
static void test_sim_never_calls_forbidden_symbols(void)
{
char* h_raw = read_whole_file(XCE_SIM_H_PATH);
char* c_raw = read_whole_file(XCE_SIM_C_PATH);
char* loop_raw = read_whole_file(XCE_SIM_LOOP_C_PATH);
char* record_raw = read_whole_file(XCE_SIM_RECORD_C_PATH);
char* repl_c_raw = read_whole_file(XCE_SIM_REPL_C_PATH);
char* repl_h_raw = read_whole_file(XCE_SIM_REPL_H_PATH);
char* repl_break_c_raw = read_whole_file(XCE_SIM_REPL_BREAK_C_PATH);
char* repl_info_c_raw = read_whole_file(XCE_SIM_REPL_INFO_C_PATH);
char* repl_int_h_raw = read_whole_file(XCE_SIM_REPL_INTERNAL_H_PATH);
char* h_raw = read_whole_file(XCE_SIM_H_PATH);
char* c_raw = read_whole_file(XCE_SIM_C_PATH);
char* loop_raw = read_whole_file(XCE_SIM_LOOP_C_PATH);
char* record_raw = read_whole_file(XCE_SIM_RECORD_C_PATH);
char* repl_c_raw = read_whole_file(XCE_SIM_REPL_C_PATH);
char* repl_h_raw = read_whole_file(XCE_SIM_REPL_H_PATH);
char* repl_break_c_raw = read_whole_file(XCE_SIM_REPL_BREAK_C_PATH);
char* repl_info_c_raw = read_whole_file(XCE_SIM_REPL_INFO_C_PATH);
char* repl_int_h_raw = read_whole_file(XCE_SIM_REPL_INTERNAL_H_PATH);
char* repl_params_c_raw = read_whole_file(XCE_SIM_REPL_PARAMS_C_PATH);
char* h;
char* c;
char* loop;
@ -515,6 +533,7 @@ static void test_sim_never_calls_forbidden_symbols(void)
char* repl_break_c;
char* repl_info_c;
char* repl_int_h;
char* repl_params_c;
TEST_ASSERT_NOT_NULL(h_raw);
TEST_ASSERT_NOT_NULL(c_raw);
@ -525,16 +544,18 @@ static void test_sim_never_calls_forbidden_symbols(void)
TEST_ASSERT_NOT_NULL(repl_break_c_raw);
TEST_ASSERT_NOT_NULL(repl_info_c_raw);
TEST_ASSERT_NOT_NULL(repl_int_h_raw);
TEST_ASSERT_NOT_NULL(repl_params_c_raw);
h = strip_c_comments(h_raw);
c = strip_c_comments(c_raw);
loop = strip_c_comments(loop_raw);
record = strip_c_comments(record_raw);
repl_c = strip_c_comments(repl_c_raw);
repl_h = strip_c_comments(repl_h_raw);
repl_break_c = strip_c_comments(repl_break_c_raw);
repl_info_c = strip_c_comments(repl_info_c_raw);
repl_int_h = strip_c_comments(repl_int_h_raw);
h = strip_c_comments(h_raw);
c = strip_c_comments(c_raw);
loop = strip_c_comments(loop_raw);
record = strip_c_comments(record_raw);
repl_c = strip_c_comments(repl_c_raw);
repl_h = strip_c_comments(repl_h_raw);
repl_break_c = strip_c_comments(repl_break_c_raw);
repl_info_c = strip_c_comments(repl_info_c_raw);
repl_int_h = strip_c_comments(repl_int_h_raw);
repl_params_c = strip_c_comments(repl_params_c_raw);
TEST_ASSERT_NOT_NULL(h);
TEST_ASSERT_NOT_NULL(c);
TEST_ASSERT_NOT_NULL(loop);
@ -544,6 +565,7 @@ static void test_sim_never_calls_forbidden_symbols(void)
TEST_ASSERT_NOT_NULL(repl_break_c);
TEST_ASSERT_NOT_NULL(repl_info_c);
TEST_ASSERT_NOT_NULL(repl_int_h);
TEST_ASSERT_NOT_NULL(repl_params_c);
assert_no_forbidden_symbols(h, "sim.h");
assert_no_forbidden_symbols(c, "sim.c");
@ -554,6 +576,7 @@ static void test_sim_never_calls_forbidden_symbols(void)
assert_no_forbidden_symbols(repl_break_c, "repl_break.c");
assert_no_forbidden_symbols(repl_info_c, "repl_info.c");
assert_no_forbidden_symbols(repl_int_h, "repl_internal.h");
assert_no_forbidden_symbols(repl_params_c, "repl_params.c");
free(h_raw);
free(c_raw);
@ -564,6 +587,7 @@ static void test_sim_never_calls_forbidden_symbols(void)
free(repl_break_c_raw);
free(repl_info_c_raw);
free(repl_int_h_raw);
free(repl_params_c_raw);
free(h);
free(c);
free(loop);
@ -573,6 +597,7 @@ static void test_sim_never_calls_forbidden_symbols(void)
free(repl_break_c);
free(repl_info_c);
free(repl_int_h);
free(repl_params_c);
}
/*
@ -617,11 +642,12 @@ static void test_sim_driver_struct_has_no_forbidden_fields(void)
/*
* test_sim_object_has_no_forbidden_undefined_symbols - the literal
* build-time/link-time proof: sim.c + sim_loop.c + sim_record.c + repl.c +
* repl_break.c + repl_info.c, compiled together in isolation into
* sched_sim_isolation_lib (meson.build), must not reference (as an
* undefined external symbol in the compiled archive) anything matching the
* forbidden prefixes above. Independent of what any header transitively
* declares -- reflects only what this driver's compiled code actually
* repl_break.c + repl_info.c + repl_params.c, compiled together in
* isolation into sched_sim_isolation_lib (meson.build), must not reference
* (as an undefined external symbol in the compiled archive) anything
* matching the forbidden prefixes above. Independent of what any header
* transitively declares -- reflects only what this driver's compiled code
* actually
* calls. Same technique and same any_undefined_seen vacuous-pass guard as
* test_core_isolation.c's test_core_object_has_no_forbidden_undefined_symbols().
*/
@ -646,9 +672,9 @@ static void test_sim_object_has_no_forbidden_undefined_symbols(void)
/* posix format for an undefined symbol: "<name> U" (no
* value/size columns). Skip anything that doesn't parse as
* exactly that -- e.g. a blank line, or an archive member header
* some nm versions print (this archive has six member objects,
* some nm versions print (this archive has seven member objects,
* sim.c.o, sim_loop.c.o, sim_record.c.o, repl.c.o, repl_break.c.o,
* and repl_info.c.o). */
* repl_info.c.o, and repl_params.c.o). */
if (sscanf(line, "%511s %c", symbol, &type) != 2) {
continue;
}

View file

@ -76,6 +76,7 @@
#include "../src/repl.c"
#include "../src/repl_break.c"
#include "../src/repl_info.c"
#include "../src/repl_params.c"
#include "../src/sim.c"
#include "../src/sim_loop.c"
#include "../src/sim_record.c"

View file

@ -96,6 +96,7 @@
#include "../src/repl.c"
#include "../src/repl_break.c"
#include "../src/repl_info.c"
#include "../src/repl_params.c"
#include "../src/sim.c"
#include "../src/sim_loop.c"
#include "../src/sim_record.c"