use anyhow::Result;
use ktstr::assert::AssertResult;
use ktstr::ktstr_test;
use ktstr::prelude::VmResult;
use ktstr::scenario::Ctx;
use ktstr::scenario::ops::{CgroupDef, HoldSpec, Step, execute_steps};
use ktstr::test_support::{Payload, Scheduler, SchedulerSpec};
const KTSTR_SCHED: Scheduler =
Scheduler::new("ktstr_sched").binary(SchedulerSpec::Discover("scx-ktstr"));
const KTSTR_SCHED_PAYLOAD: Payload = Payload::from_scheduler(&KTSTR_SCHED);
fn assert_workers_ran_clean(result: &VmResult) -> Result<()> {
anyhow::ensure!(
!result.timed_out,
"guest timed out under the watchdog — the worker spawn or \
hold never completed"
);
anyhow::ensure!(
result.crash_message.is_none(),
"guest panicked during the run — `crash_message` = {:?}; \
a panic in the worker spawn path would surface here",
result.crash_message,
);
anyhow::ensure!(
result.exit_code == 0,
"guest exit_code = {} (expected 0) — non-zero typically \
means the in-guest scenario bailed before completing the \
hold (e.g. `apply_setup` rejected the merged WorkSpec)",
result.exit_code,
);
anyhow::ensure!(
result.success,
"VM run reported success = false (timed_out = {}, exit_code = \
{}, crash_message = {:?}); the merged comm/nice defaults \
did not produce a clean worker dispatch",
result.timed_out,
result.exit_code,
result.crash_message,
);
Ok(())
}
#[ktstr_test(
scheduler = KTSTR_SCHED_PAYLOAD,
duration_s = 3,
watchdog_timeout_s = 15,
workers_per_cgroup = 2,
auto_repro = false,
post_vm = assert_workers_ran_clean,
)]
fn worker_properties_e2e(ctx: &Ctx) -> Result<AssertResult> {
let _ = ctx;
let steps = vec![Step {
setup: vec![
CgroupDef::named("cg_props")
.comm("test_comm")
.nice(5)
.workers(2),
]
.into(),
ops: vec![],
hold: HoldSpec::FULL,
}];
execute_steps(ctx, steps)
}