Skip to content

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

Merged
aditighag merged 1 commit intocilium:masterfrom
xinyuanzzz:fake-map-and-tailcalls
Sep 2, 2021
Merged

ebpf unit testing -- handle tailcalls and support user-space map emulation#17114
aditighag merged 1 commit intocilium:masterfrom
xinyuanzzz:fake-map-and-tailcalls

Conversation

@xinyuanzzz
Copy link
Copy Markdown
Contributor

@xinyuanzzz xinyuanzzz 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

@xinyuanzzz xinyuanzzz 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 requested review from borkmann, brb and joestringer August 9, 2021 22:56
@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
@xinyuanzzz xinyuanzzz force-pushed the fake-map-and-tailcalls branch 2 times, most recently from 078f1de to a28a9e3 Compare August 10, 2021 03:26
@xinyuanzzz xinyuanzzz requested a review from a team as a code owner August 10, 2021 03:26
@xinyuanzzz xinyuanzzz force-pushed the fake-map-and-tailcalls branch 3 times, most recently from a2090fc to 75235fe Compare August 13, 2021 18:12
Copy link
Copy Markdown
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.

@xinyuanzzz xinyuanzzz force-pushed the fake-map-and-tailcalls branch from 966d5a0 to d0581f6 Compare August 23, 2021 17:48
@Weil0ng
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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>
@xinyuanzzz xinyuanzzz force-pushed the fake-map-and-tailcalls branch from da44481 to 54f3c15 Compare August 31, 2021 02:09
@xinyuanzzz
Copy link
Copy Markdown
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.

8 participants