Ejemplo n.º 1
0
    def _create_source_file(self, version, run_name):
        with open(os.path.join(self._test_dir, self._source_file), 'w') as f:
            f.write(self.sources[version])

        self._codechecker_cfg['tag'] = self.tags[version]
        codechecker.check_and_store(self._codechecker_cfg, run_name,
                                    self._test_dir)
Ejemplo n.º 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
Ejemplo n.º 3
0
    def test_store(self):
        """
        Store should fail if the source files were modified since the
        last analysis.
        """

        test_proj = os.path.join(self.test_workspace, 'test_proj')

        ret = codechecker.check_and_store(self._codechecker_cfg,
                                          'test_proj',
                                          test_proj)

        self.assertEqual(ret, 0)

        ret = codechecker.store(self._codechecker_cfg, 'test_proj')
        self.assertEqual(ret, 0)

        test_proj_path = self._testproject_data['project_path']

        test_proj_files = os.listdir(test_proj_path)
        print(test_proj_files)

        null_deref_file = os.path.join(test_proj_path, 'null_dereference.cpp')

        touch(null_deref_file)

        ret = codechecker.store(self._codechecker_cfg, 'test_proj')
        self.assertEqual(ret, 1)
Ejemplo n.º 4
0
def setup_package():
    """Setup the environment for testing review_status."""

    global TEST_WORKSPACE
    TEST_WORKSPACE = env.get_workspace('review_status')

    os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE

    dir_path = os.path.dirname(os.path.realpath(__file__))
    shutil.copytree(os.path.join(dir_path, 'review_status_files'),
                    os.path.join(TEST_WORKSPACE, 'review_status_files'))

    test_project = 'single_bug'

    test_config = {}

    project_info = project.get_info(test_project)

    test_config['test_project'] = project_info

    skip_list_file = None

    test_env = env.test_env(TEST_WORKSPACE)

    codechecker_cfg = {
        'suppress_file': None,
        'skip_list_file': skip_list_file,
        'check_env': test_env,
        'workspace': TEST_WORKSPACE,
        'checkers': []
    }

    ret = project.clean(test_project, test_env)
    if ret:
        sys.exit(ret)

    # Start or connect to the running CodeChecker server and get connection
    # details.
    print("This test uses a CodeChecker server... connecting...")
    server_access = codechecker.start_or_get_server()
    server_access['viewer_product'] = 'review_status'
    codechecker.add_test_package_product(server_access, TEST_WORKSPACE)

    # Extend the checker configuration with the server access.
    codechecker_cfg.update(server_access)

    test_project_name = project_info['name'] + '_' + uuid.uuid4().hex

    ret = codechecker.check_and_store(codechecker_cfg, test_project_name,
                                      project.path(test_project))

    if ret:
        sys.exit(1)
    print("Analyzing the test project was successful.")

    codechecker_cfg['run_names'] = [test_project_name]

    test_config['codechecker_cfg'] = codechecker_cfg

    env.export_test_cfg(TEST_WORKSPACE, test_config)
Ejemplo n.º 5
0
def setup_package():
    """Setup the environment for testing blame information."""

    global TEST_WORKSPACE
    TEST_WORKSPACE = env.get_workspace('blame')

    os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE

    test_project = 'cpp'
    test_config = {}
    project_info = project.get_info(test_project)

    test_project_path = os.path.join(TEST_WORKSPACE, "test_proj")
    shutil.copytree(project.path(test_project), test_project_path)

    project_info['project_path'] = test_project_path
    test_project_name = project_info['name'] + '_' + uuid.uuid4().hex
    test_config['test_project'] = project_info

    suppress_file = None
    skip_list_file = None
    test_env = env.test_env(TEST_WORKSPACE)

    codechecker_cfg = {
        'suppress_file': suppress_file,
        'skip_list_file': skip_list_file,
        'check_env': test_env,
        'workspace': TEST_WORKSPACE,
        'checkers': [],
        'clean': True
    }

    # Start or connect to the running CodeChecker server and get connection
    # details.
    print("This test uses a CodeChecker server... connecting...")
    server_access = codechecker.start_or_get_server(auth_required=True)
    server_access['viewer_product'] = 'blame'
    codechecker.add_test_package_product(server_access, TEST_WORKSPACE)

    # Extend the checker configuration with the server access.
    codechecker_cfg.update(server_access)

    # Clean the test project, if needed by the tests.
    ret = project.clean(test_project)
    if ret:
        sys.exit(ret)

    ret = codechecker.check_and_store(
      codechecker_cfg, test_project_name, project.path(test_project))
    if ret:
        sys.exit(1)
    print("Analyzing test project was succcessful.")

    # Save the run names in the configuration.
    codechecker_cfg['run_names'] = [test_project_name]

    test_config['codechecker_cfg'] = codechecker_cfg

    # Export the test configuration to the workspace.
    env.export_test_cfg(TEST_WORKSPACE, test_config)
Ejemplo n.º 6
0
    def test_disable_checker(self):
        """
        The test depends on a run which was configured for update mode.
        Compared to the original test analysis in this run
        the deadcode.Deadstores checker was disabled.
        """

        run_results = get_all_run_results(self._cc_client, self._runid)

        print_run_results(run_results)

        # Get check command for the first storage.
        original_check_command = \
            self._cc_client.getCheckCommand(None, self._runid)

        # 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)

        initial_codechecker_cfg = env.import_test_cfg(
            self._test_workspace)['codechecker_cfg']

        # Disable some checkers for the analysis.
        deadcode = 'deadcode.DeadStores'
        initial_codechecker_cfg['checkers'] = ['-d', deadcode]

        initial_test_project_name = self._run_name

        ret = codechecker.check_and_store(initial_codechecker_cfg,
                                          initial_test_project_name,
                                          test_project_path)
        if ret:
            sys.exit(1)

        # Get the results to compare.
        updated_results = get_all_run_results(self._cc_client, self._runid)

        all_bugs = self._testproject_data[self._clang_to_test]['bugs']
        deadcode_bugs = \
            [bug['hash'] for bug in all_bugs if bug['checker'] == deadcode]

        self.assertEquals(len(updated_results), len(all_bugs))
        self.assertTrue(all(map(
            lambda b: b.detectionStatus == 'unresolved',
            filter(lambda x: x in deadcode_bugs, updated_results))))

        # Get check command for the updated storage.
        updated_check_command = \
            self._cc_client.getCheckCommand(None, self._runid)

        # Check that the check command is changed.
        self.assertNotEqual(original_check_command, updated_check_command)
        self.assertTrue(deadcode not in original_check_command)
        self.assertTrue(deadcode in updated_check_command)
    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)
Ejemplo n.º 8
0
    def __get_files_in_report(self, run_name):
        codechecker.check_and_store(self.codechecker_cfg, run_name,
                                    self.test_dir)

        run_id = self.__get_run_id([run_name])

        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
Ejemplo n.º 9
0
def setup_package():
    """Setup the environment for the tests. """

    global TEST_WORKSPACE
    TEST_WORKSPACE = env.get_workspace('cleanup_plan')

    os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE

    test_project = 'cpp'

    test_project_path = project.path(test_project)

    test_config = {}

    project_info = project.get_info(test_project)

    test_config['test_project'] = project_info
    test_env = env.test_env(TEST_WORKSPACE)

    codechecker_cfg = {
        'check_env': test_env,
        'workspace': TEST_WORKSPACE,
        'reportdir': os.path.join(TEST_WORKSPACE, 'reports'),
        'checkers': []
    }

    # Start or connect to the running CodeChecker server and get connection
    # details.
    print("This test uses a CodeChecker server... connecting...")
    server_access = codechecker.start_or_get_server()
    server_access['viewer_product'] = 'cleanup_plan'
    codechecker.add_test_package_product(server_access, TEST_WORKSPACE)

    # Extend the checker configuration with the server access.
    codechecker_cfg.update(server_access)

    # Check the test project for the first time.
    test_project_name = project_info['name'] + '_' + uuid.uuid4().hex
    ret = codechecker.check_and_store(codechecker_cfg,
                                      test_project_name,
                                      test_project_path)
    if ret:
        sys.exit(1)
    print("Analyzing test project was successful.")

    codechecker_cfg['run_names'] = [test_project_name]
    test_config['codechecker_cfg'] = codechecker_cfg
    env.export_test_cfg(TEST_WORKSPACE, test_config)
Ejemplo n.º 10
0
def setup_package():
    """Setup the environment for the tests. """

    global TEST_WORKSPACE
    TEST_WORKSPACE = env.get_workspace('comment')

    os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE

    test_project = 'cpp'

    test_project_path = project.path(test_project)

    test_config = {}

    project_info = project.get_info(test_project)

    test_config['test_project'] = project_info

    suppress_file = None

    skip_list_file = None

    test_env = env.test_env(TEST_WORKSPACE)

    codechecker_cfg = {
        'suppress_file': suppress_file,
        'skip_list_file': skip_list_file,
        'check_env': test_env,
        'workspace': TEST_WORKSPACE,
        'reportdir': os.path.join(TEST_WORKSPACE, 'reports'),
        'checkers':
        ['-d', 'core.CallAndMessage', '-e', 'core.StackAddressEscape']
    }

    # Start or connect to the running CodeChecker server and get connection
    # details.
    print("This test uses a CodeChecker server... connecting...")
    server_access = codechecker.start_or_get_server(auth_required=True)
    server_access['viewer_product'] = 'comment'
    codechecker.add_test_package_product(server_access, TEST_WORKSPACE)

    # Extend the checker configuration with the server access.
    codechecker_cfg.update(server_access)

    # Check the test project for the first time.
    test_project_names = []
    test_project_name = project_info['name'] + '_' + uuid.uuid4().hex
    test_project_names.append(test_project_name)

    ret = codechecker.check_and_store(codechecker_cfg, test_project_name,
                                      test_project_path)
    if ret:
        sys.exit(1)
    print("Analyzing test project was successful.")

    # Check the test project again.
    test_project_name = project_info['name'] + '_' + uuid.uuid4().hex
    test_project_names.append(test_project_name)

    ret = codechecker.check_and_store(codechecker_cfg, test_project_name,
                                      test_project_path)
    if ret:
        sys.exit(1)
    print("Analyzing test project was succcessful.")

    codechecker_cfg['run_names'] = test_project_names
    test_config['codechecker_cfg'] = codechecker_cfg
    env.export_test_cfg(TEST_WORKSPACE, test_config)
Ejemplo n.º 11
0
def setup_package():
    """Setup the environment for testing products."""

    global TEST_WORKSPACE
    TEST_WORKSPACE = env.get_workspace('producttest')

    # Set the TEST_WORKSPACE used by the tests.
    os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE

    test_config = {}

    test_project = 'single_bug'

    project_info = project.get_info(test_project)

    # Copy the test project to the workspace. The tests should
    # work only on this test project.
    test_proj_path = os.path.join(TEST_WORKSPACE, "test_proj")
    shutil.copytree(project.path(test_project), test_proj_path)

    project_info['project_path'] = test_proj_path

    # Generate a unique name for this test run.
    test_project_name = project_info['name'] + '_' + uuid.uuid4().hex

    test_config['test_project'] = project_info

    # Get an environment which should be used by the tests.
    test_env = env.test_env(TEST_WORKSPACE)

    # Create a basic CodeChecker config for the tests, this should
    # be imported by the tests and they should only depend on these
    # configuration options.
    codechecker_cfg = {
        'check_env': test_env,
        'workspace': TEST_WORKSPACE,
        'checkers': []
    }

    # Start or connect to the running CodeChecker server and get connection
    # details.
    print("This test uses a CodeChecker server... connecting...")
    server_access = codechecker.start_or_get_server(auth_required=True)
    server_access['viewer_product'] = 'producttest'
    codechecker.add_test_package_product(server_access, TEST_WORKSPACE)

    # Extend the checker configuration with the server access.
    codechecker_cfg.update(server_access)

    # Clean the test project, if needed by the tests.
    ret = project.clean(test_project)
    if ret:
        sys.exit(ret)

    # Check the test project, if needed by the tests.
    ret = codechecker.check_and_store(codechecker_cfg, test_project_name,
                                      project.path(test_project))
    if ret:
        sys.exit(1)
    print("Analyzing the test project was successful.")

    # Save the run names in the configuration.
    codechecker_cfg['run_names'] = [test_project_name]

    test_config['codechecker_cfg'] = codechecker_cfg

    # Export the test configuration to the workspace.
    env.export_test_cfg(TEST_WORKSPACE, test_config)
Ejemplo n.º 12
0
def setup_package():
    """Setup the environment for the tests."""

    global TEST_WORKSPACE
    TEST_WORKSPACE = env.get_workspace('cmdline')

    os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE

    test_project = 'cpp'

    test_config = {}

    project_info = project.get_info(test_project)

    # Copy the test project to the workspace. The tests should
    # work only on this test project.
    test_proj_path = os.path.join(TEST_WORKSPACE, "test_proj")
    shutil.copytree(project.path(test_project), test_proj_path)

    project_info['project_path'] = test_proj_path

    test_config['test_project'] = project_info

    suppress_file = None

    skip_list_file = None

    test_env = env.test_env(TEST_WORKSPACE)

    codechecker_cfg = {
        'suppress_file': suppress_file,
        'skip_list_file': skip_list_file,
        'check_env': test_env,
        'workspace': TEST_WORKSPACE,
        'checkers': [],
        'description': "Runs for command line test."
    }

    ret = project.clean(test_project)
    if ret:
        sys.exit(ret)

    # Start or connect to the running CodeChecker server and get connection
    # details.
    print("This test uses a CodeChecker server... connecting...")
    server_access = codechecker.start_or_get_server()
    server_access['viewer_product'] = 'cmdline'
    codechecker.add_test_package_product(server_access, TEST_WORKSPACE)

    # Extend the checker configuration with the server access.
    codechecker_cfg.update(server_access)

    # Generate a unique name for this test run.
    test_project_name_1 = project_info['name'] + '1_' + uuid.uuid4().hex

    ret = codechecker.check_and_store(codechecker_cfg, test_project_name_1,
                                      project.path(test_project))
    if ret:
        sys.exit(1)
    print("Analyzing the test project was successful.")

    test_project_name_2 = project_info['name'] + '2_' + uuid.uuid4().hex

    ret = codechecker.check_and_store(codechecker_cfg, test_project_name_2,
                                      project.path(test_project))
    if ret:
        sys.exit(1)
    print("Analyzing the test project was successful.")

    codechecker_cfg['run_names'] = [test_project_name_1, test_project_name_2]

    test_config['codechecker_cfg'] = codechecker_cfg

    env.export_test_cfg(TEST_WORKSPACE, test_config)
Ejemplo n.º 13
0
def setup_package():
    """Setup the environment for testing delete_runs."""

    global TEST_WORKSPACE
    TEST_WORKSPACE = env.get_workspace('delete_runs')

    # Set the TEST_WORKSPACE used by the tests.
    os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE

    test_config = {}

    test_project = 'simple'

    project_info = project.get_info(test_project)

    # Copy the test project to the workspace. The tests should
    # work only on this test project.
    test_proj_path = os.path.join(TEST_WORKSPACE, "test_proj")
    shutil.copytree(project.path(test_project), test_proj_path)

    project_info['project_path'] = test_proj_path

    # Generate a unique name for this test run.
    test_project_name = project_info['name']

    test_config['test_project'] = project_info

    # Suppress file should be set here if needed by the tests.
    suppress_file = None

    # Skip list file should be set here if needed by the tests.
    skip_list_file = None

    # Get an environment which should be used by the tests.
    test_env = env.test_env(TEST_WORKSPACE)

    # Create a basic CodeChecker config for the tests, this should
    # be imported by the tests and they should only depend on these
    # configuration options.
    codechecker_cfg = {
        'suppress_file': suppress_file,
        'skip_list_file': skip_list_file,
        'check_env': test_env,
        'workspace': TEST_WORKSPACE,
        'checkers': []
    }

    # Start or connect to the running CodeChecker server and get connection
    # details.
    print("This test uses a CodeChecker server... connecting...")
    server_access = codechecker.start_or_get_server()
    server_access['viewer_product'] = 'delete_runs'
    codechecker.add_test_package_product(server_access, TEST_WORKSPACE)

    # Extend the checker configuration with the server access.
    codechecker_cfg.update(server_access)

    for i in range(0, 5):
        # Clean the test project, if needed by the tests.
        ret = project.clean(test_project)
        if ret:
            sys.exit(ret)

        # Check the test project, if needed by the tests.
        ret = codechecker.check_and_store(codechecker_cfg,
                                          test_project_name + '_' + str(i),
                                          test_proj_path)
        if ret:
            sys.exit(1)

        print("Analyzing the test project was successful {}.".format(str(i)))

        # If the check process is very fast, datetime of multiple runs can be
        # almost the same different in microseconds. Test cases of delete runs
        # can be failed for this reason because we didn't process microseconds
        # in command line arguments.
        time.sleep(1)

    # Save the run names in the configuration.
    codechecker_cfg['run_names'] \
        = [test_project_name + '_' + str(i) for i in range(0, 5)]

    test_config['codechecker_cfg'] = codechecker_cfg

    # Export the test configuration to the workspace.
    env.export_test_cfg(TEST_WORKSPACE, test_config)
Ejemplo n.º 14
0
 def _check_source_file(self, cfg):
     codechecker.check_and_store(cfg, self._run_name, self._test_dir)
Ejemplo n.º 15
0
def setup_package():
    """Setup the environment for the tests."""

    global TEST_WORKSPACE
    TEST_WORKSPACE = env.get_workspace('report_viewer_api')

    os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE

    test_project = 'cpp'

    test_config = {}

    project_info = project.get_info(test_project)

    test_proj_path = os.path.join(TEST_WORKSPACE, "test_proj")
    shutil.copytree(project.path(test_project), test_proj_path)

    project_info['project_path'] = test_proj_path

    test_config['test_project'] = project_info

    suppress_file = None

    skip_list_file = None

    tag = 'v1.0'

    test_env = env.test_env(TEST_WORKSPACE)

    codechecker_cfg = {
        'suppress_file': suppress_file,
        'skip_list_file': skip_list_file,
        'check_env': test_env,
        'workspace': TEST_WORKSPACE,
        'checkers': ['-e', 'clang-diagnostic-return-type'],
        'tag': tag
    }

    ret = project.clean(test_project)
    if ret:
        sys.exit(ret)

    # Start or connect to the running CodeChecker server and get connection
    # details.
    print("This test uses a CodeChecker server... connecting...")
    server_access = codechecker.start_or_get_server()
    server_access['viewer_product'] = 'report_viewer_api'
    codechecker.add_test_package_product(server_access, TEST_WORKSPACE)

    # Extend the checker configuration with the server access.
    codechecker_cfg.update(server_access)

    test_project_name = project_info['name'] + '_' + uuid.uuid4().hex + '**'

    ret = codechecker.check_and_store(codechecker_cfg,
                                      test_project_name,
                                      project.path(test_project))
    if ret:
        sys.exit(1)
    print("Analyzing the test project was successful.")

    test_project_name_new = project_info['name'] + '*' + uuid.uuid4().hex + '%'

    # Let's run the second analysis with different
    # checkers to have some real difference.
    codechecker_cfg['checkers'] = ['-e', 'core.CallAndMessage',
                                   '-d', 'core.StackAddressEscape',
                                   '-d', 'unix.Malloc'
                                   ]
    codechecker_cfg['tag'] = None
    ret = codechecker.check_and_store(codechecker_cfg,
                                      test_project_name_new,
                                      project.path(test_project))

    if ret:
        sys.exit(1)
    print("Second analysis of the test project was successful.")

    test_project_name_third = project_info['name'] + uuid.uuid4().hex

    # Let's run the third analysis.
    ret = codechecker.check_and_store(codechecker_cfg,
                                      test_project_name_third,
                                      project.path(test_project))

    if ret:
        sys.exit(1)
    print("Third analysis of the test project was successful.")

    # Let's run the second analysis and updat the same run.
    codechecker_cfg['checkers'] = ['-d', 'core.StackAddressEscape']
    ret = codechecker.check_and_store(codechecker_cfg,
                                      test_project_name_third,
                                      project.path(test_project))

    if ret:
        sys.exit(1)
    print("4th analysis of the test project was successful.")

    codechecker_cfg['run_names'] = [test_project_name,
                                    test_project_name_new]

    test_config['codechecker_cfg'] = codechecker_cfg

    env.export_test_cfg(TEST_WORKSPACE, test_config)
Ejemplo n.º 16
0
    def test_suppress_comment_in_db(self):
        """
        Exported source suppress comment stored as a review status in the db.
        """
        runid = self._runid
        logging.debug("Get all run results from the db for runid: " +
                      str(runid))

        hash_to_suppress_msgs = {}
        with open(os.path.join(self._test_project_path, "suppress.expected"),
                  'r', encoding="utf-8", errors="ignore") as expected:
            for line in expected:
                src_code_info = line.strip().split('||')

                status = None
                if len(src_code_info) == 4:
                    # Newest source code comment format where status is given.
                    bug_hash, _, msg, status = src_code_info
                elif len(src_code_info) == 3:
                    # Old format where review status is not given.
                    bug_hash, _, msg = src_code_info
                else:
                    # Oldest source code comment format where status and file
                    # name are not given.
                    bug_hash, msg = src_code_info

                rw_status = ReviewStatus.FALSE_POSITIVE
                if status == 'confirmed':
                    rw_status = ReviewStatus.CONFIRMED
                elif status == 'intentional':
                    rw_status = ReviewStatus.INTENTIONAL

                hash_to_suppress_msgs[bug_hash] = {'message': msg,
                                                   'status': rw_status}

        run_results = get_all_run_results(self._cc_client, runid)
        self.assertIsNotNone(run_results)
        self.assertNotEqual(len(run_results), 0)

        for bug_hash in hash_to_suppress_msgs:
            expected = hash_to_suppress_msgs[bug_hash]
            report = [x for x in run_results if x.bugHash == bug_hash][0]

            # Check the stored suppress comment
            self.assertEqual(report.reviewData.comment, expected['message'])
            self.assertEqual(report.reviewData.status, expected['status'])

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

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

        # Get the results to compare.
        updated_results = get_all_run_results(self._cc_client, self._runid)
        self.assertIsNotNone(updated_results)
        self.assertNotEqual(len(updated_results), 0)

        for bug_hash in hash_to_suppress_msgs:
            report = [x for x in updated_results if x.bugHash == bug_hash][0]

            # Check the stored suppress comment
            self.assertEqual(report.reviewData.comment, "This is really a bug")
            self.assertEqual(report.reviewData.status, ReviewStatus.CONFIRMED)

        # Check the same project again.
        codechecker_cfg = env.import_test_cfg(
            self._test_workspace)['codechecker_cfg']

        initial_test_project_name = self._run_name

        ret = codechecker.check_and_store(codechecker_cfg,
                                          initial_test_project_name,
                                          self._test_project_path)
        if ret:
            sys.exit(1)

        # Get the results to compare.
        updated_results = get_all_run_results(self._cc_client, self._runid)
        self.assertIsNotNone(updated_results)
        self.assertNotEqual(len(updated_results), 0)

        for bug_hash in hash_to_suppress_msgs:
            expected = hash_to_suppress_msgs[bug_hash]
            report = [x for x in updated_results if x.bugHash == bug_hash][0]

            # Check that source code comments in the database are changed back
            # after storage.
            self.assertEqual(report.reviewData.comment, expected['message'])
            self.assertEqual(report.reviewData.status, expected['status'])
Ejemplo n.º 17
0
    def test_garbage_file_collection(self):
        event = multiprocessing.Event()
        event.clear()

        self.codechecker_cfg['viewer_port'] = env.get_free_port()
        env.export_test_cfg(self.test_workspace,
                            {'codechecker_cfg': self.codechecker_cfg})

        env.enable_auth(self.test_workspace)

        server_access = codechecker.start_server(self.codechecker_cfg, event)
        server_access['viewer_port'] \
            = self.codechecker_cfg['viewer_port']
        server_access['viewer_product'] \
            = self.codechecker_cfg['viewer_product']

        codechecker.add_test_package_product(server_access,
                                             self.test_workspace)

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

        run_name1 = 'db_cleanup_test'
        run_name2 = f'{run_name1}2'

        self.__create_test_dir()

        # Store the results.
        codechecker.check_and_store(self.codechecker_cfg, run_name1,
                                    self.test_dir)

        # Store the results to a different run too to see if we remove only one
        # run, comments and review statuses not cleared.
        codechecker.check_and_store(self.codechecker_cfg, run_name2,
                                    self.test_dir)

        run_id1 = self.__get_run_id([run_name1])
        report = self._cc_client.getRunResults(None, 1, 0, [], None, None,
                                               False)[0]

        report_hash = report.bugHash
        report_id = report.reportId

        # Add a new comment.
        comment = CommentData(author='anybody', message='Msg')
        success = self._cc_client.addComment(report_id, comment)
        self.assertTrue(success)

        # Change review status.
        success = self._cc_client.changeReviewStatus(report_id,
                                                     ReviewStatus.CONFIRMED,
                                                     'Real bug')
        self.assertTrue(success)

        # Remove the first storage.
        self._cc_client.removeRun(run_id1, None)

        # Comments and review statuses are not cleared, because the second
        # run results still reference them.
        run_id2 = self.__get_run_id([run_name2])
        r_filter = ReportFilter(reviewStatus=[ReviewStatus.CONFIRMED])
        run_results = self._cc_client.getRunResults([run_id2], 1, 0, None,
                                                    r_filter, None, False)
        self.assertTrue(run_results)

        comments = self._cc_client.getComments(run_results[0].reportId)
        self.assertTrue(comments)

        # Remove the second run too, so it will cleanup the unused commments
        # and review statuses.
        self._cc_client.removeRun(run_id2, None)

        # Store results again and check that previous comments and review
        # statuses are gone.
        files_in_report_before = self.__get_files_in_report(run_name1)

        r_filter = ReportFilter(reportHash=[report_hash])
        report = self._cc_client.getRunResults(None, 1, 0, None, r_filter,
                                               None, False)[0]
        report_id = report.reportId

        comments = self._cc_client.getComments(report_id)
        self.assertFalse(comments)

        r_filter = ReportFilter(reviewStatus=[ReviewStatus.CONFIRMED])
        run_results = self._cc_client.getRunResults(None, 1, 0, None, r_filter,
                                                    None, False)
        self.assertFalse(run_results)

        # Checker severity levels.
        self.__check_serverity_of_reports(run_name1)

        self.__rename_project_dir()

        # Delete previous analysis report directory.
        rmtree(self.codechecker_cfg['reportdir'])

        files_in_report_after = self.__get_files_in_report(run_name1)

        event.set()

        event.clear()

        # Change severity level of core.DivideZero to LOW.
        with open(self.workspace_severity_cfg,
                  'r+',
                  encoding='utf-8',
                  errors='ignore') as severity_cgf_file:
            severity_map = json.load(severity_cgf_file)
            severity_map['core.DivideZero'] = 'LOW'

            severity_cgf_file.seek(0)
            severity_cgf_file.truncate()
            severity_cgf_file.write(str(json.dumps(severity_map)))

        self.codechecker_cfg['viewer_port'] = env.get_free_port()
        env.export_test_cfg(self.test_workspace,
                            {'codechecker_cfg': self.codechecker_cfg})

        codechecker.start_server(self.codechecker_cfg, event)
        codechecker.login(self.codechecker_cfg, self.test_workspace, 'cc',
                          'test')

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

        self.assertEqual(len(files_in_report_before & files_in_report_after),
                         0)

        for file_id in files_in_report_before:
            f = self._cc_client.getSourceFileData(file_id, False, None)
            self.assertIsNone(f.fileId)

        # Checker severity levels.
        self.__check_serverity_of_reports(run_name1)

        event.set()
 def _check_source_file(self, cfg):
     codechecker.check_and_store(cfg, 'hello', self._test_dir)
Ejemplo n.º 19
0
def setup_package():
    """Setup the environment for testing $TEST_NAME$."""

    global TEST_WORKSPACE
    TEST_WORKSPACE = env.get_workspace('$TEST_NAME$')

    # Set the TEST_WORKSPACE used by the tests.
    os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE

    # Get the clang version which is used for testing.
    # Important because different clang releases might
    # find different errors.
    clang_version = env.clang_to_test()

    test_config = {}

    test_project = 'cpp'

    project_info = project.get_info(test_project)

    # Copy the test project to the workspace. The tests should
    # work only on this test project.
    test_proj_path = os.path.join(TEST_WORKSPACE, "test_proj")
    shutil.copytree(project.path(test_project), test_proj_path)

    project_info['project_path'] = test_proj_path

    # Generate a unique name for this test run.
    test_project_name = project_info['name'] + '_' + uuid.uuid4().hex

    test_config['test_project'] = project_info

    # Suppress file should be set here if needed by the tests.
    suppress_file = None

    # Skip list file should be set here if needed by the tests.
    skip_list_file = None

    # Get an environment which should be used by the tests.
    test_env = env.test_env(TEST_WORKSPACE)

    # Create a basic CodeChecker config for the tests, this should
    # be imported by the tests and they should only depend on these
    # configuration options.
    codechecker_cfg = {
        'suppress_file': suppress_file,
        'skip_list_file': skip_list_file,
        'check_env': test_env,
        'workspace': TEST_WORKSPACE,
        'checkers': []
    }

    # Start or connect to the running CodeChecker server and get connection
    # details.
    print("This test uses a CodeChecker server... connecting...")
    server_access = codechecker.start_or_get_server()
    server_access['viewer_product'] = '$TEST_NAME$'
    codechecker.add_test_package_product(server_access, TEST_WORKSPACE)

    # Extend the checker configuration with the server access.
    codechecker_cfg.update(server_access)

    # Clean the test project, if needed by the tests.
    ret = project.clean(test_project)
    if ret:
        sys.exit(ret)

    # Check the test project, if needed by the tests.
    ret = codechecker.check_and_store(codechecker_cfg, test_project_name,
                                      project.path(test_project))
    if ret:
        sys.exit(1)
    print("Analyzing the test project was successful.")

    # Save the run names in the configuration.
    codechecker_cfg['run_names'] = [test_project_name]

    test_config['codechecker_cfg'] = codechecker_cfg

    # Export the test configuration to the workspace.
    env.export_test_cfg(TEST_WORKSPACE, test_config)