diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-09 13:16:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-09 13:16:35 +0000 |
commit | e2bbf175a2184bd76f6c54ccf8456babeb1a46fc (patch) | |
tree | f0b76550d6e6f500ada964a3a4ee933a45e5a6f1 /tools/gcc-plugins/format-test.py | |
parent | Initial commit. (diff) | |
download | frr-e2bbf175a2184bd76f6c54ccf8456babeb1a46fc.tar.xz frr-e2bbf175a2184bd76f6c54ccf8456babeb1a46fc.zip |
Adding upstream version 9.1.upstream/9.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/gcc-plugins/format-test.py')
-rw-r--r-- | tools/gcc-plugins/format-test.py | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tools/gcc-plugins/format-test.py b/tools/gcc-plugins/format-test.py new file mode 100644 index 0000000..ddf71aa --- /dev/null +++ b/tools/gcc-plugins/format-test.py @@ -0,0 +1,74 @@ +import subprocess +import sys +import shlex +import os +import re + +os.environ["LC_ALL"] = "C" +os.environ["LANG"] = "C" +for k in list(os.environ.keys()): + if k.startswith("LC_"): + os.environ.pop(k) + +if len(sys.argv) < 2: + sys.stderr.write("start as format-test.py gcc-123.45 [-options ...]\n") + sys.exit(1) + +c_re = re.compile(r"//\s+(NO)?WARN") +expect = {} +lines = {} + +with open("format-test.c", "r") as fd: + for lno, line in enumerate(fd.readlines(), 1): + lines[lno] = line.strip() + m = c_re.search(line) + if m is None: + continue + if m.group(1) is None: + expect[lno] = "warn" + else: + expect[lno] = "nowarn" + +cmd = shlex.split( + "-Wall -Wextra -Wno-unused -fplugin=./frr-format.so -fno-diagnostics-show-caret -c -o format-test.o format-test.c" +) + +gcc = subprocess.Popen( + sys.argv[1:] + cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE +) +sout, serr = gcc.communicate() +gcc.wait() + +gcclines = serr.decode("UTF-8").splitlines() +line_re = re.compile(r"^format-test\.c:(\d+):(.*)$") +gcc_warns = {} + +for line in gcclines: + if line.find("In function") >= 0: + continue + m = line_re.match(line) + if m is None: + sys.stderr.write("cannot process GCC output: %s\n" % line) + continue + + lno = int(m.group(1)) + gcc_warns.setdefault(lno, []).append(line) + +for lno, val in expect.items(): + if val == "nowarn" and lno in gcc_warns: + sys.stderr.write( + "unexpected gcc warning on line %d:\n\t%s\n\t%s\n" + % (lno, lines[lno], "\n\t".join(gcc_warns[lno])) + ) + if val == "warn" and lno not in gcc_warns: + sys.stderr.write( + "expected warning on line %d but did not get one\n\t%s\n" + % (lno, lines[lno]) + ) + +leftover = set(gcc_warns.keys()) - set(expect.keys()) +for lno in sorted(leftover): + sys.stderr.write( + "unmarked gcc warning on line %d:\n\t%s\n\t%s\n" + % (lno, lines[lno], "\n\t".join(gcc_warns[lno])) + ) |