mirror of
https://github.com/jwetzell/artnet-go.git
synced 2026-08-20 06:08:59 +00:00
add benchmark and fuzz for tests with data
This commit is contained in:
@@ -52,3 +52,51 @@ func TestGoodArtIpProgUnmarshal(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkArtIpProgUnmarshalBinary(b *testing.B) {
|
||||
data := []byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0xf8, 0x00, 0x0e, 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.ArtIpProg{}
|
||||
|
||||
err := got.UnmarshalBinary(data)
|
||||
if err != nil {
|
||||
b.Fatalf("failed to decode ArtIpProg: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkArtIpProgMarshalBinary(b *testing.B) {
|
||||
data := artnet.ArtIpProg{
|
||||
Command: 0x00,
|
||||
ProgIpHi: 0x00,
|
||||
ProgIp2: 0x00,
|
||||
ProgIp1: 0x00,
|
||||
ProgIpLo: 0x00,
|
||||
ProgSmHi: 0x00,
|
||||
ProgSm2: 0x00,
|
||||
ProgSm1: 0x00,
|
||||
ProgSmLo: 0x00,
|
||||
ProgPortHi: 0x00,
|
||||
ProgPortLo: 0x00,
|
||||
ProgDgHi: 0x00,
|
||||
ProgDg2: 0x00,
|
||||
ProgDg1: 0x00,
|
||||
ProgDgLo: 0x00,
|
||||
}
|
||||
|
||||
for b.Loop() {
|
||||
_, err := data.MarshalBinary()
|
||||
if err != nil {
|
||||
b.Fatalf("failed to encode ArtIpProg: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func FuzzArtIpProgUnmarshalBinary(f *testing.F) {
|
||||
f.Add([]byte{0x41, 0x72, 0x74, 0x2d, 0x4e, 0x65, 0x74, 0x00, 0x00, 0xf8, 0x00, 0x0e, 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) {
|
||||
artIpProg := artnet.ArtIpProg{}
|
||||
artIpProg.UnmarshalBinary(data)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user