bpf: fix: Simplify and fix test structure validation logic #41139
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 forprogs.checkProg
until after the first pass. Just ensure uniqueness of each setup/pktgen/check program along the way withcheckProgUnique
. Before, the logic would not catch if a check is not defined for a test until later when a panic occurs, sinceprogs.checkProg
would be nil, but now existence of aCHECK
program is enforced.Before
If
CHECK
was not defined.After
If
CHECK
was not defined.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 withnat4_port_allocation
where the test name in theCHECK
for thenat4_port_allocation_tcp
andnat4_port_allocation_udp
tests was wrong, so fix this.