File: bisect_hang.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 (79 lines) | stat: -rw-r--r-- 2,172 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
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
import time
import sys

from bisect_common import *

# TODO: detect missing file
def run(cppcheck_path, options, elapsed_time=None):
    timeout = None
    if elapsed_time:
        timeout = elapsed_time * 2
    cmd = options.split()
    cmd.insert(0, cppcheck_path)
    print('running {}'.format(cppcheck_path))
    with subprocess.Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) as p:
        try:
            p.communicate(timeout=timeout)
            if p.returncode != 0:
                print('error')
                return None
            print('done')
        except subprocess.TimeoutExpired:
            print('timeout')
            p.kill()
            p.communicate()
            return False

    return True


# TODO: check arguments
bisect_path = sys.argv[1]
options = sys.argv[2]
if '--error-exitcode=0' not in options:
    options += ' --error-exitcode=0'
if len(sys.argv) >= 4:
    elapsed_time = float(sys.argv[3])
else:
    elapsed_time = None
if len(sys.argv) == 5:
    invert = sys.argv[4] == "2"
else:
    invert = False

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)

if not elapsed_time:
    t = time.perf_counter()
    # TODO: handle error result
    run(cppcheck_path, options)
    elapsed_time = time.perf_counter() - t
    print('elapsed_time: {}'.format(elapsed_time))
    # TODO: write to stdout and redirect all all printing to stderr
    sys.exit(round(elapsed_time + .5))  # return the time

t = time.perf_counter()
run_res = run(cppcheck_path, options, elapsed_time)
run_time = time.perf_counter() - t

if not elapsed_time:
    # TODO: handle error result
    print('elapsed_time: {}'.format(run_time))
    # TODO: write to stdout and redirect all printing to stderr
    sys.exit(round(run_time + .5))  # return the time

if run_res is None:
    sys.exit(EC_SKIP)  # error occurred

if not run_res:
    sys.exit(EC_BAD if not invert else EC_GOOD)  # timeout occurred

print('run_time: {}'.format(run_time))

sys.exit(EC_GOOD if not invert else EC_BAD)  # no timeout