示例#1
0
    def test_product_details(self):
        """
        Test that product details columns are set properly on run
        storage / removal events.
        """
        product = self._pr_client.getCurrentProduct()
        self.assertFalse(product.runCount)
        self.assertFalse(product.latestStoreToProduct)

        run_name = "product_details_test"
        store_cmd = [
            env.codechecker_cmd(), "store", self._divide_zero_workspace,
            "--name", run_name, "--url",
            env.parts_to_url(self._codechecker_cfg)
        ]

        _call_cmd(store_cmd)

        product = self._pr_client.getCurrentProduct()
        self.assertTrue(product.runCount)
        self.assertTrue(product.latestStoreToProduct)

        rm_cmd = [
            env.codechecker_cmd(), "cmd", "del", "-n", run_name, "--url",
            env.parts_to_url(self._codechecker_cfg)
        ]

        _call_cmd(rm_cmd)

        product = self._pr_client.getCurrentProduct()
        self.assertFalse(product.runCount)
        self.assertTrue(product.latestStoreToProduct)
示例#2
0
    def test_trim_path_prefix_store(self):
        """Trim the path prefix from the sored reports.

        The source file paths are converted to absolute with the
        temporary test directory, the test trims that temporary
        test directory from the source file path during the storage.
        """
        report_file = os.path.join(self._divide_zero_workspace,
                                   "divide_zero.plist")

        report_content = {}
        with open(report_file, mode="rb") as rf:
            report_content = plistlib.load(rf)

        trimmed_paths = [
            util.trim_path_prefixes(path, [self._divide_zero_workspace])
            for path in report_content["files"]
        ]

        run_name = "store_test"
        store_cmd = [
            env.codechecker_cmd(),
            "store",
            self._divide_zero_workspace,
            "--name",
            run_name,
            "--url",
            env.parts_to_url(self._codechecker_cfg),
            "--trim-path-prefix",
            self._divide_zero_workspace,
            "--verbose",
            "debug",
        ]

        ret, out, err = _call_cmd(store_cmd)
        print(out)
        print(err)
        self.assertEqual(ret, 0, "Plist file could not store.")

        query_cmd = [
            env.codechecker_cmd(),
            "cmd",
            "results",
            run_name,
            # Use the 'Default' product.
            "--url",
            env.parts_to_url(self._codechecker_cfg),
            "-o",
            "json",
        ]

        ret, out, _ = _call_cmd(query_cmd)
        self.assertEqual(ret, 0, "Could not read from server.")
        reports = json.loads(out)

        print(json.dumps(reports, indent=2))

        self.assertEqual(len(reports), 4)
        for report in reports:
            self.assertIn(report["checkedFile"], trimmed_paths)
示例#3
0
    def test_cppcheck_report_storage(self):
        """ In the stored report not the default zero hash should be used. """

        test_dir = os.path.dirname(os.path.realpath(__file__))

        report_dir = os.path.join(test_dir, 'test_proj')

        codechecker_cfg = self._test_cfg['codechecker_cfg']

        # Copy report files to a temporary directory not to modify the
        # files in the repository.
        # Report files will be overwritten during the tests.
        temp_workspace = os.path.join(codechecker_cfg['workspace'],
                                      'test_proj')
        shutil.copytree(report_dir, temp_workspace)

        report_file = os.path.join(temp_workspace, 'divide_zero.plist')
        # Convert file paths to absolute in the report.
        plist_test.prefix_file_path(report_file, temp_workspace)

        run_name = 'cppcheck'
        store_cmd = [
            env.codechecker_cmd(),
            'store',
            '--name',
            run_name,
            # Use the 'Default' product.
            '--url',
            env.parts_to_url(codechecker_cfg),
            temp_workspace
        ]

        out = subprocess.check_output(store_cmd,
                                      encoding="utf-8",
                                      errors="ignore")
        print(out)
        query_cmd = [
            env.codechecker_cmd(),
            'cmd',
            'results',
            run_name,
            # Use the 'Default' product.
            '--url',
            env.parts_to_url(codechecker_cfg),
            '-o',
            'json'
        ]

        out = subprocess.check_output(query_cmd,
                                      encoding="utf-8",
                                      errors="ignore")
        print(out)
        reports = json.loads(out)
        self.assertEqual(len(reports), 5)
        # The stored hash should not be "0".
        for report in reports:
            self.assertNotEqual(report['bugHash'], "0")
示例#4
0
    def test_store_multiple_report_dirs(self):
        """ Test storing multiple report directories.

        Analyze the same project to different report directories with different
        checker configurations and store these report directories with one
        store command to a run.
        """
        cfg = dict(self.codechecker_cfg)
        codechecker.log(cfg, self.test_proj_dir)

        report_dir1 = os.path.join(self.test_proj_dir, 'report_dir1')
        report_dir2 = os.path.join(self.test_proj_dir, 'report_dir2')

        cfg['reportdir'] = report_dir1
        cfg['checkers'] = [
            '-d', 'core.DivideZero', '-e', 'deadcode.DeadStores'
        ]
        codechecker.analyze(cfg, self.test_proj_dir)

        cfg['reportdir'] = report_dir2
        cfg['checkers'] = [
            '-e', 'core.DivideZero', '-d', 'deadcode.DeadStores'
        ]
        codechecker.analyze(cfg, self.test_proj_dir)

        run_name = "multiple_report_dirs"
        store_cmd = [
            env.codechecker_cmd(), "store", report_dir1, report_dir2, "--name",
            run_name, "--url",
            env.parts_to_url(self.codechecker_cfg)
        ]

        proc = subprocess.Popen(store_cmd,
                                encoding="utf-8",
                                errors="ignore",
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
        _, err = proc.communicate()

        self.assertNotIn("UserWarning: Duplicate name", err)

        # Check the reports.
        query_cmd = [
            env.codechecker_cmd(), "cmd", "results", run_name, "--url",
            env.parts_to_url(self.codechecker_cfg), "-o", "json"
        ]

        out = subprocess.check_output(query_cmd,
                                      encoding="utf-8",
                                      errors="ignore")
        reports = json.loads(out)

        self.assertTrue(
            any(r['checkerId'] == 'core.DivideZero' for r in reports))

        self.assertTrue(
            any(r['checkerId'] == 'deadcode.DeadStores' for r in reports))
示例#5
0
    def test_personal_access_tokens(self):
        """ Test personal access token commands. """
        codechecker_cfg = self._test_cfg['codechecker_cfg']
        host = codechecker_cfg['viewer_host']
        port = codechecker_cfg['viewer_port']

        new_token_cmd = [
            env.codechecker_cmd(), 'cmd', 'token', 'new', '--url',
            env.parts_to_url(codechecker_cfg)
        ]

        with self.assertRaises(subprocess.CalledProcessError):
            subprocess.check_output(new_token_cmd)

        # Login to the server.
        auth_client = env.setup_auth_client(self._test_workspace,
                                            session_token='_PROHIBIT')

        # A non-authenticated session should return an empty user.
        user = auth_client.getLoggedInUser()
        self.assertEqual(user, "")

        # Create a SUPERUSER login.
        session_token = auth_client.performLogin("Username:Password",
                                                 "cc:test")

        self.assertIsNotNone(session_token,
                             "Valid credentials didn't give us a token!")

        cred_manager = UserCredentials()
        cred_manager.save_token(host, port, session_token)

        # Run the new token command after login.
        subprocess.check_output(new_token_cmd)

        # List personal access tokens.
        list_token_cmd = [
            env.codechecker_cmd(), 'cmd', 'token', 'list', '--url',
            env.parts_to_url(codechecker_cfg), '-o', 'json'
        ]

        out_json = subprocess.check_output(list_token_cmd)
        tokens = json.loads(out_json)
        self.assertEqual(len(tokens), 1)

        # Remove personal access token.
        del_token_cmd = [
            env.codechecker_cmd(), 'cmd', 'token', 'del', '--url',
            env.parts_to_url(codechecker_cfg), tokens[0]['token']
        ]

        subprocess.check_output(del_token_cmd)

        cred_manager.save_token(host, port, session_token, True)
示例#6
0
    def test_valid_json_config(self):
        """ Store with a valid JSON configuration file. """
        cc_env = env.codechecker_env()
        cc_env["CC_REPORT_DIR"] = self.codechecker_cfg['reportdir']

        with open(self.config_file_json,
                  'w+',
                  encoding="utf-8",
                  errors="ignore") as config_f:
            json.dump(
                {
                    'store': [
                        '--name=' + 'store_config', '--trim-path-prefix=$HOME',
                        '--url=' + env.parts_to_url(self.codechecker_cfg),
                        '$CC_REPORT_DIR'
                    ]
                }, config_f)

        store_cmd = [
            env.codechecker_cmd(), 'store', '--config', self.config_file_json
        ]

        try:
            subprocess.check_output(store_cmd,
                                    env=cc_env,
                                    encoding="utf-8",
                                    errors="ignore")
        except subprocess.CalledProcessError as cerr:
            print(cerr.output)
            raise
    def test_suppress_import(self):
        """
        Test the suppress file importing.
        """

        generated_file = os.path.join(self._test_workspace,
                                      "generated.suppress")

        extract_cmd = ['CodeChecker', 'parse',
                       os.path.join(self._test_workspace, "reports"),
                       "--suppress", generated_file,
                       "--export-source-suppress"
                       ]

        ret = call_cmd(extract_cmd,
                       self._test_project_path,
                       env.test_env(self._test_workspace))
        self.assertEqual(ret, 0, "Failed to generate suppress file.")

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

        product_url = env.parts_to_url(codechecker_cfg)
        import_cmd = ['CodeChecker', 'cmd', 'suppress', '-i', generated_file,
                      '--url', product_url, self._run_name]

        print(import_cmd)
        ret = call_cmd(import_cmd,
                       self._test_project_path,
                       env.test_env(self._test_workspace))
        self.assertEqual(ret, 0, "Failed to import suppress file.")
    def setUp(self):

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

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

        codechecker_cfg = env.import_test_cfg(
            test_workspace)['codechecker_cfg']
        self.server_url = env.parts_to_url(codechecker_cfg)

        # Get the test project configuration from the prepared test workspace.
        self._testproject_data = env.setup_test_proj_cfg(test_workspace)
        self.assertIsNotNone(self._testproject_data)

        # Setup a viewer client to test viewer API calls.
        self._cc_client = env.setup_viewer_client(test_workspace)
        self.assertIsNotNone(self._cc_client)

        # Get the CodeChecker cmd if needed for the tests.
        self._codechecker_cmd = env.codechecker_cmd()

        # Get the run names which belong to this test.
        run_names = env.get_run_names(test_workspace)

        runs = self._cc_client.getRunData(None, None, 0, None)
        self.test_runs = [run for run in runs if run.name in run_names]
    def setUp(self):
        # TEST_WORKSPACE is automatically set by test package __init__.py .
        test_workspace = os.environ['TEST_WORKSPACE']

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

        # Get the test configuration from the prepared int the test workspace.
        self._test_cfg = env.import_test_cfg(test_workspace)

        # Get the test project configuration from the prepared test workspace.
        self._testproject_data = env.setup_test_proj_cfg(test_workspace)
        self.assertIsNotNone(self._testproject_data)

        # Setup a viewer client to test viewer API calls.
        self._cc_client = env.setup_viewer_client(test_workspace)
        self.assertIsNotNone(self._cc_client)

        # Get the CodeChecker cmd if needed for the tests.
        self._codechecker_cmd = env.codechecker_cmd()

        # Get the run names which belong to this test.
        self._run_names = env.get_run_names(test_workspace)

        local_test_project = \
            self._test_cfg['test_project']['project_path_local']

        self._local_reports = os.path.join(local_test_project, 'reports')

        self._url = env.parts_to_url(self._test_cfg['codechecker_cfg'])

        self._env = self._test_cfg['codechecker_cfg']['check_env']
示例#10
0
    def test_suppress_import(self):
        """
        Test the suppress file importing.
        """

        generated_file = os.path.join(self._test_workspace,
                                      "generated.suppress")

        extract_cmd = ['CodeChecker', 'parse',
                       os.path.join(self._test_workspace, "reports"),
                       "--suppress", generated_file,
                       "--export-source-suppress"
                       ]

        ret = call_cmd(extract_cmd,
                       self._test_project_path,
                       env.test_env(self._test_workspace))
        self.assertEqual(ret, 0, "Failed to generate suppress file.")

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

        product_url = env.parts_to_url(codechecker_cfg)
        import_cmd = ['CodeChecker', 'cmd', 'suppress', '-i', generated_file,
                      '--url', product_url, self._run_name]

        print(import_cmd)
        ret = call_cmd(import_cmd,
                       self._test_project_path,
                       env.test_env(self._test_workspace))
        self.assertEqual(ret, 0, "Failed to import suppress file.")
示例#11
0
    def test_nonauth_storage(self):
        """
        Storing the result should fail.
        Authentication is required by the server but before the
        store command there was no login so storing the report should fail.
        """

        test_dir = os.path.dirname(os.path.realpath(__file__))
        report_file = os.path.join(test_dir, 'clang-5.0-trunk.plist')

        codechecker_cfg = self._test_cfg['codechecker_cfg']

        store_cmd = [
            env.codechecker_cmd(),
            'store',
            '--name',
            'auth',
            # Use the 'Default' product.
            '--url',
            env.parts_to_url(codechecker_cfg),
            report_file
        ]

        with self.assertRaises(subprocess.CalledProcessError):
            subprocess.check_output(store_cmd,
                                    encoding="utf-8",
                                    errors="ignore")
示例#12
0
        def store_multiple_report_dirs(report_dirs):
            """ """
            run_name = "multiple_report_dirs"
            store_cmd = [
                env.codechecker_cmd(), "store",
                *report_dirs,
                "--name", run_name,
                "--url", env.parts_to_url(self.codechecker_cfg)]

            proc = subprocess.Popen(
                store_cmd, encoding="utf-8", errors="ignore",
                stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            _, err = proc.communicate()

            self.assertNotIn("UserWarning: Duplicate name", err)

            # Check the reports.
            query_cmd = [
                env.codechecker_cmd(), "cmd", "results",
                run_name,
                "--url", env.parts_to_url(self.codechecker_cfg),
                "-o", "json"]

            out = subprocess.check_output(
                query_cmd, encoding="utf-8", errors="ignore")
            reports = json.loads(out)

            self.assertTrue(
                any(r['checkerId'] == 'core.DivideZero' for r in reports))

            self.assertTrue(
                any(r['checkerId'] == 'deadcode.DeadStores' for r in reports))

            # Check the reports.
            rm_cmd = [
                env.codechecker_cmd(), "cmd", "del",
                "-n", run_name,
                "--url", env.parts_to_url(self.codechecker_cfg)]

            out = subprocess.check_output(
                rm_cmd, encoding="utf-8", errors="ignore")
示例#13
0
    def test_empty_config(self):
        """ Store with an empty configuration file. """
        with open(self.config_file, 'w+', encoding="utf-8",
                  errors="ignore") as config_f:
            config_f.write("")

        store_cmd = [
            env.codechecker_cmd(), 'store', '--name', 'store_config',
            '--config', self.config_file, '--url',
            env.parts_to_url(self.codechecker_cfg),
            self.codechecker_cfg['reportdir']
        ]

        subprocess.check_output(store_cmd, encoding="utf-8", errors="ignore")
示例#14
0
    def test_suppress_duplicated(self):
        """
        Test server if recognise duplicated suppress comments in the stored
        source code.
        """
        test_plist_file = "double_suppress.plist"

        store_cmd = [
            env.codechecker_cmd(), "store", "--url",
            env.parts_to_url(self._codechecker_cfg), "--name", "never",
            "--input-format", "plist", "--verbose", "debug", test_plist_file
        ]

        ret, _, _ = _call_cmd(store_cmd, self._double_suppress_workspace)
        self.assertEqual(ret, 1, "Duplicated suppress comments was not "
                         "recognised.")
示例#15
0
    def test_invalid_config(self):
        """ Store with an invalid configuration file. """
        with open(self.config_file, 'w+', encoding="utf-8",
                  errors="ignore") as config_f:
            json.dump({'store': ['--dummy-option']}, config_f)

        store_cmd = [
            env.codechecker_cmd(), 'store', '--name', 'store_config',
            '--config', self.config_file, '--url',
            env.parts_to_url(self.codechecker_cfg),
            self.codechecker_cfg['reportdir']
        ]

        with self.assertRaises(subprocess.CalledProcessError):
            subprocess.check_output(store_cmd,
                                    encoding="utf-8",
                                    errors="ignore")
示例#16
0
    def setUp(self):

        # 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 test configuration from the prepared int the test workspace.
        self.test_cfg = env.import_test_cfg(self.test_workspace)

        # Get the clang version which is tested.
        self._clang_to_test = env.clang_to_test()

        # Get the test project configuration from the prepared test workspace.
        self._testproject_data = env.setup_test_proj_cfg(self.test_workspace)
        self.assertIsNotNone(self._testproject_data)

        # Setup a viewer client to test viewer API calls.
        self._cc_client = env.setup_viewer_client(self.test_workspace)
        self.assertIsNotNone(self._cc_client)

        # Get the CodeChecker cmd if needed for the tests.
        self._codechecker_cmd = env.codechecker_cmd()

        # Get the run names which belong to this test.
        # Name order matters from __init__ !
        run_names = env.get_run_names(self.test_workspace)

        sort_mode = RunSortMode(RunSortType.DATE, Order.ASC)
        runs = self._cc_client.getRunData(None, None, 0, sort_mode)
        self._test_runs = [run for run in runs if run.name in run_names]

        # There should be at least two runs for this test.
        self.assertIsNotNone(runs)
        self.assertNotEqual(len(runs), 0)
        self.assertGreaterEqual(len(runs), 2)

        # Name order matters from __init__ !
        self._base_runid = self._test_runs[0].runId
        self._new_runid = self._test_runs[1].runId
        self._update_runid = self._test_runs[2].runId

        self._url = env.parts_to_url(self.test_cfg['codechecker_cfg'])

        self._env = self.test_cfg['codechecker_cfg']['check_env']
示例#17
0
    def test_valid_config(self):
        """ Store with a valid configuration file. """
        with open(self.config_file, 'w+', encoding="utf-8",
                  errors="ignore") as config_f:
            json.dump(
                {
                    'store': [
                        '--name=' + 'store_config',
                        '--url=' + env.parts_to_url(self.codechecker_cfg),
                        self.codechecker_cfg['reportdir']
                    ]
                }, config_f)

        store_cmd = [
            env.codechecker_cmd(), 'store', '--config', self.config_file
        ]

        subprocess.check_output(store_cmd, encoding="utf-8", errors="ignore")
示例#18
0
    def test_nonauth_storage(self):
        """
        Storing the result should fail.
        Authentication is required by the server but before the
        store command there was no login so storing the report should fail.
        """

        test_dir = os.path.dirname(os.path.realpath(__file__))
        report_file = os.path.join(test_dir, 'clang-5.0-trunk.plist')

        codechecker_cfg = self._test_cfg['codechecker_cfg']

        store_cmd = [env.codechecker_cmd(), 'store', '--name', 'auth',
                     # Use the 'Default' product.
                     '--url', env.parts_to_url(codechecker_cfg),
                     report_file]

        with self.assertRaises(subprocess.CalledProcessError):
            subprocess.check_output(store_cmd)
示例#19
0
    def setUp(self):
        test_workspace = os.environ['TEST_WORKSPACE']

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

        # Get the clang version which is tested.
        self._clang_to_test = env.clang_to_test()

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

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

        # Get the run names which belong to this test.
        run_names = env.get_run_names(test_workspace)

        runs = self._cc_client.getRunData(None)

        test_runs = [run for run in runs if run.name in run_names]
        for r in test_runs:
            print(r)

        # There should be at least two runs for this test.
        self.assertIsNotNone(runs)
        self.assertNotEqual(len(runs), 0)
        self.assertGreaterEqual(len(runs), 2)

        # Name order matters from __init__ !
        self._base_runid = test_runs[0].runId  # base
        self._new_runid = test_runs[1].runId  # new
        self._update_runid = test_runs[2].runId  # updated

        self._codechecker_cmd = env.codechecker_cmd()
        self._report_dir = os.path.join(test_workspace, "reports")
        self._report_dir_baseline = os.path.join(test_workspace,
                                                 "reports_baseline")
        self._test_config = env.import_test_cfg(test_workspace)
        self._run_names = env.get_run_names(test_workspace)
        self._html_reports = os.path.join(test_workspace, "html_reports")

        self._url = env.parts_to_url(self._test_config['codechecker_cfg'])
示例#20
0
    def test_get_access_control_from_cli(self):
        """ Test getting access control information by using CLI. """
        cmd_env = os.environ.copy()
        cmd_env["CC_PASS_FILE"] = os.path.join(self._test_workspace,
                                               ".codechecker.passwords.json")
        cmd_env["CC_SESSION_FILE"] = os.path.join(self._test_workspace,
                                                  ".codechecker.session.json")

        cmd = [
            env.codechecker_cmd(), 'cmd', 'permissions', '--url',
            env.parts_to_url(self.codechecker_cfg)
        ]

        out = subprocess.check_output(cmd,
                                      env=cmd_env,
                                      encoding="utf-8",
                                      errors="ignore")

        access_control = json.loads(out)
        self.assertDictEqual(
            {
                "version": 1,
                "global_permissions": {
                    "user_permissions": {
                        "root": ["SUPERUSER"]
                    },
                    "group_permissions": {
                        'admins_custom_group': ['SUPERUSER']
                    }
                },
                "product_permissions": {
                    "authentication": {
                        "user_permissions": {
                            "cc": ["PRODUCT_STORE"],
                            "john": ["PRODUCT_STORE"],
                            "admin": ["PRODUCT_ADMIN"]
                        },
                        "group_permissions": {
                            'ADMIN_group': ['PRODUCT_ADMIN']
                        }
                    }
                }
            }, access_control)
示例#21
0
    def setUp(self):
        test_workspace = os.environ['TEST_WORKSPACE']

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

        # Get the clang version which is tested.
        self._clang_to_test = env.clang_to_test()

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

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

        # Get the run names which belong to this test.
        run_names = env.get_run_names(test_workspace)

        runs = self._cc_client.getRunData(None)

        test_runs = [run for run in runs if run.name in run_names]
        for r in test_runs:
            print(r)

        # There should be at least two runs for this test.
        self.assertIsNotNone(runs)
        self.assertNotEqual(len(runs), 0)
        self.assertGreaterEqual(len(runs), 2)

        # Name order matters from __init__ !
        self._base_runid = test_runs[0].runId  # base
        self._new_runid = test_runs[1].runId  # new
        self._update_runid = test_runs[2].runId  # updated

        self._codechecker_cmd = env.codechecker_cmd()
        self._report_dir = os.path.join(test_workspace, "reports")
        self._report_dir_baseline = os.path.join(test_workspace,
                                                 "reports_baseline")
        self._test_config = env.import_test_cfg(test_workspace)
        self._run_names = env.get_run_names(test_workspace)
        self._html_reports = os.path.join(test_workspace, "html_reports")

        self._url = env.parts_to_url(self._test_config['codechecker_cfg'])
示例#22
0
    def test_empty_config(self):
        """ Store with an empty configuration file. """
        with open(self.config_file_json,
                  'w+',
                  encoding="utf-8",
                  errors="ignore") as config_f:
            config_f.write("")

        store_cmd = [
            env.codechecker_cmd(), 'store', '--name', 'store_config',
            '--config', self.config_file_json, '--url',
            env.parts_to_url(self.codechecker_cfg),
            self.codechecker_cfg['reportdir']
        ]

        try:
            subprocess.check_output(store_cmd,
                                    encoding="utf-8",
                                    errors="ignore")
        except subprocess.CalledProcessError as cerr:
            print(cerr.output)
            raise
示例#23
0
    def setUp(self):

        test_workspace = os.environ.get('TEST_WORKSPACE')

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

        codechecker_cfg = env.import_test_cfg(
            test_workspace)['codechecker_cfg']
        self.server_url = env.parts_to_url(codechecker_cfg)

        # Get the test project configuration from the prepared test workspace.
        self._testproject_data = env.setup_test_proj_cfg(test_workspace)
        self.assertIsNotNone(self._testproject_data)

        # Setup a viewer client to test viewer API calls.
        self._cc_client = env.setup_viewer_client(test_workspace)
        self.assertIsNotNone(self._cc_client)

        # Get the CodeChecker cmd if needed for the tests.
        self._codechecker_cmd = env.codechecker_cmd()

        self._test_config = env.import_test_cfg(test_workspace)
示例#24
0
    def setUp(self):
        # TEST_WORKSPACE is automatically set by test package __init__.py .
        test_workspace = os.environ['TEST_WORKSPACE']

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

        codechecker_cfg = env.import_test_cfg(test_workspace)[
            'codechecker_cfg']
        self.server_url = env.parts_to_url(codechecker_cfg)

        # Get the test project configuration from the prepared test workspace.
        self._testproject_data = env.setup_test_proj_cfg(test_workspace)
        self.assertIsNotNone(self._testproject_data)

        # Setup a viewer client to test viewer API calls.
        self._cc_client = env.setup_viewer_client(test_workspace)
        self.assertIsNotNone(self._cc_client)

        # Get the CodeChecker cmd if needed for the tests.
        self._codechecker_cmd = env.codechecker_cmd()

        self._test_config = env.import_test_cfg(test_workspace)
示例#25
0
    def test_tim_path_prefix_store(self):
        """Trim the path prefix from the sored reports.

        The source file paths are converted to absolute with the
        temporary test directory, the test trims that temporary
        test directory from the source file path during the storage.
        """

        test_dir = os.path.dirname(os.path.realpath(__file__))

        report_dir = os.path.join(test_dir, "test_proj")

        codechecker_cfg = self._test_cfg["codechecker_cfg"]

        # Copy report files to a temporary directory not to modify the
        # files in the repository.
        # Report files will be overwritten during the tests.
        temp_workspace = os.path.join(codechecker_cfg["workspace"],
                                      "test_proj")
        shutil.copytree(report_dir, temp_workspace)

        report_file = os.path.join(temp_workspace, "divide_zero.plist")

        # Convert file paths to absolute in the report.
        plist_test.prefix_file_path(report_file, temp_workspace)

        report_content = {}
        with open(report_file, mode="rb") as rf:
            report_content = plistlib.load(rf)

        trimmed_paths = [
            util.trim_path_prefixes(path, [temp_workspace])
            for path in report_content["files"]
        ]

        run_name = "store_test"
        store_cmd = [
            env.codechecker_cmd(),
            "store",
            temp_workspace,
            "--name",
            run_name,
            "--url",
            env.parts_to_url(codechecker_cfg),
            "--trim-path-prefix",
            temp_workspace,
            "--verbose",
            "debug",
        ]

        try:
            out = subprocess.check_output(store_cmd,
                                          encoding="utf-8",
                                          errors="ignore")
            print(out)
        except subprocess.CalledProcessError as cerr:
            print(cerr.stdout)
            print(cerr.stderr)
            raise

        query_cmd = [
            env.codechecker_cmd(),
            "cmd",
            "results",
            run_name,
            # Use the 'Default' product.
            "--url",
            env.parts_to_url(codechecker_cfg),
            "-o",
            "json",
        ]

        out = subprocess.check_output(query_cmd,
                                      encoding="utf-8",
                                      errors="ignore")
        reports = json.loads(out)

        print(json.dumps(reports, indent=2))

        self.assertEqual(len(reports), 4)
        for report in reports:
            self.assertIn(report["checkedFile"], trimmed_paths)
示例#26
0
        def store_multiple_report_dirs(report_dirs):
            """ """
            run_name = "multiple_report_dirs"
            store_cmd = [
                env.codechecker_cmd(), "store", *report_dirs, "--name",
                run_name, "--url",
                env.parts_to_url(self._codechecker_cfg)
            ]

            proc = subprocess.Popen(store_cmd,
                                    encoding="utf-8",
                                    errors="ignore",
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)
            _, err = proc.communicate()

            self.assertNotIn("UserWarning: Duplicate name", err)

            # Check the reports.
            query_cmd = [
                env.codechecker_cmd(), "cmd", "results", run_name, "--url",
                env.parts_to_url(self._codechecker_cfg), "-o", "json"
            ]

            out = subprocess.check_output(query_cmd,
                                          encoding="utf-8",
                                          errors="ignore")
            reports = json.loads(out)

            self.assertTrue(
                any(r['checkerId'] == 'core.DivideZero' for r in reports))

            self.assertTrue(
                any(r['checkerId'] == 'deadcode.DeadStores' for r in reports))

            # Get analysis info.
            limit = None
            offset = 0
            report = [
                r for r in reports if r['checkerId'] == 'core.DivideZero'
            ][0]

            # Get analysis info for a run.
            analysis_info_filter = AnalysisInfoFilter(runId=report['runId'])
            analysis_info = self._cc_client.getAnalysisInfo(
                analysis_info_filter, limit, offset)
            self.assertEqual(len(analysis_info), 2)
            self.assertTrue(
                any(report_dir1 in i.analyzerCommand for i in analysis_info))
            self.assertTrue(
                any(report_dir2 in i.analyzerCommand for i in analysis_info))

            # Get analysis info for a report.
            analysis_info_filter = AnalysisInfoFilter(
                reportId=report['reportId'])

            analysis_info = self._cc_client.getAnalysisInfo(
                analysis_info_filter, limit, offset)
            self.assertEqual(len(analysis_info), 1)
            self.assertTrue(
                any(report_dir2 in i.analyzerCommand for i in analysis_info))

            # Get analysis infor for run history.
            query_cmd = [
                env.codechecker_cmd(), "cmd", "history", "-n", run_name,
                "--url",
                env.parts_to_url(self._codechecker_cfg), "-o", "json"
            ]

            out = subprocess.check_output(query_cmd,
                                          encoding="utf-8",
                                          errors="ignore")
            history = json.loads(out)
            self.assertTrue(history)

            h = max(history, key=lambda h: h["id"])

            analysis_info_filter = AnalysisInfoFilter(runHistoryId=h['id'])
            analysis_info = self._cc_client.getAnalysisInfo(
                analysis_info_filter, limit, offset)
            self.assertEqual(len(analysis_info), 2)
            self.assertTrue(
                any(report_dir1 in i.analyzerCommand for i in analysis_info))
            self.assertTrue(
                any(report_dir2 in i.analyzerCommand for i in analysis_info))

            # Check the reports.
            rm_cmd = [
                env.codechecker_cmd(), "cmd", "del", "-n", run_name, "--url",
                env.parts_to_url(self._codechecker_cfg)
            ]

            out = subprocess.check_output(rm_cmd,
                                          encoding="utf-8",
                                          errors="ignore")
示例#27
0
    def test_trim_path_prefix_store(self):
        """Trim the path prefix from the sored reports.

        The source file paths are converted to absolute with the
        temporary test directory, the test trims that temporary
        test directory from the source file path during the storage.
        """
        report_file = os.path.join(self.test_proj_dir, "divide_zero.plist")

        report_content = {}
        with open(report_file, mode="rb") as rf:
            report_content = plistlib.load(rf)

        trimmed_paths = [
            util.trim_path_prefixes(path, [self.test_proj_dir])
            for path in report_content["files"]
        ]

        run_name = "store_test"
        store_cmd = [
            env.codechecker_cmd(),
            "store",
            self.test_proj_dir,
            "--name",
            run_name,
            "--url",
            env.parts_to_url(self.codechecker_cfg),
            "--trim-path-prefix",
            self.test_proj_dir,
            "--verbose",
            "debug",
        ]

        try:
            out = subprocess.check_output(store_cmd,
                                          encoding="utf-8",
                                          errors="ignore")
            print(out)
        except subprocess.CalledProcessError as cerr:
            print(cerr.stdout)
            print(cerr.stderr)
            raise

        query_cmd = [
            env.codechecker_cmd(),
            "cmd",
            "results",
            run_name,
            # Use the 'Default' product.
            "--url",
            env.parts_to_url(self.codechecker_cfg),
            "-o",
            "json",
        ]

        out = subprocess.check_output(query_cmd,
                                      encoding="utf-8",
                                      errors="ignore")
        reports = json.loads(out)

        print(json.dumps(reports, indent=2))

        self.assertEqual(len(reports), 4)
        for report in reports:
            self.assertIn(report["checkedFile"], trimmed_paths)