Skip to content

Commit c0ecdb9

Browse files
dmcppcheckclaude
andcommitted
donate-cpu-server-rest: show the assertion failure message in the crash report
donate-cpu puts the assertion failure message before the " received signal " line. Parse it and show it first in the stack trace on crash.html. Stack traces with different assertion failures are not grouped together. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 080b56e commit c0ecdb9

2 files changed

Lines changed: 64 additions & 4 deletions

File tree

‎test/tools/donate_cpu_server_rest_test.py‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@
4242
diff:
4343
'''.format(url=PKG_A, old=server.OLD_VERSION)
4444

45+
# crash with an assertion failure message before the ' received signal ' line (donate-cpu 1.4.2)
46+
ASSERTION = "build/symboldatabase.cpp:6760: bool Variable::arrayDimensions(const Settings&, bool&): Assertion `x == 1' failed."
47+
RESULT_CRASH_ASSERTION = '''{url}
48+
cppcheck: head {old}
49+
count: Crash! 5
50+
elapsed-time: -6.0 3.0
51+
head results:
52+
Checking bbb/x.cpp ...
53+
54+
{assertion}
55+
Program received signal SIGABRT, Aborted.
56+
0x00007fdd4b3b569c in ?? () from /lib/x86_64-linux-gnu/libc.so.6
57+
#0 0x00007fdd4b3b569c in ?? () from /lib/x86_64-linux-gnu/libc.so.6
58+
#1 0x00007fdd4b349420 in abort () from /lib/x86_64-linux-gnu/libc.so.6
59+
#2 0x0000562c2c38806f in Variable::arrayDimensions (this=0x562c53552490) at build/symboldatabase.cpp:6760
60+
61+
diff:
62+
'''.format(url=PKG_B, old=server.OLD_VERSION, assertion=ASSERTION)
63+
4564
INFO = '''{url}
4665
cppcheck: head {old}
4766
info messages:
@@ -102,13 +121,38 @@ def test_parse_result():
102121
def test_parse_crash():
103122
entry = server.parse_result('2026-11-27 10:00\n' + RESULT_CRASH)
104123
assert entry['crash'] == {
124+
'assertions': [],
105125
'crash_line': '0x000055 in Foo::bar (this=0x0) at lib/foo.cpp:12',
106126
'code_line': '12\t return x->y;',
107127
'stack_trace': ['#0 Foo::bar(...) at lib/foo.cpp:12', '#1 main(...) at cli/main.cpp:3'],
108128
}
109129
assert entry['head_ids'] == {'syntaxError': 1}
110130

111131

132+
def test_parse_crash_assertion():
133+
entry = server.parse_result('2026-11-27 10:00\n' + RESULT_CRASH_ASSERTION)
134+
assert entry['crash'] == {
135+
'assertions': [ASSERTION],
136+
'crash_line': '0x00007fdd4b3b569c in ?? () from /lib/x86_64-linux-gnu/libc.so.6',
137+
'code_line': '',
138+
'stack_trace': ['#0 ?? (...) from /lib/x86_64-linux-gnu/libc.so.6',
139+
'#1 abort (...) from /lib/x86_64-linux-gnu/libc.so.6',
140+
'#2 Variable::arrayDimensions(...) at build/symboldatabase.cpp:6760'],
141+
}
142+
# the "Checking" line is not an assertion failure
143+
entry = server.parse_result('2026-11-27 10:00\n' + RESULT_CRASH_ASSERTION.replace(ASSERTION + '\n', ''))
144+
assert entry['crash']['assertions'] == []
145+
146+
147+
def test_crash_report_assertion(client):
148+
assert client.post('/api/v1/results', content=RESULT_CRASH).status_code == 201
149+
assert client.post('/api/v1/results', content=RESULT_CRASH_ASSERTION).status_code == 201
150+
crash = client.get('/api/v1/reports/crash').json()
151+
assert [g['assertions'] for g in crash['stack_traces']] == [[], [ASSERTION]]
152+
page = client.get('/crash.html').text
153+
assert "Variable::arrayDimensions(const Settings&amp;, bool&amp;): Assertion `x == 1&#39; failed." in page
154+
155+
112156
def test_parse_info():
113157
entry = server.parse_info('2026-11-27 10:00\n' + INFO)
114158
assert entry['info_ids'] == {'checkLibraryFunction': 2, 'checkLibraryNoReturn': 1, 'checkLibraryCheckType': 1}

‎tools/donate-cpu-server-rest.py‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
MAX_LATEST = 20
5757

5858
# Bump this when the parsing changes, so that all persisted summaries are regenerated.
59-
PARSER_VERSION = 1
59+
PARSER_VERSION = 2
6060

6161
# A cached report is reused as long as no new data arrived. When new data has arrived, the
6262
# cached report is still reused if it is younger than this (in seconds).
@@ -112,6 +112,21 @@ def is_url(line: str) -> bool:
112112
]
113113

114114

115+
# Assertion failure message that donate-cpu puts before the ' received signal ' line (glibc format without the
116+
# program name): build/token.cpp:123: void Token::foo(): Assertion `x' failed.
117+
_ASSERTION_FAILURE_RE = re.compile(r"^[^:\s]+:\d+: .+: Assertion `.+' failed\.$")
118+
119+
120+
def _parse_assertion_failures(lines: List[str], i: int) -> List[str]:
121+
"""Assertion failure messages just before lines[i] (the ' received signal ' line)."""
122+
assertions: List[str] = []
123+
j = i - 1
124+
while j >= 0 and _ASSERTION_FAILURE_RE.match(lines[j].strip()):
125+
assertions.insert(0, lines[j].strip())
126+
j -= 1
127+
return assertions
128+
129+
115130
def _parse_stack_frame(line: str) -> Optional[str]:
116131
for pattern, sep in _STACK_FRAME_PATTERNS:
117132
m = pattern.search(line)
@@ -122,6 +137,7 @@ def _parse_stack_frame(line: str) -> Optional[str]:
122137

123138
def _parse_crash(lines: List[str], i: int) -> Tuple[Dict[str, Any], int]:
124139
"""lines[i] is the line after the ' received signal ' line."""
140+
assertions = _parse_assertion_failures(lines, i - 1)
125141
crash_line = lines[i].strip() if i < len(lines) else ''
126142
i += 1
127143
code_line = ''
@@ -138,7 +154,7 @@ def _parse_crash(lines: List[str], i: int) -> Tuple[Dict[str, Any], int]:
138154
if frame is None:
139155
break
140156
stack.append(frame)
141-
return {'crash_line': crash_line, 'code_line': code_line, 'stack_trace': stack}, i
157+
return {'assertions': assertions, 'crash_line': crash_line, 'code_line': code_line, 'stack_trace': stack}, i
142158

143159

144160
def message_id_of(line: str) -> Optional[str]:
@@ -604,7 +620,7 @@ def crash_report(entries: Dict[str, Dict[str, Any]]) -> Dict[str, Any]:
604620
rows.append(dict(package_row(package, entry), head_crash=head_crash, old_crash=old_crash))
605621
crash = entry.get('crash')
606622
if head_crash and crash:
607-
key = '\n'.join(crash['stack_trace'])
623+
key = '\n'.join(crash.get('assertions', []) + crash['stack_trace'])
608624
group = stack_traces.get(key)
609625
if group is None:
610626
stack_traces[key] = dict(crash, packages=[package])
@@ -1402,7 +1418,7 @@ def html_crash(pkgs: Optional[str] = None):
14021418
blocks.append({
14031419
'heading': '#{}: {} package{}'.format(n, len(g['packages']), '' if len(g['packages']) == 1 else 's'),
14041420
'links': [(p, package_href(p)) for p in g['packages']],
1405-
'text': '\n'.join([g['crash_line'], g['code_line']] + g['stack_trace']),
1421+
'text': '\n'.join(g.get('assertions', []) + [g['crash_line'], g['code_line']] + g['stack_trace']),
14061422
})
14071423
sections = [
14081424
{'columns': ['Package', 'Date', OLD_VERSION, 'Head'], 'rows': rows},

0 commit comments

Comments
 (0)