Skip to content

Conversation

jrife
Copy link
Contributor

@jrife jrife commented Aug 13, 2025

Originally I made this change as part of #40759, but I'm moving it to its own PR, since it seems like a nice standalone fix.

Simplify the logic a bit to get rid of the secondary regex match inside checkProgExists and instead defer the existence check for progs.checkProg until after the first pass. Just ensure uniqueness of each setup/pktgen/check program along the way with checkProgUnique. Before, the logic would not catch if a check is not defined for a test until later when a panic occurs, since progs.checkProg would be nil, but now existence of a CHECK program is enforced.

Before

If CHECK was not defined.

...
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x7db080]

goroutine 844 [running]:
testing.tRunner.func1.2({0x2a02a40, 0x4ef3880})
	/usr/local/go/src/testing/testing.go:1734 +0x21c
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1737 +0x35e
panic({0x2a02a40?, 0x4ef3880?})
	/usr/local/go/src/runtime/panic.go:792 +0x132
github.com/cilium/ebpf.(*Program).Type(0x4e5f5a0?)
	/go/src/github.com/cilium/cilium/vendor/github.com/cilium/ebpf/prog.go:573
github.com/cilium/cilium/bpf/tests/bpftest.loadAndRunSpec.subTest.func4(0xc0007028c0)
	/go/src/github.com/cilium/cilium/bpf/tests/bpftest/bpf_test.go:334 +0x9a
testing.tRunner(0xc0007028c0, 0xc0008eb230)
	/usr/local/go/src/testing/testing.go:1792 +0xf4
created by testing.(*T).Run in goroutine 973
	/usr/local/go/src/testing/testing.go:1851 +0x413
FAIL	github.com/cilium/cilium/bpf/tests/bpftest	8.257s
...

After

If CHECK was not defined.

...
--- FAIL: TestBPF (20.63s)
--- FAIL: TestBPF/skip_tunnel_nodeport_nat.o (0.21s)

    bpf_test.go:224: ... does not contain a check program for the ... test.
...

Don't rely on the program name at all, only the section names. Before, weird edge cases could occur with strings.Replace() if the test program name itself had the words "setup", "pktgen", or "check" in them. This change uncovered the case with nat4_port_allocation where the test name in the CHECK for the nat4_port_allocation_tcp and
nat4_port_allocation_udp tests was wrong, so fix this.

@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Aug 13, 2025
@jrife jrife marked this pull request as ready for review August 13, 2025 20:03
@jrife jrife requested a review from a team as a code owner August 13, 2025 20:03
@jrife jrife requested a review from YutaroHayakawa August 13, 2025 20:03
@jrife jrife force-pushed the jrife/bpf-test-fix branch from cf4d8c2 to 1012556 Compare August 13, 2025 21:15
Simplify the logic a bit to get rid of the secondary regex match inside
checkProgExists and instead defer the existence check for
progs.checkProg until after the first pass. Just ensure uniqueness of
each setup/pktgen/check program along the way with checkProgUnique.
Before, the logic would not catch if a check is not defined for a test
until later when a panic occurs, since progs.checkProg would be nil, but
now existence of a CHECK program is enforced.

BEFORE
======

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x7db080]

goroutine 844 [running]:
testing.tRunner.func1.2({0x2a02a40, 0x4ef3880})
	/usr/local/go/src/testing/testing.go:1734 +0x21c
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1737 +0x35e
panic({0x2a02a40?, 0x4ef3880?})
	/usr/local/go/src/runtime/panic.go:792 +0x132
github.com/cilium/ebpf.(*Program).Type(0x4e5f5a0?)
	/go/src/github.com/cilium/cilium/vendor/github.com/cilium/ebpf/prog.go:573
github.com/cilium/cilium/bpf/tests/bpftest.loadAndRunSpec.subTest.func4(0xc0007028c0)
	/go/src/github.com/cilium/cilium/bpf/tests/bpftest/bpf_test.go:334 +0x9a
testing.tRunner(0xc0007028c0, 0xc0008eb230)
	/usr/local/go/src/testing/testing.go:1792 +0xf4
created by testing.(*T).Run in goroutine 973
	/usr/local/go/src/testing/testing.go:1851 +0x413
FAIL	github.com/cilium/cilium/bpf/tests/bpftest	8.257s

AFTER
=====

--- FAIL: TestBPF (20.63s)
--- FAIL: TestBPF/skip_tunnel_nodeport_nat.o (0.21s)

    bpf_test.go:224: ... does not contain a check program for the ... test.

Don't rely on the program name at all, only the section names. Before,
weird edge cases could occur with strings.Replace() if the test program
name itself had the words "setup", "pktgen", or "check" in them. This
change uncovered the case with nat4_port_allocation where the test name
in the CHECK for the nat4_port_allocation_tcp and
nat4_port_allocation_udp tests was wrong, so fix this.

Signed-off-by: Jordan Rife <jrife@google.com>
@jrife jrife force-pushed the jrife/bpf-test-fix branch from 1012556 to 737ac5a Compare August 14, 2025 14:29
@jrife
Copy link
Contributor Author

jrife commented Aug 14, 2025

/test

Copy link
Member

@pchaigno pchaigno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@pchaigno pchaigno added area/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages. release-note/ci This PR makes changes to the CI. labels Aug 14, 2025
@pchaigno pchaigno removed the request for review from YutaroHayakawa August 14, 2025 21:39
@pchaigno pchaigno enabled auto-merge August 14, 2025 21:39
@pchaigno pchaigno removed the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Aug 14, 2025
@pchaigno pchaigno added this pull request to the merge queue Aug 14, 2025
@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Aug 14, 2025
Merged via the queue into cilium:main with commit 705bbeb Aug 14, 2025
68 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/ci This PR makes changes to the CI.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants