mirror of
https://github.com/jwetzell/artnet-go.git
synced 2026-08-20 14:18:58 +00:00
add benchmark and fuzz for tests with data
This commit is contained in:
@@ -193,3 +193,39 @@ func TestGoodArtTodRequestUnmarshal(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkArtTodRequestUnmarshalBinary(b *testing.B) {
|
||||
data := []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x80, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
||||
|
||||
for b.Loop() {
|
||||
got := artnet.ArtTodRequest{}
|
||||
|
||||
err := got.UnmarshalBinary(data)
|
||||
if err != nil {
|
||||
b.Fatalf("failed to decode ArtTodRequest: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkArtTodRequestMarshalBinary(b *testing.B) {
|
||||
data := artnet.ArtTodRequest{
|
||||
Command: artnet.TodFull,
|
||||
Net: 0x00,
|
||||
Address: []uint8{0x10},
|
||||
}
|
||||
|
||||
for b.Loop() {
|
||||
_, err := data.MarshalBinary()
|
||||
if err != nil {
|
||||
b.Fatalf("failed to encode ArtTodRequest: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func FuzzArtTodRequestUnmarshalBinary(f *testing.F) {
|
||||
f.Add([]byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x80, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00})
|
||||
f.Fuzz(func(t *testing.T, data []byte) {
|
||||
artTodRequest := artnet.ArtTodRequest{}
|
||||
artTodRequest.UnmarshalBinary(data)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user