MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / Reduce

Class Reduce

tools/reduce.py:23–275  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21
22
23class Reduce:
24 def __init__(self, cmd, expected, file, segfault=None):
25 if not "".join(cmd):
26 raise RuntimeError('Abort: No --cmd')
27
28 if not segfault and not expected:
29 raise RuntimeError('Abort: No --expected')
30
31 if not file:
32 raise RuntimeError('Abort: No --file')
33
34 # need to add '--error-exitcode=0' so detected issues will not be interpreted as a crash
35 if segfault and '--error-exitcode=0' not in cmd:
36 print("Adding '--error-exitcode=0' to --cmd")
37 self.__cmd = cmd + ['--error-exitcode=0']
38 else:
39 self.__cmd = cmd
40 self.__expected = expected
41 self.__file = file
42 self.__segfault = segfault
43 self.__origfile = self.__file + '.org'
44 self.__backupfile = self.__file + '.bak'
45 self.__timeoutfile = self.__file + '.timeout'
46 self.__elapsed_time = None
47
48 def print_info(self):
49 print('CMD=', " ".join(self.__cmd))
50 if self.__segfault:
51 print('EXPECTED=SEGFAULT')
52 else:
53 print('EXPECTED=' + self.__expected)
54 print('FILE=' + self.__file)
55
56 def __communicate(self, p, timeout=None, **kwargs):
57 return p.communicate(timeout=timeout)
58
59 def runtool(self, filedata=None):
60 TimeoutExpired = subprocess.TimeoutExpired
61
62 timeout = None
63 if self.__elapsed_time:
64 timeout = self.__elapsed_time * 2
65 p = subprocess.Popen(self.__cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
66 try:
67 stdout, stderr = self.__communicate(p, timeout=timeout)
68 except TimeoutExpired:
69 print('timeout')
70 p.kill()
71 p.communicate()
72 if filedata:
73 self.writetimeoutfile(filedata)
74 return False
75 # print(p.returncode)
76 # print(comm)
77 if self.__segfault:
78 if p.returncode != 0:
79 return True
80 elif p.returncode == 0:

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected