CtxBuilder

Struct CtxBuilder 

Source
pub struct CtxBuilder<'a> { /* private fields */ }
Expand description

Fluent builder for Ctx.

Scenario unit tests reach for a Ctx with sane defaults so they can exercise scenario logic without booting a VM. The direct struct-literal construction at ~14 call sites forces every test to repeat the full 12-field init and keeps diverging defaults in sync by hand; this builder centralises those defaults and keeps required fields (borrowed cgroups/topo) in their types.

Defaults:

  • duration: 1 s — matches the scenario::basic test helper (scenario::stress uses 2 s and sets it explicitly)
  • workers_per_cgroup: 1
  • sched_pid: Nonerun_scenario short-circuits the liveness checks when sched_pid.is_none().
  • settle: 0 ms — tests do not need to wait for scheduler stabilisation
  • work_type_override: None
  • assert: crate::assert::Assert::default_checks() — the same policy production paths merge through
  • wait_for_map_write: false

Override any default via the corresponding method, then materialise the context with CtxBuilder::build.

§Example

let cgroups = CgroupManager::new("/nonexistent");
let topo = TestTopology::synthetic(4, 1);
let ctx = Ctx::builder(&cgroups, &topo)
    .workers_per_cgroup(3)
    .duration(Duration::from_secs(2))
    .build();

Implementations§

Source§

impl<'a> CtxBuilder<'a>

Source

pub fn duration(self, d: Duration) -> Self

Wall-clock budget for the workload phase of the scenario.

Source

pub fn workers_per_cgroup(self, n: usize) -> Self

Number of worker threads started per cgroup by the default workload.

Source

pub fn sched_pid(self, pid: Option<pid_t>) -> Self

PID of the scheduler process; None disables the liveness checks in run_scenario.

Source

pub fn settle(self, s: Duration) -> Self

Time to wait after cgroup creation for scheduler stabilisation.

Source

pub fn work_type_override(self, wt: Option<WorkType>) -> Self

Override the default work type for scenarios that would otherwise use SpinWait.

Source

pub fn assert(self, a: Assert) -> Self

Merged assertion config. Callers that want the production layering should pass Assert::default_checks().merge(&...); tests that pin a specific policy can pass crate::assert::Assert::NO_OVERRIDES directly.

Source

pub fn wait_for_map_write(self, v: bool) -> Self

When true, execute_steps blocks on the bpf_map_write_done latch (set on the host’s SIGNAL_BPF_WRITE_DONE over virtio-console RX) after writing the scenario start marker. See the field doc on Ctx::wait_for_map_write.

Source

pub fn current_step(self, cs: Arc<AtomicU16>) -> Self

Inject a caller-owned per-VM step-index publisher. The default Ctx::builder already constructs a fresh Arc<AtomicU16> initialised to 0, so most callers do not need this setter; it exists so the host-side VM runner can hand the same Arc to both the scenario driver Ctx and the freeze-coordinator thread, giving both halves a single per-VM source of truth for the current phase.

Source

pub fn entry_name(self, name: &'static str) -> Self

Drift-safe path derivation. Stamp the &'static str name of the KtstrTestEntry the dispatched test body was registered as. Drives the body-side path-derivation methods on Ctx (failure_dump_path, wprof_pb_path, repro_wprof_pb_path) so test authors get the drift-safe per-test sidecar path without re-hardcoding the test fn name in the body — a future test rename surfaces a deterministic Result<PathBuf> bail rather than a runtime ENOENT against a stale literal.

The framework’s macro-stamped dispatch path (maybe_dispatch_vm_test_with_args + the host-only dispatcher) calls this with the entry name at Ctx construction time, before the test body runs. Ad-hoc scenario unit tests that build Ctx without the dispatch path skip this setter, and the path-derivation methods bail with an actionable diagnostic — see Ctx::failure_dump_path for the None-case bail shape.

Source

pub fn variant_hash(self, hash: u64) -> Self

Stamp the run’s variant hash (see variant_hash_from_parts) so the body-side failure_dump_path / wprof_pb_path derivations embed it as the -{16-hex} filename suffix. Set at the macro dispatch site alongside Self::entry_name; ad-hoc fixtures leave it 0.

Source

pub fn build(self) -> Ctx<'a>

Materialise the configured Ctx.

Auto Trait Implementations§

§

impl<'a> Freeze for CtxBuilder<'a>

§

impl<'a> !RefUnwindSafe for CtxBuilder<'a>

§

impl<'a> !Send for CtxBuilder<'a>

§

impl<'a> !Sync for CtxBuilder<'a>

§

impl<'a> Unpin for CtxBuilder<'a>

§

impl<'a> !UnwindSafe for CtxBuilder<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more