2019-07-26 06:38:03 +02:00
|
|
|
# Helpers for pytest tests
|
|
|
|
import subprocess
|
|
|
|
import json
|
2019-12-10 18:32:41 +01:00
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
def find_cppcheck_binary():
|
|
|
|
possible_locations = [
|
|
|
|
"./cppcheck",
|
2020-06-08 15:58:17 +02:00
|
|
|
"./build/bin/cppcheck",
|
2019-12-10 18:32:41 +01:00
|
|
|
r".\bin\cppcheck.exe",
|
|
|
|
]
|
|
|
|
for location in possible_locations:
|
|
|
|
if os.path.exists(location):
|
|
|
|
break
|
|
|
|
else:
|
2020-05-20 16:02:13 +02:00
|
|
|
raise RuntimeError("Could not find cppcheck binary")
|
2019-12-10 18:32:41 +01:00
|
|
|
|
|
|
|
return location
|
2019-07-26 06:38:03 +02:00
|
|
|
|
|
|
|
def dump_create(fpath, *argv):
|
2019-12-10 18:32:41 +01:00
|
|
|
cppcheck_binary = find_cppcheck_binary()
|
2021-07-22 08:46:28 +02:00
|
|
|
cmd = [cppcheck_binary, "--dump", "-DDUMMY", "--quiet", fpath] + list(argv)
|
2019-07-26 06:38:03 +02:00
|
|
|
p = subprocess.Popen(cmd)
|
|
|
|
p.communicate()
|
|
|
|
if p.returncode != 0:
|
|
|
|
raise OSError("cppcheck returns error code: %d" % p.returncode)
|
|
|
|
subprocess.Popen(["sync"])
|
|
|
|
|
|
|
|
|
|
|
|
def dump_remove(fpath):
|
|
|
|
subprocess.Popen(["rm", "-f", fpath + ".dump"])
|
|
|
|
|
|
|
|
|
|
|
|
def convert_json_output(raw_json_strings):
|
|
|
|
"""Convert raw stdout/stderr cppcheck JSON output to python dict."""
|
|
|
|
json_output = {}
|
|
|
|
for line in raw_json_strings:
|
|
|
|
try:
|
|
|
|
json_line = json.loads(line)
|
|
|
|
# json_output[json_line['errorId']] = json_line
|
|
|
|
json_output.setdefault(json_line['errorId'], []).append(json_line)
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
return json_output
|