Add fixed-size, process-lifetime counters (received/enqueued/dropped/ drained/dequeued/decoded/decode-errors/reader-errors/canceled) for the process and DNS eBPF event paths, exposed as individually-atomic snapshots. Wire DNSEventCounters and ProcessEventCounters through the perf reader/enqueue/decode loop in daemon/dns and daemon/procmon/ebpf, with a matching ebpf_prog/event_stats.h and a structural eBPF test. Counters hold totals only, never event payloads. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
37 lines
1.2 KiB
Go
37 lines
1.2 KiB
Go
package ebpf
|
|
|
|
import (
|
|
"context"
|
|
"encoding/binary"
|
|
"testing"
|
|
|
|
"github.com/evilsocket/opensnitch/daemon/core"
|
|
)
|
|
|
|
func TestEventProcessWorkerDiagnostics(t *testing.T) {
|
|
oldCtx, oldOrder := ctxTasks, hostByteOrder
|
|
defer func() { ctxTasks = oldCtx; hostByteOrder = oldOrder }()
|
|
ctxTasks = context.Background()
|
|
hostByteOrder = binary.LittleEndian
|
|
before := core.ProcessEventCounters.Snapshot()
|
|
q := make(chan []byte, 2)
|
|
q <- []byte{0}
|
|
q <- make([]byte, binary.Size(execEvent{})) // EVENT_NONE: decode, no process I/O.
|
|
close(q)
|
|
streamEventsWorker(0, q, nil)
|
|
after := core.ProcessEventCounters.Snapshot()
|
|
if after.Dequeued-before.Dequeued != 2 || after.Decoded-before.Decoded != 1 || after.DecodeErrors-before.DecodeErrors != 1 || after.Canceled != before.Canceled {
|
|
t.Fatalf("before=%+v after=%+v", before, after)
|
|
}
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
cancel()
|
|
ctxTasks = ctx
|
|
q = make(chan []byte, 1)
|
|
q <- []byte{0}
|
|
close(q)
|
|
streamEventsWorker(0, q, nil)
|
|
final := core.ProcessEventCounters.Snapshot()
|
|
if final.Canceled-after.Canceled != 1 || final.Dequeued-after.Dequeued != 1 || final.DecodeErrors != after.DecodeErrors {
|
|
t.Fatalf("cancellation: before=%+v after=%+v", after, final)
|
|
}
|
|
}
|