...

Source file src/github.com/klauspost/compress/zstd/zstd_test.go

Documentation: github.com/klauspost/compress/zstd

     1  // Copyright 2019+ Klaus Post. All rights reserved.
     2  // License information can be found in the LICENSE file.
     3  
     4  package zstd
     5  
     6  import (
     7  	"flag"
     8  	"fmt"
     9  	"os"
    10  	"runtime"
    11  	"runtime/pprof"
    12  	"testing"
    13  	"time"
    14  )
    15  
    16  var isRaceTest bool
    17  
    18  // Fuzzing tweaks:
    19  var fuzzStartF = flag.Int("fuzz-start", int(SpeedFastest), "Start fuzzing at this level")
    20  var fuzzEndF = flag.Int("fuzz-end", int(SpeedBestCompression), "End fuzzing at this level (inclusive)")
    21  var fuzzMaxF = flag.Int("fuzz-max", 1<<20, "Maximum input size")
    22  
    23  func TestMain(m *testing.M) {
    24  	flag.Parse()
    25  	ec := m.Run()
    26  	if ec == 0 && runtime.NumGoroutine() > 2 {
    27  		n := 0
    28  		for n < 15 {
    29  			n++
    30  			time.Sleep(time.Second)
    31  			if runtime.NumGoroutine() == 2 {
    32  				os.Exit(0)
    33  			}
    34  		}
    35  		fmt.Println("goroutines:", runtime.NumGoroutine())
    36  		pprof.Lookup("goroutine").WriteTo(os.Stderr, 1)
    37  		os.Exit(1)
    38  	}
    39  	os.Exit(ec)
    40  }
    41  
    42  func TestMatchLen(t *testing.T) {
    43  	a := make([]byte, 130)
    44  	for i := range a {
    45  		a[i] = byte(i)
    46  	}
    47  	b := append([]byte{}, a...)
    48  
    49  	check := func(x, y []byte, l int) {
    50  		if m := matchLen(x, y); m != l {
    51  			t.Error("expected", l, "got", m)
    52  		}
    53  	}
    54  
    55  	for l := range a {
    56  		a[l] = ^a[l]
    57  		check(a, b, l)
    58  		check(a[:l], b, l)
    59  		a[l] = ^a[l]
    60  	}
    61  }
    62  

View as plain text