Skip to content

Commit

Permalink
Do separate fuzz for best.
Browse files Browse the repository at this point in the history
  • Loading branch information
klauspost committed Mar 24, 2023
1 parent 6ad8551 commit a010da0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
16 changes: 12 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@ jobs:
- name: Test Noasm
run: go test -tags=noasm ./...

- name: Test Race
- name: Test Race 1 CPU
env:
CGO_ENABLED: 1
run: go test -cpu="1,4" -short -race -v ./...
run: go test -cpu=1 -short -race -v ./...

- name: Test Race 4 CPU
env:
CGO_ENABLED: 1
run: go test -cpu=4 -short -race -v ./...

generate:
strategy:
Expand Down Expand Up @@ -163,7 +168,7 @@ jobs:
run: go test -run=none -fuzz=FuzzNoBMI2Dec -fuzztime=500000x -test.fuzzminimizetime=10ms ./zstd/.

- name: zstd/FuzzEncoding
run: go test -run=none -fuzz=FuzzEncoding -fuzztime=250000x -test.fuzzminimizetime=10ms ./zstd/.
run: cd zstd&&go test -run=none -fuzz=FuzzEncoding -fuzztime=250000x -test.fuzzminimizetime=10ms -fuzz-end=3&&cd ..

- name: zstd/FuzzDecodeAll/noasm
run: go test -tags=noasm -run=none -fuzz=FuzzDecodeAll -fuzztime=500000x -test.fuzzminimizetime=10ms ./zstd/.
Expand All @@ -172,7 +177,10 @@ jobs:
run: go test -tags=noasm -run=none -fuzz=FuzzDecoder -fuzztime=500000x -test.fuzzminimizetime=10ms ./zstd/.

- name: zstd/FuzzEncoding/noasm
run: go test -tags=noasm -run=none -fuzz=FuzzEncoding -fuzztime=250000x -test.fuzzminimizetime=10ms ./zstd/.
run: cd zstd&&go test -tags=noasm -run=none -fuzz=FuzzEncoding -fuzztime=250000x -test.fuzzminimizetime=10ms -fuzz-end=3&&cd ..

- name: zstd/FuzzEncodingBest
run: cd zstd&&go test -run=none -fuzz=FuzzEncoding -fuzztime=25000x -test.fuzzminimizetime=10ms -fuzz-start=4&&cd ..

fuzz-other:
env:
Expand Down
13 changes: 7 additions & 6 deletions zstd/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ func FuzzEncoding(f *testing.F) {

// Also tests with dictionaries...
testDicts = true

// Max input size:
maxSize = 1 << 20
)

var dec *Decoder
Expand All @@ -152,9 +149,13 @@ func FuzzEncoding(f *testing.F) {
dicts = readDicts(f, zr)
}

if testing.Short() && *fuzzEndF > int(SpeedBetterCompression) {
*fuzzEndF = int(SpeedBetterCompression)
}

initEnc := func() func() {
var err error
dec, err = NewReader(nil, WithDecoderConcurrency(2), WithDecoderDicts(dicts...), WithDecoderMaxWindow(64<<10), WithDecoderMaxMemory(maxSize))
dec, err = NewReader(nil, WithDecoderConcurrency(2), WithDecoderDicts(dicts...), WithDecoderMaxWindow(64<<10), WithDecoderMaxMemory(uint64(*fuzzMaxF)))
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -193,7 +194,7 @@ func FuzzEncoding(f *testing.F) {
t.Fatalf("%v:\n%v", r, string(stack))
}
}()
if len(data) > maxSize {
if len(data) > *fuzzMaxF {
return
}
var bufSize = len(data)
Expand All @@ -205,7 +206,7 @@ func FuzzEncoding(f *testing.F) {
}
}

for level := startFuzz; level <= endFuzz; level++ {
for level := *fuzzStartF; level <= *fuzzEndF; level++ {
enc := encs[level]
dst.Reset()
enc.Reset(&dst)
Expand Down
7 changes: 7 additions & 0 deletions zstd/zstd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package zstd

import (
"flag"
"fmt"
"os"
"runtime"
Expand All @@ -14,7 +15,13 @@ import (

var isRaceTest bool

// Fuzzing tweaks:
var fuzzStartF = flag.Int("fuzz-start", int(SpeedFastest), "Start fuzzing at this level")
var fuzzEndF = flag.Int("fuzz-end", int(SpeedBestCompression), "End fuzzing at this level (inclusive)")
var fuzzMaxF = flag.Int("fuzz-max", 1<<20, "Maximum input size")

func TestMain(m *testing.M) {
flag.Parse()
ec := m.Run()
if ec == 0 && runtime.NumGoroutine() > 2 {
n := 0
Expand Down

0 comments on commit a010da0

Please sign in to comment.