Did you know that Bombadil tries to reach for the star? Given the mysterious fellow he is, one would expect so. A voidstar, to be exact, and whether he reaches it depends on where he runs. When Bombadil starts, it tries to load a library, /usr/lib/libvoidstar.so. If the library is not there, Bombadil runs as it would locally on your laptop and makes every decision itself. If it is there, Bombadil draws its random values from the library, and tells it the moments when the program it tests reaches a new state and the results of the properties it checks. When it finds the library, Bombadil says so on its standard error with one line: libvoidstar dlopen successful! In Why Run Bombadil in a Deterministic Hypervisor?, it never printed that line. In this post, we look at what Bombadil does with the library, and how we got it to exclaim that line inside TestFlows Machine.
If you want to jump into the code before reading, see the complete example in our public repository under examples/compose/bombadil-antithesis. Now, let’s see what Bombadil has in store for us.
How Bombadil knows where it is
Bombadil is an open-source project with core development supported by Antithesis, and libvoidstar.so is how programs talk to the Antithesis platform and its fuzzer. Inside Antithesis, that path holds the real library. Everywhere else, it usually holds nothing.
Bombadil looks for two things. The first is the environment variable ANTITHESIS_OUTPUT_DIR. Its whole check fits in one line of antithesis.rs:
1 | static IS_IN_GUEST: LazyLock<bool> = |
The second is the library /usr/lib/libvoidstar.so. Bombadil opens it from a small C shim, libvoidstar_shim.c, which runs from .init_array before main is executed:
1 | libvoidstar_handle = dlopen("/usr/lib/libvoidstar.so", RTLD_NOW); |
The debug_out above prints to standard error only when ANTITHESIS_OUTPUT_DIR is set, so on your laptop Bombadil stays quiet whether or not it found the library.
To make it print that line, both have to be there: the variable, and a library at that exact path that exports all three symbols.
However, the shim is not the only one opening the library. Bombadil is also built with the Antithesis Rust SDK, version 0.2.9, and one of the first things its main does is call antithesis_init(). The SDK opens /usr/lib/libvoidstar.so on its own and looks for fuzz_json_data, fuzz_get_random and fuzz_flush. If it can’t load them, it falls back to writing its messages to the file ANTITHESIS_SDK_LOCAL_OUTPUT names, or to nothing.
So the same library is opened twice in one process, for two different sets of calls.
The interface to the fuzzer
So what does Bombadil do with the library once it has it? Reading the source, there are four things, and each one goes through a call into libvoidstar.so:
| What Bombadil does | Call into libvoidstar | Through |
|---|---|---|
| Draws every random value | fuzz_get_random |
the SDK's AntithesisRng |
Reports each property as an Always assertion |
fuzz_json_data, then fuzz_flush |
the SDK's assert_raw |
| Marks a state boundary at every change of the screen or page | fuzz_getchar, its result discarded |
the shim |
| Reports new coverage of the web application under test | init_coverage_module, notify_coverage |
the shim |
Random values
The random values are the obvious part. In a terminal test, AntithesisRng picks the next action from the specification’s action tree, and then the action’s own values: the text to type, the rows and columns of a resize, the row and column of a click. Every one of them is a call to fuzz_get_random. The Antithesis documentation explains that the SDK’s randomness lets the platform learn the input space, which is why you should never seed your own generator from it. And Bombadil doesn’t.
Properties
The properties are reported at every step. After each new state, Bombadil evaluates its properties and calls assert_raw for each one, as an Always assertion that must be hit. A property that holds, or is not decided yet, is reported with its condition true. A violated one is reported with its condition false and the violation in its details. The SDK passes on only the first of each: a property’s first pass and its first violation reach the library, and the rest are counted and dropped.
The checks stay Bombadil’s own: Bombadil decides whether a property holds before it makes the call, and the assertion only reports that result. Bombadil reports its violations and exits with its own code, as it does locally.
State boundary
The state boundary is the interesting part. This is the comment above the call in runner.rs:
1 | if antithesis::is_in_guest() { |
And mark_state_boundary is just this:
1 | pub fn mark_state_boundary() { |
A call that reads a character, whose character nobody reads. Its only purpose is to tell the fuzzer: here is a good place to fork. Every new screen nano draws is a point from which the fuzzer may try other random values.
Coverage
Coverage is reported only by the browser driver, for the JavaScript of the page under test, and only for edges that are new to Bombadil’s own map. The terminal examples report no coverage.
One thing we noticed while reading the shim: init_coverage_module returns the offset of the module in the coverage map. Bombadil’s Rust code declares it as returning a usize. The browser driver keeps it as coverage_map_offset and adds it to every edge it reports. But the shim’s typedef for the real function and its own wrapper both return void:
1 | typedef void (*init_coverage_module_fn)(size_t edge_count, |
So, by the C source, the offset Rust reads is whatever is left in the return register. In the binary we ran, the compiler turned that call into a tail jump, so with the library loaded, Rust reads exactly the value the library returned. Without the library, the wrapper returns without setting the register, and the offset is whatever was left there. Only the browser driver uses the offset, so the terminal examples never meet it.
Everything else
Everything else stays the same. Even inside Antithesis, Bombadil picks actions with the same weights and writes the same trace as it does locally. Earlier versions did not: they ignored the action weights and wrote no trace inside Antithesis, until #402 removed both differences. The one thing it does refuse is its own fuzz mode, with bombadil fuzzing mode is not available in antithesis; use `test` or `test-external`. That makes sense. When the platform does the fuzzing, Bombadil’s own fuzzer would only get in the way.
The public stub is not enough
Antithesis publishes a stub of the libvoidstar library, antithesis_stub, MIT-licensed. Outside Antithesis, the stub answers fuzz_get_random from getrandom, and every output and coverage call does nothing. It is what an SDK is meant to find outside Antithesis.
But look at the list of symbols the shim requires. The stub’s libvoidstar.c exports init_coverage_module and notify_coverage, but not fuzz_getchar. So if you copy the stub to /usr/lib/libvoidstar.so and set ANTITHESIS_OUTPUT_DIR, Bombadil ends up only halfway to his desired star. The SDK finds its three calls and uses the stub for random values and assertions. But the shim finds two of its three calls and gives up with the libvoidstar missing expected symbols; coverage calls will no-op message.
It never exclaims, because the stub has no
fuzz_getchar.
Serving libvoidstar.so to every container
Now let’s see how we can make Bombadil use the library inside a machine where a program runs in a container, from an image someone else built. We did not want anyone to change their images, their Compose file or their programs. So the library is not in the disk the user builds. The machine itself can provide it.
Every program in a machine that opens /usr/lib/libvoidstar.so gets Machine’s library, in every container, whatever the image has at that path. Even an image that carries the stub there gets Machine’s copy. The library is read-only, so no program in the machine can change it. And because the library is part of the machine, a replay loads exactly the same one as the recording did.
Machine’s library exports every function of the stub, plus fuzz_getchar, and it loads into programs built against glibc and musl alike.
With all that in place, the variable is the easy part. machine disks build sets ANTITHESIS_OUTPUT_DIR in each service that does not set it itself, to the machine’s drop directory, /.machine/output/drop, the same directory as MACHINE_DROP_OUTPUT_DIR.
A Bombadil that can load a library
Here is a detail that cost us a little time. Bombadil’s release download, bombadil-x86_64-linux, the one we used in the previous post, is a statically linked binary, built against musl. In a statically linked musl program, dlopen fails at once with “Dynamic loading not supported”, without opening any file. So that Bombadil never finds the library, in a machine, in Antithesis, or anywhere else. It runs as it would on a laptop.
The dynamically linked build is the one inside Antithesis’s own antithesishq/bombadil image. We could have built a dynamically linked Bombadil ourselves from source. Instead, we chose to take the binary out of that image, so that what we run in the machine is the same unmodified binary that runs inside Antithesis. The image carries Chromium and is about 4 GB. Our example image takes from it only the bombadil binary and the three Nix store directories the binary links, glibc, gcc’s runtime libraries and libgcc, and adds nano. The result is 211 MB instead of 4 GB. The Dockerfile pins Antithesis’s image by digest and checks the nano specification by its SHA-256.
Running it
Our example runs Bombadil’s nano example for 30 seconds. A small script, run.sh, prints what Bombadil found: the value of ANTITHESIS_OUTPUT_DIR in Bombadil’s environment, read from /proc/<pid>/environ, and the library Bombadil mapped, read from /proc/<pid>/maps.
Here are the commands to build the Compose environment, create a session, build the disk, start the machine and run it until nano exits:
1 | $ docker compose build |
Once executed, you can examine the output from the console:
1 | $ machine output bombadil-exclaim-dev --source console | grep 'app |' |
And there it is, on the very first line! That line is Bombadil’s own, printed by the shim when bombadil --version starts. The next lines are the example’s: the variable Bombadil reads, and the library it mapped. The run took 34.4 seconds of machine time and had 290,237 entries. The complete console of the run, with the entries that printed each line, is bombadil-antithesis.log in the example.
nano exited 1 is the nano example’s result. It does report violations of hasStandardBindings, the property about nano’s key bindings. As we showed in the previous post, those violations are a race between Bombadil’s sampling and nano’s repaint after a resize, not bugs in nano.
Bombadil finds a new home
Bombadil now believes it is in Antithesis. It draws its random values from the library, and tells it its state boundaries and the results of its properties. Making it exclaim was the first step, and in our run these calls already mean something in the machine. Each of the 5,544 random values Bombadil drew is a decision the machine recorded. The first pass and the first violation of hasStandardBindings are events in the run, and so is each of the 2,210 state boundaries. The next step is to use them: answer a decision differently on a branch, and fork at a state boundary, which is exactly what Bombadil’s comment asks the fuzzer to do. While Antithesis will always be his original home, it can be just one of many.
And Bombadil laughed. His road was long, and he did miss his home, but the voidstar had led him to another, and he knew it would not be his last.
If you have Bombadil specifications, or any program built with an Antithesis SDK, we’d love to work with you to get it running in Machine. You can sign up for free, and for a bigger session, just drop us a note at contact@testflows.com.