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

ebpf unit testing -- handle tailcalls and support user-space map emulation #17114

Merged
merged 1 commit into from Sep 2, 2021

Conversation

xinyuannn
Copy link
Contributor

@xinyuannn xinyuannn commented Aug 9, 2021

This is a follow-up PR for #16862. As listed in #16951, this PR gives a demo on how to handle tailcalls and also supports user-space eBPF map emulation which is a part of our fake kernel model library. See the commit message for details.

Signed-off-by: Xinyuan Zhang zhangxinyuan@google.com

@xinyuannn xinyuannn requested review from a team and joamaki August 9, 2021 22:53
@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 9, 2021
@Weil0ng Weil0ng self-requested a review August 9, 2021 22:56
@Weil0ng Weil0ng added release-note/ci This PR makes changes to the CI. and removed dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. labels Aug 9, 2021
@xinyuannn xinyuannn force-pushed the fake-map-and-tailcalls branch 2 times, most recently from 078f1de to a28a9e3 Compare August 10, 2021 03:26
@xinyuannn xinyuannn requested a review from a team as a code owner August 10, 2021 03:26
bpf/tests/drop_test.h Outdated Show resolved Hide resolved
bpf/tests/drop_test.h Outdated Show resolved Hide resolved
bpf/tests/nat_test.h Show resolved Hide resolved
bpf/tests/nat_test.h Outdated Show resolved Hide resolved
@xinyuannn xinyuannn force-pushed the fake-map-and-tailcalls branch 3 times, most recently from a2090fc to 75235fe Compare August 13, 2021 18:12
Copy link
Member

@joestringer joestringer left a comment

Choose a reason for hiding this comment

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

I scanned over the Makefile changes, LGTM.

I'd like for us to figure out at some point how to add new tests without adding a new individual Makefile target each time, but I don't think it's a problem yet. Maybe after a couple more tests we'll have a good set of example commands for the test targets and we can figure out the common pieces & set up a more generic target.

bpf/tests/nat_test.h Outdated Show resolved Hide resolved
@Weil0ng
Copy link
Contributor

Weil0ng commented Aug 23, 2021

test-me-please

Job 'Cilium-PR-K8s-1.19-kernel-5.4' hit: #17069 (92.44% similarity)

Job 'Cilium-PR-K8s-GKE' failed and has not been observed before, so may be related to your PR:

Click to show.

Test Name

K8sDatapathConfig Host firewall With VXLAN

Failure Output

FAIL: Failed to reach 10.128.15.229:80 from testclient-jb9c4

If it is a flake, comment /mlh new-flake Cilium-PR-K8s-GKE so I can create a new GitHub issue to track it.

@Weil0ng
Copy link
Contributor

Weil0ng commented Aug 23, 2021

test-me-please

@Weil0ng Weil0ng added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Aug 24, 2021
@twpayne
Copy link
Contributor

twpayne commented Aug 30, 2021

Could you rebase this on the latest master please?

…ation

This commit contains a demo on how to handle tailcalls and also supports
user-space eBPF map emulation which is a part of our fake kernel model library.

We resolve tailcalls by mocking the tailcall helper function and stubbing a
callback since tailcalls are achieved by the tailcall helper function. In this
way, the callback will be called instead whenever the tailcall helper function
is encountered.

We also provide a library to support user-space map emulation. Since eBPF maps
are maintained by the kernel, we do not actually know if the map operations are
safe or not without testing in the actual kernel. Considering that eBPF maps
are actually hashmaps, we create a user-space hashmap and emulate the eBPF map
operations in the user space via callbacks.

new file:
bpf/mock/fake_maps.h: wrap up raw hashmap operations.
bpf/tests/drop_notify_test.h: include a demo test showing how to handle
tailcalls
test/bpf/drop_notify_test.c: contains main function to run test functions in drop_notify_test.h

modified:
bpf/mock/Dockerfile: add hashmap library
bpf/tests/nat_test.h: add a demo test showing how to use user-space map emulation
test/bpf/nat-test.c: add the new test in bpf/tests/nat_test.h into main
function
bpf/mock/Makefile: put all the generated files into folder "mocks" for
later cleaning
bpf/mock/mock_helpers.sh: put all the generated files into folder "mocks" for
later cleaning
test/bpf/Makefile: clean bpf/mock/mocks

Signed-off-by: Xinyuan Zhang <zhangxinyuan@google.com>
@xinyuannn
Copy link
Contributor Author

Could you rebase this on the latest master please?

Done!

@aditighag aditighag merged commit ffd050f into cilium:master Sep 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

None yet

8 participants