-
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fuzzing] Fix oss-fuzz build and use a different file for benchmark t…
…esting Signed-off-by: Arjun Singh <ajsinghyadav00@gmail.com>
- Loading branch information
Showing
8 changed files
with
151 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package message | ||
|
||
import "testing" | ||
|
||
func BenchmarkPathOption(b *testing.B) { | ||
buf := make([]byte, 256) | ||
b.ResetTimer() | ||
for i := uint32(0); i < uint32(b.N); i++ { | ||
options := make(Options, 0, 10) | ||
path := "a/b/c" | ||
|
||
options, bufLen, err := options.SetPath(buf, path) | ||
if err != nil { | ||
b.Fatalf("unexpected error %d", err) | ||
} | ||
if bufLen != 3 { | ||
b.Fatalf("unexpected length %d", bufLen) | ||
} | ||
|
||
v := make([]string, 3) | ||
n, err := options.GetStrings(URIPath, v) | ||
if n != 3 { | ||
b.Fatalf("bad length") | ||
} | ||
if err != nil { | ||
b.Fatalf("unexpected code") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package coder | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/plgd-dev/go-coap/v3/message" | ||
"github.com/plgd-dev/go-coap/v3/message/codes" | ||
) | ||
|
||
func BenchmarkMarshalMessage(b *testing.B) { | ||
options := make(message.Options, 0, 32) | ||
bufOptions := make([]byte, 1024) | ||
bufOptionsUsed := bufOptions | ||
|
||
enc := 0 | ||
|
||
options, enc, _ = options.SetPath(bufOptionsUsed, "/a/b/c/d/e") | ||
bufOptionsUsed = bufOptionsUsed[enc:] | ||
|
||
options, _, _ = options.SetContentFormat(bufOptionsUsed, message.TextPlain) | ||
msg := message.Message{ | ||
Code: codes.GET, | ||
Payload: []byte{0x1}, | ||
Token: []byte{0x1, 0x2, 0x3}, | ||
Options: options, | ||
} | ||
buffer := make([]byte, 1024) | ||
|
||
b.ResetTimer() | ||
for i := uint32(0); i < uint32(b.N); i++ { | ||
_, err := DefaultCoder.Encode(msg, buffer) | ||
if err != nil { | ||
b.Fatalf("cannot marshal") | ||
} | ||
} | ||
} | ||
|
||
func BenchmarkUnmarshalMessage(b *testing.B) { | ||
buffer := []byte{211, 0, 1, 1, 2, 3, 177, 97, 1, 98, 1, 99, 1, 100, 1, 101, 16, 255, 1} | ||
options := make(message.Options, 0, 32) | ||
msg := message.Message{ | ||
Options: options, | ||
} | ||
|
||
b.ResetTimer() | ||
for i := uint32(0); i < uint32(b.N); i++ { | ||
msg.Options = options | ||
_, err := DefaultCoder.Decode(buffer, &msg) | ||
if err != nil { | ||
b.Fatalf("cannot unmarshal: %v", err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package client | ||
|
||
import "testing" | ||
|
||
func BenchmarkM(b *testing.B) { | ||
m := NewMutexMap() | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
// run uncontended lock/unlock - should be quite fast | ||
m.Lock(i).Unlock() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package coder | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/plgd-dev/go-coap/v3/message" | ||
"github.com/plgd-dev/go-coap/v3/message/codes" | ||
) | ||
|
||
func BenchmarkMarshalMessage(b *testing.B) { | ||
options := make(message.Options, 0, 32) | ||
bufOptions := make([]byte, 1024) | ||
bufOptionsUsed := bufOptions | ||
|
||
enc := 0 | ||
options, enc, _ = options.SetPath(bufOptionsUsed, "/a/b/c/d/e") | ||
bufOptionsUsed = bufOptionsUsed[enc:] | ||
|
||
options, _, _ = options.SetContentFormat(bufOptionsUsed, message.TextPlain) | ||
msg := message.Message{ | ||
Code: codes.GET, | ||
Payload: []byte{0x1}, | ||
Token: []byte{0x1, 0x2, 0x3}, | ||
Options: options, | ||
} | ||
buffer := make([]byte, 1024) | ||
|
||
b.ResetTimer() | ||
for i := uint32(0); i < uint32(b.N); i++ { | ||
_, err := DefaultCoder.Encode(msg, buffer) | ||
if err != nil { | ||
b.Fatalf("cannot marshal") | ||
} | ||
} | ||
} | ||
|
||
func BenchmarkUnmarshalMessage(b *testing.B) { | ||
buffer := []byte{ | ||
0x40, 0x1, 0x30, 0x39, 0x46, 0x77, | ||
0x65, 0x65, 0x74, 0x61, 0x67, 0xa1, 0x3, | ||
0xff, 'h', 'i', | ||
} | ||
options := make(message.Options, 0, 32) | ||
msg := message.Message{ | ||
Options: options, | ||
} | ||
|
||
b.ResetTimer() | ||
for i := uint32(0); i < uint32(b.N); i++ { | ||
msg.Options = options | ||
_, err := DefaultCoder.Decode(buffer, &msg) | ||
if err != nil { | ||
b.Fatalf("cannot unmarshal: %v", err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters