PayloadRun

Struct PayloadRun 

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

Builder returned by Ctx::payload.

Configure the run via chainable methods, then invoke .run() (foreground, blocking) or .spawn() (background) to execute the payload’s binary inside the guest VM and receive the extracted crate::test_support::PayloadMetrics plus an AssertResult for any declared MetricChecks.

Implementations§

Source§

impl<'a> PayloadRun<'a>

Source

pub fn arg(self, arg: impl Into<String>) -> Self

Append one CLI argument to the effective argv.

Source

pub fn args<I, S>(self, args: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Append multiple CLI arguments to the effective argv.

Source

pub fn clear_args(self) -> Self

Wipe ALL args (both payload.default_args and any prior .arg() calls). Subsequent .arg() calls start from empty.

Source

pub fn check(self, c: MetricCheck) -> Self

Append a MetricCheck to the effective check list.

Source

pub fn clear_checks(self) -> Self

Wipe ALL checks (both payload.default_checks and any prior .check() calls).

Source

pub fn in_cgroup(self, name: impl Into<Cow<'static, str>>) -> Self

Place the spawned child in the named cgroup (a plain name, resolved relative to ctx.cgroups.parent_path()). When omitted, the child inherits the spawning process’s cgroup.

Accepts &'static str (zero-alloc, the common case of a const cgroup name) or any owned string type via Cow’s From impls.

The name is validated at .run()/.spawn() — leading / is stripped, .. and NUL bytes are rejected.

Source

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

Bound .run()’s wait for the payload to exit. None (the default when .timeout is not called) waits indefinitely — suitable for payloads whose runtime is bounded internally (schbench -r 10, fio --runtime, …). Some(duration) arms a deadline watchdog inside .run() that SIGKILLs the payload’s whole process group if it has not exited by the deadline. Ignored by .spawn() — background handles manage their own timing.

The builder shape keeps .run() zero-arg so non-timeout call sites read naturally, and leaves room for future knobs (per-test environment, stdin, …) without another signature break.

Source

pub fn run(self) -> Result<(AssertResult, PayloadMetrics)>

Blocking foreground run. Spawns the payload binary, waits for it to exit, extracts metrics from its output per the payload’s OutputFormat (stdout-primary with stderr fallback for Json; no extraction for ExitCode), and evaluates declared MetricChecks into an AssertResult. See the module-level # Stdout-primary, stderr-fallback metric extraction section for the full contract.

Runtime is bounded by the value set via timeout. When the deadline expires, kill_payload_process_group fires and the returned (AssertResult, PayloadMetrics) reflects the captured output plus the killed-child exit code; status.code() returns None for a SIGKILL’d child, which spawn_and_wait surfaces as exit_code = -1 in SpawnOutput. The timeout case is not an error — the caller can still inspect metrics collected before the kill. A post-kill drain failure is reported as Err (wraps the original I/O error with “drain after timeout of N”); the caller loses no output that was already captured because the partial reader-thread buffers have been consumed in the error path too.

Metrics are also recorded to the per-test sidecar via the SHM ring; the returned tuple is a convenience view of the same values.

Returns Err when the payload is not PayloadKind::Binary (schedulers are framework-launched, not test-body-launched), when the cgroup name fails validation, when the spawn itself fails, or when post-kill drain fails (see the timeout paragraph).

Source

pub fn spawn(self) -> Result<PayloadHandle>

Spawn the payload binary in the background and return a PayloadHandle the caller can .wait(), .kill(), or .try_wait() on.

The child runs in the guest’s process namespace (all ktstr tests execute inside the VM); PayloadHandle is a thin wrapper over std::process::Child. No cross-VM proxy.

Dropping the handle without first calling one of the waiters emits a stderr warning and SIGKILLs the child — leaked handles would lose metrics and potentially outlive the test.

Returns Err when the payload is not PayloadKind::Binary or when the spawn itself fails.

Trait Implementations§

Source§

impl Debug for PayloadRun<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for PayloadRun<'a>

§

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

§

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

§

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

§

impl<'a> Unpin for PayloadRun<'a>

§

impl<'a> !UnwindSafe for PayloadRun<'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