def setup_package(): """Setup the environment for testing diff_local_remote.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('diff_local_remote') # 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_local = os.path.join(TEST_WORKSPACE, "test_proj_local") shutil.copytree(project.path(test_project), test_proj_path_local) # Copy the test project to the workspace. The tests should # work only on this test project. test_proj_path_remote = os.path.join(TEST_WORKSPACE, "test_proj_remote") shutil.copytree(project.path(test_project), test_proj_path_remote) project_info['project_path_local'] = test_proj_path_local project_info['project_path_remote'] = test_proj_path_remote 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'] = 'diff_local_remote' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) # Analyze local, these reports will not be stored to the server. altered_file = os.path.join(test_proj_path_local, "call_and_message.cpp") project.insert_suppression(altered_file) codechecker_cfg['reportdir'] = os.path.join(test_proj_path_local, 'reports') codechecker_cfg['checkers'] = [ '-e', 'core.CallAndMessage', '-d', 'core.NullDereference' ] ret = codechecker.log_and_analyze(codechecker_cfg, test_proj_path_local) if ret: sys.exit(1) print('Analyzing local was successful.') # Remote analysis, results will be stored to the remote server. altered_file = os.path.join(test_proj_path_local, "call_and_message.cpp") project.insert_suppression(altered_file) codechecker_cfg['reportdir'] = os.path.join(test_proj_path_remote, 'reports') codechecker_cfg['checkers'] = [ '-d', 'core.CallAndMessage', '-e', 'core.NullDereference' ] ret = codechecker.log_and_analyze(codechecker_cfg, test_proj_path_remote) if ret: sys.exit(1) print('Analyzing new was successful.') # Store results to the remote server. test_project_name_remote = project_info['name'] + '_' + uuid.uuid4().hex ret = codechecker.store(codechecker_cfg, test_project_name_remote) if ret: sys.exit(1) print('Analyzing remote was successful.') # Save the run names in the configuration. codechecker_cfg['run_names'] = [test_project_name_remote] test_config['codechecker_cfg'] = codechecker_cfg # Export the test configuration to the workspace. env.export_test_cfg(TEST_WORKSPACE, test_config)
def setup_package(): """Setup the environment for testing diff_remote.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('diff_remote') # Set the TEST_WORKSPACE used by the tests. os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE 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_base = os.path.join(TEST_WORKSPACE, "test_proj_base") shutil.copytree(project.path(test_project), test_proj_path_base) # Copy the test project to the workspace. The tests should # work only on this test project. test_proj_path_new = os.path.join(TEST_WORKSPACE, "test_proj_new") shutil.copytree(project.path(test_project), test_proj_path_new) # Copy the test project to the workspace. The tests should # work only on this test project. test_proj_path_update = os.path.join(TEST_WORKSPACE, "test_proj_update") shutil.copytree(project.path(test_project), test_proj_path_update) project_info['project_path_base'] = test_proj_path_base project_info['project_path_new'] = test_proj_path_new project_info['project_path_update'] = test_proj_path_update # 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'] = 'diff_remote' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) # Base analysis altered_file = os.path.join(test_proj_path_base, "call_and_message.cpp") project.insert_suppression(altered_file) codechecker_cfg['reportdir'] = os.path.join(test_proj_path_base, 'reports') codechecker_cfg['checkers'] = ['-e', 'core.CallAndMessage', '-d', 'core.NullDereference'] ret = codechecker.log_and_analyze(codechecker_cfg, test_proj_path_base) if ret: sys.exit(1) print('Analyzing base was successful.') # Store base results. codechecker_cfg['reportdir'] = os.path.join(test_proj_path_base, 'reports') test_project_name_base = project_info['name'] + '_' + uuid.uuid4().hex ret = codechecker.store(codechecker_cfg, test_project_name_base) if ret: sys.exit(1) # Store with a literal ':' in the name. ret = codechecker.store(codechecker_cfg, test_project_name_base + ":base") if ret: sys.exit(1) # New analysis altered_file = os.path.join(test_proj_path_new, "call_and_message.cpp") project.insert_suppression(altered_file) codechecker_cfg['reportdir'] = os.path.join(test_proj_path_new, 'reports') codechecker_cfg['checkers'] = ['-d', 'core.CallAndMessage', '-e', 'core.NullDereference'] ret = codechecker.log_and_analyze(codechecker_cfg, test_proj_path_new) if ret: sys.exit(1) print('Analyzing new was successful.') # Store new results. codechecker_cfg['reportdir'] = os.path.join(test_proj_path_new, 'reports') test_project_name_new = project_info['name'] + '_' + uuid.uuid4().hex ret = codechecker.store(codechecker_cfg, test_project_name_new) if ret: sys.exit(1) # Store with a literal ':' in the name. ret = codechecker.store(codechecker_cfg, test_project_name_new + ":new") if ret: sys.exit(1) # Analyze multiple times to store results with multiple tags. codechecker_cfg['reportdir'] = os.path.join(test_proj_path_update, 'reports') test_project_name_update = project_info['name'] + '_' + uuid.uuid4().hex codechecker_cfg['tag'] = 't1' codechecker_cfg['checkers'] = ['-d', 'core.CallAndMessage', '-e', 'core.StackAddressEscape' ] codechecker_cfg['reportdir'] = os.path.join(test_proj_path_update, 'reports') ret = codechecker.log_and_analyze(codechecker_cfg, test_proj_path_update) if ret: sys.exit(1) # Store update with t1 tag. ret = codechecker.store(codechecker_cfg, test_project_name_update) if ret: sys.exit(1) codechecker_cfg['tag'] = 't2' codechecker_cfg['checkers'] = ['-e', 'core.CallAndMessage', '-d', 'core.StackAddressEscape' ] ret = codechecker.analyze(codechecker_cfg, test_proj_path_update) if ret: sys.exit(1) # Store update with t2 tag. ret = codechecker.store(codechecker_cfg, test_project_name_update) if ret: sys.exit(1) codechecker_cfg['tag'] = 't3' ret = codechecker.log_and_analyze(codechecker_cfg, test_proj_path_update) if ret: sys.exit(1) # Store update with t3 tag. ret = codechecker.store(codechecker_cfg, test_project_name_update) if ret: sys.exit(1) # Order of the test run names matter at comparison! codechecker_cfg['run_names'] = [test_project_name_base, test_project_name_new, test_project_name_update] test_config['test_project'] = project_info test_config['codechecker_cfg'] = codechecker_cfg # Export the test configuration to the workspace. env.export_test_cfg(TEST_WORKSPACE, test_config) # Remove report directories which are not used anymore. shutil.rmtree(test_proj_path_base, ignore_errors=True) shutil.rmtree(test_proj_path_new, ignore_errors=True)