Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Scenarios

Scenarios define the scheduling conditions a test creates. Each scenario sets up cgroups, workers, and cpusets to produce a specific condition, then verifies the scheduler handles it correctly.

Canned scenarios (scenarios::*)

ktstr::scenario::scenarios provides curated scenario functions that can be called directly from #[ktstr_test]:

use ktstr::prelude::*;

#[ktstr_test(llcs = 1, cores = 2, threads = 1)]
fn my_test(ctx: &Ctx) -> Result<AssertResult> {
    scenarios::steady(ctx)
}
FunctionCondition testedSetup
steadyBaseline fairness2 cgroups, no cpusets, equal CPU-spin load
steady_llcLLC-boundary scheduling2 cgroups with LLC-aligned cpusets
oversubscribedDispatch under oversubscription2 cgroups, 32 mixed workers each
cpuset_applyCpuset assignment on running tasksDisjoint cpusets applied mid-run
cpuset_clearCpuset removal on confined tasksCpusets cleared mid-run
cpuset_resizeCpuset resizing adaptationCpusets shrink then grow
cgroup_addNew cgroup appearanceCgroups added mid-run
cgroup_removeCgroup removal while others runCgroups removed mid-run
affinity_changeAffinity mask changesWorker affinities randomized mid-run
affinity_pinnedNarrow-affinity contentionWorkers pinned to 2-CPU subset
host_contentionFairness between cgroup and host tasksHost workers vs cgroup workers
mixed_workloadsMixed workload fairnessHeavy + bursty + IO cgroups
nested_steadyNested cgroup hierarchyWorkers in nested sub-cgroups
nested_task_moveCross-level task migrationTasks moved between nested cgroups

Additional custom_* functions are available in ktstr::scenario::{affinity, basic, cpuset, dynamic, interaction, nested, performance, stress}. See the API docs for the full list.

Most tests use these canned functions or build custom scenarios with CgroupDef and execute_defs / execute_steps (see Ops and Steps). Custom scenarios receive a Ctx reference and use the same building blocks; see Custom Scenarios for the Ctx struct and helper functions.