2015-01-01 09:59:47 +01:00
|
|
|
|
|
|
|
import glob
|
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
|
|
|
|
if len(sys.argv) != 3:
|
|
|
|
print('usage: triage.py project resultsfile.txt')
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
project = sys.argv[1]
|
|
|
|
resultfile = sys.argv[2]
|
|
|
|
|
|
|
|
f = open(project + '/true-positives.txt', 'rt')
|
|
|
|
truepositives = f.read()
|
2015-01-08 19:48:35 +01:00
|
|
|
f.close()
|
2015-01-01 09:59:47 +01:00
|
|
|
|
|
|
|
f = open(project + '/false-positives.txt', 'rt')
|
|
|
|
falsepositives = f.read()
|
2015-01-08 19:48:35 +01:00
|
|
|
f.close()
|
2015-01-01 09:59:47 +01:00
|
|
|
|
2015-01-08 19:48:35 +01:00
|
|
|
fin = open(resultfile, 'rt')
|
2015-01-02 09:13:05 +01:00
|
|
|
results = fin.read()
|
2015-01-01 09:59:47 +01:00
|
|
|
fin.close()
|
|
|
|
|
|
|
|
out = {}
|
|
|
|
out['untriaged'] = ''
|
2015-01-07 21:12:09 +01:00
|
|
|
out['fn'] = ''
|
2015-01-01 09:59:47 +01:00
|
|
|
out['fp'] = ''
|
|
|
|
out['tp'] = ''
|
|
|
|
|
2015-01-06 19:35:15 +01:00
|
|
|
numberOfFalsePositives = 0
|
2014-07-21 16:10:04 +02:00
|
|
|
numberOfTruePositives = 0
|
2015-01-07 21:12:09 +01:00
|
|
|
numberOfFalseNegatives = 0
|
2015-01-06 19:35:15 +01:00
|
|
|
|
2015-01-02 09:13:05 +01:00
|
|
|
for result in results.split('\n'):
|
2015-01-01 09:59:47 +01:00
|
|
|
result = result.strip()
|
|
|
|
|
2014-07-21 16:10:04 +02:00
|
|
|
res = re.match('\\[(' + project + '.+):([0-9]+)\\]:\s+[(][a-z]+[)] (.+)', result)
|
2015-01-08 19:48:35 +01:00
|
|
|
if res is None:
|
2015-01-01 09:59:47 +01:00
|
|
|
continue
|
|
|
|
|
|
|
|
filename = res.group(1)
|
2014-07-21 16:10:04 +02:00
|
|
|
linenr = res.group(2)
|
|
|
|
message = res.group(3)
|
|
|
|
css = 'untriaged'
|
2015-01-01 09:59:47 +01:00
|
|
|
classification = 'Untriaged'
|
|
|
|
if result in truepositives:
|
|
|
|
css = 'tp'
|
2015-01-07 21:12:09 +01:00
|
|
|
classification = 'True Positive'
|
2015-01-06 19:35:15 +01:00
|
|
|
numberOfTruePositives += 1
|
2015-01-01 09:59:47 +01:00
|
|
|
elif result in falsepositives:
|
|
|
|
css = 'fp'
|
2015-01-07 21:12:09 +01:00
|
|
|
classification = 'False Positive'
|
2015-01-06 19:35:15 +01:00
|
|
|
numberOfFalsePositives += 1
|
2015-01-06 13:04:49 +01:00
|
|
|
href = None
|
2015-01-01 09:59:47 +01:00
|
|
|
|
2014-07-21 16:10:04 +02:00
|
|
|
html = ' <tr>'
|
|
|
|
html += '<td class=' + css + '>' + filename + '</td>'
|
|
|
|
html += '<td class=' + css + '>' + linenr + '</td>'
|
|
|
|
html += '<td class=' + css + '>' + message + '</td>'
|
2015-01-08 19:48:35 +01:00
|
|
|
if project == 'linux-3.11':
|
2015-01-06 13:04:49 +01:00
|
|
|
href = 'http://github.com/torvalds/linux/blob/v3.11' + filename[filename.find('/'):] + '#L' + linenr
|
|
|
|
if href:
|
2014-07-21 16:10:04 +02:00
|
|
|
html += '<td class=' + css + '><a href="' + href + '">' + classification + '</a></td>'
|
2015-01-06 13:04:49 +01:00
|
|
|
else:
|
2014-07-21 16:10:04 +02:00
|
|
|
html += '<td class=' + css + '>' + classification + '</td>'
|
2015-01-01 09:59:47 +01:00
|
|
|
html += '</tr>\n'
|
|
|
|
|
|
|
|
out[css] += html
|
|
|
|
|
2015-01-02 09:13:05 +01:00
|
|
|
f = open(project + '/true-positives.txt', 'rt')
|
|
|
|
for line in f.readlines():
|
|
|
|
line = line.strip()
|
|
|
|
if line.find('] -> [') > 0 or line.find('(error)') < 0:
|
|
|
|
continue
|
|
|
|
|
2014-07-21 16:10:04 +02:00
|
|
|
res = re.match('\\[(' + project + '.+):([0-9]+)\\]:\s+[(][a-z]+[)] (.+)', line)
|
2015-01-08 19:48:35 +01:00
|
|
|
if res is None:
|
2015-01-02 09:13:05 +01:00
|
|
|
continue
|
|
|
|
|
|
|
|
if line in results:
|
|
|
|
continue
|
|
|
|
|
2015-01-07 21:12:09 +01:00
|
|
|
numberOfFalseNegatives += 1
|
|
|
|
|
2014-07-21 16:10:04 +02:00
|
|
|
filename = res.group(1)
|
|
|
|
linenr = res.group(2)
|
|
|
|
message = res.group(3)
|
2015-01-07 21:12:09 +01:00
|
|
|
classification = 'False Negative'
|
2014-07-21 16:10:04 +02:00
|
|
|
css = 'fn'
|
2015-01-02 09:13:05 +01:00
|
|
|
|
2014-07-21 16:10:04 +02:00
|
|
|
html = ' <tr>'
|
|
|
|
html += '<td class=' + css + '>' + filename + '</td>'
|
|
|
|
html += '<td class=' + css + '>' + linenr + '</td>'
|
|
|
|
html += '<td class=' + css + '>' + message + '</td>'
|
|
|
|
html += '<td class=' + css + '>' + classification + '</td>'
|
2015-01-02 09:13:05 +01:00
|
|
|
html += '</tr>\n'
|
|
|
|
|
|
|
|
out[css] += html
|
|
|
|
|
2015-01-08 19:48:35 +01:00
|
|
|
f.close()
|
2015-01-02 09:13:05 +01:00
|
|
|
|
2015-01-06 19:35:15 +01:00
|
|
|
project2 = ''
|
|
|
|
if project.find('-') > 0:
|
|
|
|
project2 = project[:project.find('-')]
|
|
|
|
else:
|
|
|
|
project2 = project
|
2015-01-02 09:13:05 +01:00
|
|
|
|
2015-01-08 19:48:35 +01:00
|
|
|
fout = open('report.html', 'wt')
|
2015-01-06 19:35:15 +01:00
|
|
|
fout.write('<html><head><title>Cppcheck results for ' + project + '</title><link rel="stylesheet" type="text/css" href="theme1.css"></head><body>\n')
|
|
|
|
fout.write('<h1>Cppcheck results for ' + project + '</h1>\n')
|
2015-01-07 21:12:09 +01:00
|
|
|
fout.write('<p>Number of false negatives: ' + str(numberOfFalseNegatives) + '</p>\n')
|
2015-01-06 19:35:15 +01:00
|
|
|
fout.write('<p>Number of true positives: ' + str(numberOfTruePositives) + '</p>\n')
|
|
|
|
fout.write('<p>Number of false positives: ' + str(numberOfFalsePositives) + '</p>\n')
|
|
|
|
fout.write('<table border="0">\n')
|
|
|
|
fout.write('<tr><th>Filename</th><th>Line</th><th>Message</th><th>Classification</th></tr>\n')
|
2015-01-07 21:12:09 +01:00
|
|
|
fout.write(out['fn'])
|
2015-01-01 09:59:47 +01:00
|
|
|
fout.write(out['tp'])
|
2015-01-02 09:13:05 +01:00
|
|
|
fout.write(out['fp'])
|
2015-01-07 21:12:09 +01:00
|
|
|
fout.write(out['untriaged'])
|
2015-01-01 09:59:47 +01:00
|
|
|
|
|
|
|
fout.write('</table></body></html>')
|
|
|
|
fout.close()
|