Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar committed Nov 8, 2023
1 parent 45c5019 commit cede3ae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
18 changes: 15 additions & 3 deletions addons/misra.py
Original file line number Diff line number Diff line change
Expand Up @@ -4618,6 +4618,19 @@ def fillVerifyExpected(verify_expected, tok):
self.executeCheck(2209, self.misra_22_9, cfg)
self.executeCheck(2210, self.misra_22_10, cfg)

def read_ctu_info_line(self, line):
if not line.startswith('{'):
return None
try:
ctu_info = json.loads(line)
except json.decoder.JSONDecodeError:
return None
if 'summary' not in ctu_info:
return None
if 'data' not in ctu_info:
return None
return ctu_info

def analyse_ctu_info(self, ctu_info_files):
all_typedef_info = {}
all_tagname_info = {}
Expand All @@ -4639,10 +4652,9 @@ def is_different_file(loc1, loc2):
try:
for filename in ctu_info_files:
for line in open(filename, 'rt'):
if not line.startswith('{'):
s = read_ctu_info_line(line)
if s is None:
continue

s = json.loads(line)
summary_type = s.get('summary', '')
summary_data = s.get('data', None)

Expand Down
11 changes: 5 additions & 6 deletions addons/test/test-misra.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,8 @@ def test_arguments_regression():
sys.argv = sys_argv_old


def test_ctu_info_1(checker):
with tempfile.TemporaryDirectory() as tempdir:
f = os.path.join(tempdir, 'crash.ctu-info')
with open(f, 'w') as fout:
fout.write('{"ctu-info": {"version": 1}}')
checker.analyse_ctu_info((f,))
def test_read_ctu_info_line(checker):
assert checker.read_ctu_info_line('{') is None
assert checker.read_ctu_info_line('{"summary":"123"}') is None
assert checker.read_ctu_info_line('{"data":123}') is None
assert checker.read_ctu_info_line('{"summary":"123","data":123}') is not None

0 comments on commit cede3ae

Please sign in to comment.