def convert_reports_to_firehose(): reports = [] # scan-build (clang analyzer) scanbuild_report_results = [] metadata = None for resultdir in glob.glob(os.path.join('reports/scan-build', '*')): scanbuild_tmp_firehose_report = clanganalyzer.parse_scandir(resultdir) for report in scanbuild_tmp_firehose_report: metadata = report.metadata scanbuild_report_results += report.results scanbuild_firehose_report = Analysis(metadata, scanbuild_report_results) reports.append(scanbuild_firehose_report) # framac with open('reports/frama-c/frama-c.log') as framac_raw_report: framac_firehose_report = frama_c.parse_file(framac_raw_report) reports.append(framac_firehose_report) # flawfinder with open('reports/flawfinder/flawfinder.log') as flawfinder_raw_report: flawfinder_firehose_report = flawfinder.parse_file(flawfinder_raw_report) reports.append(flawfinder_firehose_report) # cppcheck with open('reports/cppcheck/cppcheck.log') as cppcheck_raw_report: cppcheck_firehose_report = cppcheck.parse_file(cppcheck_raw_report) reports.append(cppcheck_firehose_report) os.makedirs('reports/firehose') for report in reports: tool_name = report.metadata.generator.name fh_report_path = 'reports/firehose/' + tool_name + '.xml' with open(fh_report_path, 'wb') as fh_report: report.to_xml().write(fh_report, encoding='utf-8')
def test_paths(self): mock_file = self.get_file_with_warning() analysis = frama_c.parse_file(mock_file) self.assertIsInstance(analysis, Analysis) self.assertEqual(len(analysis.results), 1) results = analysis.results[0] self.assertIsInstance(results.location, Location) self.assertIsInstance(results.location.file, File) self.assertIsInstance(results.location.point, Point) self.assertEqual(results.location.function, None) self.assertIsInstance(results.message, Message) self.assertEqual(results.location.line, 13) self.assertEqual( results.message.text, "Body of function foo falls-through. Adding a return statement") self.assertEqual(results.location.file.givenpath, "new.c") self.assertEqual(results.location.file.abspath, None)
def test_no_warning(self): mock_file = self.get_file_without_warning() ret = frama_c.parse_file(mock_file) self.assertEqual(len(ret.results), 0)
def test_new_line(self): mock_file = self.create_mock_file(["\n"]) ret = frama_c.parse_file(mock_file) self.assertEqual(len(ret.results), 0)
def test_empty(self): mock_file = self.create_mock_file([""]) ret = frama_c.parse_file(mock_file) self.assertEqual(len(ret.results), 0)
def test_parse_warning(self): mock_file = self.get_file_with_warning() ret = frama_c.parse_file(mock_file) self.assertIsInstance(ret, Analysis) self.assertIsInstance(ret.results[0], Result) self.assertEqual(len(ret.results), 1)
def test_empty(self): mock_file = self.create_mock_file([""]) ret = frama_c.parse_file(mock_file) print(ret) print(type(ret)) self.assertEqual(len(ret.results), 0)