ebpf unit testing -- handle tailcalls and support user-space map emulation#17114
Conversation
078f1de to
a28a9e3
Compare
a2090fc to
75235fe
Compare
joestringer
left a comment
There was a problem hiding this comment.
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.
75235fe to
966d5a0
Compare
966d5a0 to
d0581f6
Compare
|
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 NameFailure OutputIf it is a flake, comment |
d0581f6 to
da44481
Compare
|
test-me-please |
|
Could you rebase this on the latest |
…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>
da44481 to
54f3c15
Compare
Done! |
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