Steering programs
By default the scheduler of the machine’s kernel decides which thread runs when. A bug that needs one thread to run past another will not show up if the scheduler never picks that order, so Machine lets you pick it.
Every command on this page is recorded in the run, so a replay repeats it exactly.
Looking at tasks
1 | machine tasks app |
That lists the tasks in the machine, one row per task by its tid, with the
tgid each one belongs to. You will want a tid, or a program’s path, in the
commands below. machine syscalls app and machine ints app list the kernel’s
system calls and interrupt vectors.
Focus
machine focus tells Machine which programs
to watch and steer. It matches a program by its absolute path in the machine:
1 | machine focus app add /app |
Focus also takes a cgroup (cgroup=/path), a single process (tgid=12), or
the processes with a task of a given name (comm=cat). A name picks out one
tool of a multi-call binary such as busybox, or a script, which a path cannot.
machine tasks app exist comm=cat lists the tasks with
that name; focus takes every thread of their processes.
A program that renames itself after it starts, with prctl(PR_SET_NAME) or
/proc/self/comm, is focused by its new name at its next fork, exec or exit,
not at the rename, and until then --until comm=worker:on keeps waiting. To
steer such a program from the start, focus it by its path.
1 | machine focus app add comm=cat |
focus remove stops steering one program, named as it was added, and
focus clear stops steering them all.
Whatever you focus by, the conditions below and a plan’s when name it the
same way: /app:exit, cgroup=/path:on, comm=cat:kernel.
Once a program is focused you can wait for things that happen to it. The task
conditions take the form program:what, where what is one of:
| What | Means |
|---|---|
exec |
the program started |
exit |
the program exited |
sched |
one of its threads was given a CPU |
desched |
one of its threads gave its CPU up |
on |
a thread is running its own code |
kernel |
a thread is running in the kernel |
off |
the thread is not on a CPU at all |
A run can also stop where a thread reaches a location, or after it writes or touches bytes. These conditions need no focus, because they name a tid or a tgid:
1 | machine run app --until 'tid=56:at=parse' # until tid 56 reaches parse |
Each condition takes one of the run’s 3 hardware breakpoints and watchpoints,
for that machine run alone. Debugging says what they take and
what the run says when it stops.
Holding threads
1 | machine tasks app hold 56 # take tid 56 off the run queue |
Each of these takes effect at the next scheduling decision. If you hold the
last task that could run, the machine has nothing to run. Release it, then
force a decision with machine irq app preempt --vcpu all.
There is also pin, which places a thread on the vCPUs you choose the next
time it wakes:
1 | machine tasks app pin 56 2 # on vCPU 2 |
A set is one vCPU or a range, both ends included. A pin decides where the
thread goes when it wakes, so a thread already queued on another vCPU stays
there until then. none keeps a thread from running at all, until you pin it
somewhere again.
tasks has two more lists. machine tasks app exits lists the
tasks that have left and how each one ended, and machine tasks app cgroups
groups them by cgroup. machine tasks app --focused shows only the tasks you
are steering.
From Python, the same verbs are run.tasks.hold(56), run.tasks.release(56),
run.tasks.yield_(56), run.tasks.slice(56, "10us") and
run.tasks.pin(56, "2"). run.tasks.exits() and run.tasks.cgroups() read
the other two lists.
Plans
When one rule isn’t enough, write a plan file. A plan is a list of clauses, and each one says when it applies and what to do.
1 | when /test:on mode step,fast fast=1:100k step=1:200 |
Machine tries the clauses in order and the last match wins, so a later
clause overrides an earlier one. else covers whatever nothing matched.
Each when names a state of a program (/test:on is the program running its
own code, and /test:kernel is the program running in the kernel). After the
condition come the choices the clause makes for each dispatch it covers, such
as the mode, how many conditional branches to run, or what to do with the
scheduler. machine plan
--help lists all of them.
1 | machine plan app plan.txt |
A clause draws any of these, once per dispatch, and irq-delay once per
interrupt:
| Axis | Draws |
|---|---|
mode |
how the machine runs: fast, step, step-into, free, fence or keep, with the length of a stretch as fast=1:100k |
task-sched |
what the task on the vCPU does: keep, hold, yield, drain, drain-all |
task-int |
whether to preempt that task: none or preempt |
task-slice |
how long that task runs between decisions: keep,default,10us:600us |
task-pin |
where a task goes when it next wakes: a vCPU set, free or none |
vtime-rate |
how fast the machine’s clock passes, as in Clock rate |
vtime-add |
time added to the clock before the dispatch, such as 10us:2ms |
timer-slack |
how late a timer may be, such as 0:20ms |
irq-delay |
how long each interrupt is held, as in Holding interrupts |
Every axis is a comma list of choices, and [N] makes a
choice N times as likely: mode step[3],fast[1] draws step three times as
often as fast. keep draws nothing and leaves the axis as it was, so a clause
can leave an axis alone part of the time. A range such as 1:200 draws one
value from it, and the plan’s --seed makes every draw repeatable.
A when names what a task is doing: /path:on for a program running its own
code, /path:kernel in the kernel, /path:syscall=openat in one system call. The
subject can also be tid=N, tgid=N, comm=NAME or cgroup=PATH, and
vcpu=1 narrows it to one vCPU. Braces may group a clause, # starts a
comment, and a file named - is read from standard input.
1 | # Find the race: interrupt the writer, and move it between vCPUs. |
The plan applies only to that machine plan. A later machine run does not
use it.
From Python, run.plan("plan.txt", seed=3) runs a plan from a file, and the
RunResult it returns lists each clause with the iterations it applied to. The
plan_file.py example shows one.
Interrupts
Inject an interrupt by name or number.
1 | machine irq app preempt --vcpu 1 |
The interrupt is queued, then delivered at the next boundary and recorded there, so a replay delivers it at the same place.
--nmi delivers a non-maskable interrupt instead, which reaches a vCPU even
while it has interrupts turned off, so you can test how a program or
the kernel handles one:
1 | machine irq app --nmi --vcpu 0 |
Holding interrupts
machine run can hold each interrupt a drawn time
before it is delivered, at most one second:
1 | machine run app --irq-delay 0:2ms |
A bare span holds every interrupt. Name a target to hold one kind: timer,
ipi, init, blk, rng, console, serial, keyboard, device or
all. The most specific target wins. An interrupt is never delivered before
one held earlier on its line, its MSI vector, or its vCPU’s timer, IPI
vector, or INIT and SIPI.
machine irqs lists every interrupt the machine
owes or holds, then the vectors machine irq
injects. An owed interrupt was raised by a device or a timer and is injected
at the next dispatch. A held one waits for the time the draw gave it. The
state hash irq_pending covers the held interrupts, and
machine state shows how many are held.
1 | machine irqs app |
The run log keeps each hold, and a checkpoint keeps what is held. At the
control prompt the same option is
irq-delay on /run. From Python it is run.run(irq_delay="0:2ms"), and
run.irq.pending() lists them.
Machine time
Machine time is not the host’s. machine vtime app rate
changes how fast it passes, and machine vtime app add pushes it forward
without running anything.
1 | machine vtime app add 5s |
Neither command moves the clock back, because the machine’s clock only goes
forward. To return to an earlier time, branch there with machine go app 1.5s.
Starting date
Every machine’s clock starts at 2026-03-01 00:00 UTC, whatever the date is on your computer, so a program that reads the date reads the same one in every run. To test code that depends on the date, such as a certificate that expires or a job that runs at the end of a month, give the start as a Unix timestamp when you create the run:
1 | machine create app --disk app --vtime-base 1893456000 # 2030-01-01 00:00 UTC |
The run keeps its starting date, and every branch of it has the same one.
Clock rate
The machine’s clock moves with the work its vCPUs do: 10 nanoseconds for
each conditional branch a vCPU retires, unless the run was created with
--vtime-rate. A higher rate makes the same work take more machine time,
which brings timeouts closer, and a lower one makes it take less. The rate
is a number or a fraction:
1 | machine vtime app rate 20 # the same work takes twice as long |
The change is recorded, so a replay changes the rate at the same point. Idle time is a separate matter: Time compression skips it whatever the rate.
From Python, client.create("app", disk="app", vtime_base=1893456000) sets
the starting date, run.vtime.rate("20") the rate, and run.vtime.add("5s")
pushes the clock forward.
The Machine SDK
A program in the machine can also take part in its own test. The Machine SDK is the interface a program calls from inside the machine for three things: a random value or a choice when the program makes a decision, an event when it checks an assertion or finishes its setup, and coverage of the code it reaches. The run records the answers, so a replay gives the program the same values.
The Machine SDK is compatible with the Antithesis SDK. A program built with an
Antithesis SDK, in Go, Rust, Python, C++, Java or another language, runs in
the machine unchanged, and the Machine SDK serves its calls. A Go program needs
cgo for that. Built without cgo, the Antithesis SDK answers its decisions
itself and writes its events to sdk.jsonl, which machine events reads too.
Three commands read what the Machine SDK records:
| Command | Shows |
|---|---|
machine decisions |
the program’s decisions, the seed of their default answers, and the rules that answer them with values you choose |
machine events |
the events the program reported: assertions that passed or failed, its setup, and events of its own |
machine coverage |
the modules of an instrumented program and the code edges it reached |
A decision no rule answers takes the next value of a default stream, seeded
by machine create --rng-seed. To see what the program does with another
answer, fork the run before the decision and add a rule on the branch with
machine decisions add.
Fault injection makes things fail: system calls, the kernel and the disk, a service’s container, and the date the machine and its containers read.