Exemplo n.º 1
0
def start_server(codechecker_cfg, event):
    """Start the CodeChecker server."""
    def start_server_proc(event, server_cmd, checking_env):
        """Target function for starting the CodeChecker server."""
        proc = subprocess.Popen(server_cmd, env=checking_env)

        # Blocking termination until event is set.
        event.wait()

        # If proc is still running, stop it.
        if proc.poll() is None:
            proc.terminate()

    # The server is started in the same folder as the "master" one.
    server_cmd = codechecker.serv_cmd(env.get_workspace(None),
                                      str(codechecker_cfg['viewer_port']),
                                      env.get_postgresql_cfg())

    server_proc = multiprocessing.Process(name='server',
                                          target=start_server_proc,
                                          args=(event, server_cmd,
                                                codechecker_cfg['check_env']))

    server_proc.start()

    # Wait for server to start and connect to database.
    time.sleep(5)
Exemplo n.º 2
0
def _start_server(codechecker_cfg, test_config, auth=False):
    """Start the CodeChecker server."""
    def start_server_proc(event, server_cmd, checking_env):
        """Target function for starting the CodeChecker server."""
        proc = subprocess.Popen(server_cmd, env=checking_env)

        # Blocking termination until event is set.
        event.wait()

        # If proc is still running, stop it.
        if proc.poll() is None:
            proc.terminate()

    server_cmd = codechecker.serv_cmd(codechecker_cfg['workspace'],
                                      str(codechecker_cfg['viewer_port']),
                                      env.get_postgresql_cfg())

    server_proc = multiprocessing.Process(name='server',
                                          target=start_server_proc,
                                          args=(__STOP_SERVER, server_cmd,
                                                codechecker_cfg['check_env']))

    server_proc.start()

    # Wait for server to start and connect to database.
    time.sleep(20)
Exemplo n.º 3
0
def setup_package():
    """Setup the environment for the tests then start the server."""

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

    os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE

    test_project_path = project.path()

    clang_version = env.clang_to_test()

    pg_db_config = env.get_postgresql_cfg()

    test_config = {}

    project_info = project.get_info(project.path())

    test_config['test_project'] = project_info

    suppress_file = None

    skip_list_file = None

    # Setup environment varaibled for the test cases.
    host_port_cfg = env.get_host_port_cfg()

    test_env = env.test_env()

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

    codechecker_cfg.update(host_port_cfg)

    codechecker_cfg['run_names'] = []

    test_config['codechecker_cfg'] = codechecker_cfg

    # Export configuration for the tests.
    env.export_test_cfg(TEST_WORKSPACE, test_config)

    # Enable authentication and start the CodeChecker server.
    enable_auth(TEST_WORKSPACE)
    print("Starting server to get results")
    _start_server(codechecker_cfg, test_config, False)
Exemplo n.º 4
0
def setup_package():
    """
    Setup the environment for the report_server_api test.
    """

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

    os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE

    test_project_path = project.path()

    pg_db_config = env.get_postgresql_cfg()

    test_config = {}

    suppress_file = None

    skip_list_file = None

    # Setup env vars for test cases.
    host_port_cfg = env.get_host_port_cfg()

    test_env = env.test_env()

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

    codechecker_cfg.update(host_port_cfg)

    test_config['codechecker_cfg'] = codechecker_cfg

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

    # Start the CodeChecker server.
    _start_server(codechecker_cfg, test_config, False)
Exemplo n.º 5
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

    # PostgreSQL configuration might be empty if tests are run
    # with SQLite.
    pg_db_config = env.get_postgresql_cfg()

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

    # 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,
        'pg_db_config': pg_db_config,
        'checkers': []
    }

    # Get new unique port numbers for this test run.
    host_port_cfg = env.get_host_port_cfg()

    # Extend the checker configuration with the port numbers.
    codechecker_cfg.update(host_port_cfg)

    # Start the CodeChecker server.
    print("Starting server to get results")
    _start_server(codechecker_cfg, test_config, False)

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

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

    os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE

    test_project_path = project.path()

    clang_version = env.clang_to_test()

    pg_db_config = env.get_postgresql_cfg()

    test_config = {}

    project_info = project.get_info(project.path())

    test_project_path = os.path.join(TEST_WORKSPACE, "test_proj")
    shutil.copytree(project.path(), 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

    # Get port numbers for the tests.
    host_port_cfg = env.get_host_port_cfg()

    test_env = env.test_env()

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

    codechecker_cfg.update(host_port_cfg)

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

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

    if pg_db_config:
        print("Waiting for PotgreSQL to stop.")
        codechecker.wait_for_postgres_shutdown(TEST_WORKSPACE)

    codechecker_cfg['run_names'] = [test_project_name]

    test_config['codechecker_cfg'] = codechecker_cfg

    env.export_test_cfg(TEST_WORKSPACE, test_config)

    # Start the CodeChecker server.
    print("Starting server to get results")
    _start_server(codechecker_cfg, test_config, False)
Exemplo n.º 7
0
def setup_package():
    """
    Setup the environment for the tests.
    Check the test project twice, then start the server.
    """

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

    os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE

    test_project = 'cpp'

    test_project_path = project.path(test_project)

    pg_db_config = env.get_postgresql_cfg()

    test_config = {}

    project_info = project.get_info(test_project)

    test_config['test_project'] = project_info

    suppress_file = None

    skip_list_file = None

    # Setup environment variabled for test cases.
    host_port_cfg = env.get_host_port_cfg()

    test_env = env.test_env()

    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'),
        'pg_db_config': pg_db_config,
        'checkers':
        ['-d', 'core.CallAndMessage', '-e', 'core.StackAddressEscape']
    }

    codechecker_cfg.update(host_port_cfg)

    test_config['codechecker_cfg'] = codechecker_cfg

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

    # Start the CodeChecker server.
    print("Starting server to get results")
    _start_server(codechecker_cfg, test_config, False)

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

    ret = codechecker.check(codechecker_cfg, test_project_name_base,
                            test_project_path)
    if ret:
        sys.exit(1)
    print("First analysis of the test project was successful.")

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

    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'
    ]
    ret = codechecker.check(codechecker_cfg, test_project_name_new,
                            test_project_path)
    if ret:
        sys.exit(1)
    print("Second analysis of the test project was successful.")

    # Run the second analysis results
    # into a report directory
    ret = codechecker.analyze(codechecker_cfg, test_project_name_new,
                              test_project_path)
    if ret:
        sys.exit(1)
    print("CodeChecker analyze of test project was successful.")

    if pg_db_config:
        print("Waiting for PotgreSQL to stop.")
        codechecker.wait_for_postgres_shutdown(TEST_WORKSPACE)

    # Order of the test run names matter at comparison!
    codechecker_cfg['run_names'] = [
        test_project_name_base, test_project_name_new
    ]

    test_config['codechecker_cfg'] = codechecker_cfg

    # Export test configuration to the workspace.
    env.export_test_cfg(TEST_WORKSPACE, test_config)
Exemplo n.º 8
0
    def setUp(self):
        """
        Set up the environment and the test module's configuration from the
        package.
        """

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

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

        # Set up a configuration for the main server.
        # Get the test configuration from the prepared int the test workspace.
        self.test_cfg = env.import_test_cfg(self.test_workspace_main)

        self.product_name = self.test_cfg['codechecker_cfg']['viewer_product']

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

        # Setup an authentication client for creating sessions.
        self._auth_client = env.setup_auth_client(self.test_workspace_main,
                                                  session_token='_PROHIBIT')

        # Create a SUPERUSER login.
        root_token = self._auth_client.performLogin("Username:Password",
                                                    "root:root")

        ret = self._auth_client.addPermission(Permission.SUPERUSER, "root",
                                              False, "")
        self.assertTrue(ret)

        # Setup a product client to test product API calls.
        self._pr_client = env.setup_product_client(self.test_workspace_main)
        self.assertIsNotNone(self._pr_client)

        # Setup a product client to test product API calls which requires root.
        self._root_client = env.setup_product_client(self.test_workspace_main,
                                                     session_token=root_token)
        self.assertIsNotNone(self._pr_client)

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

        runs = self._cc_client.getRunData(None, None, 0)
        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.")
        self._runid = test_runs[0].runId

        # Start a second server with the same configuration database as the
        # main one.
        self.test_workspace_secondary = env.get_workspace('producttest_second')
        self.codechecker_cfg_2 = {
            'check_env': self.test_cfg['codechecker_cfg']['check_env'],
            'workspace': self.test_workspace_secondary,
            'checkers': [],
            'viewer_host': 'localhost',
            'viewer_port': env.get_free_port(),
            'viewer_product': 'producttest_second'
        }
        self.codechecker_cfg_2['check_env']['HOME'] = \
            self.test_workspace_secondary
        env.export_test_cfg(self.test_workspace_secondary,
                            {'codechecker_cfg': self.codechecker_cfg_2})

        server_config = dict(self.codechecker_cfg_2)
        server_config['workspace'] = os.path.join(env.get_workspace(None),
                                                  'global_auth_server')

        codechecker.start_server(server_config, EVENT, None,
                                 env.get_postgresql_cfg())

        # Set up API clients for the secondary server.
        self._auth_client_2 = env.setup_auth_client(
            self.test_workspace_secondary, session_token='_PROHIBIT')
        root_token_2 = self._auth_client_2.performLogin(
            "Username:Password", "root:root")
        self._pr_client_2 = env.setup_product_client(
            self.test_workspace_secondary, session_token=root_token_2)
        self.assertIsNotNone(self._pr_client_2)
Exemplo n.º 9
0
def setup_package():
    """Setup the environment for the tests. Check the test project twice,
    then start the server."""

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

    os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE

    test_project = 'cpp'

    pg_db_config = env.get_postgresql_cfg()

    test_config = {}

    project_info = project.get_info(test_project)

    test_config['test_project'] = project_info

    suppress_file = None

    # Generate skip list file for the tests.
    skip_list_file = os.path.join(TEST_WORKSPACE, 'skip_file')
    if os.path.isfile(skip_list_file):
        os.remove(skip_list_file)
    _generate_skip_list_file(skip_list_file)

    # Get port numbers for the tests.
    host_port_cfg = env.get_host_port_cfg()

    test_env = env.test_env()

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

    codechecker_cfg.update(host_port_cfg)

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

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

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

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

    if pg_db_config:
        print("Waiting for PostgreSQL to stop.")
        codechecker.wait_for_postgres_shutdown(TEST_WORKSPACE)

    codechecker_cfg['run_names'] = [test_project_name]

    test_config['codechecker_cfg'] = codechecker_cfg

    env.export_test_cfg(TEST_WORKSPACE, test_config)

    # Start the CodeChecker server.
    print("Starting server to get results.")
    _start_server(codechecker_cfg, test_config, False)
Exemplo n.º 10
0
def setup_package():
    """Setup the environment for the tests. Then start the server."""

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

    os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE

    test_project = 'cpp'

    pg_db_config = env.get_postgresql_cfg()

    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

    # Get port numbers for the tests.
    host_port_cfg = env.get_host_port_cfg()

    test_env = env.test_env()

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

    codechecker_cfg.update(host_port_cfg)

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

    print("Starting server to get results.")
    _start_server(codechecker_cfg, test_config, False)

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

    ret = codechecker.check(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)
Exemplo n.º 11
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()

    # PostgreSQL configuration might be empty if tests are run
    # with SQLite.
    pg_db_config = env.get_postgresql_cfg()

    test_config = {}

    project_info = project.get_info(project.path())

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

    # 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,
        'pg_db_config': pg_db_config,
        'checkers': []
    }

    # Get new unique port numbers for this test run.
    host_port_cfg = env.get_host_port_cfg()

    # Extend the checker configuration with the port numbers.
    codechecker_cfg.update(host_port_cfg)

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

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

    if pg_db_config:
        print("Waiting for PostgreSQL to stop.")
        codechecker.wait_for_postgres_shutdown(TEST_WORKSPACE)

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

    # Start the CodeChecker server.
    print("Starting server to get results")
    _start_server(codechecker_cfg, test_config, False)
Exemplo n.º 12
0
def setup_package():
    """
    Setup the environment for the tests.
    Check the test project twice, then start the server.
    """

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

    os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE

    test_project_path = project.path()

    clang_version = env.clang_to_test()

    pg_db_config = env.get_postgresql_cfg()

    test_config = {}

    project_info = project.get_info(project.path())

    test_config['test_project'] = project_info

    suppress_file = None

    skip_list_file = None

    # Setup environment variabled for test cases.
    host_port_cfg = env.get_host_port_cfg()

    test_env = env.test_env()

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

    codechecker_cfg.update(host_port_cfg)

    test_config['codechecker_cfg'] = codechecker_cfg

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

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

    ret = codechecker.check(codechecker_cfg, test_project_name_base,
                            test_project_path)
    if ret:
        sys.exit(1)
    print("First analysis of the test project was successful.")

    if pg_db_config:
        print("Waiting for PotgreSQL to stop.")
        codechecker.wait_for_postgres_shutdown(TEST_WORKSPACE)

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

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

    ret = codechecker.check(codechecker_cfg, test_project_name_new,
                            test_project_path)
    if ret:
        sys.exit(1)
    print("Second analysis of the test project was successful.")

    if pg_db_config:
        print("Waiting for PotgreSQL to stop.")
        codechecker.wait_for_postgres_shutdown(TEST_WORKSPACE)

    # Order of the test run names matter at comparison!
    codechecker_cfg['run_names'] = [
        test_project_name_base, test_project_name_new
    ]

    test_config['codechecker_cfg'] = codechecker_cfg

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

    # Start the CodeChecker server.
    print("Starting server to get results")
    _start_server(codechecker_cfg, test_config, False)