-
Notifications
You must be signed in to change notification settings - Fork 1.6k
felix/bpf/ut: drain shared ring buffer in BPF UT helpers #12515
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,8 +22,6 @@ import ( | |
| "github.com/gopacket/gopacket/layers" | ||
| . "github.com/onsi/gomega" | ||
| log "github.com/sirupsen/logrus" | ||
|
|
||
| "github.com/projectcalico/calico/felix/bpf/ringbuf" | ||
| ) | ||
|
|
||
| const ( | ||
|
|
@@ -42,8 +40,7 @@ func TestRingBufBasic(t *testing.T) { | |
| ipv4 := iphdr.(*layers.IPv4) | ||
| udp := l4.(*layers.UDP) | ||
|
|
||
| rb, err := ringbuf.New(ringBufMap, rbSize) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| rb := newTestRingBuf() | ||
| defer rb.Close() | ||
|
|
||
| // Send a UDP packet and verify the event. | ||
|
|
@@ -98,8 +95,7 @@ func TestRingBufReaderRecovery(t *testing.T) { | |
| _, _, _, _, pktBytes, err := testPacketUDPDefault() | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| rb, err := ringbuf.New(ringBufMap, rbSize) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| rb := newTestRingBuf() | ||
|
|
||
|
Comment on lines
+98
to
99
|
||
| runBpfUnitTest(t, "ringbuf_events.c", func(bpfrun bpfProgRunFn) { | ||
| res, err := bpfrun(pktBytes) | ||
|
|
@@ -114,8 +110,7 @@ func TestRingBufReaderRecovery(t *testing.T) { | |
| // Close the first reader and create a new one on the same map. | ||
| rb.Close() | ||
|
|
||
| rb2, err := ringbuf.New(ringBufMap, rbSize) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| rb2 := newTestRingBuf() | ||
| defer rb2.Close() | ||
|
|
||
| // Send another event — the new reader should pick it up. | ||
|
|
@@ -145,14 +140,11 @@ func TestRingBufFillup(t *testing.T) { | |
| _, _, _, _, pktBytes, err := testPacketUDPDefault() | ||
| Expect(err).NotTo(HaveOccurred()) | ||
|
|
||
| rb, err := ringbuf.New(ringBufMap, rbSize) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| rb := newTestRingBuf() | ||
| defer rb.Close() | ||
|
|
||
| // Drain any leftover events from previous tests and reset the drops map | ||
| // so we start with a completely clean state. | ||
| rb.Drain() | ||
| // Reset the single-entry drops map (struct rb_drops_val = 16 bytes). | ||
| // Reset the single-entry drops map (struct rb_drops_val = 16 bytes) so | ||
| // this test's accounting isn't affected by earlier ring-buffer-full tests. | ||
| k := make([]byte, 4) // key = 0 | ||
| zeroVal := make([]byte, 16) | ||
| err = ringBufDropsMap.Update(k, zeroVal) | ||
|
|
@@ -232,8 +224,7 @@ func TestRingBufMultipleEvents(t *testing.T) { | |
| RegisterTestingT(t) | ||
| hostIP = node1ip | ||
|
|
||
| rb, err := ringbuf.New(ringBufMap, rbSize) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| rb := newTestRingBuf() | ||
| defer rb.Close() | ||
|
|
||
| numEvents := 10 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newTestRingBuf()depends onrbSize, which is currently declared inringbuf_events_test.go, andinitMapsOnce()hard-codes the ring buffer map size as1024*1024. That cross-file coupling makes it easy for these values to drift or for the helper to stop compiling if the constant is moved/guarded by build tags. Consider defining a single shared constant (e.g., inbpf_prog_test.go) and using it both forringbuf.Map(..., size)andringbuf.New(..., size)(and have tests reference that constant).