Skip to contentSkip to conversation

selftests/bpf: Fix parsing of prog types in UAPI hdr for bpftool sync

PATCH Applied Quentin Monnet 2 participants 2 messages Apr 4, 2022

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/bpf: Fix parsing of prog types in UAPI hdr for bpftool sync

The script for checking that various lists of types in bpftool remain in sync with the UAPI BPF header uses a regex to parse enum bpf_prog_type. If this enum contains a set of values different from the list of program types in bpftool, it complains.

This script should have reported the addition, some time ago, of the new BPF_PROG_TYPE_SYSCALL, which was not reported to bpftool's program types list. It failed to do so, because it failed to parse that new type from the enum. This is because the new value, in the BPF header, has an explicative comment on the same line, and the regex does not support that.

Let's update the script to support parsing enum values when they have comments on the same line.

Cc Andrii Nakryiko <[email protected]>
Cc Milan Landaverde <[email protected]>
---
 tools/testing/selftests/bpf/test_bpftool_synctypes.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/test_bpftool_synctypes.py +1 -1
index 6bf21e47882a..c0e7acd698ed 100755
@@ -180,7 +180,7 @@ class FileExtractor(object):
         @enum_name: name of the enum to parse
         """
         start_marker = re.compile(f'enum {enum_name} {{\n')
-        pattern = re.compile('^\s*(BPF_\w+),?$')
+        pattern = re.compile('^\s*(BPF_\w+),?(\s+/\*.*\*/)?$')
         end_marker = re.compile('^};')
         parser = BlockParser(self.reader)
         parser.search_block(start_marker)
Signature · 1 line
2.32.0
#1 lore raw
This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <[email protected]>:

Quoted 5 lines · On Mon, 4 Apr 2022 15:09:44 +0100 you wrote:

The script for checking that various lists of types in bpftool remain in sync with the UAPI BPF header uses a regex to parse enum bpf_prog_type. If this enum contains a set of values different from the list of program types in bpftool, it complains.

Quoted 8 lines

This script should have reported the addition, some time ago, of the new BPF_PROG_TYPE_SYSCALL, which was not reported to bpftool's program types list. It failed to do so, because it failed to parse that new type from the enum. This is because the new value, in the BPF header, has an explicative comment on the same line, and the regex does not support that.

[...]

Here is the summary with links:
- [bpf-next] selftests/bpf: Fix parsing of prog types in UAPI hdr for bpftool sync

    https://git.kernel.org/bpf/bpf-next/c/4eeebce6ac4a

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html