diff options
| author | David Lamparter <equinox@diac24.net> | 2020-03-29 10:22:15 +0200 |
|---|---|---|
| committer | David Lamparter <equinox@diac24.net> | 2020-03-29 10:45:46 +0200 |
| commit | 2537f690c31249ca70395395c4ecc2bcd68333bb (patch) | |
| tree | e23ba9d3677e5fcedb2b3395866918cad7b0d8fe /tools/gcc-plugins/format-test.py | |
| parent | 7ff912069825c0d93ceed8a305f839170d3acca7 (diff) | |
tools/gcc-plugins: add small test for frr-format
Just enough to check that it works.
Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'tools/gcc-plugins/format-test.py')
| -rw-r--r-- | tools/gcc-plugins/format-test.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tools/gcc-plugins/format-test.py b/tools/gcc-plugins/format-test.py new file mode 100644 index 0000000000..cc6ca6100e --- /dev/null +++ b/tools/gcc-plugins/format-test.py @@ -0,0 +1,57 @@ +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) + +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('gcc -Wall -Wextra -Wno-unused -fplugin=./frr-format.so -fno-diagnostics-show-caret -c -o format-test.o format-test.c') + +gcc = subprocess.Popen(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]))) |
