Example #1
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)
Example #2
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)

    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)

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

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

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

    # Start the CodeChecker server.
    print("Starting server to get results")
    _start_server(codechecker_cfg, test_config, False)
Example #3
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)
Example #4
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)
Example #5
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)