File: uncovered-api-functions.py

package info (click to toggle)
cvc5 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 87,260 kB
  • sloc: cpp: 383,850; java: 12,207; python: 12,090; sh: 5,679; ansic: 4,729; lisp: 763; perl: 208; makefile: 38
file content (48 lines) | stat: -rwxr-xr-x 1,501 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3

import json
import re
import subprocess
import sys


def demangle(name):
    """Demangle a C++ symbol using c++filt."""
    pipe = subprocess.Popen(['c++filt', name],
                            stdin=subprocess.PIPE,
                            stdout=subprocess.PIPE)
    stdout, _ = pipe.communicate()
    return stdout.decode().strip()


def get_uncovered(data, file_patterns):
    """Collect all uncovered functions from files matching the given patterns.
       Returns a list of dicts with filename, function and startline."""
    notcovered = []

    for file, fdata in data['sources'].items():
        if all([re.search(f, file) == None for f in file_patterns]):
            continue
        for function, funcdata in fdata['']['functions'].items():
            if funcdata['execution_count'] == 0:
                notcovered.append({
                    'filename': file,
                    'startline': funcdata['start_line'],
                    'function': demangle(function),
                })

    notcovered.sort(key=lambda s: (s['filename'], s['startline']))
    return notcovered


if __name__ == "__main__":
    patterns = ['src/api/cpp/cvc5.*']
    data = json.load(open('coverage.json', 'r'))
    notcovered = get_uncovered(data, patterns)
    for nc in notcovered:
        print('starting in {filename}:{startline}'.format(**nc))
        print('function {function}'.format(**nc))
        print('')
    if notcovered:
        sys.exit(1)
    sys.exit(0)