Skip to content

celbpf randomized testing - #5362

Open
kkourt wants to merge 9 commits into
mainfrom
pr/kkourt/celbpf-randtest
Open

celbpf randomized testing#5362
kkourt wants to merge 9 commits into
mainfrom
pr/kkourt/celbpf-randtest

Conversation

@kkourt

@kkourt kkourt commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

This PR implements randomized testing for celbpf expressions.

There are two functionalities needed for this:

  1. A way to evalute cel expressions in user-space, to act as an oracle
  2. A way to generate random cel expressions

See commits for details.

The PR also fixes a minor issue that was discovered using this randomized testing.

kkourt added 9 commits July 31, 2026 11:26
This commit adds some additional tests for celbpf expressions.

Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
Refactor add/sub overloads to make it easier to support more int types
and operators. It's also helpful for subsequent commits.

Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
This will make it easier to add new int types (e.g., u8, s8, u16, s16)
in the future. This is also helpful for subsequent commits.

Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
These test cases which, specify i) an expression, ii) a set of
arguments, and iii) the expected value, were local to the test function
(TestArgExprs).

Subsequent patches, will introduce an oracle for evaluating these
expressions in user-space so that we can test the code generation of
random expressions against the oracle.

This commit splits the test cases so that they can be used to test the
oracle.

Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
This commit introduces the evalCEL function that evaluates CEL
expressions in user-space. This is meant to be used as an oracle to test
random CEL expressions in a subsequent commit.

AIL: 3 (https://danielmiessler.com/blog/ai-influence-level-ail)

Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
Factor out evalCELBPF so that it can be used for randomized testing.

Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
This commit refactors the definitions of functions and overloads celbpf
supports, so that they can be used to generate random cel expressions.
No functional changes intended.

Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
The idea here is to implement randomized testing for celbpf by
generating  random cel expressions, evaluate them in user-space using
the oracle introduced in the previous commit, and check the result of
the celbpf implementation.

Random CEL expressions are generated using a recursive function
(celExpr), where we provide an operations "budget" and a target type of
the expression.

The algorithm starts with a budget of 4 operations (hardcoded for now),
and requests an expression of type Bool.

On each step of the recursion, we scan the available functions for those
who return the desired type, and select one randomly. This consumes 1
operation from our budget, and then we recurse to generate expressions
for the operands of the selected function.

The recursion ends when we run out of budget, where we generate an
expression based on the available arguments (if they match the type) or
a random literal value.

We use the above random expressions to implement a fuzzing test that
compares the evaluation using BPF and the user-space oracle.

All random choices are, currently, uniform. We might want to revisit
this in the feature. For example, it probably makes sense to frequently generate
boundary argument values so that we reliably test things like
overflows.

Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
The code generator rejected _!=_ operations on boolean values.
Fix it and add a simple test case.

Signed-off-by: Kornilios Kourtis <kornilios@isovalent.com>
@kkourt
kkourt requested a review from a team as a code owner July 31, 2026 09:31
@kkourt
kkourt requested a review from olsajiri July 31, 2026 09:31
@kkourt kkourt added the release-note/ci This PR makes changes to the CI. label Jul 31, 2026
@netlify

netlify Bot commented Jul 31, 2026

Copy link
Copy Markdown

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit e3a1861
🔍 Latest deploy log https://app.netlify.com/projects/tetragon/deploys/6a6c6b70348e1200089f5786
😎 Deploy Preview https://deploy-preview-5362--tetragon.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/ci This PR makes changes to the CI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant