Skip to content
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

Introduce fuzz testing #66

Open
kruskall opened this issue Jun 18, 2023 · 2 comments
Open

Introduce fuzz testing #66

kruskall opened this issue Jun 18, 2023 · 2 comments

Comments

@kruskall
Copy link
Member

Followup from #63

We should introduce fuzz testing to make sure we are not missing anything

As this is a library we might also evaluate adding fuzz testing into APM Server and fuzz the intake endpoint directly.

@kruskall
Copy link
Member Author

RE #63 (comment):

the stdlib does not support structured fuzzing or fuzzing complex types (structs). We need a compatibility layer to cover that usage. In that PR I used https://github.com/google/gofuzz.

Gofuzz has full support for the stdlib fuzzing engine and the test looks like this:

func FuzzError(f *testing.F) {
	f.Fuzz(func(t *testing.T, data []byte) {
		c := complexStruct{}
		fuzz.NewFromGoFuzz(data).NilChance(.1).NumElements(1, 10).MaxDepth(5).Fuzz(&c) // populate complex struct
		foo(&c) // run target method with fuzzed data 
	})
}

The stdlib is generating random data ([]byte) which are used as a seed to populate the complex struct (this is to make the tests reproducible).

I looked into https://github.com/AdaLogics/go-fuzz-headers but my understanding is that it is used for https://github.com/dvyukov/go-fuzz and not to wire complex structs with the stdlib engine.

@axw
Copy link
Member

axw commented Jun 19, 2023

https://adalogics.com/blog/structure-aware-go-fuzzing-complex-types gives some examples of using go-fuzz-headers with Go's native fuzz testing.

@axw axw mentioned this issue Jun 19, 2023
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

No branches or pull requests

2 participants