Commit b4e4e73e authored by Steven Allen's avatar Steven Allen

test(buzhash): fuzz

parent ca4d27be
...@@ -2,7 +2,6 @@ package chunk ...@@ -2,7 +2,6 @@ package chunk
import ( import (
"bytes" "bytes"
"fmt"
"io" "io"
"testing" "testing"
...@@ -11,6 +10,11 @@ import ( ...@@ -11,6 +10,11 @@ import (
func TestBuzhashChunking(t *testing.T) { func TestBuzhashChunking(t *testing.T) {
data := make([]byte, 1024*1024*16) data := make([]byte, 1024*1024*16)
chunkCount := 0
rounds := 100
for i := 0; i < rounds; i++ {
util.NewTimeSeededRand().Read(data) util.NewTimeSeededRand().Read(data)
r := NewBuzhash(bytes.NewReader(data)) r := NewBuzhash(bytes.NewReader(data))
...@@ -28,16 +32,26 @@ func TestBuzhashChunking(t *testing.T) { ...@@ -28,16 +32,26 @@ func TestBuzhashChunking(t *testing.T) {
chunks = append(chunks, chunk) chunks = append(chunks, chunk)
} }
chunkCount += len(chunks)
for i, chunk := range chunks {
if len(chunk) == 0 {
t.Fatalf("chunk %d/%d is empty", i+1, len(chunks))
}
}
t.Logf("average block size: %d\n", len(data)/len(chunks)) for i, chunk := range chunks[:len(chunks)-1] {
if len(chunk) < buzMin {
t.Fatalf("chunk %d/%d is less than the minimum size", i+1, len(chunks))
}
}
unchunked := bytes.Join(chunks, nil) unchunked := bytes.Join(chunks, nil)
if !bytes.Equal(unchunked, data) { if !bytes.Equal(unchunked, data) {
fmt.Printf("%d %d\n", len(unchunked), len(data))
//ioutil.WriteFile("./incorrect", unchunked, 0777)
//ioutil.WriteFile("./correct", data, 0777)
t.Fatal("data was chunked incorrectly") t.Fatal("data was chunked incorrectly")
} }
}
t.Logf("average block size: %d\n", len(data)*rounds/chunkCount)
} }
func TestBuzhashChunkReuse(t *testing.T) { func TestBuzhashChunkReuse(t *testing.T) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment