def test_get_diff_res_count_unresolved(self): """ Count the unresolved results with no filter. """ runs = self._cc_client.getRunData() self.assertIsNotNone(runs) self.assertNotEqual(len(runs), 0) self.assertGreaterEqual(len(runs), 2) base_run_id = runs[0].runId new_run_id = runs[1].runId base_count = self._cc_client.getRunResultCount(base_run_id, []) logging.debug("Base run id: %d", base_run_id) logging.debug("Base count: %d", base_count) base_run_res = get_all_run_results(self._cc_client, base_run_id) print_run_results(base_run_res) new_count = self._cc_client.getRunResultCount(new_run_id, []) logging.debug("New run id: %d", new_run_id) logging.debug("New count: %d", new_count) new_run_res = get_all_run_results(self._cc_client, new_run_id) print_run_results(new_run_res) diff_res = self._cc_client.getDiffResultCount(base_run_id, new_run_id, DiffType.UNRESOLVED, []) self.assertEqual(diff_res, 23)
def test_double_suppress(self): """ Suppressing the same bug for the second time should be successfull. The second suppress should not overwrite the already stored suppress comment. """ runid = self._runid logging.debug('Get all run results from the db for runid: ' + str(runid)) run_results = get_all_run_results(self._cc_client, runid) self.assertIsNotNone(run_results) self.assertNotEqual(len(run_results), 0) suppress_comment = r'First suppress msg' bug = run_results[0] success = self._cc_client.suppressBug([runid], bug.reportId, suppress_comment) self.assertTrue(success) logging.debug('Bug suppressed successfully') # try to suppress the same bug again second_suppress_msg = r'Second suppress msg' success = self._cc_client.suppressBug([runid], bug.reportId, second_suppress_msg) self.assertTrue(success) logging.debug('Same bug suppressed successfully for the second time') simple_filters = [ReportFilter(suppressed=True)] run_results_suppressed = get_all_run_results(self._cc_client, runid, filters=simple_filters) self.assertIsNotNone(run_results_suppressed) self.assertEqual(len(run_results_suppressed), 1) bug_to_suppress = bug bug_to_suppress.suppressed = True bug_to_suppress.suppressComment = suppress_comment # The only one suppressed bug should be returned. self.assertEqual(bug_to_suppress, run_results_suppressed[0]) success = self._cc_client.unSuppressBug([runid], bug_to_suppress.reportId) self.assertTrue(success) logging.debug('Bug unsuppressed successfully') simple_filters = [ReportFilter(suppressed=False)] run_results_unsuppressed = get_all_run_results(self._cc_client, runid, filters=simple_filters) self.assertIsNotNone(run_results_unsuppressed) self.assertEqual(len(run_results), len(run_results_unsuppressed))
def test_zzzzz_get_run_results_checker_msg_filter_suppressed(self): """ This test must be run for last, suppresses some results which potentially changes the result counts. """ runid = self._runid logging.debug('Get all run results from the db for runid: ' + str(runid)) simple_filters = [ReportFilter(suppressed=False)] run_results = get_all_run_results(self._cc_client, runid, filters=simple_filters) self.assertIsNotNone(run_results) self.assertNotEqual(len(run_results), 0) suppress_msg = r'My beautiful Unicode comment.' bug = run_results[0] success = self._cc_client.suppressBug([runid], bug.reportId, suppress_msg) self.assertTrue(success) logging.debug('Bug suppressed successfully') simple_filters = [ReportFilter(suppressed=True)] run_results = get_all_run_results(self._cc_client, runid, filters=simple_filters) self.assertIsNotNone(run_results) self.assertNotEqual(len(run_results), 0) filtered_run_results = filter( lambda result: (result.reportId == bug.reportId) and result.suppressed, run_results) self.assertEqual(len(filtered_run_results), 1) suppressed_bug = filtered_run_results[0] self.assertEqual(suppressed_bug.suppressComment, suppress_msg) success = self._cc_client.unSuppressBug([runid], suppressed_bug.reportId) self.assertTrue(success) logging.debug('Bug unsuppressed successfully') simple_filters = [ReportFilter(suppressed=False)] run_results = get_all_run_results(self._cc_client, runid, filters=simple_filters) self.assertIsNotNone(run_results) self.assertNotEqual(len(run_results), 0) filtered_run_results = filter( lambda result: (result.reportId == bug.reportId) and not result.suppressed, run_results) self.assertEqual(len(filtered_run_results), 1) logging.debug('Done.\n')
def test_get_source_file_content(self): """ Test getting the source file content stored to the database. Test unicode support the stored file can be decoded properly compare results form the database to the original file. """ runid = self._runid simple_filters = [ReportFilter(checkerId='*', filepath='*.c*')] run_result_count = self._cc_client.getRunResultCount(runid, simple_filters) self.assertTrue(run_result_count) run_results = get_all_run_results(self._cc_client, runid, filters=simple_filters) self.assertIsNotNone(run_results) for run_res in run_results: self.assertTrue(re.match(r'.*\.c(pp)?$', run_res.checkedFile)) logging.debug('Getting the content of ' + run_res.checkedFile) file_data = self._cc_client.getSourceFileData(run_res.fileId, True) self.assertIsNotNone(file_data) file_content1 = file_data.fileContent self.assertIsNotNone(file_content1) with open(run_res.checkedFile) as source_file: file_content2 = source_file.read() self.assertEqual(file_content1, file_content2) logging.debug('got ' + str(len(run_results)) + ' files') self.assertEqual(run_result_count, len(run_results))
def test_get_run_results_sorted2(self): """ Get the run results and sort them by file name and checker name ASC. """ runid = self._runid logging.debug('Get all run results from the db for runid: ' + str(runid)) sortMode1 = SortMode(SortType.FILENAME, Order.ASC) sortMode2 = SortMode(SortType.CHECKER_NAME, Order.ASC) sort_types = [sortMode1, sortMode2] run_result_count = self._cc_client.getRunResultCount(runid, []) self.assertTrue(run_result_count) run_results = get_all_run_results(self._cc_client, runid, sort_types, []) self.assertIsNotNone(run_results) print_run_results(run_results) self.assertEqual(run_result_count, len(run_results)) for i in range(run_result_count - 1): bug1 = run_results[i] bug2 = run_results[i + 1] self.assertTrue(bug1.checkedFile <= bug2.checkedFile) self.assertTrue((bug1.checkedFile != bug2.checkedFile) or (bug1.lastBugPosition.startLine <= bug2.lastBugPosition.startLine) or (bug1.checkerId <= bug2.checkerId))
def test_get_run_results_severity_sort(self): """ Get the run results and sort them by severity and filename ASC. """ runid = self._runid logging.debug('Get all run results from the db for runid: ' + str(runid)) sort_mode1 = SortMode(SortType.SEVERITY, Order.ASC) sort_mode2 = SortMode(SortType.FILENAME, Order.ASC) sort_types = [sort_mode1, sort_mode2] run_result_count = self._cc_client.getRunResultCount(runid, []) self.assertTrue(run_result_count) run_results = get_all_run_results(self._cc_client, runid, sort_types, []) self.assertIsNotNone(run_results) for i in range(run_result_count - 1): bug1 = run_results[i] bug2 = run_results[i + 1] self.assertTrue(bug1.severity <= bug2.severity) self.assertTrue((bug1.severity != bug2.severity) or (bug1.checkedFile <= bug2.checkedFile)) print_run_results(run_results) self.assertEqual(run_result_count, len(run_results))
def test_get_run_results_checker_id_and_file_path(self): """ Test if all the bugs are found based on the test project configuration. """ runid = self._runid logging.debug('Get all run results from the db for runid: ' + str(runid)) run_result_count = self._cc_client.getRunResultCount(runid, []) self.assertTrue(run_result_count) run_results = get_all_run_results(self._cc_client, runid) self.assertIsNotNone(run_results) self.assertEqual(run_result_count, len(run_results)) found_all = True not_found = [] for bug in self._testproject_data['bugs']: found = False for run_res in run_results: found |= ((run_res.checkedFile.endswith(bug['file'])) and (run_res.lastBugPosition.startLine == bug['line']) and (run_res.checkerId == bug['checker']) and (run_res.bugHash == bug['hash'])) found_all &= found if not found: not_found.append(bug) print_run_results(run_results) print('Not found bugs:') for bug in not_found: print(bug) self.assertTrue(found_all)
def test_get_run_results_checker_id_and_file_path(self): """ Test if all the bugs are found based on the test project configuration. """ runid = self._runid logging.debug('Get all run results from the db for runid: ' + str(runid)) run_result_count = self._cc_client.getRunResultCount(runid, []) self.assertTrue(run_result_count) run_results = get_all_run_results(self._cc_client, runid) self.assertIsNotNone(run_results) self.assertEqual(run_result_count, len(run_results)) not_found = find_all(run_results, self._testproject_data['bugs']) print_run_results(run_results) if not_found: print('Not found bugs:') for bug in not_found: print(bug) self.assertTrue(len(not_found) == 0)
def test_get_source_file_content(self): """ Test getting the source file content stored to the database. Test unicode support the stored file can be decoded properly compare results form the database to the original file. """ runid = self._runid simple_filters = [ReportFilter(checkerId='*', filepath='*.c*')] run_result_count = self._cc_client.getRunResultCount( runid, simple_filters) self.assertTrue(run_result_count) run_results = get_all_run_results(self._cc_client, runid, filters=simple_filters) self.assertIsNotNone(run_results) for run_res in run_results: self.assertTrue(re.match(r'.*\.c(pp)?$', run_res.checkedFile)) logging.debug('Getting the content of ' + run_res.checkedFile) file_data = self._cc_client.getSourceFileData(run_res.fileId, True) self.assertIsNotNone(file_data) file_content1 = file_data.fileContent self.assertIsNotNone(file_content1) with open(run_res.checkedFile) as source_file: file_content2 = source_file.read() self.assertEqual(file_content1, file_content2) logging.debug('got ' + str(len(run_results)) + ' files') self.assertEqual(run_result_count, len(run_results))
def test_get_run_results_no_filter(self): """ Get all the run results without any filtering. """ runid = self._runid logging.debug('Get all run results from the db for runid: ' + str(runid)) run_result_count = self._cc_client.getRunResultCount(runid, []) self.assertTrue(run_result_count) run_results = get_all_run_results(self._cc_client, runid) print_run_results(run_results) self.assertIsNotNone(run_results) self.assertEqual(run_result_count, len(run_results))
def measure(test_conf, performance_data, store_done, proc_done_counter, proc_counter_lock, keep): """ Fill up a run with the configured values. """ try: log.debug("Generating and storing results ...") number_of_runs = test_conf.get("number_of_runs", 1) # TODO simulate append by using the same run name in multiple threads run_perf = {} for run_count in range(number_of_runs): run_name = 'name_' + str(run_count) + '_' + str(uuid4()) file_line_size = test_conf.get("file_line_size") file_content = zlib.compress('\n'.join(['A' * 80] * file_line_size), zlib.Z_BEST_COMPRESSION) with Timer('store', run_perf): run_id = store(test_conf, run_name, file_content) log.debug("Storing results for run " + str(run_id) + " done.") with proc_counter_lock: proc_done_counter.value -= 1 # wait here for other processes to finish storing results # before measuiring queries store_done.wait() view_host, view_port = get_viewer_host_port(test_conf) with CCViewerHelper(view_host, view_port, '/') as viewer_client: with Timer('getRunData', run_perf): run_data = viewer_client.getRunData() with Timer('getAllRunResulst', run_perf): res = get_all_run_results(viewer_client, run_id) with Timer('getReportDetails', run_perf): viewer_client.getReportDetails(res[-1].reportId) add_measurement_data(run_id, performance_data, run_perf) clean_after_fill = test_conf.get("clean_after_fill", True) if clean_after_fill and not keep: delete_results(view_host, view_port, run_id, performance_data) except Exception as ex: log.error(ex) with proc_counter_lock: proc_done_counter.value -= 1 sys.exit(1)