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 then start the server.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('instances') os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE test_config = {} test_env = env.test_env(TEST_WORKSPACE) # Setup environment variables for the test cases. host_port_cfg = { 'viewer_host': 'localhost', 'viewer_port': env.get_free_port() } codechecker_cfg = { 'workspace': TEST_WORKSPACE, 'check_env': test_env, 'run_names': [], 'checkers': [] } codechecker_cfg.update(host_port_cfg) test_config['codechecker_1'] = codechecker_cfg # We need a second server codechecker_cfg = { 'workspace': TEST_WORKSPACE, 'check_env': test_env, 'run_names': [], 'checkers': [] } host_port_cfg = { 'viewer_host': 'localhost', 'viewer_port': env.get_free_port() } if host_port_cfg['viewer_port'] == \ test_config['codechecker_1']['viewer_port']: host_port_cfg['viewer_port'] = int(host_port_cfg['viewer_port']) + 1 codechecker_cfg.update(host_port_cfg) test_config['codechecker_2'] = codechecker_cfg # Export configuration for the tests. env.export_test_cfg(TEST_WORKSPACE, test_config) # Wait for previous test instances to terminate properly and # clean the instance file in the user's home directory. time.sleep(5)
def setup_package(): """Setup the environment for the tests then start the server.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('instances') os.environ['TEST_WORKSPACE'] = TEST_WORKSPACE test_config = {} test_env = env.test_env(TEST_WORKSPACE) # Setup environment variables for the test cases. host_port_cfg = {'viewer_host': 'localhost', 'viewer_port': env.get_free_port()} codechecker_cfg = { 'workspace': TEST_WORKSPACE, 'check_env': test_env, 'run_names': [], 'checkers': [] } codechecker_cfg.update(host_port_cfg) test_config['codechecker_1'] = codechecker_cfg # We need a second server codechecker_cfg = { 'workspace': TEST_WORKSPACE, 'check_env': test_env, 'run_names': [], 'checkers': [] } host_port_cfg = {'viewer_host': 'localhost', 'viewer_port': env.get_free_port()} if host_port_cfg['viewer_port'] == \ test_config['codechecker_1']['viewer_port']: host_port_cfg['viewer_port'] = int(host_port_cfg['viewer_port']) + 1 codechecker_cfg.update(host_port_cfg) test_config['codechecker_2'] = codechecker_cfg # Export configuration for the tests. env.export_test_cfg(TEST_WORKSPACE, test_config) # Wait for previous test instances to terminate properly and # clean the instance file in the user's home directory. time.sleep(5)
def test_valid_yaml_config(self): """ Start server with a valid YAML configuration file. """ with open(self.config_file_yaml, 'w+', encoding="utf-8", errors="ignore") as config_f: config_f.write(""" # Server related options: server: - --skip-db-cleanup""") event = multiprocessing.Event() event.clear() self.codechecker_cfg['viewer_port'] = env.get_free_port() server_access = \ codechecker.start_server(self.codechecker_cfg, event, ['--config', self.config_file_yaml]) event.set() event.clear() with open(server_access['server_output_file'], 'r', encoding='utf-8', errors='ignore') as out: content = out.read() self.assertFalse('usage: CodeChecker' in content)
def setup_package(): """Setup the environment for the tests then start the server.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('ssl') 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': 'ssl' } test_env = env.test_env(TEST_WORKSPACE) codechecker_cfg = { 'check_env': test_env, 'workspace': TEST_WORKSPACE, 'checkers': [] } codechecker_cfg.update(host_port_cfg) test_config['codechecker_cfg'] = codechecker_cfg # Export configuration for the tests. env.export_test_cfg(TEST_WORKSPACE, test_config) # Enable SSL # ON travis auto-test fails because due to the environment # self signed certs are not accepted # [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661) # Operation not permitted # Will need to solve this to re-enable SSL in this test. # env.enable_ssl(TEST_WORKSPACE) # Enable authentication and start the CodeChecker server. env.enable_auth(TEST_WORKSPACE) print("Starting server to get results") _start_server(codechecker_cfg, test_config, False)
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 the tests then start the server.""" global TEST_WORKSPACE TEST_WORKSPACE = env.get_workspace('ssl') 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': 'ssl'} test_env = env.test_env(TEST_WORKSPACE) codechecker_cfg = { 'check_env': test_env, 'workspace': TEST_WORKSPACE, 'checkers': [] } codechecker_cfg.update(host_port_cfg) test_config['codechecker_cfg'] = codechecker_cfg # Export configuration for the tests. env.export_test_cfg(TEST_WORKSPACE, test_config) # Enable SSL # ON travis auto-test fails because due to the environment # self signed certs are not accepted # [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661) # Operation not permitted # Will need to solve this to re-enable SSL in this test. # env.enable_ssl(TEST_WORKSPACE) # 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)
def test_empty_config(self): """ Start server with an empty configuration file. """ with open(self.config_file, 'w+', encoding="utf-8", errors="ignore") as config_f: config_f.write("") event = multiprocessing.Event() event.clear() self.codechecker_cfg['viewer_port'] = env.get_free_port() server_access = \ codechecker.start_server(self.codechecker_cfg, event, ['--config', self.config_file]) event.set() event.clear() with open(server_access['server_output_file'], 'r', encoding='utf-8', errors='ignore') as out: content = out.read() self.assertFalse('usage: CodeChecker' in content)
def test_invalid_config(self): """ Start server with an invalid configuration file. """ with open(self.config_file, 'w+', encoding="utf-8", errors="ignore") as config_f: json.dump({'server': ['--dummy-option']}, config_f) event = multiprocessing.Event() event.clear() self.codechecker_cfg['viewer_port'] = env.get_free_port() server_access = \ codechecker.start_server(self.codechecker_cfg, event, ['--config', self.config_file]) event.set() event.clear() with open(server_access['server_output_file'], 'r', encoding='utf-8', errors='ignore') as out: content = out.read() self.assertTrue('usage: CodeChecker' in content)
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)
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 setUp(self): """ Set up the environment and the test module's configuration from the package. """ # TEST_WORKSPACE is automatically set by test package __init__.py . self.test_workspace_main = os.environ['TEST_WORKSPACE'] test_class = self.__class__.__name__ print('Running ' + test_class + ' tests in ' + self.test_workspace_main) # Set up a configuration for the main server. # Get the test configuration from the prepared int the test workspace. self.test_cfg = env.import_test_cfg(self.test_workspace_main) self.product_name = self.test_cfg['codechecker_cfg']['viewer_product'] # Setup a viewer client to test viewer API calls. self._cc_client = env.setup_viewer_client(self.test_workspace_main) self.assertIsNotNone(self._cc_client) # Setup an authentication client for creating sessions. self._auth_client = env.setup_auth_client(self.test_workspace_main, session_token='_PROHIBIT') # Create a SUPERUSER login. root_token = self._auth_client.performLogin("Username:Password", "root:root") ret = self._auth_client.addPermission(Permission.SUPERUSER, "root", False, "") self.assertTrue(ret) # Setup a product client to test product API calls. self._pr_client = env.setup_product_client(self.test_workspace_main) self.assertIsNotNone(self._pr_client) # Setup a product client to test product API calls which requires root. self._root_client = env.setup_product_client(self.test_workspace_main, session_token=root_token) self.assertIsNotNone(self._pr_client) # Get the run names which belong to this test. run_names = env.get_run_names(self.test_workspace_main) runs = self._cc_client.getRunData(None) test_runs = [run for run in runs if run.name in run_names] self.assertEqual(len(test_runs), 1, "There should be only one run for this test.") self._runid = test_runs[0].runId # Start a second server with the same configuration database as the # main one. self.test_workspace_secondary = env.get_workspace('producttest_second') self.codechecker_cfg_2 = { 'check_env': self.test_cfg['codechecker_cfg']['check_env'], 'workspace': self.test_workspace_secondary, 'checkers': [], 'viewer_host': 'localhost', 'viewer_port': env.get_free_port(), 'viewer_product': 'producttest_second' } self.codechecker_cfg_2['check_env']['HOME'] = \ self.test_workspace_secondary env.export_test_cfg(self.test_workspace_secondary, {'codechecker_cfg': self.codechecker_cfg_2}) start_server(self.codechecker_cfg_2, EVENT) # Set up API clients for the secondary server. self._auth_client_2 = env.setup_auth_client( self.test_workspace_secondary, session_token='_PROHIBIT') root_token_2 = self._auth_client_2.performLogin( "Username:Password", "root:root") self._pr_client_2 = env.setup_product_client( self.test_workspace_secondary, session_token=root_token_2) self.assertIsNotNone(self._pr_client_2)
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_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()