예제 #1
0
    def __set_up_test_dir(self, project_path):
        self.test_dir = project.path(project_path)

        # Get if clang is CTU-capable or not.
        cmd = [self._codechecker_cmd, 'analyze', '-h']
        output, _ = call_command(cmd, cwd=self.test_dir, env=self.env)
        self.ctu_capable = '--ctu-' in output
        print("'analyze' reported CTU-compatibility? " + str(self.ctu_capable))

        self.ctu_has_analyzer_display_ctu_progress = \
            host_check.has_analyzer_config_option(self.__getClangSaPath(),
                                                  'display-ctu-progress',
                                                  self.env)

        print("Has display-ctu-progress=true? " +
              str(self.ctu_has_analyzer_display_ctu_progress))

        # Fix the "template" build JSONs to contain a proper directory
        # so the tests work.
        raw_buildlog = os.path.join(self.test_dir, 'buildlog.json')
        with open(raw_buildlog, encoding="utf-8", errors="ignore") as log_file:
            build_json = json.load(log_file)
            for command in build_json:
                command['directory'] = self.test_dir

        self.__old_pwd = os.getcwd()
        os.chdir(self.test_workspace)
        self.buildlog = os.path.join(self.test_workspace, 'buildlog.json')
        with open(self.buildlog, 'w', encoding="utf-8",
                  errors="ignore") as log_file:
            json.dump(build_json, log_file)
예제 #2
0
def is_ctu_display_progress_capable(clangsa_path: str, env: Dict) -> bool:
    """
    Returns True if the used clang is CTU display progress capable or if it's
    force enabled by environment variable.
    """
    ctu_display_progress_capable = host_check.has_analyzer_config_option(
        clangsa_path, 'display-ctu-progress', env)

    return check_force_ctu_capable(ctu_display_progress_capable)
예제 #3
0
    def display_progress(self):
        """Return analyzer args if it is capable to display ctu progress.

        Returns None if the analyzer can not display ctu progress.
        The ctu display progress arguments depend on
        the clang analyzer version.
        """

        if not self.analyzer_version_info:
            return None
        ctu_display_progress_args = ['-Xclang',
                                     '-analyzer-config',
                                     '-Xclang',
                                     'display-ctu-progress=true']

        ok = host_check.has_analyzer_config_option(
            self.__analyzer_binary, "display-ctu-progress", self.environ)
        if not ok:
            return None
        return ctu_display_progress_args
예제 #4
0
    def setUp(self):
        """ Set up workspace."""

        # TEST_WORKSPACE is automatically set by test package __init__.py .
        self.test_workspace = os.environ['TEST_WORKSPACE']

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

        # Get the CodeChecker cmd if needed for the tests.
        self._codechecker_cmd = env.codechecker_cmd()
        self.env = env.codechecker_env()
        self.report_dir = os.path.join(self.test_workspace, 'reports')
        os.makedirs(self.report_dir)

        # Get if clang is CTU-capable or not.
        cmd = [self._codechecker_cmd, 'analyze', '-h']
        output, _, result = call_command(cmd,
                                         cwd=self.test_workspace,
                                         env=self.env)
        self.assertEqual(result, 0, "Analyzing failed.")
        setattr(self, CTU_ATTR, '--ctu-' in output)
        print("'analyze' reported CTU compatibility? " +
              str(getattr(self, CTU_ATTR)))

        setattr(self, ON_DEMAND_ATTR, '--ctu-ast-mode' in output)
        print("'analyze' reported CTU-on-demand-compatibility? " +
              str(getattr(self, ON_DEMAND_ATTR)))

        setattr(
            self, DISPLAY_PROGRESS_ATTR,
            host_check.has_analyzer_config_option(self.__getClangSaPath(),
                                                  'display-ctu-progress',
                                                  self.env))

        print("Has display-ctu-progress=true? " +
              str(getattr(self, DISPLAY_PROGRESS_ATTR)))

        self.__old_pwd = os.getcwd()
예제 #5
0
 def test_non_existent_config_option_binary(self):
     with self.assertRaises(OSError):
         hc.has_analyzer_config_option("non-existent-binary-Yg4pEna5P7", "")
예제 #6
0
 def test_non_existing_congif_option(self):
     self.assertEqual(
         hc.has_analyzer_config_option("clang",
                                       "non-existent-config-option"), False)