mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-25 09:48:09 +02:00
Make the test non-random
This commit is contained in:
@@ -5,12 +5,14 @@ package rsync
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"kitty/tools/utils"
|
"strconv"
|
||||||
"kitty/tools/utils/random"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
|
|
||||||
|
"kitty/tools/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
@@ -102,36 +104,42 @@ func run_roundtrip_test(t *testing.T, src_data, changed []byte, num_of_patches,
|
|||||||
if limit > -1 && p.total_data_in_delta > limit {
|
if limit > -1 && p.total_data_in_delta > limit {
|
||||||
t.Fatalf("%sUnexpectedly poor delta performance: total_patch_size: %d total_delta_size: %d limit: %d", prefix_msg(), total_patch_size, p.total_data_in_delta, limit)
|
t.Fatalf("%sUnexpectedly poor delta performance: total_patch_size: %d total_delta_size: %d limit: %d", prefix_msg(), total_patch_size, p.total_data_in_delta, limit)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func generate_data(block_size, num_of_blocks int) []byte {
|
||||||
|
ans := make([]byte, num_of_blocks*block_size)
|
||||||
|
utils.Memset(ans, '_')
|
||||||
|
for i := 0; i < num_of_blocks; i++ {
|
||||||
|
offset := i * block_size
|
||||||
|
copy(ans[offset:], strconv.Itoa(i+1))
|
||||||
|
}
|
||||||
|
return ans
|
||||||
|
}
|
||||||
|
|
||||||
|
func patch_data(data []byte, patches ...string) (num_of_patches, total_patch_size int) {
|
||||||
|
num_of_patches = len(patches)
|
||||||
|
for _, patch := range patches {
|
||||||
|
o, r, _ := strings.Cut(patch, ":")
|
||||||
|
total_patch_size += len(r)
|
||||||
|
if offset, err := strconv.Atoi(o); err == nil {
|
||||||
|
copy(data[offset:], r)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRsyncRoundtrip(t *testing.T) {
|
func TestRsyncRoundtrip(t *testing.T) {
|
||||||
src_data := make([]byte, 4*1024*1024)
|
block_size := 16
|
||||||
random.Bytes(src_data)
|
src_data := generate_data(block_size, 16)
|
||||||
total_patch_size := 0
|
|
||||||
num_of_patches := 8
|
|
||||||
|
|
||||||
random_patch := func(data []byte) (size int) {
|
|
||||||
if offset := random.Int(len(data)); offset < len(data) {
|
|
||||||
max_size := utils.Min(257, len(data)-offset)
|
|
||||||
if size = random.Int(max_size); size > 0 {
|
|
||||||
total_patch_size += size
|
|
||||||
random.Bytes(data[offset : offset+size])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
changed := slices.Clone(src_data)
|
changed := slices.Clone(src_data)
|
||||||
for i := 0; i < num_of_patches; i++ {
|
num_of_patches, total_patch_size := patch_data(changed, "3:patch1", "16:patch2", "130:ptch3")
|
||||||
random_patch(changed)
|
|
||||||
}
|
|
||||||
|
|
||||||
run_roundtrip_test(t, src_data, changed, num_of_patches, total_patch_size)
|
run_roundtrip_test(t, src_data, changed, num_of_patches, total_patch_size)
|
||||||
run_roundtrip_test(t, src_data, []byte{}, -1, 0)
|
run_roundtrip_test(t, src_data, []byte{}, -1, 0)
|
||||||
run_roundtrip_test(t, src_data, src_data, 0, 0)
|
run_roundtrip_test(t, src_data, src_data, 0, 0)
|
||||||
|
|
||||||
// p := NewPatcher(int64(len(src_data)))
|
|
||||||
// block_size := p.rsync.BlockSize
|
|
||||||
// run_roundtrip_test(t, src_data, src_data[block_size:], 0, 0)
|
// run_roundtrip_test(t, src_data, src_data[block_size:], 0, 0)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user