1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later
package diskio_test
import (
"bytes"
"testing"
"testing/iotest"
"git.lukeshu.com/btrfs-progs-ng/lib/diskio"
)
type byteReaderWithName struct {
*bytes.Reader
name string
}
func (r byteReaderWithName) Name() string {
return r.name
}
func (r byteReaderWithName) Close() error {
return nil
}
func (r byteReaderWithName) WriteAt([]byte, int64) (int, error) {
panic("not implemented")
}
func FuzzStatefulReader(f *testing.F) {
f.Fuzz(func(t *testing.T, content []byte) {
t.Logf("content=%q", content)
var file diskio.File[int64] = byteReaderWithName{
Reader: bytes.NewReader(content),
name: t.Name(),
}
reader := diskio.NewStatefulFile[int64](file)
if err := iotest.TestReader(reader, content); err != nil {
t.Error(err)
}
})
}
func FuzzStatefulBufferedReader(f *testing.F) {
f.Fuzz(func(t *testing.T, content []byte) {
t.Logf("content=%q", content)
var file diskio.File[int64] = byteReaderWithName{
Reader: bytes.NewReader(content),
name: t.Name(),
}
file = diskio.NewBufferedFile[int64](file, 4, 2)
reader := diskio.NewStatefulFile[int64](file)
if err := iotest.TestReader(reader, content); err != nil {
t.Error(err)
}
})
}
|