Skip to content

7. Reproducers and coverage

Take the tmp group from the previous page:

$ stitch write c5
[stitch] main:c5 (latest campaign; also: probe): running the minimized program .stitch/campaigns/main/w0/crashes/4141d2e5c3d584be.min.stp
warning: .stitch/campaigns/main/w0/crashes/4141d2e5c3d584be.min.stp now crashes differently from bucket c5 (KeyError at roundtrip (stub) instead of roundtrip stubs.py); the reproducer expects the new crash
wrote .stitch/standalone/c5/repro.py (71 lines, 3 calls, crash in call #2)
expected: KeyError in Store.items
SAME CRASH: .stitch/standalone/c5/repro.py -> KeyError in Store.items
next: cp .stitch/standalone/c5/repro.py .stitch/standalone/c5/min.py, shrink it, and run `stitch try .stitch/standalone/c5/min.py` after each edit
$ stitch write c2
[stitch] main:c2 (latest campaign; also: probe): running the minimized program .stitch/campaigns/main/w0/crashes/3ab9ff5378154395.min.stp
wrote .stitch/standalone/c2/repro.cpp (66 lines, 4 calls, crash in call #3)
expected: heap-use-after-free READ in kv_dump
SAME CRASH: .stitch/standalone/c2/repro.cpp -> heap-use-after-free READ in kv_dump
next: cp .stitch/standalone/c2/repro.cpp .stitch/standalone/c2/min.cpp, shrink it, and run `stitch try .stitch/standalone/c2/min.cpp` after each edit
$ stitch write c4
[stitch] main:c4 (latest campaign; also: probe): running the minimized program .stitch/campaigns/main/w0/crashes/b9f14b85cad8c307.min.stp
warning: .stitch/campaigns/main/w0/crashes/b9f14b85cad8c307.min.stp now crashes differently from bucket c4 (TypeError at Endpoint.fn (stub) instead of Endpoint.fn stubs.js); the reproducer expects the new crash
wrote .stitch/standalone/c4/repro.js (85 lines, 3 calls, crash in call #2)
expected: TypeError in anonymous@index.js
SAME CRASH: .stitch/standalone/c4/repro.js -> TypeError in anonymous@index.js
next: cp .stitch/standalone/c4/repro.js .stitch/standalone/c4/min.js, shrink it, and run `stitch try .stitch/standalone/c4/min.js` after each edit
$ stitch write c2
[stitch] main:c2 (latest campaign; also: probe): running the minimized program .stitch/campaigns/main/w1/crashes/34e651e6094e7fd3.min.stp
warning: .stitch/campaigns/main/w1/crashes/34e651e6094e7fd3.min.stp now crashes differently from bucket c2 (NullPointerException at Stubs.roundtrip (stub) instead of Stubs.roundtrip Stubs.java); the reproducer expects the new crash
wrote .stitch/standalone/c2/Repro.java (22 lines, 3 calls, crash in call #2)
expected: NullPointerException in Store.dump
SAME CRASH: .stitch/standalone/c2/Repro.java -> NullPointerException in Store.dump
next: cp .stitch/standalone/c2/Repro.java .stitch/standalone/c2/min.java, shrink it, and run `stitch try .stitch/standalone/c2/min.java` after each edit
$ stitch write c3
[stitch] main:c3 (latest campaign; also: probe): running the minimized program .stitch/campaigns/main/w0/crashes/b0b8b173289d4cc0.min.stp
wrote .stitch/standalone/c3/repro.go (28 lines, 3 calls, crash in call #2)
expected: nil pointer dereference in kvgo.Store.Dump
SAME CRASH: .stitch/standalone/c3/repro.go -> nil pointer dereference in kvgo.Store.Dump
next: cp .stitch/standalone/c3/repro.go .stitch/standalone/c3/min.go, shrink it, and run `stitch try .stitch/standalone/c3/min.go` after each edit
$ stitch write c2
[stitch] main:c2 (latest campaign; also: probe): running the minimized program .stitch/campaigns/main/w0/crashes/7fb95ce3ff1dccea.min.stp
warning: .stitch/campaigns/main/w0/crashes/7fb95ce3ff1dccea.min.stp now crashes differently from bucket c2 (called `Option::unwrap()` on a `None` value at stitch_harness::stubs::roundtrip (stub) instead of (no frame)); the reproducer expects the new crash
wrote .stitch/standalone/c2/repro.rs (24 lines, 3 calls, crash in call #2)
expected: called `Option::unwrap()` on a `None` value in kvrs::Store::dump::{{closure}}
SAME CRASH: .stitch/standalone/c2/repro.rs -> called `Option::unwrap()` on a `None` value in kvrs::Store::dump::{{closure}}
next: cp .stitch/standalone/c2/repro.rs .stitch/standalone/c2/min.rs, shrink it, and run `stitch try .stitch/standalone/c2/min.rs` after each edit
$ stitch write c4
[stitch] main:c4 (latest campaign; also: probe): running the minimized program .stitch/campaigns/main/w1/crashes/b1548eecfaf69d0d.min.stp
wrote .stitch/standalone/c4/repro.rb (66 lines, 3 calls, crash in call #2)
expected: KeyError in Hash#fetch
SAME CRASH: .stitch/standalone/c4/repro.rb -> KeyError in Hash#fetch
next: cp .stitch/standalone/c4/repro.rb .stitch/standalone/c4/min.rb, shrink it, and run `stitch try .stitch/standalone/c4/min.rb` after each edit
$ stitch write c4
[stitch] main:c4 (latest campaign; also: probe): running the minimized program .stitch/campaigns/main/w1/crashes/57865b83790633d8.min.stp
wrote .stitch/standalone/c4/repro.swift (25 lines, 4 calls, crash in call #3)
expected: Unexpectedly found nil while unwrapping an Optional value in closure
SAME CRASH: .stitch/standalone/c4/repro.swift -> Unexpectedly found nil while unwrapping an Optional value in closure
next: cp .stitch/standalone/c4/repro.swift .stitch/standalone/c4/min.swift, shrink it, and run `stitch try .stitch/standalone/c4/min.swift` after each edit
$ stitch write c4
[stitch] main:c4 (latest campaign; also: probe): running the minimized program .stitch/campaigns/main/w0/crashes/733243a843626d65.min.stp
wrote .stitch/standalone/c4/repro.m (25 lines, 3 calls, crash in call #2)
expected: NSInvalidArgumentException in -[KVStore items]
SAME CRASH: .stitch/standalone/c4/repro.m -> NSInvalidArgumentException in -[KVStore items]
next: cp .stitch/standalone/c4/repro.m .stitch/standalone/c4/min.m, shrink it, and run `stitch try .stitch/standalone/c4/min.m` after each edit

The file replays each call of the program with its recorded arguments, using your stub code:

def main():
# #0 load(text)
store0 = stitch.call(0, 'load', lambda: load('欀���\x19�=\x00 /Uc*ib%(\nCJ=8N;=fG\ntmp='))
# #1 remove(st=store0, key)
stitch.call(1, 'remove', lambda: remove(store0, 'tmp'))
# #2 roundtrip(st=store0) <-- crashes here in the original run
stitch.call(2, 'roundtrip', lambda: roundtrip(store0))
# the original run crashed in call #2; nothing after it ran
if __name__ == "__main__":
stitch.run(main)
int main() {
stitch::init();
// #0 new_store() [harness/stubs.cpp:16]
Obj<Store> store0 = stitch::call(0, "new_store", [&]() -> New<Store> {
return kv_new();
});
// #1 put(st=store0, key, value) [harness/stubs.cpp:26]
stitch::call(1, "put", [&] {
Borrow<Store> st = store0;
Str<16> key("tmp");
Str<32> value("");
stitch::require(kv_put(st, key.c_str(), value.c_str()) == 0, "invalid key or value");
});
// #2 remove_key(st=store0, key) [harness/stubs.cpp:31]
stitch::call(2, "remove_key", [&] {
Borrow<Store> st = store0;
Str<16> key("tmp");
kv_remove(st, key.c_str());
});
// #3 roundtrip(st=store0) [harness/stubs.cpp:34] <-- crashes here in the original run
stitch::call(3, "roundtrip", [&] {
Borrow<Store> st = store0;
char* text = kv_dump(st);
kv_store* again = kv_load(text);
free(text);
stitch::require(again, "dump did not load");
size_t n = kv_len(again);
kv_free(again);
stitch::check(n == kv_len(st), "dump/load roundtrip");
});
// the original run crashed in call #3; nothing after it ran
return 0;
}
async function main() {
// #0 load(text)
const store0 = await stitch.call(0, "load", { text: "%Knn *%(Z=\ufffdu\ufffd\nf\f\ufffd=\ufffd\u1d94\u0001\u0015{\ufffd~\ufffd\ntmp=" });
// #1 remove(st=store0, key)
await stitch.call(1, "remove", { st: store0, key: "tmp" });
// #2 roundtrip(st=store0) <-- crashes here in the original run
await stitch.call(2, "roundtrip", { st: store0 });
// the original run crashed in call #2; nothing after it ran
}
stitch.run(main);
import stitch.Standalone;
public class Repro {
public static void main(String[] args) {
Standalone.run(() -> {
// #0 load(text)
var store0 = Standalone.call(0, "load", () -> Stubs.load("tmp=\n"));
// #1 remove(st=store0, key)
Standalone.exec(1, "remove", () -> Stubs.remove(store0, "tmp"));
// #2 roundtrip(st=store0) <-- crashes here in the original run
Standalone.exec(2, "roundtrip", () -> Stubs.roundtrip(store0));
// the original run crashed in call #2; nothing after it ran
});
}
}
package main
import (
"stitch"
_ "stitchharness" // the harness: registers the stubs
)
func main() {
stitch.Run(func() {
// #0 load(text)
r0 := stitch.Call(0, "load", "tmp=\n")
store0 := r0[0]
_ = r0
// #1 remove(st=store0, key)
stitch.Call(1, "remove", store0, "tmp")
// #2 roundtrip(st=store0) <-- crashes here in the original run
stitch.Call(2, "roundtrip", store0)
// the original run crashed in call #2; nothing after it ran
_ = store0
})
}
use stitch::*;
use stitch_harness::stubs::*;
fn main() {
stitch_harness::__stitch_register();
stitch::run(|| {
// #0 load(text)
let mut r0 = stitch::call(0, "load", || load(Str::from("tmp=\n")));
let mut store0 = r0.get::<Store>(0);
// #1 remove(st=store0, key)
stitch::call(1, "remove", || remove(stitch::borrow(&mut store0), Str::from("tmp")));
// #2 roundtrip(st=store0) <-- crashes here in the original run
stitch::call(2, "roundtrip", || roundtrip(stitch::borrow(&mut store0)));
// the original run crashed in call #2; nothing after it ran
});
}
def main
# #0 load(text)
store0 = Stitch.call(0, :load) { Stitch.stub(:load).call("e]H\xef\xbf\xbd=\xef\xbf\xbd\xef\xbf\xbd^\xef\xbf\xbd\xef\xbf\xbd1\n\#!=Zf[Ro%\ntmp=") }
# #1 remove(st=store0, key)
Stitch.call(1, :remove) { Stitch.stub(:remove).call(store0, "tmp") }
# #2 roundtrip(st=store0) <-- crashes here in the original run
Stitch.call(2, :roundtrip) { Stitch.stub(:roundtrip).call(store0) }
# the original run crashed in call ##2; nothing after it ran
end
Stitch.run { main }
exit(reproMain {
// #0 load()
let store0 = obj(try call(0, "load") { try load.body(Str("")) })
// #1 put(=store0, , )
_ = try call(1, "put") { try put.body(store0.borrow, Str("tmp"), Str("")) }
// #2 remove(=store0, )
_ = try call(2, "remove") { try remove.body(store0.borrow, Str("tmp")) }
// #3 roundtrip(=store0) <-- crashes here in the original run
_ = try call(3, "roundtrip") { try roundtrip.body(store0.borrow) }
// the original run crashed in call #3; nothing after it ran
})
int main(void) {
// The program. Each STCall is one harness call with its arguments filled in.
return STReproMain(^{
// #0 load(text)
stitch_obj_Store store0 = STCall(0, "load", ^id { return stub_load(@"tmp="); });
// #1 remove(st=store0, key)
STCall(1, "remove", ^id { stub_remove(store0, @"tmp"); return nil; });
// #2 roundtrip(st=store0) <-- crashes here in the original run
STCall(2, "roundtrip", ^id { stub_roundtrip(store0); return nil; });
// the original run crashed in call #2; nothing after it ran
});
}

Copy the file and cut it down to plain library calls. After each edit, run stitch try: it builds and runs the file and compares the crash with the original.

cp .stitch/standalone/c5/repro.py .stitch/standalone/c5/min.py
# edit min.py
stitch try .stitch/standalone/c5/min.py
cp .stitch/standalone/c2/repro.cpp .stitch/standalone/c2/min.c
# edit min.c
stitch try .stitch/standalone/c2/min.c
cp .stitch/standalone/c4/repro.js .stitch/standalone/c4/min.js
# edit min.js
stitch try .stitch/standalone/c4/min.js
cp .stitch/standalone/c2/Repro.java .stitch/standalone/c2/Min.java
# edit Min.java
stitch try .stitch/standalone/c2/Min.java
cp .stitch/standalone/c3/repro.go .stitch/standalone/c3/min.go
# edit min.go
stitch try .stitch/standalone/c3/min.go
cp .stitch/standalone/c2/repro.rs .stitch/standalone/c2/min.rs
# edit min.rs
stitch try .stitch/standalone/c2/min.rs
cp .stitch/standalone/c4/repro.rb .stitch/standalone/c4/min.rb
# edit min.rb
stitch try .stitch/standalone/c4/min.rb
cp .stitch/standalone/c4/repro.swift .stitch/standalone/c4/min.swift
# edit min.swift
stitch try .stitch/standalone/c4/min.swift
cp .stitch/standalone/c4/repro.m .stitch/standalone/c4/min.m
# edit min.m
stitch try .stitch/standalone/c4/min.m

A finished reproducer:

import kvlib
st = kvlib.load("tmp=")
st.remove("tmp") # removes "tmp" from the data, but not from the order list
st.dump() # KeyError: 'tmp'
#include <kv.h>
int main(void) {
kv_store *st = kv_new();
kv_put(st, "tmp", "");
kv_remove(st, "tmp"); /* frees the entry, but leaves it in the order list */
kv_dump(st); /* reads the freed entry */
return 0;
}
const kv = require("kvjs");
const st = new kv.Store();
st.put("tmp", "x");
st.remove("tmp"); // removes "tmp" from the data, but not from the order list
st.dump(); // TypeError
import demo.kv.Store;
public class Min {
public static void main(String[] args) {
Store st = new Store();
st.put("tmp", "x");
st.remove("tmp"); // removes "tmp" from the data, but not from the order list
st.dump(); // NullPointerException
}
}
package main
import "example.com/kvgo"
func main() {
st := kvgo.New()
st.Put("tmp", "x")
st.Remove("tmp") // removes "tmp" from the data, but not from the order list
st.Dump() // nil pointer dereference
}
fn main() {
let mut st = kvrs::Store::new();
st.put("tmp", "x").unwrap();
st.remove("tmp"); // removes "tmp" from the data, but not from the order list
st.dump(); // panics on unwrap() of None
}
require "kvrb"
st = Kvrb::Store.new
st.put("tmp", "x")
st.remove("tmp") # removes "tmp" from the data, but not from the order list
st.dump # KeyError
import KVSwift
let st = KVSwift.Store() // the harness has its own type named Store
try st.put("tmp", "x")
st.remove("tmp") // removes "tmp" from the data, but not from the order list
_ = st.dump() // force unwrap of nil
#import "KVStore.h"
int main(void) {
KVStore *st = [KVStore new];
[st putValue:@"x" forKey:@"tmp" error:NULL];
[st removeKey:@"tmp"]; // removes "tmp" from the data, but not from the order list
[st dump]; // NSInvalidArgumentException
return 0;
}
$ stitch try .stitch/standalone/c5/min.py
SAME CRASH: .stitch/standalone/c5/min.py -> KeyError in Store.items
4 code lines, plain library code
$ stitch try .stitch/standalone/c2/min.c
SAME CRASH: .stitch/standalone/c2/min.c -> heap-use-after-free READ in kv_dump
8 code lines, plain library code
$ stitch try .stitch/standalone/c4/min.js
SAME CRASH: .stitch/standalone/c4/min.js -> TypeError in anonymous@index.js
5 code lines, plain library code
$ stitch try .stitch/standalone/c2/Min.java
SAME CRASH: .stitch/standalone/c2/Min.java -> NullPointerException in Store.dump
9 code lines, plain library code
$ stitch try .stitch/standalone/c3/min.go
SAME CRASH: .stitch/standalone/c3/min.go -> nil pointer dereference in kvgo.Store.Dump
8 code lines, plain library code
$ stitch try .stitch/standalone/c2/min.rs
SAME CRASH: .stitch/standalone/c2/min.rs -> called `Option::unwrap()` on a `None` value in kvrs::Store::dump::{{closure}}
6 code lines, plain library code
$ stitch try .stitch/standalone/c4/min.rb
SAME CRASH: .stitch/standalone/c4/min.rb -> KeyError in Hash#fetch
5 code lines, plain library code
$ stitch try .stitch/standalone/c4/min.swift
SAME CRASH: .stitch/standalone/c4/min.swift -> Unexpectedly found nil while unwrapping an Optional value in closure
5 code lines, plain library code
$ stitch try .stitch/standalone/c4/min.m
SAME CRASH: .stitch/standalone/c4/min.m -> NSInvalidArgumentException in -[KVStore items]
7 code lines, plain library code

If an edit removes the bug, stitch try says so. Here the key is a instead of tmp:

$ stitch try .stitch/standalone/c5/bad.py
NO CRASH: .stitch/standalone/c5/bad.py ran to completion (expected KeyError in Store.items)
$ stitch try .stitch/standalone/c2/bad.c
NO CRASH: .stitch/standalone/c2/bad.c ran to completion (expected heap-use-after-free READ in kv_dump)
$ stitch try .stitch/standalone/c4/bad.js
NO CRASH: .stitch/standalone/c4/bad.js ran to completion (expected TypeError in anonymous@index.js)
$ stitch try .stitch/standalone/c2/Bad.java
NO CRASH: .stitch/standalone/c2/Bad.java ran to completion (expected NullPointerException in Store.dump)
$ stitch try .stitch/standalone/c3/bad.go
NO CRASH: .stitch/standalone/c3/bad.go ran to completion (expected nil pointer dereference in kvgo.Store.Dump)
$ stitch try .stitch/standalone/c2/bad.rs
NO CRASH: .stitch/standalone/c2/bad.rs ran to completion (expected called `Option::unwrap()` on a `None` value in kvrs::Store::dump::{{closure}})
$ stitch try .stitch/standalone/c4/bad.rb
NO CRASH: .stitch/standalone/c4/bad.rb ran to completion (expected KeyError in Hash#fetch)
$ stitch try .stitch/standalone/c4/bad.swift
NO CRASH: .stitch/standalone/c4/bad.swift ran to completion (expected Unexpectedly found nil while unwrapping an Optional value in closure)
$ stitch try .stitch/standalone/c4/bad.m
NO CRASH: .stitch/standalone/c4/bad.m ran to completion (expected NSInvalidArgumentException in -[KVStore items])

This short file is what you send to the library’s maintainers. stitch report <id> (the crash id you shrank) packages it for them: a Dockerfile that builds the library at the pinned commit (package versions as of when the crash was found), the file, run.sh, and ISSUE.md, the text of a GitHub issue. Nobody needs STITCH++ to run it:

stitch report <id>
cd .stitch/reports/<id> && ./run.sh # docker build + docker run

stitch repro writes a folder that rebuilds the library and replays the crash with nothing but Docker, and checks that it works:

$ stitch repro c5
[stitch] main:c5 (latest campaign; also: probe): running the minimized program .stitch/campaigns/main/w0/crashes/4141d2e5c3d584be.min.stp
[stitch] verifying the reproducer from scratch (~/STITCHplusplus/examples/kv/.stitch/repros/kv-c5/run.sh)...
[stitch] verified: same crash
reproducer: ~/STITCHplusplus/examples/kv/.stitch/repros/kv-c5
run it anywhere with docker: ~/STITCHplusplus/examples/kv/.stitch/repros/kv-c5/run.sh
$ stitch repro c2
[stitch] main:c2 (latest campaign; also: probe): running the minimized program .stitch/campaigns/main/w0/crashes/3ab9ff5378154395.min.stp
[stitch] verifying the reproducer from scratch (~/STITCHplusplus/examples/kv/.stitch/repros/kv-c2/run.sh)...
[stitch] verified: same crash
reproducer: ~/STITCHplusplus/examples/kv/.stitch/repros/kv-c2
run it anywhere with docker: ~/STITCHplusplus/examples/kv/.stitch/repros/kv-c2/run.sh
$ stitch repro c4
[stitch] main:c4 (latest campaign; also: probe): running the minimized program .stitch/campaigns/main/w0/crashes/b9f14b85cad8c307.min.stp
[stitch] verifying the reproducer from scratch (~/STITCHplusplus/examples/kv/.stitch/repros/kv-c4/run.sh)...
[stitch] verified: same crash
reproducer: ~/STITCHplusplus/examples/kv/.stitch/repros/kv-c4
run it anywhere with docker: ~/STITCHplusplus/examples/kv/.stitch/repros/kv-c4/run.sh
$ stitch repro c2
[stitch] main:c2 (latest campaign; also: probe): running the minimized program .stitch/campaigns/main/w1/crashes/34e651e6094e7fd3.min.stp
[stitch] verifying the reproducer from scratch (~/STITCHplusplus/examples/kv/.stitch/repros/kv-c2/run.sh)...
[stitch] verified: same crash
reproducer: ~/STITCHplusplus/examples/kv/.stitch/repros/kv-c2
run it anywhere with docker: ~/STITCHplusplus/examples/kv/.stitch/repros/kv-c2/run.sh
$ stitch repro c3
[stitch] main:c3 (latest campaign; also: probe): running the minimized program .stitch/campaigns/main/w0/crashes/b0b8b173289d4cc0.min.stp
[stitch] verifying the reproducer from scratch (~/STITCHplusplus/examples/kv/.stitch/repros/kv-c3/run.sh)...
[stitch] verified: same crash
reproducer: ~/STITCHplusplus/examples/kv/.stitch/repros/kv-c3
run it anywhere with docker: ~/STITCHplusplus/examples/kv/.stitch/repros/kv-c3/run.sh
$ stitch repro c2
[stitch] main:c2 (latest campaign; also: probe): running the minimized program .stitch/campaigns/main/w0/crashes/7fb95ce3ff1dccea.min.stp
[stitch] verifying the reproducer from scratch (~/STITCHplusplus/examples/kv/.stitch/repros/kv-c2/run.sh)...
[stitch] verified: same crash
reproducer: ~/STITCHplusplus/examples/kv/.stitch/repros/kv-c2
run it anywhere with docker: ~/STITCHplusplus/examples/kv/.stitch/repros/kv-c2/run.sh
$ stitch repro c4
[stitch] main:c4 (latest campaign; also: probe): running the minimized program .stitch/campaigns/main/w1/crashes/b1548eecfaf69d0d.min.stp
[stitch] verifying the reproducer from scratch (~/STITCHplusplus/examples/kv/.stitch/repros/kv-c4/run.sh)...
[stitch] verified: same crash
reproducer: ~/STITCHplusplus/examples/kv/.stitch/repros/kv-c4
run it anywhere with docker: ~/STITCHplusplus/examples/kv/.stitch/repros/kv-c4/run.sh
$ stitch repro c4
[stitch] main:c4 (latest campaign; also: probe): running the minimized program .stitch/campaigns/main/w1/crashes/57865b83790633d8.min.stp
[stitch] verifying the reproducer from scratch (~/STITCHplusplus/examples/kv/.stitch/repros/kv-c4/run.sh)...
[stitch] verified: same crash
reproducer: ~/STITCHplusplus/examples/kv/.stitch/repros/kv-c4
run it anywhere with docker: ~/STITCHplusplus/examples/kv/.stitch/repros/kv-c4/run.sh
$ stitch repro c4
[stitch] main:c4 (latest campaign; also: probe): running the minimized program .stitch/campaigns/main/w0/crashes/733243a843626d65.min.stp
[stitch] verifying the reproducer from scratch (~/STITCHplusplus/examples/kv/.stitch/repros/kv-c4/run.sh)...
[stitch] verified: same crash
reproducer: ~/STITCHplusplus/examples/kv/.stitch/repros/kv-c4
run it anywhere with docker: ~/STITCHplusplus/examples/kv/.stitch/repros/kv-c4/run.sh

When the project’s source is a git repository (stitch init --git URL --rev REV), you can run a crash against other versions:

stitch exec c1 --rev HEAD # does the newest code still crash?
stitch bisect c1 # the commit that introduced the bug
stitch bisect c1 --fixed # the commit that fixed it
$ stitch cov
[stitch] coverage build + 33 programs (main)
coverage of 33 programs (28 ok, 5 crashed, 0 timed out), library at local
library:
lines 32 / 33 97.0%
functions 6 / 7 85.7%
branches 15 / 16 93.8%
file lines functions
v/lib/python3.12/site-packages/kvlib/__init__.py 97.0% 85.7%
never called: 1 library functions, 1 of them not static
Store.get opt/venv/lib/python3.12/site-packages/kvlib/__init__.py:16
lcov: .stitch/cov/main/lcov.info
html: .stitch/cov/main/html/index.html
summary: .stitch/cov/main/summary.json
$ stitch cov
[stitch] coverage build + 303 programs (main)
[stitch] building project image stitch-kv:local-cov (log: ~/.cache/stitch/logs/kv-local-cov.log)
coverage of 303 programs (298 ok, 5 crashed, 0 timed out), library at local
library:
lines 90 / 94 95.7%
functions 8 / 9 88.9%
branches 35 / 38 92.1%
file lines functions
src/kv.c 95.7% 88.9%
never called: 1 library functions, 1 of them not static
kv_get src/kv.c:45
lcov: .stitch/cov/main/lcov.info
html: .stitch/cov/main/html/index.html
summary: .stitch/cov/main/summary.json
$ stitch cov
[stitch] coverage build + 96 programs (main)
coverage of 96 programs (94 ok, 2 crashed, 0 timed out), library at local
library:
lines 41 / 51 80.4%
functions 5 / 6 83.3%
branches 23 / 23 100.0%
file lines functions
src/index.js 80.4% 83.3%
never called: 1 library functions, 1 of them not static
setPath src/index.js:40
lcov: .stitch/cov/main/lcov.info
html: .stitch/cov/main/html/index.html
summary: .stitch/cov/main/summary.json
$ stitch cov
[stitch] coverage build + 81 programs (main)
coverage of 81 programs (78 ok, 3 crashed, 0 timed out), library at local
library:
lines 22 / 22 100.0%
functions 6 / 6 100.0%
branches 22 / 22 100.0%
file lines functions
src/demo/kv/Store.java 100.0% 100.0%
lcov: .stitch/cov/main/lcov.info
html: .stitch/cov/main/html/index.html
summary: .stitch/cov/main/summary.json
$ stitch cov
[stitch] coverage build + 122 programs (main)
coverage of 122 programs (117 ok, 5 crashed, 0 timed out), library at local
library:
lines 45 / 45 100.0%
functions 6 / 6 100.0%
branches -
file lines functions
src/kv.go 100.0% 100.0%
lcov: .stitch/cov/main/lcov.info
html: .stitch/cov/main/html/index.html
summary: .stitch/cov/main/summary.json
$ stitch cov
[stitch] coverage build + 501 programs (main)
coverage of 501 programs (461 ok, 40 crashed, 0 timed out), library at local
library:
lines 37 / 45 82.2%
functions 9 / 11 81.8%
branches -
file lines functions
src/src/lib.rs 82.2% 81.8%
never called: 2 library functions, 2 of them not static
<kvrs::Store>::byte_at src/src/lib.rs:41
<kvrs::Store>::byte_at::{closure#0} src/src/lib.rs:42
lcov: .stitch/cov/main/lcov.info
html: .stitch/cov/main/html/index.html
summary: .stitch/cov/main/summary.json
$ stitch cov
[stitch] coverage build + 76 programs (main)
coverage of 76 programs (72 ok, 4 crashed, 0 timed out), library at local
library:
lines 25 / 25 100.0%
functions 6 / 7 85.7%
branches 13 / 14 92.9%
file lines functions
usr/local/bundle/gems/kvrb-0.1.0/lib/kvrb.rb 100.0% 85.7%
never called: 1 library functions, 1 of them not static
Kvrb::Store#get usr/local/bundle/gems/kvrb-0.1.0/lib/kvrb.rb:18
lcov: .stitch/cov/main/lcov.info
html: .stitch/cov/main/html/index.html
summary: .stitch/cov/main/summary.json
$ stitch cov
[stitch] coverage build + 314 programs (main)
coverage of 314 programs (292 ok, 22 crashed, 0 timed out), library at local
library:
lines 68 / 75 90.7%
functions 18 / 21 85.7%
branches -
file lines functions
src/Sources/KVSwift/KV.swift 85.4% 83.3%
tch-swift-cov/app/pkg/Sources/worker/stubs.swift 96.4% 87.5%
itch-swift-cov/app/pkg/Sources/worker/main.swift 100.0% 100.0%
never called: 3 library functions, 3 of them not static
$s7KVSwift5StoreC3getySSSgSSF src/Sources/KVSwift/KV.swift:21
$s7KVSwift5StoreC6byteAtys5UInt8VSgSS_SitF src/Sources/KVSwift/KV.swift:33
$s6worker9roundtrip6Stitch5Stub1VyAC6BorrowVyAA5StoreOGytGvpfiyAJKcfU_S2S_SStXEfU_ tmp/stitch-swift-cov/app/pkg/Sources/worker/stubs.swift:35
lcov: .stitch/cov/main/lcov.info
html: .stitch/cov/main/html/index.html
summary: .stitch/cov/main/summary.json
$ stitch cov
[stitch] coverage build + 126 programs (main)
coverage of 126 programs (124 ok, 2 crashed, 0 timed out), library at local
library:
lines 54 / 69 78.3%
functions 7 / 10 70.0%
branches 23 / 32 71.9%
file lines functions
src/KVStore.m 78.3% 70.0%
never called: 3 library functions, 3 of them not static
KVStore.m:invalid src/KVStore.m:6
KVStore.m:_i_KVStore__stringForKey_ src/KVStore.m:53
KVStore.m:_i_KVStore__byteForKey_atIndex_ src/KVStore.m:78
lcov: .stitch/cov/main/lcov.info
html: .stitch/cov/main/html/index.html
summary: .stitch/cov/main/summary.json

When the report has a “never called” list, those are library functions that no stub calls. Writing stubs for them is the next step: add them, then stitch build and stitch probe again. html/index.html shows each line and branch the campaign never reached.

  • described an API with stubs, objects and fuzzed parameters
  • used the probe report to find a stub that wasted runs, and fixed it with a data type
  • asserted a property with a check
  • grouped crashes, separated three bugs, and reduced one to a few lines of library code

The finished harness is in examples/<language>-demo/harness/. It has a few more stubs than this tutorial, including put_all, which takes a list of pairs from a decoder. Concepts covers the ideas in more depth, and Reference › Languages has the full API for each language.