def setup_package(): """Setup the environment for testing detection_status.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('extended_report_data') # Set the TEST_WORKSPACE used by the tests. os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE test_env = env.test_env(TEST_WORKSPACE) # Configuration options. codechecker_cfg = { 'check_env': test_env, 'workspace': TEST_WORKSPACE, 'run_names': [] } # 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'] = 'extended_report_data' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) # Copy test projects and replace file path in plist files. test_projects = ['notes', 'macros'] for test_project in test_projects: test_project_path = os.path.join(TEST_WORKSPACE, "test_proj", test_project) shutil.copytree(project.path(test_project), test_project_path) for test_file in os.listdir(test_project_path): if test_file.endswith(".plist"): test_file_path = os.path.join(test_project_path, test_file) with open(test_file_path, 'r+', encoding="utf-8", errors="ignore") as plist_file: content = plist_file.read() new_content = content.replace("$FILE_PATH$", test_project_path) plist_file.seek(0) plist_file.truncate() plist_file.write(new_content) codechecker_cfg['reportdir'] = test_project_path ret = codechecker.store(codechecker_cfg, test_project) if ret: sys.exit(1) print("Analyzing test project was succcessful.") codechecker_cfg['run_names'].append(test_project) # Export the test configuration to the workspace. env.export_test_cfg(TEST_WORKSPACE, {'codechecker_cfg': codechecker_cfg})
def setup_package(): """Setup the environment for the tests.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('config') # Set the TEST_WORKSPACE used by the tests. os.environ['TEST_WORKSPACE'] = 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 = { 'workspace': TEST_WORKSPACE, 'check_env': env.test_env(TEST_WORKSPACE), 'reportdir': os.path.join(TEST_WORKSPACE, 'reports') } # 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'] = 'config' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) test_config = {'codechecker_cfg': codechecker_cfg} env.export_test_cfg(TEST_WORKSPACE, test_config)
def setup_package(): """Setup the environment for testing detection_status.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('detection_status') # Set the TEST_WORKSPACE used by the tests. os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE # Configuration options. codechecker_cfg = { 'suppress_file': None, 'skip_list_file': None, 'check_env': env.test_env(TEST_WORKSPACE), 'workspace': TEST_WORKSPACE, 'checkers': [], 'reportdir': os.path.join(TEST_WORKSPACE, 'reports'), 'test_project': 'hello' } # 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'] = 'detection_status' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) # Export the test configuration to the workspace. env.export_test_cfg(TEST_WORKSPACE, {'codechecker_cfg': codechecker_cfg})
def setup_package(): """Setup the environment for testing blame information.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('blame') os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE test_project = 'cpp' test_config = {} project_info = project.get_info(test_project) test_project_path = os.path.join(TEST_WORKSPACE, "test_proj") shutil.copytree(project.path(test_project), 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 test_env = env.test_env(TEST_WORKSPACE) codechecker_cfg = { 'suppress_file': suppress_file, 'skip_list_file': skip_list_file, 'check_env': test_env, 'workspace': TEST_WORKSPACE, 'checkers': [], 'clean': True } # 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(auth_required=True) server_access['viewer_product'] = 'blame' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) # Clean the test project, if needed by the tests. ret = project.clean(test_project) if ret: sys.exit(ret) ret = codechecker.check_and_store( codechecker_cfg, test_project_name, project.path(test_project)) if ret: sys.exit(1) print("Analyzing test project was succcessful.") # 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)
def setup_package(): """Setup the environment for testing review_status.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('review_status') os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE dir_path = os.path.dirname(os.path.realpath(__file__)) shutil.copytree(os.path.join(dir_path, 'review_status_files'), os.path.join(TEST_WORKSPACE, 'review_status_files')) test_project = 'single_bug' test_config = {} project_info = project.get_info(test_project) test_config['test_project'] = project_info skip_list_file = None test_env = env.test_env(TEST_WORKSPACE) codechecker_cfg = { 'suppress_file': None, 'skip_list_file': skip_list_file, 'check_env': test_env, 'workspace': TEST_WORKSPACE, 'checkers': [] } ret = project.clean(test_project, test_env) if ret: sys.exit(ret) # 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'] = 'review_status' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) test_project_name = project_info['name'] + '_' + uuid.uuid4().hex ret = codechecker.check_and_store(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)
def setup_package(): """Setup the environment for the tests then start the server.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('store_test') os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE # Configuration options. codechecker_cfg = { 'suppress_file': None, 'skip_list_file': None, 'check_env': env.test_env(TEST_WORKSPACE), 'workspace': TEST_WORKSPACE, 'checkers': [], 'reportdir': os.path.join(TEST_WORKSPACE, 'reports'), 'test_project': 'store_test' } # 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'] = 'store_test' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) # Export the test configuration to the workspace. env.export_test_cfg(TEST_WORKSPACE, {'codechecker_cfg': codechecker_cfg})
def setup_package(): """Setup the environment for testing detection_status.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('extended_report_data') # Set the TEST_WORKSPACE used by the tests. os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE test_env = env.test_env(TEST_WORKSPACE) # Configuration options. codechecker_cfg = { 'check_env': test_env, 'workspace': TEST_WORKSPACE, 'run_names': [] } # 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'] = 'extended_report_data' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) # Copy test projects and replace file path in plist files. test_projects = ['notes', 'macros'] for test_project in test_projects: test_project_path = os.path.join(TEST_WORKSPACE, "test_proj", test_project) shutil.copytree(project.path(test_project), test_project_path) for test_file in os.listdir(test_project_path): if test_file.endswith(".plist"): test_file_path = os.path.join(test_project_path, test_file) with open(test_file_path, 'r+') as plist_file: content = plist_file.read() new_content = content.replace("$FILE_PATH$", test_project_path) plist_file.seek(0) plist_file.truncate() plist_file.write(new_content) codechecker_cfg['reportdir'] = test_project_path ret = codechecker.store(codechecker_cfg, test_project) if ret: sys.exit(1) print("Analyzing test project was succcessful.") codechecker_cfg['run_names'].append(test_project) # Export the test configuration to the workspace. env.export_test_cfg(TEST_WORKSPACE, {'codechecker_cfg': codechecker_cfg})
def setup_package(): """Setup the environment for testing review_status.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('review_status') os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE test_project = 'single_bug' test_config = {} project_info = project.get_info(test_project) test_config['test_project'] = project_info skip_list_file = None test_env = env.test_env(TEST_WORKSPACE) codechecker_cfg = { 'suppress_file': None, 'skip_list_file': skip_list_file, 'check_env': test_env, 'workspace': TEST_WORKSPACE, 'checkers': [] } ret = project.clean(test_project, test_env) if ret: sys.exit(ret) # 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'] = 'review_status' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) 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)
def test_garbage_file_collection(self): event = multiprocessing.Event() event.clear() self.codechecker_cfg['viewer_port'] = env.get_free_port() env.export_test_cfg(self.test_workspace, {'codechecker_cfg': self.codechecker_cfg}) env.enable_auth(self.test_workspace) server_access = codechecker.start_server(self.codechecker_cfg, event) server_access['viewer_port'] \ = self.codechecker_cfg['viewer_port'] server_access['viewer_product'] \ = self.codechecker_cfg['viewer_product'] codechecker.add_test_package_product(server_access, self.test_workspace) self._cc_client = env.setup_viewer_client(self.test_workspace) self.assertIsNotNone(self._cc_client) self.__create_test_dir() files_in_report_before = self.__get_files_in_report() self.__rename_project_dir() files_in_report_after = self.__get_files_in_report() event.set() time.sleep(5) event.clear() self.codechecker_cfg['viewer_port'] = env.get_free_port() env.export_test_cfg(self.test_workspace, {'codechecker_cfg': self.codechecker_cfg}) codechecker.start_server(self.codechecker_cfg, event) codechecker.login(self.codechecker_cfg, self.test_workspace, 'cc', 'test') self._cc_client = env.setup_viewer_client(self.test_workspace) self.assertIsNotNone(self._cc_client) self.assertEqual(len(files_in_report_before & files_in_report_after), 0) for file_id in files_in_report_before: f = self._cc_client.getSourceFileData(file_id, False, None) self.assertIsNone(f.fileId) event.set() time.sleep(5)
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_config = {} test_project_name = uuid.uuid4().hex test_project_path = os.path.join(test_dir, "test_proj") temp_test_project_data = project.prepare(test_project_path, TEST_WORKSPACE) test_config['test_project'] = temp_test_project_data test_env = env.test_env(TEST_WORKSPACE) base_reports = os.path.join(temp_test_project_data['test_project_reports'], 'base') codechecker_cfg = { 'suppress_file': None, 'skip_list_file': None, 'check_env': test_env, 'workspace': TEST_WORKSPACE, 'checkers': [], 'reportdir': base_reports } # 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'] = 'update' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) ret = codechecker.store(codechecker_cfg, test_project_name) if ret: sys.exit(1) print("Storing the base reports was succcessful.") codechecker_cfg['run_names'] = [test_project_name] test_config['codechecker_cfg'] = codechecker_cfg env.export_test_cfg(TEST_WORKSPACE, test_config)
def setup_package(): """Setup the environment for the tests. """ global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('cleanup_plan') os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE test_project = 'cpp' test_project_path = project.path(test_project) test_config = {} project_info = project.get_info(test_project) test_config['test_project'] = project_info test_env = env.test_env(TEST_WORKSPACE) codechecker_cfg = { 'check_env': test_env, 'workspace': TEST_WORKSPACE, 'reportdir': os.path.join(TEST_WORKSPACE, 'reports'), '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'] = 'cleanup_plan' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) # Check the test project for the first time. test_project_name = project_info['name'] + '_' + uuid.uuid4().hex ret = codechecker.check_and_store(codechecker_cfg, test_project_name, test_project_path) if ret: sys.exit(1) print("Analyzing 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)
def setup_package(): """Setup the environment for the tests then start the server.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('store_test') os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE # Configuration options. codechecker_cfg = { 'check_env': env.test_env(TEST_WORKSPACE), 'workspace': TEST_WORKSPACE, 'checkers': [], 'reportdir': os.path.join(TEST_WORKSPACE, 'reports'), 'test_project': 'store_test' } # 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'] = 'store_test' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) # Export the test configuration to the workspace. env.export_test_cfg(TEST_WORKSPACE, {'codechecker_cfg': codechecker_cfg}) # Copy test files to a temporary directory not to modify the # files in the repository. # Report files will be overwritten during the tests. test_dir = os.path.dirname(os.path.realpath(__file__)) dst_dir = os.path.join(TEST_WORKSPACE, "test_proj") shutil.copytree(os.path.join(test_dir, "test_proj"), dst_dir) prefix_file_paths = [ os.path.join(dst_dir, "divide_zero", "divide_zero.plist"), os.path.join(dst_dir, "double_suppress", "double_suppress.plist") ] for file_name in prefix_file_paths: plist_test.prefix_file_path(file_name, os.path.dirname(file_name))
def setup_package(): """Setup the environment for the tests then start the server.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('storage_of_analysis_statistics') os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE test_config = {} # Setup environment variables for the test cases. host_port_cfg = { 'viewer_host': 'localhost', 'viewer_port': env.get_free_port(), 'viewer_product': 'storage_of_analysis_statistics' } test_env = env.test_env(TEST_WORKSPACE) codechecker_cfg = { 'check_env': test_env, 'workspace': TEST_WORKSPACE, 'checkers': [], 'viewer_product': 'storage_of_analysis_statistics', 'reportdir': os.path.join(TEST_WORKSPACE, 'reports') } 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 storage of analysis statistics and start the CodeChecker server. env.enable_storage_of_analysis_statistics(TEST_WORKSPACE) print("Starting server to get results") server_access = codechecker.start_server(codechecker_cfg, EVENT_1) server_access['viewer_product'] = codechecker_cfg['viewer_product'] codechecker.add_test_package_product(server_access, TEST_WORKSPACE)
def setup_package(): """Setup the environment for the tests then start the server.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('storage_of_analysis_statistics') os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE test_config = {} # Setup environment variables for the test cases. host_port_cfg = {'viewer_host': 'localhost', 'viewer_port': env.get_free_port(), 'viewer_product': 'storage_of_analysis_statistics'} test_env = env.test_env(TEST_WORKSPACE) codechecker_cfg = { 'check_env': test_env, 'workspace': TEST_WORKSPACE, 'checkers': [], 'viewer_product': 'storage_of_analysis_statistics', 'reportdir': os.path.join(TEST_WORKSPACE, 'reports') } 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 storage of analysis statistics and start the CodeChecker server. env.enable_storage_of_analysis_statistics(TEST_WORKSPACE) print("Starting server to get results") server_access = codechecker.start_server(codechecker_cfg, EVENT_1) server_access['viewer_product'] = codechecker_cfg['viewer_product'] codechecker.add_test_package_product(server_access, TEST_WORKSPACE)
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_config = {} # Setup environment variables for the test cases. host_port_cfg = { 'viewer_host': 'localhost', 'viewer_port': env.get_free_port(), 'viewer_product': 'authentication' } test_env = env.test_env(TEST_WORKSPACE) codechecker_cfg = { 'check_env': test_env, 'workspace': TEST_WORKSPACE, '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. env.enable_auth(TEST_WORKSPACE) print("Starting server to get results") codechecker.start_server(codechecker_cfg, __STOP_SERVER) codechecker.add_test_package_product(host_port_cfg, TEST_WORKSPACE)
def setup_package(): """Setup the environment for testing server_configuration.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('server_configuration') # Set the TEST_WORKSPACE used by the tests. os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE test_config = {} # Get an environment which should be used by the tests. test_env = env.test_env(TEST_WORKSPACE) codechecker_cfg = { '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'] = 'server_configuration' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) # Save the run names in the configuration. codechecker_cfg['run_names'] = [] 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 server_configuration.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('server_configuration') # Set the TEST_WORKSPACE used by the tests. os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE test_config = {} # Get an environment which should be used by the tests. test_env = env.test_env(TEST_WORKSPACE) codechecker_cfg = { '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(auth_required=True) server_access['viewer_product'] = 'server_configuration' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) # Save the run names in the configuration. codechecker_cfg['run_names'] = [] 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 products.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('producttest') # Set the TEST_WORKSPACE used by the tests. os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE test_config = {} test_project = 'single_bug' 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'] + '_' + uuid.uuid4().hex test_config['test_project'] = project_info # 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 = { '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'] = 'producttest' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) # 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, project.path(test_project)) if ret: sys.exit(1) print("Analyzing the test project was successful.") # 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)
def test_privileged_access(self): """ Tests that initially, a non-authenticating server is accessible, but an authenticating one is not. """ auth_client = env.setup_auth_client(self._test_workspace, session_token='_PROHIBIT') handshake = auth_client.getAuthParameters() self.assertTrue( handshake.requiresAuthentication, "Privileged server " + "did not report that it requires authentication.") self.assertFalse(handshake.sessionStillActive, "Empty session was " + "reported to be still active.") with self.assertRaises(RequestFailed): auth_client.performLogin("Username:Password", "invalid:invalid") print("Invalid credentials gave us a token!") # A non-authenticated session should return an empty user. user = auth_client.getLoggedInUser() self.assertEqual(user, "") # We still need to create a product on the new server, because # in PostgreSQL mode, the same database is used for configuration # by the newly started instance of this test suite too. codechecker.add_test_package_product( self._test_cfg['codechecker_cfg'], self._test_workspace, # Use the test's home directory to find the session token file. self._test_cfg['codechecker_cfg']['check_env']) self.sessionToken = auth_client.performLogin("Username:Password", "cc:test") self.assertIsNotNone(self.sessionToken, "Valid credentials didn't give us a token!") handshake = auth_client.getAuthParameters() self.assertTrue( handshake.requiresAuthentication, "Privileged server " + "did not report that it requires authentication.") self.assertFalse(handshake.sessionStillActive, "Valid session was " + "reported not to be active.") client = env.setup_viewer_client(self._test_workspace, session_token=self.sessionToken) self.assertIsNotNone(client.getPackageVersion(), "Privileged server didn't respond properly.") authd_auth_client = \ env.setup_auth_client(self._test_workspace, session_token=self.sessionToken) user = authd_auth_client.getLoggedInUser() self.assertEqual(user, "cc") auth_client = env.setup_auth_client(self._test_workspace, session_token=self.sessionToken) result = auth_client.destroySession() self.assertTrue(result, "Server did not allow us to destroy session.") # Kill the session token that was created by login() too. codechecker.logout(self._test_cfg['codechecker_cfg'], self._test_workspace) with self.assertRaises(TProtocolException): # The server reports a HTTP 401 error which is not a valid # Thrift response. But if it does so, it passes the test! client.getPackageVersion() print("Privileged client allowed access after logout.") handshake = auth_client.getAuthParameters() self.assertFalse( handshake.sessionStillActive, "Destroyed session was " + "reported to be still active.")
def test_garbage_file_collection(self): event = multiprocessing.Event() event.clear() self.codechecker_cfg['viewer_port'] = env.get_free_port() env.export_test_cfg(self.test_workspace, {'codechecker_cfg': self.codechecker_cfg}) env.enable_auth(self.test_workspace) server_access = codechecker.start_server(self.codechecker_cfg, event) server_access['viewer_port'] \ = self.codechecker_cfg['viewer_port'] server_access['viewer_product'] \ = self.codechecker_cfg['viewer_product'] codechecker.add_test_package_product(server_access, self.test_workspace) self._cc_client = env.setup_viewer_client(self.test_workspace) self.assertIsNotNone(self._cc_client) self.__create_test_dir() files_in_report_before = self.__get_files_in_report() # Checker severity levels. self.__check_serverity_of_reports() self.__rename_project_dir() # Delete previous analysis report directory. rmtree(self.codechecker_cfg['reportdir']) files_in_report_after = self.__get_files_in_report() event.set() event.clear() # Change severity level of core.DivideZero to LOW. with io.open(self.workspace_severity_cfg, 'r+') as severity_cgf_file: severity_map = json.load(severity_cgf_file) severity_map['core.DivideZero'] = 'LOW' severity_cgf_file.seek(0) severity_cgf_file.truncate() severity_cgf_file.write(unicode(json.dumps(severity_map))) self.codechecker_cfg['viewer_port'] = env.get_free_port() env.export_test_cfg(self.test_workspace, {'codechecker_cfg': self.codechecker_cfg}) codechecker.start_server(self.codechecker_cfg, event) codechecker.login(self.codechecker_cfg, self.test_workspace, 'cc', 'test') self._cc_client = env.setup_viewer_client(self.test_workspace) self.assertIsNotNone(self._cc_client) self.assertEqual(len(files_in_report_before & files_in_report_after), 0) for file_id in files_in_report_before: f = self._cc_client.getSourceFileData(file_id, False, None) self.assertIsNone(f.fileId) # Checker severity levels. self.__check_serverity_of_reports() event.set()
def setup_package(): """Setup the environment for the tests.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('report_viewer_api') os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE test_project = 'cpp' 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 tag = 'v1.0' test_env = env.test_env(TEST_WORKSPACE) codechecker_cfg = { 'suppress_file': suppress_file, 'skip_list_file': skip_list_file, 'check_env': test_env, 'workspace': TEST_WORKSPACE, 'checkers': [], 'tag': tag } ret = project.clean(test_project) if ret: sys.exit(ret) # 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'] = 'report_viewer_api' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) 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.") 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', '-d', 'unix.Malloc' ] codechecker_cfg['tag'] = None ret = codechecker.check(codechecker_cfg, test_project_name_new, project.path(test_project)) if ret: sys.exit(1) print("Second analysis of the test project was successful.") codechecker_cfg['run_names'] = [test_project_name, test_project_name_new] test_config['codechecker_cfg'] = codechecker_cfg env.export_test_cfg(TEST_WORKSPACE, test_config)
def setup_package(): """Setup the environment for the tests. """ global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('comment') os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE test_project = 'cpp' test_project_path = project.path(test_project) test_config = {} project_info = project.get_info(test_project) test_config['test_project'] = project_info suppress_file = None skip_list_file = None test_env = env.test_env(TEST_WORKSPACE) 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'), 'checkers': ['-d', 'core.CallAndMessage', '-e', 'core.StackAddressEscape'] } # 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(auth_required=True) server_access['viewer_product'] = 'comment' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) # Check the test project for the first time. test_project_names = [] test_project_name = project_info['name'] + '_' + uuid.uuid4().hex test_project_names.append(test_project_name) ret = codechecker.check_and_store(codechecker_cfg, test_project_name, test_project_path) if ret: sys.exit(1) print("Analyzing test project was successful.") # Check the test project again. test_project_name = project_info['name'] + '_' + uuid.uuid4().hex test_project_names.append(test_project_name) ret = codechecker.check_and_store(codechecker_cfg, test_project_name, test_project_path) if ret: sys.exit(1) print("Analyzing test project was succcessful.") codechecker_cfg['run_names'] = test_project_names test_config['codechecker_cfg'] = codechecker_cfg env.export_test_cfg(TEST_WORKSPACE, test_config)
def setup_package(): """Setup the environment for the tests. """ global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('comment') os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE test_project = 'cpp' test_project_path = project.path(test_project) test_config = {} project_info = project.get_info(test_project) test_config['test_project'] = project_info suppress_file = None skip_list_file = None test_env = env.test_env(TEST_WORKSPACE) 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'), 'checkers': ['-d', 'core.CallAndMessage', '-e', 'core.StackAddressEscape'] } # 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'] = 'comment' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) # Check the test project for the first time. test_project_names = [] test_project_name = project_info['name'] + '_' + uuid.uuid4().hex test_project_names.append(test_project_name) ret = codechecker.check(codechecker_cfg, test_project_name, test_project_path) if ret: sys.exit(1) print("Analyzing test project was successful.") # Check the test project again. test_project_name = project_info['name'] + '_' + uuid.uuid4().hex test_project_names.append(test_project_name) ret = codechecker.check(codechecker_cfg, test_project_name, test_project_path) if ret: sys.exit(1) print("Analyzing test project was succcessful.") codechecker_cfg['run_names'] = test_project_names test_config['codechecker_cfg'] = codechecker_cfg env.export_test_cfg(TEST_WORKSPACE, test_config)
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() 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 = 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'] + '_' + 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(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'] = '$TEST_NAME$' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) # 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_and_store(codechecker_cfg, test_project_name, project.path(test_project)) if ret: sys.exit(1) print("Analyzing the test project was successful.") # 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)
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)
def test_garbage_file_collection(self): event = multiprocessing.Event() event.clear() self.codechecker_cfg['viewer_port'] = env.get_free_port() env.export_test_cfg(self.test_workspace, {'codechecker_cfg': self.codechecker_cfg}) env.enable_auth(self.test_workspace) server_access = codechecker.start_server(self.codechecker_cfg, event) server_access['viewer_port'] \ = self.codechecker_cfg['viewer_port'] server_access['viewer_product'] \ = self.codechecker_cfg['viewer_product'] codechecker.add_test_package_product(server_access, self.test_workspace) self._cc_client = env.setup_viewer_client(self.test_workspace) self.assertIsNotNone(self._cc_client) run_name1 = 'db_cleanup_test' run_name2 = f'{run_name1}2' self.__create_test_dir() # Store the results. codechecker.check_and_store(self.codechecker_cfg, run_name1, self.test_dir) # Store the results to a different run too to see if we remove only one # run, comments and review statuses not cleared. codechecker.check_and_store(self.codechecker_cfg, run_name2, self.test_dir) run_id1 = self.__get_run_id([run_name1]) report = self._cc_client.getRunResults(None, 1, 0, [], None, None, False)[0] report_hash = report.bugHash report_id = report.reportId # Add a new comment. comment = CommentData(author='anybody', message='Msg') success = self._cc_client.addComment(report_id, comment) self.assertTrue(success) # Change review status. success = self._cc_client.changeReviewStatus(report_id, ReviewStatus.CONFIRMED, 'Real bug') self.assertTrue(success) # Remove the first storage. self._cc_client.removeRun(run_id1, None) # Comments and review statuses are not cleared, because the second # run results still reference them. run_id2 = self.__get_run_id([run_name2]) r_filter = ReportFilter(reviewStatus=[ReviewStatus.CONFIRMED]) run_results = self._cc_client.getRunResults([run_id2], 1, 0, None, r_filter, None, False) self.assertTrue(run_results) comments = self._cc_client.getComments(run_results[0].reportId) self.assertTrue(comments) # Remove the second run too, so it will cleanup the unused commments # and review statuses. self._cc_client.removeRun(run_id2, None) # Store results again and check that previous comments and review # statuses are gone. files_in_report_before = self.__get_files_in_report(run_name1) r_filter = ReportFilter(reportHash=[report_hash]) report = self._cc_client.getRunResults(None, 1, 0, None, r_filter, None, False)[0] report_id = report.reportId comments = self._cc_client.getComments(report_id) self.assertFalse(comments) r_filter = ReportFilter(reviewStatus=[ReviewStatus.CONFIRMED]) run_results = self._cc_client.getRunResults(None, 1, 0, None, r_filter, None, False) self.assertFalse(run_results) # Checker severity levels. self.__check_serverity_of_reports(run_name1) self.__rename_project_dir() # Delete previous analysis report directory. rmtree(self.codechecker_cfg['reportdir']) files_in_report_after = self.__get_files_in_report(run_name1) event.set() event.clear() # Change severity level of core.DivideZero to LOW. with open(self.workspace_severity_cfg, 'r+', encoding='utf-8', errors='ignore') as severity_cgf_file: severity_map = json.load(severity_cgf_file) severity_map['core.DivideZero'] = 'LOW' severity_cgf_file.seek(0) severity_cgf_file.truncate() severity_cgf_file.write(str(json.dumps(severity_map))) self.codechecker_cfg['viewer_port'] = env.get_free_port() env.export_test_cfg(self.test_workspace, {'codechecker_cfg': self.codechecker_cfg}) codechecker.start_server(self.codechecker_cfg, event) codechecker.login(self.codechecker_cfg, self.test_workspace, 'cc', 'test') self._cc_client = env.setup_viewer_client(self.test_workspace) self.assertIsNotNone(self._cc_client) self.assertEqual(len(files_in_report_before & files_in_report_after), 0) for file_id in files_in_report_before: f = self._cc_client.getSourceFileData(file_id, False, None) self.assertIsNone(f.fileId) # Checker severity levels. self.__check_serverity_of_reports(run_name1) event.set()
def test_privileged_access(self): """ Tests that initially, a non-authenticating server is accessible, but an authenticating one is not. """ # Switch off certificate validation on the clients. os.environ["OSPYTHONHTTPSVERIFY"] = '0' # FIXME: change this to https access_protocol = 'http' auth_client = env.setup_auth_client(self._test_workspace, session_token='_PROHIBIT', proto=access_protocol) handshake = auth_client.getAuthParameters() self.assertTrue( handshake.requiresAuthentication, "Privileged server " + "did not report that it requires authentication.") self.assertFalse(handshake.sessionStillActive, "Empty session was " + "reported to be still active.") with self.assertRaises(RequestFailed): auth_client.performLogin("Username:Password", "invalid:invalid") print("Invalid credentials gave us a token!") # A non-authenticated session should return an empty user. user = auth_client.getLoggedInUser() self.assertEqual(user, "") # We still need to create a product on the new server, because # in PostgreSQL mode, the same database is used for configuration # by the newly started instance of this test suite too. codechecker.add_test_package_product( self._test_cfg['codechecker_cfg'], self._test_workspace, # Use the test's home directory to find the session token file. self._test_cfg['codechecker_cfg']['check_env'], access_protocol) self.sessionToken = auth_client.performLogin("Username:Password", "cc:test") self.assertIsNotNone(self.sessionToken, "Valid credentials didn't give us a token!") handshake = auth_client.getAuthParameters() self.assertTrue( handshake.requiresAuthentication, "Privileged server " + "did not report that it requires authentication.") self.assertFalse(handshake.sessionStillActive, "Valid session was " + "reported not to be active.") client = env.setup_viewer_client(self._test_workspace, session_token=self.sessionToken, proto=access_protocol) self.assertIsNotNone(client.getPackageVersion(), "Privileged server didn't respond properly.") authd_auth_client = \ env.setup_auth_client(self._test_workspace, session_token=self.sessionToken, proto=access_protocol) user = authd_auth_client.getLoggedInUser() self.assertEqual(user, "cc") auth_client = env.setup_auth_client(self._test_workspace, session_token=self.sessionToken, proto=access_protocol) result = auth_client.destroySession() self.assertTrue(result, "Server did not allow us to destroy session.") # Kill the session token that was created by login() too. codechecker.logout(self._test_cfg['codechecker_cfg'], self._test_workspace, access_protocol) # The server reports a HTTP 401 error which is not a valid # Thrift response. But if it does so, it passes the test! # FIXME: Because of the local session cache this check will fail. # To enable this again we need to eliminate the local cache. # version = client.getPackageVersion() # self.assertIsNone(version, # "Privileged client allowed access after logout.") # handshake = auth_client.getAuthParameters() # self.assertFalse(handshake.sessionStillActive, # "Destroyed session was " + # "reported to be still active.") codechecker.remove_test_package_product( self._test_workspace, # Use the test's home directory to find the session token file. self._test_cfg['codechecker_cfg']['check_env'], access_protocol)
def setup_package(): """Setup the environment for the tests.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('suppress') os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE test_project = 'suppress' 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 # Generate a suppress file for the tests. suppress_file = os.path.join(TEST_WORKSPACE, 'suppress_file') if os.path.isfile(suppress_file): os.remove(suppress_file) _generate_suppress_file(suppress_file) test_env = env.test_env(TEST_WORKSPACE) codechecker_cfg = { 'suppress_file': None, 'skip_list_file': None, 'check_env': test_env, 'workspace': TEST_WORKSPACE, 'checkers': [] } ret = project.clean(test_project, test_env) if ret: sys.exit(ret) # 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'] = 'suppress' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) 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)
def setup_package(): """ Setup the environment for the tests. Check the test project twice. """ 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) test_project_path_altered = os.path.join(TEST_WORKSPACE, "cpp_copy") # We create a copy of the test project which we will change # to simulate code editing. dir_util.copy_tree(test_project_path, test_project_path_altered) test_config = {} project_info = project.get_info(test_project) test_config['test_project'] = project_info suppress_file = None skip_list_file = None test_env = env.test_env(TEST_WORKSPACE) codechecker_cfg = { 'suppress_file': suppress_file, 'skip_list_file': skip_list_file, 'check_env': test_env, 'force': True, 'workspace': TEST_WORKSPACE, 'reportdir': os.path.join(TEST_WORKSPACE, 'reports'), 'checkers': ['-d', 'core.CallAndMessage', '-e', 'core.StackAddressEscape'] } test_config['codechecker_cfg'] = codechecker_cfg ret = project.clean(test_project, test_env) if ret: sys.exit(ret) # 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' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) 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.") dir_util.copy_tree(codechecker_cfg['reportdir'], os.path.join(TEST_WORKSPACE, 'reports_baseline')) 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_altered) if ret: sys.exit(1) print("Second analysis of the test project was successful.") # Insert a real suppression into the code altered_file = os.path.join(test_project_path_altered, "call_and_message.cpp") insert_suppression(altered_file) 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_WORKSPACE, 'reports2') ret = codechecker.check(codechecker_cfg, test_project_name_update, test_project_path) if ret: sys.exit(1) print("Third analysis of the test project was successful.") codechecker_cfg['tag'] = 't2' codechecker_cfg['checkers'] = ['-e', 'core.CallAndMessage', '-d', 'core.StackAddressEscape' ] ret = codechecker.check(codechecker_cfg, test_project_name_update, test_project_path) if ret: sys.exit(1) print("Fourth analysis of the test project was successful.") codechecker_cfg['tag'] = 't3' ret = codechecker.check(codechecker_cfg, test_project_name_update, test_project_path) if ret: sys.exit(1) print("Fifth analysis of the test project was successful.") # 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['codechecker_cfg'] = codechecker_cfg # Export test configuration to the workspace. env.export_test_cfg(TEST_WORKSPACE, test_config)
def setup_package(): """ Setup the environment for the tests. Check the test project twice. """ 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) test_project_path_altered = os.path.join(TEST_WORKSPACE, "cpp_copy") # We create a copy of the test project which we will change # to simulate code editing. dir_util.copy_tree(test_project_path, test_project_path_altered) test_config = {} project_info = project.get_info(test_project) test_config['test_project'] = project_info suppress_file = None skip_list_file = None test_env = env.test_env(TEST_WORKSPACE) codechecker_cfg = { 'suppress_file': suppress_file, 'skip_list_file': skip_list_file, 'check_env': test_env, 'force': True, 'workspace': TEST_WORKSPACE, 'reportdir': os.path.join(TEST_WORKSPACE, 'reports'), 'checkers': ['-d', 'core.CallAndMessage', '-e', 'core.StackAddressEscape'] } test_config['codechecker_cfg'] = codechecker_cfg ret = project.clean(test_project, test_env) if ret: sys.exit(ret) # 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' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) 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_altered) if ret: sys.exit(1) print("Second analysis of the test project was successful.") # Insert a real suppression into the code altered_file = os.path.join(test_project_path_altered, "call_and_message.cpp") insert_suppression(altered_file) # Run the second analysis results # into a report directory ret = codechecker.analyze(codechecker_cfg, test_project_name_new, test_project_path_altered) if ret: sys.exit(1) print("CodeChecker analyze of test project was successful.") 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_WORKSPACE, 'reports2') ret = codechecker.check(codechecker_cfg, test_project_name_update, test_project_path) if ret: sys.exit(1) print("Third analysis of the test project was successful.") codechecker_cfg['tag'] = 't2' codechecker_cfg['checkers'] = [ '-e', 'core.CallAndMessage', '-d', 'core.StackAddressEscape' ] ret = codechecker.check(codechecker_cfg, test_project_name_update, test_project_path) if ret: sys.exit(1) print("Fourth analysis of the test project was successful.") codechecker_cfg['tag'] = 't3' ret = codechecker.check(codechecker_cfg, test_project_name_update, test_project_path) if ret: sys.exit(1) print("Fifth analysis of the test project was successful.") # 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['codechecker_cfg'] = codechecker_cfg # Export test configuration to the workspace. env.export_test_cfg(TEST_WORKSPACE, test_config)
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 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(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'] = 'delete_runs' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) 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)
def setup_package(): """Setup the environment for testing products.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('producttest') # Set the TEST_WORKSPACE used by the tests. os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE test_config = {} test_project = 'single_bug' 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'] + '_' + uuid.uuid4().hex test_config['test_project'] = project_info # 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 = { '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(auth_required=True) server_access['viewer_product'] = 'producttest' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) # 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_and_store(codechecker_cfg, test_project_name, project.path(test_project)) if ret: sys.exit(1) print("Analyzing the test project was successful.") # 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)
def test_privileged_access(self): """ Tests that initially, a non-authenticating server is accessible, but an authenticating one is not. """ auth_client = env.setup_auth_client(self._test_workspace, session_token='_PROHIBIT') handshake = auth_client.getAuthParameters() self.assertTrue(handshake.requiresAuthentication, "Privileged server " + "did not report that it requires authentication.") self.assertFalse(handshake.sessionStillActive, "Empty session was " + "reported to be still active.") with self.assertRaises(RequestFailed): auth_client.performLogin("Username:Password", "invalid:invalid") print("Invalid credentials gave us a token!") # A non-authenticated session should return an empty user. user = auth_client.getLoggedInUser() self.assertEqual(user, "") # We still need to create a product on the new server, because # in PostgreSQL mode, the same database is used for configuration # by the newly started instance of this test suite too. codechecker.add_test_package_product( self._test_cfg['codechecker_cfg'], self._test_workspace, # Use the test's home directory to find the session token file. self._test_cfg['codechecker_cfg']['check_env']) self.sessionToken = auth_client.performLogin("Username:Password", "cc:test") self.assertIsNotNone(self.sessionToken, "Valid credentials didn't give us a token!") handshake = auth_client.getAuthParameters() self.assertTrue(handshake.requiresAuthentication, "Privileged server " + "did not report that it requires authentication.") self.assertFalse(handshake.sessionStillActive, "Valid session was " + "reported not to be active.") client = env.setup_viewer_client(self._test_workspace, session_token=self.sessionToken) self.assertIsNotNone(client.getPackageVersion(), "Privileged server didn't respond properly.") authd_auth_client = \ env.setup_auth_client(self._test_workspace, session_token=self.sessionToken) user = authd_auth_client.getLoggedInUser() self.assertEqual(user, "cc") # No personal token in the database. personal_tokens = authd_auth_client.getTokens() self.assertEqual(len(personal_tokens), 0) # Create a new personal token. description = "description" personal_token = authd_auth_client.newToken(description) token = personal_token.token self.assertEqual(personal_token.description, description) # Check whether the new token has been added. personal_tokens = authd_auth_client.getTokens() self.assertEqual(len(personal_tokens), 1) self.assertEqual(personal_tokens[0].token, token) self.assertEqual(personal_tokens[0].description, description) auth_client = env.setup_auth_client(self._test_workspace, session_token=self.sessionToken) result = auth_client.destroySession() self.assertTrue(result, "Server did not allow us to destroy session.") self.sessionToken = auth_client.performLogin("Username:Password", "colon:my:password") self.assertIsNotNone(self.sessionToken, "Valid credentials didn't give us a token!") result = auth_client.destroySession() self.assertTrue(result, "Server did not allow us to destroy session.") # Kill the session token that was created by login() too. codechecker.logout(self._test_cfg['codechecker_cfg'], self._test_workspace) auth_token_client = \ env.setup_auth_client(self._test_workspace, session_token=token) # Log-in by using an already generated personal token. self.sessionToken = auth_token_client.performLogin("Username:Password", "cc:" + token) self.assertIsNotNone(self.sessionToken, "Valid credentials didn't give us a token!") user = auth_token_client.getLoggedInUser() self.assertEqual(user, "cc") result = auth_token_client.destroySession() self.assertTrue(result, "Server did not allow us to destroy session.") # Kill the session token that was created by login() too. codechecker.logout(self._test_cfg['codechecker_cfg'], self._test_workspace) self.sessionToken = auth_client.performLogin("Username:Password", "cc:test") self.assertIsNotNone(self.sessionToken, "Valid credentials didn't give us a token!") auth_client = env.setup_auth_client(self._test_workspace, session_token=self.sessionToken) # Remove the generated personal token. ret = auth_client.removeToken(token) self.assertTrue(ret) # Check whether no more personal token in the database. personal_tokens = auth_client.getTokens() self.assertEqual(len(personal_tokens), 0) result = auth_client.destroySession() self.assertTrue(result, "Server did not allow us to destroy session.") with self.assertRaises(TProtocolException): # The server reports a HTTP 401 error which is not a valid # Thrift response. But if it does so, it passes the test! client.getPackageVersion() print("Privileged client allowed access after logout.") handshake = auth_client.getAuthParameters() self.assertFalse(handshake.sessionStillActive, "Destroyed session was " + "reported to be still active.")
def test_garbage_file_collection(self): event = multiprocessing.Event() event.clear() self.codechecker_cfg['viewer_port'] = env.get_free_port() env.export_test_cfg(self.test_workspace, {'codechecker_cfg': self.codechecker_cfg}) env.enable_auth(self.test_workspace) server_access = codechecker.start_server(self.codechecker_cfg, event) server_access['viewer_port'] \ = self.codechecker_cfg['viewer_port'] server_access['viewer_product'] \ = self.codechecker_cfg['viewer_product'] codechecker.add_test_package_product(server_access, self.test_workspace) self._cc_client = env.setup_viewer_client(self.test_workspace) self.assertIsNotNone(self._cc_client) self.__create_test_dir() files_in_report_before = self.__get_files_in_report() # Checker severity levels. self.__check_serverity_of_reports() self.__rename_project_dir() # Delete previous analysis report directory. rmtree(self.codechecker_cfg['reportdir']) files_in_report_after = self.__get_files_in_report() event.set() time.sleep(5) event.clear() # Change severity level of core.DivideZero to LOW. with io.open(self.workspace_severity_cfg, 'r+') as severity_cgf_file: severity_map = json.load(severity_cgf_file) severity_map['core.DivideZero'] = 'LOW' severity_cgf_file.seek(0) severity_cgf_file.truncate() severity_cgf_file.write(unicode(json.dumps(severity_map))) self.codechecker_cfg['viewer_port'] = env.get_free_port() env.export_test_cfg(self.test_workspace, {'codechecker_cfg': self.codechecker_cfg}) codechecker.start_server(self.codechecker_cfg, event) codechecker.login(self.codechecker_cfg, self.test_workspace, 'cc', 'test') self._cc_client = env.setup_viewer_client(self.test_workspace) self.assertIsNotNone(self._cc_client) self.assertEqual(len(files_in_report_before & files_in_report_after), 0) for file_id in files_in_report_before: f = self._cc_client.getSourceFileData(file_id, False, None) self.assertIsNone(f.fileId) # Checker severity levels. self.__check_serverity_of_reports() event.set() time.sleep(5)
def test_privileged_access(self): """ Tests that initially, a non-authenticating server is accessible, but an authenticating one is not. """ # Switch off certificate validation on the clients. os.environ["OSPYTHONHTTPSVERIFY"] = '0' # FIXME: change this to https access_protocol = 'http' auth_client = env.setup_auth_client(self._test_workspace, session_token='_PROHIBIT', proto=access_protocol) handshake = auth_client.getAuthParameters() self.assertTrue(handshake.requiresAuthentication, "Privileged server " + "did not report that it requires authentication.") self.assertFalse(handshake.sessionStillActive, "Empty session was " + "reported to be still active.") with self.assertRaises(RequestFailed): auth_client.performLogin("Username:Password", "invalid:invalid") print("Invalid credentials gave us a token!") # A non-authenticated session should return an empty user. user = auth_client.getLoggedInUser() self.assertEqual(user, "") # We still need to create a product on the new server, because # in PostgreSQL mode, the same database is used for configuration # by the newly started instance of this test suite too. codechecker.add_test_package_product( self._test_cfg['codechecker_cfg'], self._test_workspace, # Use the test's home directory to find the session token file. self._test_cfg['codechecker_cfg']['check_env'], access_protocol) self.sessionToken = auth_client.performLogin("Username:Password", "cc:test") self.assertIsNotNone(self.sessionToken, "Valid credentials didn't give us a token!") handshake = auth_client.getAuthParameters() self.assertTrue(handshake.requiresAuthentication, "Privileged server " + "did not report that it requires authentication.") self.assertFalse(handshake.sessionStillActive, "Valid session was " + "reported not to be active.") client = env.setup_viewer_client(self._test_workspace, session_token=self.sessionToken, proto=access_protocol) self.assertIsNotNone(client.getPackageVersion(), "Privileged server didn't respond properly.") authd_auth_client = \ env.setup_auth_client(self._test_workspace, session_token=self.sessionToken, proto=access_protocol) user = authd_auth_client.getLoggedInUser() self.assertEqual(user, "cc") auth_client = env.setup_auth_client(self._test_workspace, session_token=self.sessionToken, proto=access_protocol) result = auth_client.destroySession() self.assertTrue(result, "Server did not allow us to destroy session.") # Kill the session token that was created by login() too. codechecker.logout(self._test_cfg['codechecker_cfg'], self._test_workspace, access_protocol) with self.assertRaises(TProtocolException): # The server reports a HTTP 401 error which is not a valid # Thrift response. But if it does so, it passes the test! client.getPackageVersion() print("Privileged client allowed access after logout.") handshake = auth_client.getAuthParameters() self.assertFalse(handshake.sessionStillActive, "Destroyed session was " + "reported to be still active.") codechecker.remove_test_package_product( self._test_workspace, # Use the test's home directory to find the session token file. self._test_cfg['codechecker_cfg']['check_env'], access_protocol)
def setup_package(): """Setup the environment for the tests.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('skip') os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE test_project = 'cpp' 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) test_env = env.test_env(TEST_WORKSPACE) codechecker_cfg = { 'suppress_file': suppress_file, 'skip_file': skip_list_file, 'check_env': test_env, 'workspace': TEST_WORKSPACE, 'checkers': [] } ret = project.clean(test_project, test_env) if ret: sys.exit(ret) # 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'] = 'skip' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) test_project_name = project_info['name'] + '_' + uuid.uuid4().hex skip_file = codechecker_cfg.pop('skip_file') output_dir = codechecker_cfg['reportdir'] \ if 'reportdir' in codechecker_cfg \ else os.path.join(codechecker_cfg['workspace'], 'reports') codechecker_cfg['reportdir'] = output_dir # Analyze without skip. ret = codechecker.log_and_analyze(codechecker_cfg, project.path(test_project)) if ret: print("Analyzing the test project without a skip file failed.") sys.exit(1) codechecker_cfg['skip_file'] = skip_file # Analyze with skip. ret = codechecker.log_and_analyze(codechecker_cfg, project.path(test_project)) if ret: print("Analyzing the test project with a skip file failed.") sys.exit(1) ret = codechecker.store(codechecker_cfg, test_project_name) if ret: print("Storing the results failed.") sys.exit(1) codechecker_cfg['run_names'] = [test_project_name] test_config['codechecker_cfg'] = codechecker_cfg env.export_test_cfg(TEST_WORKSPACE, test_config)
def setup_package(): """Setup the environment for the tests.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('cmdline') os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE test_project = 'cpp' test_config = {} 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 test_config['test_project'] = project_info suppress_file = None skip_list_file = None test_env = env.test_env(TEST_WORKSPACE) codechecker_cfg = { 'suppress_file': suppress_file, 'skip_list_file': skip_list_file, 'check_env': test_env, 'workspace': TEST_WORKSPACE, 'checkers': [] } ret = project.clean(test_project) if ret: sys.exit(ret) # 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'] = 'cmdline' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) # Generate a unique name for this test run. test_project_name_1 = project_info['name'] + '1_' + uuid.uuid4().hex ret = codechecker.check(codechecker_cfg, test_project_name_1, project.path(test_project)) if ret: sys.exit(1) print("Analyzing the test project was successful.") test_project_name_2 = project_info['name'] + '2_' + uuid.uuid4().hex ret = codechecker.check(codechecker_cfg, test_project_name_2, project.path(test_project)) if ret: sys.exit(1) print("Analyzing the test project was successful.") codechecker_cfg['run_names'] = [test_project_name_1, test_project_name_2] test_config['codechecker_cfg'] = codechecker_cfg env.export_test_cfg(TEST_WORKSPACE, test_config)
def setup_package(): """Setup the environment for the tests.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('cmdline') os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE test_project = 'cpp' test_config = {} 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 test_config['test_project'] = project_info suppress_file = None skip_list_file = None test_env = env.test_env(TEST_WORKSPACE) codechecker_cfg = { 'suppress_file': suppress_file, 'skip_list_file': skip_list_file, 'check_env': test_env, 'workspace': TEST_WORKSPACE, 'checkers': [], 'description': "Runs for command line test." } ret = project.clean(test_project) if ret: sys.exit(ret) # 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'] = 'cmdline' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) # Generate a unique name for this test run. test_project_name_1 = project_info['name'] + '1_' + uuid.uuid4().hex ret = codechecker.check_and_store(codechecker_cfg, test_project_name_1, project.path(test_project)) if ret: sys.exit(1) print("Analyzing the test project was successful.") test_project_name_2 = project_info['name'] + '2_' + uuid.uuid4().hex ret = codechecker.check_and_store(codechecker_cfg, test_project_name_2, project.path(test_project)) if ret: sys.exit(1) print("Analyzing the test project was successful.") codechecker_cfg['run_names'] = [test_project_name_1, test_project_name_2] test_config['codechecker_cfg'] = codechecker_cfg env.export_test_cfg(TEST_WORKSPACE, test_config)
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 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(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'] = 'delete_runs' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) 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)
def setup_package(): """Setup the environment for the tests.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('report_viewer_api') os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE test_project = 'cpp' 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 tag = 'v1.0' test_env = env.test_env(TEST_WORKSPACE) codechecker_cfg = { 'suppress_file': suppress_file, 'skip_list_file': skip_list_file, 'check_env': test_env, 'workspace': TEST_WORKSPACE, 'checkers': [], 'tag': tag } ret = project.clean(test_project) if ret: sys.exit(ret) # 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'] = 'report_viewer_api' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) 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.") 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', '-d', 'unix.Malloc' ] codechecker_cfg['tag'] = None ret = codechecker.check(codechecker_cfg, test_project_name_new, project.path(test_project)) if ret: sys.exit(1) print("Second analysis of the test project was successful.") test_project_name_third = project_info['name'] + uuid.uuid4().hex # Let's run the third analysis. ret = codechecker.check(codechecker_cfg, test_project_name_third, project.path(test_project)) if ret: sys.exit(1) print("Third analysis of the test project was successful.") codechecker_cfg['run_names'] = [test_project_name, test_project_name_new] test_config['codechecker_cfg'] = codechecker_cfg env.export_test_cfg(TEST_WORKSPACE, test_config)
def setup_package(): """Setup the environment for testing components.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('component') os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE test_project = 'cpp' test_config = {} project_info = project.get_info(test_project) test_project_path = os.path.join(TEST_WORKSPACE, "test_proj") shutil.copytree(project.path(test_project), 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 test_env = env.test_env(TEST_WORKSPACE) 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'] = 'component' codechecker.add_test_package_product(server_access, TEST_WORKSPACE) # Extend the checker configuration with the server access. codechecker_cfg.update(server_access) # Clean the test project, if needed by the tests. ret = project.clean(test_project) 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.") # 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)