Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Last active March 28, 2022 17:25
Show Gist options
  • Save percybolmer/81217d614c304e7620f1afbdf2c0f399 to your computer and use it in GitHub Desktop.
Save percybolmer/81217d614c304e7620f1afbdf2c0f399 to your computer and use it in GitHub Desktop.
func MultipleInputs(a, b int, name string) {
// ... fancy code goes here
}
func FuzzMultipleInputs(f *testing.F) {
// We can add Multiple Seeds, but it has to be the same order as the input parameters for MultipleInputs
f.Add(10,20,"John the Ripper")
f.Fuzz(func(t *testing.T,a int,b int,name string){
MultipleInputs(a,b,name)
})
}
@monkrus
Copy link

monkrus commented Mar 26, 2022

Does it look right? Getting an undeclared name error for x and y in the last line.Thank you!

func Mult(x int, y int) int {
	return x * y
}
func FuzzMult(f *testing.F) {
	f.Add(10, 20)
	f.Fuzz(func(t *testing.T, x int, y int) {
		Mult(x, y)
	})

}

@percybolmer
Copy link
Author

Hey Monkrus! Thanks for reachig out,

It does look correct, there is just one small minor issue.

f.Fuzz accepts a function, which you pass in as a anonymous function( undecleared function) This is a short syntax, but it can confuse sometimes.

In your function you declare that there will be 3 local scoped variables
t which is a *testing.T
a and b which are ints.

But then you pass x and y into Multi. So simply rename the variables in the function to x and y and it should work :)

To make it clearer, you could use 3 functions instead

`func Multi(x int, y int) int {
return x * y
}

func FuzzMulti(f *testing.F) {
f.Add(10,20)
f.Fuzz(StuffToFuzz)
}

func StuffToFuzz(f *testing.F, x int, y int) {
Multi(x,y)
}

`

@monkrus
Copy link

monkrus commented Mar 28, 2022

Hi @percybolmer, thank you very much for the detailed explanation! Not it is all clear for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment