mirror of
https://github.com/jwetzell/osc-go.git
synced 2026-07-26 10:28:42 +00:00
mess around with benchmarks and fuzzing
This commit is contained in:
@@ -210,3 +210,31 @@ func TestBadOSCBundleDecoding(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func FuzzBundleFromBytes(f *testing.F) {
|
||||
seedBytes := [][]byte{
|
||||
{},
|
||||
{35, 98, 117, 110, 100, 108, 101, 0, 0, 0, 0,
|
||||
32, 0, 0, 0, 0, 0, 0, 0, 32, 47, 111,
|
||||
115, 99, 105, 108, 108, 97, 116, 111, 114, 47, 52,
|
||||
47, 102, 114, 101, 113, 117, 101, 110, 99, 121, 0,
|
||||
44, 102, 0, 0, 67, 220, 0, 0},
|
||||
{35, 98, 117, 110, 100, 108, 101, 0, // #bundle
|
||||
0, 0, 0, 32, 0, 0, 0, 0, // time tag
|
||||
0, 0, 0, 52, // content size
|
||||
35, 98, 117, 110, 100, 108, 101, 0, // #bundle
|
||||
0, 0, 0, 64, 0, 0, 0, 0, // time tag
|
||||
0, 0, 0, 32, // content size
|
||||
47, 111, 115, 99, 105, 108, 108, 97, 116, 111, 114, 47, 52,
|
||||
47, 102, 114, 101, 113, 117, 101, 110, 99, 121, 0,
|
||||
44, 102, 0, 0, 67, 220, 0, 0},
|
||||
}
|
||||
|
||||
for _, seed := range seedBytes {
|
||||
f.Add(seed)
|
||||
}
|
||||
|
||||
f.Fuzz(func(t *testing.T, data []byte) {
|
||||
_, _, _ = BundleFromBytes(data)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -511,3 +511,46 @@ func TestBadOSCMessageDecoding(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMessageToBytes(b *testing.B) {
|
||||
message := &OSCMessage{
|
||||
Address: "/hello",
|
||||
Args: []OSCArg{
|
||||
{Type: "i", Value: 35},
|
||||
},
|
||||
}
|
||||
|
||||
for b.Loop() {
|
||||
_, err := message.ToBytes()
|
||||
if err != nil {
|
||||
b.Fatalf("failed to encode properly: %s", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkMessageFromBytes(b *testing.B) {
|
||||
bytes := []byte{47, 104, 101, 108, 108, 111, 0, 0, 44, 105, 0, 0, 0, 0, 0, 35}
|
||||
|
||||
for b.Loop() {
|
||||
_, err := MessageFromBytes(bytes)
|
||||
if err != nil {
|
||||
b.Fatalf("failed to decode properly: %s", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func FuzzMessageFromBytes(f *testing.F) {
|
||||
seedBytes := [][]byte{
|
||||
{},
|
||||
{47, 104, 101, 108, 108, 111, 0, 0},
|
||||
{47, 104, 101, 108, 108, 111, 0, 0, 44, 105, 0, 0, 0, 0, 0, 35},
|
||||
}
|
||||
|
||||
for _, seed := range seedBytes {
|
||||
f.Add(seed)
|
||||
}
|
||||
|
||||
f.Fuzz(func(t *testing.T, data []byte) {
|
||||
_, _ = MessageFromBytes(data)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
go test fuzz v1
|
||||
[]byte("#bundle\x0000000000\x00\x00\x00\x00")
|
||||
@@ -0,0 +1,2 @@
|
||||
go test fuzz v1
|
||||
[]byte("/00\x00,b0\x00\xff000")
|
||||
@@ -0,0 +1,2 @@
|
||||
go test fuzz v1
|
||||
[]byte("/00\x00,b0\x00\x00\x00\x00\x010")
|
||||
@@ -0,0 +1,2 @@
|
||||
go test fuzz v1
|
||||
[]byte("/00\x00,d\x0000000")
|
||||
Reference in New Issue
Block a user