-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy patheventqueue_fuzz_test.go
More file actions
54 lines (47 loc) · 1005 Bytes
/
eventqueue_fuzz_test.go
File metadata and controls
54 lines (47 loc) · 1005 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// CGo binding for Avahi
//
// Copyright (C) 2025 by Prashant Andoriya
// See LICENSE for license terms and conditions
//
// Fuzz tests for eventqueue robustness
//
//go:build linux || freebsd
package avahi
import "testing"
// FuzzEventQueueOperations fuzzes combinations of Push, read,
// and Close operations to validate that eventqueue:
//
// - never panics
// - never deadlocks
// - always allows Close() to complete safely
func FuzzEventQueueOperations(f *testing.F) {
// Seed inputs
f.Add(0)
f.Add(1)
f.Add(10)
f.Add(100)
f.Fuzz(func(t *testing.T, n int) {
if n < 0 {
return
}
if n > 1000 {
n = 1000
}
var q eventqueue[int]
q.init()
// Push n values into the queue
for i := 0; i < n; i++ {
q.Push(i)
}
// Drain some values on a best effort basis.
// Partial reads are intentional and valid.
for i := 0; i < n/2; i++ {
select {
case <-q.Chan():
default:
}
}
// Close must always complete without panic or deadlock
q.Close()
})
}