Skip to content

bpf: program testing framework

Alexei Starovoitov netdev 2 versions In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest6 patches 11 repliesIn review
  2. v16 patches 11 repliesSuperseded

Changes in v2 from the cover letter

- rename bpf_program_test_run->bpf_prog_test_run
- add missing #include <linux/bpf.h> since libbpf.h shouldn't depend on prior includes
- reordered patches 3 and 4 to keep bisect clean

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6bpf: introduce BPF_PROG_TEST_RUN commandinclude/linux/bpf.h include/uapi/linux/bpf.h kernel/bpf/syscall.c +4 more+223 -33 replies
2/6tools/lib/bpf: add support for BPF_PROG_TEST_RUN commandtools/include/uapi/linux/bpf.h tools/lib/bpf/bpf.c tools/lib/bpf/bpf.h+51 -11 reply
3/6tools/lib/bpf: expose bpf_program__set_type()tools/lib/bpf/libbpf.c tools/lib/bpf/libbpf.h+3 -26 replies
4/6selftests/bpf: add a test for overlapping packet range checkstools/testing/selftests/bpf/Makefile tools/testing/selftests/bpf/test_pkt_access.c tools/testing/selftests/bpf/test_progs.c+215 -40 replies
5/6selftests/bpf: add a test for basic XDP functionalitytools/testing/selftests/bpf/Makefile tools/testing/selftests/bpf/test_iptunnel_common.h tools/testing/selftests/bpf/test_progs.c +1 more+332 -10 replies
6/6selftests/bpf: add l4 load balancer test based on sched_clstools/testing/selftests/bpf/Makefile tools/testing/selftests/bpf/test_l4lb.c tools/testing/selftests/bpf/test_progs.c+563 -10 replies

Reviews trailers per patch

All 6 patches have a Reviewed-by or Acked-by.

PatchDaniel BorkmannMartin KaFai LauWang NanJesper Dangaard Brouer
1/6A-b A-b A-b
2/6A-b A-b A-b
3/6A-b A-b
4/6A-b A-b
5/6A-b A-b
6/6A-b A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v2 thread

Cover letter [PATCH v2 net-next 0/6] bpf: program testing framework

Development and testing of networking bpf programs is quite cumbersome. Especially tricky are XDP programs that attach to real netdevices and program development feels like working on the car engine while the car is in motion.
Another problem is ongoing changes to upstream llvm core that can introduce an optimization that verifier will not recognize. llvm bpf backend tests have no ability to run the programs. To improve this situation introduce BPF_PROG_TEST_RUN command to test and performance benchmark bpf programs.
It achieves several goals:
- development of xdp and skb based bpf programs can be done in a canned environment with unit tests
- program performance optimizations can be benchmarked outside of networking core (without driver and skb costs)
- continuous testing of upstream changes is finally practical

Patches 4,5,6 add C based test cases of various complexity to cover some sched_cls and xdp features. More tests will be added in the future. The tests were run on centos7 only.

For now the framework supports only skb and xdp programs. In the future it can be extended to socket_filter and tracing program types.

More details are in individual patches.

v1->v2:
- rename bpf_program_test_run->bpf_prog_test_run
- add missing #include <linux/bpf.h> since libbpf.h shouldn't depend on prior includes
- reordered patches 3 and 4 to keep bisect clean

Alexei Starovoitov (6):
bpf: introduce BPF_PROG_TEST_RUN command tools/lib/bpf: add support for BPF_PROG_TEST_RUN command tools/lib/bpf: expose bpf_program__set_type() selftests/bpf: add a test for overlapping packet range checks selftests/bpf: add a test for basic XDP functionality selftests/bpf: add l4 load balancer test based on sched_cls

 include/linux/bpf.h                                |   7 +
 include/uapi/linux/bpf.h                           |  12 +
 kernel/bpf/syscall.c                               |  27 +-
 net/Makefile                                       |   2 +-
 net/bpf/Makefile                                   |   1 +
 net/bpf/test_run.c                                 | 172 ++++++++
 net/core/filter.c                                  |   5 +
 tools/include/uapi/linux/bpf.h                     |  24 ++
 tools/lib/bpf/bpf.c                                |  24 ++
 tools/lib/bpf/bpf.h                                |   4 +-
 tools/lib/bpf/libbpf.c                             |   3 +-
 tools/lib/bpf/libbpf.h                             |   2 +
 tools/testing/selftests/bpf/Makefile               |  17 +-
 tools/testing/selftests/bpf/test_iptunnel_common.h |  37 ++
 tools/testing/selftests/bpf/test_l4lb.c            | 474 +++++++++++++++++++++
 tools/testing/selftests/bpf/test_pkt_access.c      |  64 +++
 tools/testing/selftests/bpf/test_progs.c           | 284 ++++++++++++
 tools/testing/selftests/bpf/test_xdp.c             | 236 ++++++++++
 18 files changed, 1385 insertions(+), 10 deletions(-)
 create mode 100644 net/bpf/Makefile
 create mode 100644 net/bpf/test_run.c
 create mode 100644 tools/testing/selftests/bpf/test_iptunnel_common.h
 create mode 100644 tools/testing/selftests/bpf/test_l4lb.c
 create mode 100644 tools/testing/selftests/bpf/test_pkt_access.c
 create mode 100644 tools/testing/selftests/bpf/test_progs.c
 create mode 100644 tools/testing/selftests/bpf/test_xdp.c
Signature · 1 line
2.9.3