Debian Codegraph @

simd/fuzz_test.go

raw symbols SCIP
1 package simdscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/
2
3 import (
4 "bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/"
5 "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/"
6 )
7
8 // Fuzz targets comparing every search function against the scalar
9 // references from the unit tests. The seeds cover the known traps (SWAR
10 // borrow adjacency, high-bit bytes on signed vector compares, vector-tail
11 // boundaries); go test runs the seeds as regular tests, go test -fuzz
12 // explores beyond them.
13
14 func FuzzMemchr2scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/FuzzMemchr2().(f *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Fscip-go gomod github.com/golang/go/src go1.25.0 testing/F#) {
15 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().([]byte("hello world"), byte('o'), byte('w'))
16 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().([]byte{0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01}, byte(0), byte(2))
17 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().(bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 bytes/Repeat().([]byte{'x'}, 65), byte('a'), byte('x'))
18 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().([]byte{}, byte(0), byte(0))
19 f.Fuzzscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Fuzz().(func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#, h []byte, a, b byte) {
20 want := refMemchr2scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/refMemchr2().(h, a, b)
21 if got := Memchr2scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/Memchr2().(h, a, b); got != want {
22 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Memchr2(%q, %#x, %#x) = %d, want %d", h, a, b, got, want)
23 }
24 if got := memchr2Genericscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/memchr2Generic().(h, a, b); got != want {
25 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("memchr2Generic(%q, %#x, %#x) = %d, want %d", h, a, b, got, want)
26 }
27 })
28 }
29
30 func FuzzMemchr3scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/FuzzMemchr3().(f *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Fscip-go gomod github.com/golang/go/src go1.25.0 testing/F#) {
31 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().([]byte("hello\tworld\nfoo"), byte(' '), byte('\t'), byte('\n'))
32 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().([]byte{0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01}, byte(0), byte(2), byte(3))
33 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().(bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 bytes/Repeat().([]byte{0xff}, 40), byte(0x80), byte(0xfe), byte(0xff))
34 f.Fuzzscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Fuzz().(func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#, h []byte, a, b, c byte) {
35 want := refMemchr3scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/refMemchr3().(h, a, b, c)
36 if got := Memchr3scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/Memchr3().(h, a, b, c); got != want {
37 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Memchr3(%q, %#x, %#x, %#x) = %d, want %d", h, a, b, c, got, want)
38 }
39 if got := memchr3Genericscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/memchr3Generic().(h, a, b, c); got != want {
40 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("memchr3Generic(%q, %#x, %#x, %#x) = %d, want %d", h, a, b, c, got, want)
41 }
42 })
43 }
44
45 func FuzzMemchrPairscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/FuzzMemchrPair().(f *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Fscip-go gomod github.com/golang/go/src go1.25.0 testing/F#) {
46 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().([]byte("hello example world"), byte('e'), byte('x'), 1)
47 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().([]byte{0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01}, byte(1), byte(0), 1)
48 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().(bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 bytes/Repeat().([]byte{'a'}, 100), byte('a'), byte('a'), 33)
49 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().([]byte("abc"), byte('a'), byte('b'), -1)
50 f.Fuzzscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Fuzz().(func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#, h []byte, b1, b2 byte, offset int) {
51 if offset > len(h) {
52 offset %= len(h) + 1 // keep the search space interesting
53 }
54 want := refMemchrPairscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/refMemchrPair().(h, b1, b2, offset)
55 if offset == 0 && b1 != b2 {
56 want = -1 // same position cannot hold two different bytes
57 }
58 if got := MemchrPairscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/MemchrPair().(h, b1, b2, offset); got != want {
59 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("MemchrPair(%q, %#x, %#x, %d) = %d, want %d", h, b1, b2, offset, got, want)
60 }
61 // Pin the SWAR fallback directly: through the exported function it
62 // is only reachable below the AVX2 dispatch length on amd64 hosts.
63 if offset >= 1 && len(h) > offset {
64 if got := memchrPairGenericscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/memchrPairGeneric().(h, b1, b2, offset); got != want {
65 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("memchrPairGeneric(%q, %#x, %#x, %d) = %d, want %d", h, b1, b2, offset, got, want)
66 }
67 }
68 })
69 }
70
71 func FuzzMemmemscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/FuzzMemmem().(f *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Fscip-go gomod github.com/golang/go/src go1.25.0 testing/F#) {
72 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().([]byte("hello world"), []byte("world"))
73 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().(bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 bytes/Repeat().([]byte("ab"), 100), []byte("aba"))
74 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().(bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 bytes/Repeat().([]byte{'a'}, 200), []byte("aab"))
75 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().([]byte{}, []byte{})
76 // Miss-budget handover seeds: every position is an anchor and the
77 // needle keeps mismatching, so memmemSingle (all-'z' needle) and
78 // memmemPaired ('zqe' over dense false pairs) both reach
79 // memmemFallback from the seed corpus alone — with the match absent
80 // and with it found only by the fallback.
81 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().(bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 bytes/Repeat().([]byte{'z'}, 200), append(bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 bytes/Repeat().([]byte{'z'}, 30), 'b'))
82 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().(bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 bytes/Repeat().([]byte("zqf"), 40), []byte("zqe"))
83 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().(append(bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 bytes/Repeat().([]byte("zqf"), 40), 'z', 'q', 'e'), []byte("zqe"))
84 f.Fuzzscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Fuzz().(func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#, h, needle []byte) {
85 want := bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Indexscip-go gomod github.com/golang/go/src go1.25.0 bytes/Index().(h, needle)
86 if got := Memmemscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/Memmem().(h, needle); got != want {
87 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("Memmem(%q, %q) = %d, want %d", h, needle, got, want)
88 }
89 // Drive the prefilter helpers directly so they are fuzzed even
90 // where Memmem's routing (no AVX2, sub-128B haystack) would skip
91 // them; both are pure Go and must match bytes.Index everywhere.
92 if len(needle) >= 2 && len(h) >= len(needle) {
93 info := SelectRareBytesscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/SelectRareBytes().(needle)
94 if got := memmemSinglescip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/memmemSingle().(h, needle, info.Byte1scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/RareByteInfo#Byte1., info.Index1scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/RareByteInfo#Index1.); got != want {
95 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("memmemSingle(%q, %q) = %d, want %d", h, needle, got, want)
96 }
97 if info.Byte1scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/RareByteInfo#Byte1. != info.Byte2scip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/RareByteInfo#Byte2. {
98 if got := memmemPairedscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/memmemPaired().(h, needle, info); got != want {
99 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("memmemPaired(%q, %q) = %d, want %d", h, needle, got, want)
100 }
101 }
102 }
103 })
104 }
105
106 func FuzzIsASCIIscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/FuzzIsASCII().(f *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Fscip-go gomod github.com/golang/go/src go1.25.0 testing/F#) {
107 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().([]byte("hello world"))
108 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().([]byte("h\xc3\xa9llo"))
109 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().(bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 bytes/Repeat().([]byte{0x7f}, 64))
110 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().(append(bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 bytes/Repeat().([]byte{'a'}, 63), 0x80))
111 f.Fuzzscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Fuzz().(func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#, h []byte) {
112 want := refIsASCIIscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/refIsASCII().(h)
113 if got := IsASCIIscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/IsASCII().(h); got != want {
114 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("IsASCII(%q) = %v, want %v", h, got, want)
115 }
116 if got := isASCIIGenericscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/isASCIIGeneric().(h); got != want {
117 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("isASCIIGeneric(%q) = %v, want %v", h, got, want)
118 }
119 // Check the index itself, not just its sign: the AVX2 kernel
120 // locates the byte by re-extracting four per-vector masks in
121 // address order, so a transposed arm returns a wrong-but-positive
122 // index that a consistency check with IsASCII cannot see.
123 wantFirst := refFirstNonASCIIscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/refFirstNonASCII().(h)
124 if got := FirstNonASCIIscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/FirstNonASCII().(h); got != wantFirst {
125 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("FirstNonASCII(%q) = %d, want %d", h, got, wantFirst)
126 }
127 if got := firstNonASCIIGenericscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/firstNonASCIIGeneric().(h); got != wantFirst {
128 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("firstNonASCIIGeneric(%q) = %d, want %d", h, got, wantFirst)
129 }
130 wantCount := refCountNonASCIIscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/refCountNonASCII().(h)
131 if got := CountNonASCIIscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/CountNonASCII().(h); got != wantCount {
132 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("CountNonASCII(%q) = %d, want %d", h, got, wantCount)
133 }
134 if got := countNonASCIIGenericscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/countNonASCIIGeneric().(h); got != wantCount {
135 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("countNonASCIIGeneric(%q) = %d, want %d", h, got, wantCount)
136 }
137 })
138 }
139
140 // FuzzMemchrClass covers the \w classifier, which the AVX2 kernels compute
141 // from a hand-built pair of VPSHUFB nibble tables and the fallbacks from
142 // SWAR range masks — two independent derivations of one character class,
143 // so a table nibble that is wrong for some byte value shows up here.
144 func FuzzMemchrClassscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/FuzzMemchrClass().(f *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Fscip-go gomod github.com/golang/go/src go1.25.0 testing/F#) {
145 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().([]byte("hello world"))
146 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().([]byte("________"))
147 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().([]byte("!\"#$%&'()*+,-./:;<=>?@[\\]^`{|}~ "))
148 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().(append(bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 bytes/Repeat().([]byte{'a'}, 63), '.'))
149 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().(append(bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.Repeatscip-go gomod github.com/golang/go/src go1.25.0 bytes/Repeat().([]byte{'.'}, 129), '_'))
150 f.Addscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Add().([]byte{0x2f, 0x30, 0x39, 0x3a, 0x40, 0x41, 0x5a, 0x5b, 0x5e, 0x5f, 0x60, 0x7a, 0x7b, 0x7f, 0x80, 0xff})
151 f.Fuzzscip-go gomod github.com/golang/go/src go1.25.0 testing/F#Fuzz().(func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#, h []byte) {
152 wantWord, wantNot, wantDigit := -1, -1, -1
153 for i, b := range h {
154 if wantWord < 0 && refIsWordscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/refIsWord().(b) {
155 wantWord = i
156 }
157 if wantNot < 0 && !refIsWordscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/refIsWord().(b) {
158 wantNot = i
159 }
160 if wantDigit < 0 && b >= '0' && b <= '9' {
161 wantDigit = i
162 }
163 }
164 if got := MemchrWordscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/MemchrWord().(h); got != wantWord {
165 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("MemchrWord(%q) = %d, want %d", h, got, wantWord)
166 }
167 if got := memchrWordGenericscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/memchrWordGeneric().(h); got != wantWord {
168 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("memchrWordGeneric(%q) = %d, want %d", h, got, wantWord)
169 }
170 if got := MemchrNotWordscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/MemchrNotWord().(h); got != wantNot {
171 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("MemchrNotWord(%q) = %d, want %d", h, got, wantNot)
172 }
173 if got := memchrNotWordGenericscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/memchrNotWordGeneric().(h); got != wantNot {
174 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("memchrNotWordGeneric(%q) = %d, want %d", h, got, wantNot)
175 }
176 if got := MemchrDigitscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/MemchrDigit().(h); got != wantDigit {
177 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("MemchrDigit(%q) = %d, want %d", h, got, wantDigit)
178 }
179 if got := memchrDigitGenericscip-go gomod github.com/gofiber/utils/v2 . `github.com/gofiber/utils/v2/simd`/memchrDigitGeneric().(h); got != wantDigit {
180 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("memchrDigitGeneric(%q) = %d, want %d", h, got, wantDigit)
181 }
182 })
183 }