(f *testing.F)
| 152 | } |
| 153 | |
| 154 | func FuzzEncoding(f *testing.F) { |
| 155 | fuzz.AddFromZip(f, "testdata/fuzz/encode-corpus-raw.zip", fuzz.TypeRaw, testing.Short()) |
| 156 | fuzz.AddFromZip(f, "testdata/comp-crashers.zip", fuzz.TypeRaw, false) |
| 157 | fuzz.AddFromZip(f, "testdata/fuzz/encode-corpus-encoded.zip", fuzz.TypeGoFuzz, testing.Short()) |
| 158 | // Fuzzing tweaks: |
| 159 | const ( |
| 160 | // Test a subset of encoders. |
| 161 | startFuzz = SpeedFastest |
| 162 | endFuzz = SpeedBestCompression |
| 163 | |
| 164 | // Also tests with dictionaries... |
| 165 | testDicts = true |
| 166 | ) |
| 167 | |
| 168 | var dec *Decoder |
| 169 | var encs [SpeedBestCompression + 1]*Encoder |
| 170 | var encsD [SpeedBestCompression + 1]*Encoder |
| 171 | |
| 172 | var dicts [][]byte |
| 173 | if testDicts { |
| 174 | zr := testCreateZipReader("testdata/dict-tests-small.zip", f) |
| 175 | dicts = readDicts(f, zr) |
| 176 | } |
| 177 | |
| 178 | if testing.Short() && *fuzzEndF > int(SpeedBetterCompression) { |
| 179 | *fuzzEndF = int(SpeedBetterCompression) |
| 180 | } |
| 181 | |
| 182 | initEnc := func() func() { |
| 183 | var err error |
| 184 | dec, err = NewReader(nil, WithDecoderConcurrency(2), WithDecoderDicts(dicts...), WithDecoderMaxWindow(64<<10), WithDecoderMaxMemory(uint64(*fuzzMaxF))) |
| 185 | if err != nil { |
| 186 | panic(err) |
| 187 | } |
| 188 | for level := startFuzz; level <= endFuzz; level++ { |
| 189 | encs[level], err = NewWriter(nil, WithEncoderCRC(true), WithEncoderLevel(level), WithEncoderConcurrency(2), WithWindowSize(64<<10), WithZeroFrames(true), WithLowerEncoderMem(true)) |
| 190 | if testDicts { |
| 191 | encsD[level], err = NewWriter(nil, WithEncoderCRC(true), WithEncoderLevel(level), WithEncoderConcurrency(2), WithWindowSize(64<<10), WithZeroFrames(true), WithEncoderDict(dicts[int(level)%len(dicts)]), WithLowerEncoderMem(true), WithLowerEncoderMem(true)) |
| 192 | } |
| 193 | } |
| 194 | return func() { |
| 195 | dec.Close() |
| 196 | for _, enc := range encs { |
| 197 | if enc != nil { |
| 198 | enc.Close() |
| 199 | } |
| 200 | } |
| 201 | if testDicts { |
| 202 | for _, enc := range encsD { |
| 203 | if enc != nil { |
| 204 | enc.Close() |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | f.Cleanup(initEnc()) |
nothing calls this directly
no test coverage detected
searching dependent graphs…