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:
parent
2fecea3592
commit
2329dbf2a8
18 changed files with 2755 additions and 110 deletions
|
|
@ -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'])
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
845
src/scheduler/testsuite/test_repl_snapshot_params.c
Normal file
845
src/scheduler/testsuite/test_repl_snapshot_params.c
Normal 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();
|
||||
}
|
||||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue