Skip to content

kvnemesis: first step towards a fuzzed KVNemesis #148634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stevendanna
Copy link
Collaborator

You can run this test with the go fuzzer with something like:

go test ./pkg/kv/kvnemesis/ -test.fuzz=FuzzKVNemesisSingleNode
-test.fuzzcachedir=_fuzzcache -v -test.run=^$
-tags crdb_test -timeout=300m -parallel=4

It can also be run under bazel, but I have not yet sorted out all of the flags needed to get a coverage enabled build and to ensure that the failing test cases get written somewhere that can be referenced on subsequent runs.

The idea here is that the fuzzer provides a []byte that then determines the output of all random decisions in KVNemesis. This doesn't account for metamorphic decisions made outside of KVNemesis.

KVNemesis is a rather heavyweight test which seemed to be a problem for running it reliably under go-fuzz; however, go-fuzz's poor diagnostics when the test worker crash has made it hard to determine the exact cause so far.

Epic: none
Release note: None

@stevendanna stevendanna requested a review from a team as a code owner June 21, 2025 21:45
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@stevendanna stevendanna requested a review from srosenberg June 21, 2025 21:50
You can run this test with the go fuzzer with something like:

  go test ./pkg/kv/kvnemesis/ -test.fuzz=FuzzKVNemesisSingleNode \
  -test.fuzzcachedir=_fuzzcache -v -test.run=^$ \
  -tags crdb_test  -timeout=300m -parallel=4

It can also be run under bazel, but I have not yet sorted out all of the
flags needed to get a coverage enabled build and to ensure that the
failing test cases get written somewhere that can be referenced on
subsequent runs.

The idea here is that the fuzzer provides a []byte that then determines
the output of all random decisions in KVNemesis. This doesn't account
for metamorphic decisions made outside of KVNemesis.

KVNemesis is a rather heavyweight test which seemed to be a problem for
running it reliably under go-fuzz; however, go-fuzz's poor diagnostics
when the test worker crash has made it hard to determine the exact cause
so far.

Epic: none
Release note: None
srosenberg added a commit to srosenberg/cockroach that referenced this pull request Jun 23, 2025
To run natively,

```
go build -buildmode=c-archive -gcflags=all=-d=libfuzzer -tags "crdb_test,gofuzz,gofuzz_libfuzzer,libfuzzer" -trimpath -gcflags syscall=-d=libfuzzer=0 -o kvnemesis_fuzz.a pkg/kv/kvnemesis/main/main.go
clang -o kvnemesis_fuzz kvnemesis_fuzz.a /home/stan_cockroachlabs_com/go/src/github.com/cockroachdb/cockroach/bin/c-deps/archived_cdep_libjemalloc_linux/lib/libjemalloc.a /home/stan_cockroachlabs_com/go/src/github.com/cockroachdb/cockroach/bin/c-deps/archived_cdep_libproj_linux/lib/libproj.a -fsanitize=fuzzer
./kvnemesis_fuzz -max_len=8192 seeds  >libfuzzer.out 2>&1
```

To run in go with libfuzzer instrumentation,

```
bazel run --override_repository=io_bazel_rules_go=/home/stan_cockroachlabs_com/go/src/github.com/cockroachdb/rules_go --@io_bazel_rules_go//go/config:gc_goopts=-d=libfuzzer --crdb_test pkg/kv/kvnemesis:kvnemesis_test -- -test.run notests -test.fuzz FuzzKVNemesisSingleNode  -test.fuzzcachedir /tmp/foobar/ -test.v >gofuzzer.out 2>&1
```

[1] cockroachdb#148634
[2] https://cockroachlabs.slack.com/archives/C023S0V4YEB/p1750542607409039?thread_ts=1750341116.758639&cid=C023S0V4YEB

Epic: none

Release note: None
@stevendanna
Copy link
Collaborator Author

Test failure is unrelated (but important and fixed here #148660)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants