File: bisect_res.py

package info (click to toggle)
cppcheck 2.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,132 kB
  • sloc: cpp: 268,935; python: 20,890; ansic: 8,090; sh: 1,045; makefile: 1,008; xml: 1,005; cs: 291
file content (68 lines) | stat: -rw-r--r-- 1,872 bytes parent folder | download | duplicates (2)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
import sys

from bisect_common import *

# TODO: detect missing file
def run(cppcheck_path, options):
    cmd = options.split()
    cmd.insert(0, cppcheck_path)
    print('running {}'.format(cppcheck_path))
    with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) as p:
        stdout, stderr = p.communicate()
        rc = p.returncode
    # only 0 and 1 are well-defined in this case
    if rc > 1:
        print('error')
        return None, None, None
    # signals are reported as negative exitcode (e.g. SIGSEGV -> -11)
    if rc < 0:
        print('crash')
        return rc, stderr, stdout
    print('done')
    return rc, stderr, stdout


# TODO: check arguments
bisect_path = sys.argv[1]
options = sys.argv[2]
expected = None
if len(sys.argv) == 4:
    expected = sys.argv[3]
if len(expected) == 0:
    expected = None
if expected is None:
    if '--error-exitcode=1' not in options:
        options += ' --error-exitcode=1'
else:
    if '--error-exitcode=0' not in options:
        options += ' --error-exitcode=0'

try:
    cppcheck_path = build_cppcheck(bisect_path)
except Exception as e:
    # TODO: how to persist this so we don't keep compiling these
    print(e)
    sys.exit(EC_SKIP)

run_ec, run_stderr, run_stdout = run(cppcheck_path, options)

if expected is None:
    print(run_ec)
print(run_stdout)
print(run_stderr)

# if no ec is set we encountered an unexpected error
if run_ec is None:
    sys.exit(EC_SKIP)  # error occurred
elif run_ec < 0:
    sys.exit(EC_BAD) # crash occurred

# check output for expected string
if expected is not None:
    if (expected not in run_stderr) and (expected not in run_stdout):
        sys.exit(EC_BAD)  # output not found occurred

    sys.exit(EC_GOOD)  # output found

sys.exit(run_ec) # return the elapsed time - not a result for bisect