Skip to content

Commit e12cd15

Browse files
qmonnetborkmann
authored andcommitted
selftests/bpf: Configure dir paths via env in test_bpftool_synctypes.py
Script test_bpftool_synctypes.py parses a number of files in the bpftool directory (or even elsewhere in the repo) to make sure that the list of types or options in those different files are consistent. Instead of having fixed paths, let's make the directories configurable through environment variable. This should make easier in the future to run the script in a different setup, for example on an out-of-tree bpftool mirror with a different layout. Signed-off-by: Quentin Monnet <quentin@isovalent.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/20211115225844.33943-4-quentin@isovalent.com
1 parent b623181 commit e12cd15

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

tools/testing/selftests/bpf/test_bpftool_synctypes.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@
99

1010
LINUX_ROOT = os.path.abspath(os.path.join(__file__,
1111
os.pardir, os.pardir, os.pardir, os.pardir, os.pardir))
12-
BPFTOOL_DIR = os.path.join(LINUX_ROOT, 'tools/bpf/bpftool')
12+
BPFTOOL_DIR = os.getenv('BPFTOOL_DIR',
13+
os.path.join(LINUX_ROOT, 'tools/bpf/bpftool'))
14+
BPFTOOL_BASHCOMP_DIR = os.getenv('BPFTOOL_BASHCOMP_DIR',
15+
os.path.join(BPFTOOL_DIR, 'bash-completion'))
16+
BPFTOOL_DOC_DIR = os.getenv('BPFTOOL_DOC_DIR',
17+
os.path.join(BPFTOOL_DIR, 'Documentation'))
18+
INCLUDE_DIR = os.getenv('INCLUDE_DIR',
19+
os.path.join(LINUX_ROOT, 'tools/include'))
20+
1321
retval = 0
1422

1523
class BlockParser(object):
@@ -300,7 +308,7 @@ class ManSubstitutionsExtractor(SourceFileExtractor):
300308
"""
301309
An extractor for substitutions.rst
302310
"""
303-
filename = os.path.join(BPFTOOL_DIR, 'Documentation/substitutions.rst')
311+
filename = os.path.join(BPFTOOL_DOC_DIR, 'substitutions.rst')
304312

305313
def get_common_options(self):
306314
"""
@@ -393,7 +401,7 @@ class BpfHeaderExtractor(FileExtractor):
393401
"""
394402
An extractor for the UAPI BPF header.
395403
"""
396-
filename = os.path.join(LINUX_ROOT, 'tools/include/uapi/linux/bpf.h')
404+
filename = os.path.join(INCLUDE_DIR, 'uapi/linux/bpf.h')
397405

398406
def get_prog_types(self):
399407
return self.get_enum('bpf_prog_type')
@@ -417,7 +425,7 @@ class ManProgExtractor(ManPageExtractor):
417425
"""
418426
An extractor for bpftool-prog.rst.
419427
"""
420-
filename = os.path.join(BPFTOOL_DIR, 'Documentation/bpftool-prog.rst')
428+
filename = os.path.join(BPFTOOL_DOC_DIR, 'bpftool-prog.rst')
421429

422430
def get_attach_types(self):
423431
return self.get_rst_list('ATTACH_TYPE')
@@ -426,7 +434,7 @@ class ManMapExtractor(ManPageExtractor):
426434
"""
427435
An extractor for bpftool-map.rst.
428436
"""
429-
filename = os.path.join(BPFTOOL_DIR, 'Documentation/bpftool-map.rst')
437+
filename = os.path.join(BPFTOOL_DOC_DIR, 'bpftool-map.rst')
430438

431439
def get_map_types(self):
432440
return self.get_rst_list('TYPE')
@@ -435,7 +443,7 @@ class ManCgroupExtractor(ManPageExtractor):
435443
"""
436444
An extractor for bpftool-cgroup.rst.
437445
"""
438-
filename = os.path.join(BPFTOOL_DIR, 'Documentation/bpftool-cgroup.rst')
446+
filename = os.path.join(BPFTOOL_DOC_DIR, 'bpftool-cgroup.rst')
439447

440448
def get_attach_types(self):
441449
return self.get_rst_list('ATTACH_TYPE')
@@ -454,7 +462,7 @@ class BashcompExtractor(FileExtractor):
454462
"""
455463
An extractor for bpftool's bash completion file.
456464
"""
457-
filename = os.path.join(BPFTOOL_DIR, 'bash-completion/bpftool')
465+
filename = os.path.join(BPFTOOL_BASHCOMP_DIR, 'bpftool')
458466

459467
def get_prog_attach_types(self):
460468
return self.get_bashcomp_list('BPFTOOL_PROG_ATTACH_TYPES')
@@ -605,7 +613,7 @@ def main():
605613
help_cmd_options = source_info.get_options()
606614
source_info.close()
607615

608-
man_cmd_info = ManGenericExtractor(os.path.join('Documentation', 'bpftool-' + cmd + '.rst'))
616+
man_cmd_info = ManGenericExtractor(os.path.join(BPFTOOL_DOC_DIR, 'bpftool-' + cmd + '.rst'))
609617
man_cmd_options = man_cmd_info.get_options()
610618
man_cmd_info.close()
611619

@@ -616,7 +624,7 @@ def main():
616624
help_main_options = source_main_info.get_options()
617625
source_main_info.close()
618626

619-
man_main_info = ManGenericExtractor(os.path.join('Documentation', 'bpftool.rst'))
627+
man_main_info = ManGenericExtractor(os.path.join(BPFTOOL_DOC_DIR, 'bpftool.rst'))
620628
man_main_options = man_main_info.get_options()
621629
man_main_info.close()
622630

0 commit comments

Comments
 (0)