celbpf randomized testing - #5362
Open
kkourt wants to merge 9 commits into
Open
Conversation
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>
✅ Deploy Preview for tetragon ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR implements randomized testing for
celbpfexpressions.There are two functionalities needed for this:
See commits for details.
The PR also fixes a minor issue that was discovered using this randomized testing.