add benchmark and fuzz for tests with data

This commit is contained in:
Joel Wetzell
2026-05-30 10:31:37 -05:00
parent 07ff9daf88
commit 37ca97c5ab
5 changed files with 167 additions and 0 deletions
+48
View File
@@ -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)
})
}