]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/bpf: Clear out Python syntax warnings
authorAriel Otilibili <ariel.otilibili-anieli@eurecom.fr>
Wed, 11 Dec 2024 21:57:29 +0000 (22:57 +0100)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 20 Dec 2024 16:55:30 +0000 (17:55 +0100)
Invalid escape sequences are used, and produced syntax warnings:

  $ test_bpftool_synctypes.py
  test_bpftool_synctypes.py:69: SyntaxWarning: invalid escape sequence '\['
    self.start_marker = re.compile(f'(static )?const bool {self.array_name}\[.*\] = {{\n')
  test_bpftool_synctypes.py:83: SyntaxWarning: invalid escape sequence '\['
    pattern = re.compile('\[(BPF_\w*)\]\s*= (true|false),?$')
  test_bpftool_synctypes.py:181: SyntaxWarning: invalid escape sequence '\s'
    pattern = re.compile('^\s*(BPF_\w+),?(\s+/\*.*\*/)?$')
  test_bpftool_synctypes.py:229: SyntaxWarning: invalid escape sequence '\*'
    start_marker = re.compile(f'\*{block_name}\* := {{')
  test_bpftool_synctypes.py:229: SyntaxWarning: invalid escape sequence '\*'
    start_marker = re.compile(f'\*{block_name}\* := {{')
  test_bpftool_synctypes.py:230: SyntaxWarning: invalid escape sequence '\*'
    pattern = re.compile('\*\*([\w/-]+)\*\*')
  test_bpftool_synctypes.py:248: SyntaxWarning: invalid escape sequence '\s'
    start_marker = re.compile(f'"\s*{block_name} := {{')
  test_bpftool_synctypes.py:249: SyntaxWarning: invalid escape sequence '\w'
    pattern = re.compile('([\w/]+) [|}]')
  test_bpftool_synctypes.py:267: SyntaxWarning: invalid escape sequence '\s'
    start_marker = re.compile(f'"\s*{macro}\s*" [|}}]')
  test_bpftool_synctypes.py:267: SyntaxWarning: invalid escape sequence '\s'
    start_marker = re.compile(f'"\s*{macro}\s*" [|}}]')
  test_bpftool_synctypes.py:268: SyntaxWarning: invalid escape sequence '\w'
    pattern = re.compile('([\w-]+) ?(?:\||}[ }\]])')
  test_bpftool_synctypes.py:287: SyntaxWarning: invalid escape sequence '\w'
    pattern = re.compile('(?:.*=\')?([\w/]+)')
  test_bpftool_synctypes.py:319: SyntaxWarning: invalid escape sequence '\w'
    pattern = re.compile('([\w-]+) ?(?:\||}[ }\]"])')
  test_bpftool_synctypes.py:341: SyntaxWarning: invalid escape sequence '\|'
    start_marker = re.compile('\|COMMON_OPTIONS\| replace:: {')
  test_bpftool_synctypes.py:342: SyntaxWarning: invalid escape sequence '\*'
    pattern = re.compile('\*\*([\w/-]+)\*\*')

Escaping them clears out the warnings.

  $ tools/testing/selftests/bpf/test_bpftool_synctypes.py; echo $?
  0

Signed-off-by: Ariel Otilibili <ariel.otilibili-anieli@eurecom.fr>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Tested-by: Quentin Monnet <qmo@kernel.org>
Reviewed-by: Quentin Monnet <qmo@kernel.org>
Link: https://docs.python.org/3/library/re.html
Link: https://lore.kernel.org/bpf/20241211220012.714055-2-ariel.otilibili-anieli@eurecom.fr
tools/testing/selftests/bpf/test_bpftool_synctypes.py

index 0ed67b6b31dd0231ec8a9b3baf583b562aac80c3..238121fda5b673918e7cbb91e70592ff12d054ca 100755 (executable)
@@ -66,7 +66,7 @@ class ArrayParser(BlockParser):
 
     def __init__(self, reader, array_name):
         self.array_name = array_name
-        self.start_marker = re.compile(f'(static )?const bool {self.array_name}\[.*\] = {{\n')
+        self.start_marker = re.compile(fr'(static )?const bool {self.array_name}\[.*\] = {{\n')
         super().__init__(reader)
 
     def search_block(self):
@@ -80,7 +80,7 @@ class ArrayParser(BlockParser):
         Parse a block and return data as a dictionary. Items to extract must be
         on separate lines in the file.
         """
-        pattern = re.compile('\[(BPF_\w*)\]\s*= (true|false),?$')
+        pattern = re.compile(r'\[(BPF_\w*)\]\s*= (true|false),?$')
         entries = set()
         while True:
             line = self.reader.readline()
@@ -178,7 +178,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+),?(\s+/\*.*\*/)?$')
+        pattern = re.compile(r'^\s*(BPF_\w+),?(\s+/\*.*\*/)?$')
         end_marker = re.compile('^};')
         parser = BlockParser(self.reader)
         parser.search_block(start_marker)
@@ -226,8 +226,8 @@ class FileExtractor(object):
 
         @block_name: name of the blog to parse, 'TYPE' in the example
         """
-        start_marker = re.compile(f'\*{block_name}\* := {{')
-        pattern = re.compile('\*\*([\w/-]+)\*\*')
+        start_marker = re.compile(fr'\*{block_name}\* := {{')
+        pattern = re.compile(r'\*\*([\w/-]+)\*\*')
         end_marker = re.compile('}\n')
         return self.__get_description_list(start_marker, pattern, end_marker)
 
@@ -245,8 +245,8 @@ class FileExtractor(object):
 
         @block_name: name of the blog to parse, 'TYPE' in the example
         """
-        start_marker = re.compile(f'"\s*{block_name} := {{')
-        pattern = re.compile('([\w/]+) [|}]')
+        start_marker = re.compile(fr'"\s*{block_name} := {{')
+        pattern = re.compile(r'([\w/]+) [|}]')
         end_marker = re.compile('}')
         return self.__get_description_list(start_marker, pattern, end_marker)
 
@@ -264,8 +264,8 @@ class FileExtractor(object):
 
         @macro: macro starting the block, 'HELP_SPEC_OPTIONS' in the example
         """
-        start_marker = re.compile(f'"\s*{macro}\s*" [|}}]')
-        pattern = re.compile('([\w-]+) ?(?:\||}[ }\]])')
+        start_marker = re.compile(fr'"\s*{macro}\s*" [|}}]')
+        pattern = re.compile(r'([\w-]+) ?(?:\||}[ }\]])')
         end_marker = re.compile('}\\\\n')
         return self.__get_description_list(start_marker, pattern, end_marker)
 
@@ -283,8 +283,8 @@ class FileExtractor(object):
 
         @block_name: name of the blog to parse, 'TYPE' in the example
         """
-        start_marker = re.compile(f'local {block_name}=\'')
-        pattern = re.compile('(?:.*=\')?([\w/]+)')
+        start_marker = re.compile(fr'local {block_name}=\'')
+        pattern = re.compile(r'(?:.*=\')?([\w/]+)')
         end_marker = re.compile('\'$')
         return self.__get_description_list(start_marker, pattern, end_marker)
 
@@ -316,7 +316,7 @@ class MainHeaderFileExtractor(SourceFileExtractor):
             {'-p', '-d', '--pretty', '--debug', '--json', '-j'}
         """
         start_marker = re.compile(f'"OPTIONS :=')
-        pattern = re.compile('([\w-]+) ?(?:\||}[ }\]"])')
+        pattern = re.compile(r'([\w-]+) ?(?:\||}[ }\]"])')
         end_marker = re.compile('#define')
 
         parser = InlineListParser(self.reader)
@@ -338,8 +338,8 @@ class ManSubstitutionsExtractor(SourceFileExtractor):
 
             {'-p', '-d', '--pretty', '--debug', '--json', '-j'}
         """
-        start_marker = re.compile('\|COMMON_OPTIONS\| replace:: {')
-        pattern = re.compile('\*\*([\w/-]+)\*\*')
+        start_marker = re.compile(r'\|COMMON_OPTIONS\| replace:: {')
+        pattern = re.compile(r'\*\*([\w/-]+)\*\*')
         end_marker = re.compile('}$')
 
         parser = InlineListParser(self.reader)