Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fuzzing queue.go #165

Merged
merged 8 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: ["ubuntu-latest", "macOS-latest"]
go: ["1.17.x", "1.18.x", "1.19.x"]
go: ["1.18.x", "1.19.x"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ site

# Test binary, built with `go test -c`
*.test
testdata

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
Expand All @@ -29,4 +30,4 @@ data/
# docker genesis documents
testnet/conf/node*/config/genesis.json

plugin/ops/__pycache__
plugin/ops/__pycache__
67 changes: 66 additions & 1 deletion client/queue_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package client

import (
"testing"
"sync"

"github.com/katzenpost/client/constants"
"github.com/stretchr/testify/assert"
"testing"
)

type foo struct {
Expand Down Expand Up @@ -39,3 +41,66 @@ func TestQueue(t *testing.T) {
_, err = q.Pop()
assert.Error(err)
}

func FuzzQueue(f *testing.F) {
f.Fuzz(func(t *testing.T, _, s string) {
q := new(Queue)
t.Log("Pushing", s)
err := q.Push(foo{s})
if err != nil {
t.Errorf("Push %v %v", s, err)
}
item, err := q.Pop()
if err != nil {
t.Errorf("Pop %v %v %v", s, item, err)
}
})
}

func FuzzQueuePushSerial(f *testing.F) {
f.Fuzz(func(t *testing.T, i int, s string) {
q := new(Queue)
if i > constants.MaxEgressQueueSize {
return
}
for j := 0; j < i; j++ {
t.Log("Pushing", s)
err := q.Push(foo{s})
if err != nil {
t.Errorf("Push %v %v", s, err)
}
}
})
}

func FuzzQueuePushParalell(f *testing.F) {
f.Add(1, "abcde")
f.Add(1, "")
f.Add(1, string([]byte{0x00}))
f.Fuzz(func(t *testing.T, i int, s string) {
q := new(Queue)
if i > constants.MaxEgressQueueSize {
return
}
if i < 0 {
return
}
t.Logf("Pushing '%v' for %v times", s, i)
var wg sync.WaitGroup
for j := 0; j < i; j++ {
t.Log("Pushing", s)
wg.Add(1)
go func(wg *sync.WaitGroup, s string, q *Queue, t *testing.T) {
defer wg.Done()
err := q.Push(foo{s})
if err != nil {
t.Errorf("Push %v %v", s, err)
}
}(&wg, s, q, t)
}
wg.Wait()
if q.len != i {
t.Errorf("Expected len: %v, actual %v", i, q.len)
}
})
}