예제 #1
0
    def __check_serverity_of_reports(self, run_name):
        """
        This will check whether reports in the database has the same severity
        levels as in the severity map config file.
        """
        run_filter = RunFilter()
        run_filter.names = [run_name]
        run_filter.exactMatch = True

        runs = self._cc_client.getRunData(run_filter, None, 0, None)
        run_id = runs[0].runId

        reports \
            = self._cc_client.getRunResults([run_id], 10, 0, [], None, None,
                                            False)

        with open(self.workspace_severity_cfg,
                  'r',
                  encoding="utf-8",
                  errors="ignore") as severity_cgf_file:
            severity_map = json.load(severity_cgf_file)
            for report in reports:
                severity_id = severity_map.get(report.checkerId, 'UNSPECIFIED')
                self.assertEqual(Severity._VALUES_TO_NAMES[report.severity],
                                 severity_id)
예제 #2
0
    def __get_files_in_report(self):
        run_filter = RunFilter()
        run_filter.names = ['db_cleanup_test']
        run_filter.exactMatch = True

        codechecker.check_and_store(self.codechecker_cfg, 'db_cleanup_test',
                                    self.test_dir)

        runs = self._cc_client.getRunData(run_filter, None, 0, None)
        run_id = runs[0].runId

        reports \
            = self._cc_client.getRunResults([run_id], 10, 0, [], None, None,
                                            False)

        details = self._cc_client.getReportDetails(reports[0].reportId)

        files = set()
        files.update([bp.fileId for bp in details.pathEvents])
        files.update([bp.fileId for bp in details.executionPath])

        file_ids = set()
        for file_id in files:
            file_data = self._cc_client.getSourceFileData(file_id, False, None)
            if file_data.fileId is not None:
                file_ids.add(file_data.fileId)

        return file_ids
예제 #3
0
    def __get_runs(self, run_name_filter=None):
        """ Helper function to get all run names which belong to this test"""
        run_filter = RunFilter()
        if run_name_filter is not None:
            run_filter.names = [run_name_filter]

        runs = self._cc_client.getRunData(run_filter, None, 0, None)
        return [run for run in runs if run.name in self._run_names]
예제 #4
0
    def __get_run_id(self, run_name):
        """ Get run id based on the given run name. """
        run_filter = RunFilter()
        run_filter.names = [run_name]
        run_filter.exactMatch = True

        runs = self._cc_client.getRunData(run_filter, None, 0, None)
        return runs[0].runId
예제 #5
0
    def __get_run_results(self, run_name):
        """
        Returns list of reports for the given run name.
        """
        run_filter = RunFilter()
        run_filter.names = [run_name]
        run_filter.exactMatch = True

        runs = self._cc_client.getRunData(run_filter, None, 0, None)
        run_id = runs[0].runId

        return self._cc_client.getRunResults([run_id], None, 0, [], None, None,
                                             False)
예제 #6
0
    def setUp(self):
        self.test_workspace = os.environ['TEST_WORKSPACE']

        test_class = self.__class__.__name__
        print('Running ' + test_class + ' tests in ' + self.test_workspace)

        self._testproject_data = env.setup_test_proj_cfg(self.test_workspace)
        self.assertIsNotNone(self._testproject_data)

        self._cc_client = env.setup_viewer_client(self.test_workspace)
        self.assertIsNotNone(self._cc_client)

        # Get the run names which belong to this test.
        run_names = env.get_run_names(self.test_workspace)
        # get the current run data
        run_filter = RunFilter(names=run_names, exactMatch=True)

        runs = self._cc_client.getRunData(run_filter, None, 0, None)

        test_runs = [run for run in runs if run.name in run_names]

        self.assertEqual(
            len(test_runs), 1, 'There should be only one run for this test, '
            'with the given name configured at the test init.')
        self._runid = test_runs[0].runId
예제 #7
0
    def tearDown(self):
        """
        Remove the run which was stored by this test case.
        """
        run_filter = RunFilter(names=[self._run_name], exactMatch=True)
        runs = self._report.getRunData(run_filter, None, 0, None)
        run_id = runs[0].runId

        # Remove the run.
        self._report.removeRun(run_id, None)
예제 #8
0
    def __check_serverity_of_reports(self, run_name):
        """
        This will check whether reports in the database has the same severity
        levels as in the labels config file.
        """
        run_filter = RunFilter()
        run_filter.names = [run_name]
        run_filter.exactMatch = True

        runs = self._cc_client.getRunData(run_filter, None, 0, None)
        run_id = runs[0].runId

        reports \
            = self._cc_client.getRunResults([run_id], 10, 0, [], None, None,
                                            False)

        checker_labels = CheckerLabels(self.workspace_labels_dir)
        for report in reports:
            severity_id = checker_labels.severity(report.checkerId)
            self.assertEqual(Severity._VALUES_TO_NAMES[report.severity],
                             severity_id)
    def test_remove_run_results(self):
        """
        Test for removing run results and run.
        """
        # Run the anaysis again with different setup.
        test_project_path = self._testproject_data['project_path']
        ret = project.clean(test_project_path)
        if ret:
            sys.exit(ret)

        codechecker.check_and_store(self._codechecker_cfg,
                                    'remove_run_results', test_project_path)

        run_filter = RunFilter(names=['remove_run_results'], exactMatch=True)
        sort_mode = RunSortMode(RunSortType.DATE, Order.ASC)
        runs = self._cc_client.getRunData(run_filter, None, 0, sort_mode)
        self.assertEqual(len(runs), 1)

        run_id = runs[0].runId

        orig_results_count = \
            self._cc_client.getRunResultCount([run_id], None, None)
        self.assertNotEqual(orig_results_count, 0)

        checker_filter = ReportFilter(checkerName=["core.CallAndMessage"])
        res_count = self._cc_client.getRunResultCount([run_id], checker_filter,
                                                      None)
        self.assertNotEqual(res_count, 0)

        self._cc_client.removeRunReports([run_id], checker_filter, None)

        res_count = self._cc_client.getRunResultCount([run_id], checker_filter,
                                                      None)
        self.assertEqual(res_count, 0)

        # Remove the run.
        self._cc_client.removeRun(run_id, None)

        # Check that we removed all results from the run.
        res = self._cc_client.getRunResultCount([run_id], None, None)
        self.assertEqual(res, 0)
예제 #10
0
    def test_review_status_update_from_source_trim(self):
        """
        Test if the review status comments changes in the source code
        are updated at the server when trim path is used.

        The report is store twice and between the storage the
        review status as a source code comment is modified.
        The test checks is after the source code modification
        and storage the review status is updated correctly at
        the server too.
        """
        test_project_path = os.path.join(self.test_workspace,
                                         'review_status_files')
        test_project_name = 'review_status_update_proj'

        plist_file = os.path.join(test_project_path, 'divide_zero.plist')
        source_file = os.path.join(test_project_path, 'divide_zero.cpp')
        plist_test.prefix_file_path(plist_file, test_project_path)

        codechecker_cfg = env.import_codechecker_cfg(self.test_workspace)
        codechecker_cfg['reportdir'] = test_project_path

        codechecker.store(codechecker_cfg, test_project_name)

        codechecker_cfg['trim_path_prefix'] = test_project_path

        # Run data for the run created by this test case.
        run_filter = RunFilter(names=[test_project_name], exactMatch=True)

        runs = self._cc_client.getRunData(run_filter, None, 0, None)
        run = runs[0]
        runid = run.runId
        logging.debug('Get all run results from the db for runid: ' +
                      str(runid))

        reports = get_all_run_results(self._cc_client, runid)
        self.assertIsNotNone(reports)
        self.assertNotEqual(len(reports), 0)
        self.assertEqual(len(reports), 2)

        for report in reports:
            print(report)
            self.assertEqual(report.reviewData.status,
                             ReviewStatus.INTENTIONAL)

        # Modify review comments from intentional to confirmed for the
        # second store.
        with open(source_file, 'r+', encoding='utf-8', errors='ignore') as sf:
            content = sf.read()
            new_content = content.replace("codechecker_intentional",
                                          "codechecker_confirmed")
            sf.truncate(0)
            sf.write(new_content)

        # modify review comments and store the reports again
        with open(source_file, encoding='utf-8', errors='ignore') as sf:
            content = sf.read()

        # Update the plist file modification date to be newer than
        # the source file so it can be stored, because there was no
        # actual analysis.
        date = datetime.datetime.now() + datetime.timedelta(minutes=5)
        mod_time = time.mktime(date.timetuple())
        os.utime(plist_file, (mod_time, mod_time))

        codechecker.store(codechecker_cfg, test_project_name)

        # Check if all the review statuses were updated to the new at the
        # server.
        reports = get_all_run_results(self._cc_client, runid)
        self.assertIsNotNone(reports)
        self.assertNotEqual(len(reports), 0)
        self.assertEqual(len(reports), 2)
        for report in reports:
            self.assertEqual(report.reviewData.status, ReviewStatus.CONFIRMED)
예제 #11
0
    def test_export_import(self):
        """
        Test exporting and importing feature
        """
        run_filter = RunFilter()
        run_filter.names = [self.test_runs[0].name]
        logging.debug('Get all run results from the db for runid: ' +
                      str(self.test_runs[0].runId))

        run_results = get_all_run_results(self._cc_client,
                                          self.test_runs[0].runId)
        self.assertIsNotNone(run_results)
        self.assertNotEqual(len(run_results), 0)

        bug = run_results[0]

        # There are no comments available for the first bug
        comments = self._cc_client.getComments(bug.reportId)
        self.assertEqual(len(comments), 0)

        comment1 = CommentData(author='anybody', message='First msg')
        success = self._cc_client.addComment(bug.reportId, comment1)
        self.assertTrue(success)
        logging.debug('Bug commented successfully')

        # Try to add another new comment for the first bug
        comment2 = CommentData(author='anybody', message='Second msg')
        success = self._cc_client.addComment(bug.reportId, comment2)
        self.assertTrue(success)
        logging.debug('Bug commented successfully')

        # Change review status
        review_comment = 'This is really a bug'
        status = ReviewStatus.CONFIRMED
        success = self._cc_client.changeReviewStatus(bug.reportId, status,
                                                     review_comment)

        self.assertTrue(success)
        logging.debug('Bug review status changed successfully')

        # Export the comments and reviews
        exported = self._cc_client.exportData(run_filter)
        exported_comments = exported.comments[bug.bugHash]
        exported_review = exported.reviewData[bug.bugHash]

        # Check if the comments are same
        user_comments = get_user_comments(exported_comments)
        self.assertEqual(user_comments[0].message, comment2.message)
        self.assertEqual(user_comments[1].message, comment1.message)

        # Check for the review status
        self.assertEqual(exported_review.status, status)
        self.assertEqual(exported_review.comment, review_comment)

        new_export_command = [
            self._codechecker_cmd, 'cmd', 'export', '-n',
            self.test_runs[0].name, '--url',
            str(self.server_url)
        ]

        print(new_export_command)
        out_json = subprocess.check_output(new_export_command,
                                           encoding="utf-8",
                                           errors="ignore")
        resolved_results = json.loads(out_json)
        print(resolved_results)
        with tempfile.NamedTemporaryFile() as component_f:
            component_f.write(out_json.encode('utf-8'))
            component_f.flush()
            component_f.seek(0)

            self._cc_client.removeComment(user_comments[0].id)
            updated_message = "The new comment for testing"
            self._cc_client.updateComment(user_comments[1].id, updated_message)

            new_import_command = [
                self._codechecker_cmd, 'cmd', 'import', '-i', component_f.name,
                '--url',
                str(self.server_url)
            ]
            print(new_import_command)
            subprocess.check_output(new_import_command,
                                    encoding="utf-8",
                                    errors="ignore")

            exported = self._cc_client.exportData(run_filter)
            new_comments = exported.comments[bug.bugHash]
            print(new_comments)

            # Check if the last and second last comments
            self.assertEqual(new_comments[-1].message, comment1.message)
            self.assertEqual(new_comments[-2].message, updated_message)
 def _remove_run(self, run_names):
     """ Remove runs by run names. """
     run_filter = RunFilter()
     run_filter.names = run_names
     ret = self._cc_client.removeRun(None, run_filter)
     self.assertTrue(ret)