This repository has been archived by the owner on Dec 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
common.go
267 lines (229 loc) · 4.94 KB
/
common.go
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
package tests
import "time"
//----------------------------------------
// Struct types
type EmptyStruct struct {
}
type PrimitivesStruct struct {
Int8 int8
Int16 int16
Int32 int32
Int64 int64
Varint int64 `binary:"varint"`
Int int
Byte byte
Uint8 uint8
Uint16 uint16
Uint32 uint32
Uint64 uint64
Uvarint uint64 `binary:"varint"`
Uint uint
String string
Bytes []byte
Time time.Time
Empty EmptyStruct
}
type ShortArraysStruct struct {
TimeAr [0]time.Time
}
type ArraysStruct struct {
Int8Ar [4]int8
Int16Ar [4]int16
Int32Ar [4]int32
Int64Ar [4]int64
VarintAr [4]int64 `binary:"varint"`
IntAr [4]int
ByteAr [4]byte
Uint8Ar [4]uint8
Uint16Ar [4]uint16
Uint32Ar [4]uint32
Uint64Ar [4]uint64
UvarintAr [4]uint64 `binary:"varint"`
UintAr [4]uint
StringAr [4]string
BytesAr [4][]byte
TimeAr [4]time.Time
EmptyAr [4]EmptyStruct
}
type SlicesStruct struct {
Int8Sl []int8
Int16Sl []int16
Int32Sl []int32
Int64Sl []int64
VarintSl []int64 `binary:"varint"`
IntSl []int
ByteSl []byte
Uint8Sl []uint8
Uint16Sl []uint16
Uint32Sl []uint32
Uint64Sl []uint64
UvarintSl []uint64 `binary:"varint"`
UintSl []uint
StringSl []string
BytesSl [][]byte
TimeSl []time.Time
EmptySl []EmptyStruct
}
type SliceSlicesStruct struct {
Int8SlSl [][]int8
Int16SlSl [][]int16
Int32SlSl [][]int32
Int64SlSl [][]int64
VarintSlSl [][]int64 `binary:"varint"`
IntSlSl [][]int
ByteSlSl [][]byte
Uint8SlSl [][]uint8
Uint16SlSl [][]uint16
Uint32SlSl [][]uint32
Uint64SlSl [][]uint64
UvarintSlSl [][]uint64 `binary:"varint"`
UintSlSl [][]uint
StringSlSl [][]string
BytesSlSl [][][]byte
TimeSlSl [][]time.Time
EmptySlSl [][]EmptyStruct
}
type PointersStruct struct {
Int8Pt *int8
Int16Pt *int16
Int32Pt *int32
Int64Pt *int64
VarintPt *int64 `binary:"varint"`
IntPt *int
BytePt *byte
Uint8Pt *uint8
Uint16Pt *uint16
Uint32Pt *uint32
Uint64Pt *uint64
UvarintPt *uint64 `binary:"varint"`
UintPt *uint
StringPt *string
BytesPt *[]byte
TimePt *time.Time
EmptyPt *EmptyStruct
}
type PointerSlicesStruct struct {
Int8PtSl []*int8
Int16PtSl []*int16
Int32PtSl []*int32
Int64PtSl []*int64
VarintPtSl []*int64 `binary:"varint"`
IntPtSl []*int
BytePtSl []*byte
Uint8PtSl []*uint8
Uint16PtSl []*uint16
Uint32PtSl []*uint32
Uint64PtSl []*uint64
UvarintPtSl []*uint64 `binary:"varint"`
UintPtSl []*uint
StringPtSl []*string
BytesPtSl []*[]byte
TimePtSl []*time.Time
EmptyPtSl []*EmptyStruct
}
// NOTE: See registered fuzz funcs for *byte, **byte, and ***byte.
type NestedPointersStruct struct {
Ptr1 *byte
Ptr2 **byte
Ptr3 ***byte
}
type ComplexSt struct {
PrField PrimitivesStruct
ArField ArraysStruct
SlField SlicesStruct
PtField PointersStruct
}
type EmbeddedSt1 struct {
PrimitivesStruct
}
type EmbeddedSt2 struct {
PrimitivesStruct
ArraysStruct
SlicesStruct
PointersStruct
}
type EmbeddedSt3 struct {
*PrimitivesStruct
*ArraysStruct
*SlicesStruct
*PointersStruct
*EmptyStruct
}
type EmbeddedSt4 struct {
Foo1 int
PrimitivesStruct
Foo2 string
ArraysStructField ArraysStruct
Foo3 []byte
SlicesStruct
Foo4 bool
PointersStructField PointersStruct
Foo5 uint
}
type EmbeddedSt5 struct {
Foo1 int
*PrimitivesStruct
Foo2 string
ArraysStructField *ArraysStruct
Foo3 []byte
*SlicesStruct
Foo4 bool
PointersStructField *PointersStruct
Foo5 uint
}
var StructTypes = []interface{}{
(*EmptyStruct)(nil),
(*PrimitivesStruct)(nil),
(*ShortArraysStruct)(nil),
(*ArraysStruct)(nil),
(*SlicesStruct)(nil),
(*SliceSlicesStruct)(nil),
(*PointersStruct)(nil),
(*PointerSlicesStruct)(nil),
(*NestedPointersStruct)(nil),
(*ComplexSt)(nil),
(*EmbeddedSt1)(nil),
(*EmbeddedSt2)(nil),
(*EmbeddedSt3)(nil),
(*EmbeddedSt4)(nil),
(*EmbeddedSt5)(nil),
}
//----------------------------------------
// Type definition types
type IntDef int
type IntAr [4]int
type IntSl []int
type ByteAr [4]byte
type ByteSl []byte
type PrimitivesStructSl []PrimitivesStruct
type PrimitivesStructDef PrimitivesStruct
var DefTypes = []interface{}{
(*IntDef)(nil),
(*IntAr)(nil),
(*IntSl)(nil),
(*ByteAr)(nil),
(*ByteSl)(nil),
(*PrimitivesStructSl)(nil),
(*PrimitivesStructDef)(nil),
}
//----------------------------------------
// Register/Interface test types
type Interface1 interface {
AssertInterface1()
}
type Interface2 interface {
AssertInterface2()
}
type Concrete1 struct{}
func (_ Concrete1) AssertInterface1() {}
func (_ Concrete1) AssertInterface2() {}
type Concrete2 struct{}
func (_ Concrete2) AssertInterface1() {}
func (_ Concrete2) AssertInterface2() {}
type Concrete3 [4]byte
func (_ Concrete3) AssertInterface1() {}
type InterfaceFieldsStruct struct {
F1 Interface1
F2 Interface1
}
func (_ *InterfaceFieldsStruct) AssertInterface1() {}