Skip to content
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

Simplify the end-to-end tests harness #170

Merged
merged 2 commits into from
Nov 13, 2024

Conversation

qdeslandes
Copy link
Contributor

Improve the test harness to reduce the boilerplate required to define a new end-to-end test:

  • Automatically define the bf_hook_opts structure, as all the end-to-end test programs should have the same options: do not attach, custom generated name, and a random cgroup/ifindex value.
  • Use bf_test_prog_get() to send the chain to the daemon: all the end-to-end tests defined will send the chain to the daemon and get a reference to the corresponding BPF program. bf_test_prog_get() has been modified to perform those 2 steps at once, as there is no reason for the end-to-end tests to customize this behaviour.

Remove bf_chain_get() and replace it with bf_test_chain_get() which
doesn't allow custom hook options. bf_test_chain_get() will
automatically configure the hook options so the generate BPF program is
not attached and has a name prefixed with `bf_e2e_`.

Because bf_test_chain_get() generates a program name suffixed with
random characters, rand() is used. 2 clang-tidy checks have been
disabled as rand() is not cryptographically secure, but it's fine for
this use case.
bf_test_prog_get() is used to get a reference to a BPF program loaded
into the kernel. The user must call bf_cli_set_chain() beforehand for
bf_test_prog_get() to succeed.

However, end-to-end tests will always perform the same step:
- Call bf_cli_set_chain() to generate and load the BPF program
- Call bf_test_prog_get() to get a reference to the generated program

Modify bf_test_prog_get() to take a chain as parameter and send it to
the daemon, then, returns a reference to the program as a result. This
change reduces the boilerplate required to perform the actual test, and
ensure the user only have access to relevant high-level concepts.
@qdeslandes qdeslandes merged commit 199fc2c into facebook:main Nov 13, 2024
11 checks passed
@qdeslandes qdeslandes deleted the simplify_e2e branch November 13, 2024 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants