Skip to content

Commit

Permalink
Implement native fuzzing in Go
Browse files Browse the repository at this point in the history
  • Loading branch information
hanzei authored and agnivade committed Dec 6, 2024
1 parent fac16fe commit a65c50e
Show file tree
Hide file tree
Showing 76 changed files with 42 additions and 114 deletions.
Binary file removed fuzz/fuzz-fuzz.zip
Binary file not shown.
26 changes: 0 additions & 26 deletions fuzz/fuzz.go

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions fuzz/workdir/corpus/0324136bd592f82a0afb39d3eb7870d06e326c0d

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions fuzz/workdir/corpus/1

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion fuzz/workdir/corpus/2

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions fuzz/workdir/corpus/23d54ac1dac456100388367a829508a62752ddd9

This file was deleted.

2 changes: 0 additions & 2 deletions fuzz/workdir/corpus/23dd9f1cf3648138e68552009d8d7affd7868096

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions fuzz/workdir/corpus/3

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions fuzz/workdir/corpus/349599e8245643624aaa86bc2db2a33becfa9352

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions fuzz/workdir/corpus/4

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions fuzz/workdir/corpus/5

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions fuzz/workdir/corpus/6

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions fuzz/workdir/corpus/7

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions fuzz/workdir/corpus/8

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.
2 changes: 0 additions & 2 deletions fuzz/workdir/corpus/e11d22bb9287e17c26f10b826ab47a7cf49bd706

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions fuzz/workdir/corpus/f961048abbb7c870f5d8485d60364dc93453e6e9

This file was deleted.

42 changes: 42 additions & 0 deletions levenshtein_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,45 @@ func BenchmarkAll(b *testing.B) {
}
sink = tmp
}

// Fuzzing
// ----------------------------------------------

func FuzzComputeDistanceDifferent(f *testing.F) {
testcases := []struct{ a, b string }{
{"levenshtein", "frankenstein"},
{"resumé and café", "resumés and cafés"},
{"Hafþór Júlíus Björnsson", "Hafþor Julius Bjornsson"},
{"།་གམ་འས་པ་་མ།", "།་གམའས་པ་་མ"},
}
for _, tc := range testcases {
f.Add(tc.a, tc.b)
}
f.Fuzz(func(t *testing.T, a, b string) {
n := agnivade.ComputeDistance(a, b)
if n < 0 {
t.Errorf("Distance can not be negative: %d, a: %q, b: %q", n, a, b)
}
if n > len(a)+len(b) {
t.Errorf("Distance can not be greater than sum of lengths of a and b: %d, a: %q, b: %q", n, a, b)
}
})
}

func FuzzComputeDistanceEqual(f *testing.F) {
testcases := []string{
"levenshtein", "frankenstein",
"resumé and café", "resumés and cafés",
"Hafþór Júlíus Björnsson", "Hafþor Julius Bjornsson",
"།་གམ་འས་པ་་མ།", "།་གམའས་པ་་མ",
}
for _, tc := range testcases {
f.Add(tc)
}
f.Fuzz(func(t *testing.T, a string) {
n := agnivade.ComputeDistance(a, a)
if n != 0 {
t.Errorf("Distance must be zero: %d, a: %q", n, a)
}
})
}

0 comments on commit a65c50e

Please sign in to comment.