Skip to content

bpftool, selftests: Add tests for C dump and fix a dropped type

Ihor Solodrai bpf 2 versions – Applied

Status from this message: This series was applied to bpf/bpf-next.git (master)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest6 patches 0 repliesApplied 6/6
  2. v14 patches 8 repliesSuperseded

Changes in v2 from the cover letter

* new patches (#1-#3) introducing compare_text_to_expected() helper and refactoring btf_dump selftests
* bpftool dump selftest compares the output to the expected files exactly (Eduard)
* use VALIDATE_RAW_BTF macro in the new test (Eduard)
* drop v1 patch #4 ("selftests/bpf: Check that sorting preserves types in bpftool dump") as it became unnecessary
* nit in the bpftool fix (Andrii)

Patches in v2 All 6 applied

#Subject and filesSizeRepliesApplied
1/6selftests/bpf: Add compare_text_to_expected() helpertools/testing/selftests/bpf/prog_tests/prog_tests_framework.c tools/testing/selftests/bpf/testing_helpers.c tools/testing/selftests/bpf/testing_helpers.h+69 -00 repliesApplied
2/6selftests/bpf: Modernize btf_dump test scaffoldingtools/testing/selftests/bpf/prog_tests/btf_dump.c+8 -110 repliesApplied
3/6selftests/bpf: Compare btf_dump expected output in-processtools/testing/selftests/bpf/prog_tests/btf_dump.c+82 -300 repliesApplied
4/6selftests/bpf: NUL-terminate bpftool command outputtools/testing/selftests/bpf/bpftool_helpers.c+5 -20 repliesApplied
5/6selftests/bpf: Add tests for bpftool btf dump format ctools/testing/selftests/bpf/Makefile tools/testing/selftests/bpf/bpftool_btf_dump_sorted.expected tools/testing/selftests/bpf/bpftool_btf_dump_unsorted.expected +1 more+276 -20 repliesApplied
6/6bpftool: Don't drop a type in the sorted C dumptools/bpf/bpftool/btf.c tools/testing/selftests/bpf/bpftool_btf_dump_sorted.expected+9 -10 repliesApplied

Reviews trailers per patch

2 of 6 patches have a Reviewed-by or Acked-by.

PatchEduard Zingerman
1/6
2/6
3/6
4/6A-b
5/6
6/6A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH bpf-next v2 0/6] bpftool, selftests: Add tests for C dump and fix a dropped type

"bpftool btf dump format c" generates the vmlinux.h that BPF programs are built against, and it has no direct test coverage. Building against the header is not a substitute for testing it, nothing a compiler accepts would break the build.

Add selftests targeting C dump in particular.

While we are here, refactor btf_dump selftests to use a new compare_text_to_expected() helper and become more efficient.

Fix a bug in bpftool dump that dropped a type when sorting.

---

v1->v2:
* new patches (#1-#3) introducing compare_text_to_expected() helper and refactoring btf_dump selftests
* bpftool dump selftest compares the output to the expected files exactly (Eduard)
* use VALIDATE_RAW_BTF macro in the new test (Eduard)
* drop v1 patch #4 ("selftests/bpf: Check that sorting preserves types in bpftool dump") as it became unnecessary
* nit in the bpftool fix (Andrii)

v1: https://lore.kernel.org/bpf/[email protected]/

---

Ihor Solodrai (6):
selftests/bpf: Add compare_text_to_expected() helper selftests/bpf: Modernize btf_dump test scaffolding selftests/bpf: Compare btf_dump expected output in-process selftests/bpf: NUL-terminate bpftool command output selftests/bpf: Add tests for bpftool btf dump format c
bpftool: Don't drop a type in the sorted C dump

 tools/bpf/bpftool/btf.c                       |   6 +-
 tools/testing/selftests/bpf/Makefile          |   8 +-
 .../bpf/bpftool_btf_dump_sorted.expected      |  48 +++++
 .../bpf/bpftool_btf_dump_unsorted.expected    |  48 +++++
 tools/testing/selftests/bpf/bpftool_helpers.c |   7 +-
 .../bpf/prog_tests/bpftool_btf_dump.c         | 178 ++++++++++++++++++
 .../selftests/bpf/prog_tests/btf_dump.c       | 125 ++++++++----
 .../bpf/prog_tests/prog_tests_framework.c     |  23 +++
 tools/testing/selftests/bpf/testing_helpers.c |  43 +++++
 tools/testing/selftests/bpf/testing_helpers.h |   3 +
 10 files changed, 446 insertions(+), 43 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/bpftool_btf_dump_sorted.expected
 create mode 100644 tools/testing/selftests/bpf/bpftool_btf_dump_unsorted.expected
 create mode 100644 tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c

base-commit: cd35e1b10182c42b4ae31ee49119463b17d8ba7f

Signature · 1 line
2.55.0