def setUp(self): # Get the test workspace. self.test_workspace = os.environ['TEST_WORKSPACE'] test_class = self.__class__.__name__ print('Running ' + test_class + ' tests in ' + self.test_workspace) self._codechecker_cfg = env.import_codechecker_cfg(self.test_workspace) self._reports_dir = self._codechecker_cfg['reportdir'] # Get the CodeChecker cmd if needed for the tests. self._codechecker_cmd = env.codechecker_cmd() self._test_dir = os.path.join(self.test_workspace, 'test_files') self._product_name = self._codechecker_cfg['viewer_product'] self._analyzer_stats_dir = os.path.join(self.test_workspace, 'analysis_statistics') try: os.makedirs(self._test_dir) except os.error: # Directory already exists. pass # Setup a viewer client to test viewer API calls. self._cc_client = env.setup_viewer_client(self.test_workspace) self.assertIsNotNone(self._cc_client) # Change working dir to testfile dir so CodeChecker can be run easily. self.__old_pwd = os.getcwd() os.chdir(self._test_dir) self._source_file = "main.cpp" # Init project dir. makefile_content = "all:\n\t$(CXX) -c main.cpp -o /dev/null\n" project_info_content = { "name": "hello", "clean_cmd": "", "build_cmd": "make" } makefile = os.path.join(self._test_dir, 'Makefile') with open(makefile, 'w', encoding="utf-8", errors="ignore") as make_f: make_f.write(makefile_content) project_info = os.path.join(self._test_dir, 'project_info.json') with open(project_info, 'w', encoding="utf-8", errors="ignore") as info_f: json.dump(project_info_content, info_f) self.sources = [""" int main() { return 1 / 0; // Division by zero }""", """ int main() { return 0; xxx // Will cause a compilation error }"""]
def setUp(self): self.test_workspace = os.environ['TEST_WORKSPACE'] test_class = self.__class__.__name__ print('Running ' + test_class + ' tests in ' + self.test_workspace) self.codechecker_cfg = env.import_codechecker_cfg(self.test_workspace) self.test_dir = os.path.join(self.test_workspace, 'test_files') try: os.makedirs(self.test_dir) except os.error: # Directory already exists. pass cc_package = env.codechecker_package() self.orig_checker_labels_dir = os.path.join( cc_package, 'config', 'labels') self.workspace_labels_dir = os.path.join( self.test_workspace, 'config', 'labels') copytree(self.orig_checker_labels_dir, self.workspace_labels_dir) self.codechecker_cfg['check_env']['CC_TEST_LABELS_DIR'] = \ self.workspace_labels_dir
def setUp(self): test_workspace = os.environ['TEST_WORKSPACE'] test_class = self.__class__.__name__ print('Running ' + test_class + ' tests in ' + test_workspace) self._codechecker_cfg = env.import_codechecker_cfg(test_workspace) self._test_dir = os.path.join(test_workspace, 'test_files') # Get the clang version which is tested. self._clang_to_test = env.clang_to_test() self._testproject_data = env.setup_test_proj_cfg(test_workspace) self.assertIsNotNone(self._testproject_data) self._cc_client = env.setup_viewer_client(test_workspace) self.assertIsNotNone(self._cc_client) # Get the run names which belong to this test. run_names = env.get_run_names(test_workspace) sort_mode = RunSortMode(RunSortType.DATE, Order.ASC) runs = self._cc_client.getRunData(None, None, 0, sort_mode) test_runs = [run for run in runs if run.name in run_names] self._runid = test_runs[0].runId
def setUp(self): """ Not much setup is needed. Runs and results are automatically generated. """ test_workspace = os.environ['TEST_WORKSPACE'] test_class = self.__class__.__name__ print('Running ' + test_class + ' tests in ' + test_workspace) # Get the clang version which is tested. self._clang_to_test = env.clang_to_test() self._testproject_data = env.setup_test_proj_cfg(test_workspace) self.assertIsNotNone(self._testproject_data) self._report = env.setup_viewer_client(test_workspace) self.assertIsNotNone(self._report) # Store runs to check. self._codechecker_cfg = env.import_codechecker_cfg(test_workspace) source_dir = os.path.join(os.path.dirname(__file__), 'test_files') self._test_dir = os.path.join(test_workspace, 'test_files') shutil.copytree(source_dir, self._test_dir) _replace_path(os.path.join(self._test_dir, 'run.plist'), self._test_dir) self._codechecker_cfg['reportdir'] = self._test_dir codechecker.store(self._codechecker_cfg, 'test_hash_clash_' + uuid4().hex)
def setUp(self): # TEST_WORKSPACE is automatically set by test package __init__.py self.test_workspace = os.environ['TEST_WORKSPACE'] test_class = self.__class__.__name__ print('Running ' + test_class + ' tests in ' + self.test_workspace) self._codechecker_cfg = env.import_codechecker_cfg(self.test_workspace) # Get the clang version which is tested. self._clang_to_test = env.clang_to_test() # Get the test configuration from the prepared test workspace. self._testproject_data = env.setup_test_proj_cfg(self.test_workspace) self.assertIsNotNone(self._testproject_data) # Setup a viewer client to test viewer API calls. self._cc_client = env.setup_viewer_client(self.test_workspace) self.assertIsNotNone(self._cc_client) # Get the run names which belong to this test. run_names = env.get_run_names(self.test_workspace) runs = self._cc_client.getRunData(None, None, 0, 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
def setUp(self): self.test_workspace = os.environ['TEST_WORKSPACE'] test_class = self.__class__.__name__ print('Running ' + test_class + ' tests in ' + self.test_workspace) self.codechecker_cfg = env.import_codechecker_cfg(self.test_workspace) self.test_dir = os.path.join(self.test_workspace, 'test_files') try: os.makedirs(self.test_dir) except os.error: # Directory already exists. pass cc_package = env.codechecker_package() original_severity_cfg = os.path.join(cc_package, 'config', 'checker_severity_map.json') self.workspace_severity_cfg = os.path.join(self.test_workspace, 'checker_severity_map.json') copyfile(original_severity_cfg, self.workspace_severity_cfg) self.codechecker_cfg['check_env']['CC_SEVERITY_MAP_FILE'] = \ self.workspace_severity_cfg
def setUp(self): self.test_workspace = os.environ['TEST_WORKSPACE'] test_class = self.__class__.__name__ print('Running ' + test_class + ' tests in ' + self.test_workspace) self.codechecker_cfg = env.import_codechecker_cfg(self.test_workspace) self.test_dir = os.path.join(self.test_workspace, 'test_files') try: os.makedirs(self.test_dir) except os.error: # Directory already exists. pass cc_package = env.codechecker_package() original_severity_cfg = os.path.join(cc_package, 'config', 'checker_severity_map.json') self.workspace_severity_cfg = os.path.join( self.test_workspace, 'checker_severity_map.json') copyfile(original_severity_cfg, self.workspace_severity_cfg) self.codechecker_cfg['check_env']['CC_SEVERITY_MAP_FILE'] = \ self.workspace_severity_cfg
def setUp(self): test_workspace = os.environ['TEST_WORKSPACE'] test_class = self.__class__.__name__ print('Running ' + test_class + ' tests in ' + test_workspace) self._codechecker_cfg = env.import_codechecker_cfg(test_workspace) self._test_dir = os.path.join(test_workspace, 'test_files') # Get the clang version which is tested. self._clang_to_test = env.clang_to_test() self._testproject_data = env.setup_test_proj_cfg(test_workspace) self.assertIsNotNone(self._testproject_data) self._cc_client = env.setup_viewer_client(test_workspace) self.assertIsNotNone(self._cc_client) # Get the run names which belong to this test. run_names = env.get_run_names(test_workspace) runs = self._cc_client.getRunData(None) test_runs = [run for run in runs if run.name in run_names] self._runid = test_runs[0].runId
def setUp(self): # Get the test workspace. self.test_workspace = os.environ['TEST_WORKSPACE'] test_class = self.__class__.__name__ print('Running ' + test_class + ' tests in ' + self.test_workspace) self._codechecker_cfg = env.import_codechecker_cfg(self.test_workspace) self._reports_dir = self._codechecker_cfg['reportdir'] # Get the CodeChecker cmd if needed for the tests. self._codechecker_cmd = env.codechecker_cmd() self._test_dir = os.path.join(self.test_workspace, 'test_files') self._product_name = self._codechecker_cfg['viewer_product'] self._analyzer_stats_dir = os.path.join(self.test_workspace, 'analysis_statistics') try: os.makedirs(self._test_dir) except os.error: # Directory already exists. pass # Setup a viewer client to test viewer API calls. self._cc_client = env.setup_viewer_client(self.test_workspace) self.assertIsNotNone(self._cc_client) # Change working dir to testfile dir so CodeChecker can be run easily. self.__old_pwd = os.getcwd() os.chdir(self._test_dir) self._source_file = "main.cpp" # Init project dir. makefile_content = "all:\n\t$(CXX) -c main.cpp -o /dev/null\n" project_info_content = { "name": "hello", "clean_cmd": "", "build_cmd": "make" } makefile = os.path.join(self._test_dir, 'Makefile') with open(makefile, 'w') as make_f: make_f.write(makefile_content) project_info = os.path.join(self._test_dir, 'project_info.json') with open(project_info, 'w') as info_f: json.dump(project_info_content, info_f) self.sources = [""" int main() { return 1 / 0; // Division by zero }""", """ int main() { return 0; xxx // Will cause a compilation error }"""]
def setUp(self): # TEST_WORKSPACE is automatically set by test package __init__.py . self.test_workspace = os.environ['TEST_WORKSPACE'] test_class = self.__class__.__name__ print('Running ' + test_class + ' tests in ' + self.test_workspace) self._codechecker_cfg = env.import_codechecker_cfg(self.test_workspace) self._test_dir = os.path.join(self.test_workspace, 'test_files') try: os.makedirs(self._test_dir) except os.error: # Directory already exists. pass # Setup a viewer client to test viewer API calls. self._cc_client = env.setup_viewer_client(self.test_workspace) self.assertIsNotNone(self._cc_client) # Change working dir to testfile dir so CodeChecker can be run easily. self.__old_pwd = os.getcwd() os.chdir(self._test_dir) self._source_file = "main.cpp" # Init project dir. makefile = "all:\n\t$(CXX) -c main.cpp -o /dev/null\n" project_info = { "name": "test_run_tag", "clean_cmd": "", "build_cmd": "make" } with open(os.path.join(self._test_dir, 'Makefile'), 'w') as f: f.write(makefile) with open(os.path.join(self._test_dir, 'project_info.json'), 'w') as f: json.dump(project_info, f) self.sources = [ """ int main() { sizeof(42); sizeof(43); }""", """ int main() { sizeof(43); sizeof(44); sizeof(45); }""", """ int main() { sizeof(45); }""" ] self.tags = ['v1.0', 'v1.1', 'v1.2']
def setUp(self): # TEST_WORKSPACE is automatically set by test package __init__.py . self.test_workspace = os.environ['TEST_WORKSPACE'] test_class = self.__class__.__name__ print('Running ' + test_class + ' tests in ' + self.test_workspace) self._codechecker_cfg = env.import_codechecker_cfg(self.test_workspace) self._test_dir = os.path.join(self.test_workspace, 'test_files') try: os.makedirs(self._test_dir) except os.error: # Directory already exists. pass # Setup a viewer client to test viewer API calls. self._cc_client = env.setup_viewer_client(self.test_workspace) self.assertIsNotNone(self._cc_client) # Change working dir to testfile dir so CodeChecker can be run easily. self.__old_pwd = os.getcwd() os.chdir(self._test_dir) self._source_file = "main.cpp" # Init project dir. makefile = "all:\n\t$(CXX) -c main.cpp -o /dev/null\n" project_info = { "name": "test_run_tag", "clean_cmd": "", "build_cmd": "make" } with open(os.path.join(self._test_dir, 'Makefile'), 'w') as f: f.write(makefile) with open(os.path.join(self._test_dir, 'project_info.json'), 'w') as f: json.dump(project_info, f) self.sources = [""" int main() { sizeof(42); sizeof(43); }""", """ int main() { sizeof(43); sizeof(44); sizeof(45); }""", """ int main() { sizeof(45); }"""] self.tags = ['v1.0', 'v1.1', 'v1.2']
def setUp(self): self.test_workspace = os.environ['TEST_WORKSPACE'] test_class = self.__class__.__name__ print('Running ' + test_class + ' tests in ' + self.test_workspace) self.codechecker_cfg = env.import_codechecker_cfg(self.test_workspace) self.test_dir = os.path.join(self.test_workspace, 'test_files') try: os.makedirs(self.test_dir) except os.error: # Directory already exists. pass
def setUp(self): # TEST_WORKSPACE is automatically set by test package __init__.py . self.test_workspace = os.environ['TEST_WORKSPACE'] self.codechecker_cfg = env.import_codechecker_cfg(self.test_workspace) test_class = self.__class__.__name__ print('Running ' + test_class + ' tests in ' + self.test_workspace) # Get the CodeChecker cmd if needed for the tests. self._codechecker_cmd = env.codechecker_cmd() self.config_file = os.path.join(self.test_workspace, "codechecker.json")
def setUp(self): # TEST_WORKSPACE is automatically set by test package __init__.py . self.test_workspace = os.environ['TEST_WORKSPACE'] self.codechecker_cfg = env.import_codechecker_cfg(self.test_workspace) test_class = self.__class__.__name__ print('Running ' + test_class + ' tests in ' + self.test_workspace) # Get the CodeChecker cmd if needed for the tests. self._codechecker_cmd = env.codechecker_cmd() self.config_file = os.path.join(self.test_workspace, "codechecker.json") # Create an empty report directory which will be used to check store # command. if not os.path.exists(self.codechecker_cfg['reportdir']): os.mkdir(self.codechecker_cfg['reportdir'])
def setUp(self): # TEST_WORKSPACE is automatically set by test package __init__.py . self.test_workspace = os.environ['TEST_WORKSPACE'] test_class = self.__class__.__name__ print('Running ' + test_class + ' tests in ' + self.test_workspace) # Get the test project configuration from the prepared test workspace. self._testproject_data = env.setup_test_proj_cfg(self.test_workspace) self.assertIsNotNone(self._testproject_data) # Setup a viewer client to test viewer API calls. self._cc_client = env.setup_viewer_client(self.test_workspace) self.assertIsNotNone(self._cc_client) # Get the CodeChecker cmd if needed for the tests. self._codechecker_cmd = env.codechecker_cmd() self._codechecker_cfg = env.import_codechecker_cfg(self.test_workspace) self.env = env.codechecker_env()
def setUp(self): # TEST_WORKSPACE is automatically set by test package __init__.py . self.test_workspace = os.environ['TEST_WORKSPACE'] test_class = self.__class__.__name__ print('Running ' + test_class + ' tests in ' + self.test_workspace) # Get the test project configuration from the prepared test workspace. self._testproject_data = env.setup_test_proj_cfg(self.test_workspace) self.assertIsNotNone(self._testproject_data) # Setup a viewer client to test viewer API calls. self._cc_client = env.setup_viewer_client(self.test_workspace) self.assertIsNotNone(self._cc_client) # Get the CodeChecker cmd if needed for the tests. self._codechecker_cmd = env.codechecker_cmd() self._codechecker_cfg = env.import_codechecker_cfg(self.test_workspace) self.env = env.codechecker_env()
def test_review_status_update_from_source_trim(self): """ Test if the review status comments changes in the source code are updated at the server when trim path is used. The report is store twice and between the storage the review status as a source code comment is modified. The test checks is after the source code modification and storage the review status is updated correctly at the server too. """ test_project_path = os.path.join(self.test_workspace, 'review_status_files') test_project_name = 'review_status_update_proj' plist_file = os.path.join(test_project_path, 'divide_zero.plist') source_file = os.path.join(test_project_path, 'divide_zero.cpp') plist_test.prefix_file_path(plist_file, test_project_path) codechecker_cfg = env.import_codechecker_cfg(self.test_workspace) codechecker_cfg['reportdir'] = test_project_path codechecker.store(codechecker_cfg, test_project_name) codechecker_cfg['trim_path_prefix'] = test_project_path # Run data for the run created by this test case. run_filter = RunFilter(names=[test_project_name], exactMatch=True) runs = self._cc_client.getRunData(run_filter, None, 0, None) run = runs[0] runid = run.runId logging.debug('Get all run results from the db for runid: ' + str(runid)) reports = get_all_run_results(self._cc_client, runid) self.assertIsNotNone(reports) self.assertNotEqual(len(reports), 0) self.assertEqual(len(reports), 2) for report in reports: print(report) self.assertEqual(report.reviewData.status, ReviewStatus.INTENTIONAL) # Modify review comments from intentional to confirmed for the # second store. with open(source_file, 'r+', encoding='utf-8', errors='ignore') as sf: content = sf.read() new_content = content.replace("codechecker_intentional", "codechecker_confirmed") sf.truncate(0) sf.write(new_content) # modify review comments and store the reports again with open(source_file, encoding='utf-8', errors='ignore') as sf: content = sf.read() # Update the plist file modification date to be newer than # the source file so it can be stored, because there was no # actual analysis. date = datetime.datetime.now() + datetime.timedelta(minutes=5) mod_time = time.mktime(date.timetuple()) os.utime(plist_file, (mod_time, mod_time)) codechecker.store(codechecker_cfg, test_project_name) # Check if all the review statuses were updated to the new at the # server. reports = get_all_run_results(self._cc_client, runid) self.assertIsNotNone(reports) self.assertNotEqual(len(reports), 0) self.assertEqual(len(reports), 2) for report in reports: self.assertEqual(report.reviewData.status, ReviewStatus.CONFIRMED)
def setUp(self): # TEST_WORKSPACE is automatically set by test package __init__.py . self.test_workspace = os.environ['TEST_WORKSPACE'] test_class = self.__class__.__name__ print('Running ' + test_class + ' tests in ' + self.test_workspace) self._codechecker_cfg = env.import_codechecker_cfg(self.test_workspace) # Get the CodeChecker cmd if needed for the tests. self._codechecker_cmd = env.codechecker_cmd() self._test_dir = os.path.join(self.test_workspace, 'test_files') self._run_name = 'hello' try: os.makedirs(self._test_dir) except os.error: # Directory already exists. pass # Setup a viewer client to test viewer API calls. self._cc_client = env.setup_viewer_client(self.test_workspace) self.assertIsNotNone(self._cc_client) # Remove all runs before the test cases. runs = self._cc_client.getRunData(None, None, 0, None) if runs: run_id = max(map(lambda run: run.runId, runs)) self._cc_client.removeRun(run_id, None) self.clang_tidy_cfg = os.path.join(self._test_dir, '.clang-tidy') # Change working dir to testfile dir so CodeChecker can be run easily. self.__old_pwd = os.getcwd() os.chdir(self._test_dir) self._source_file = "main.cpp" # Init project dir. makefile = "all:\n\t$(CXX) -c main.cpp -Wno-division-by-zero " \ "-Wno-all -Wno-extra -o /dev/null\n" project_info = {"name": "hello", "clean_cmd": "", "build_cmd": "make"} with open(os.path.join(self._test_dir, 'Makefile'), 'w', encoding="utf-8", errors="ignore") as f: f.write(makefile) with open(os.path.join(self._test_dir, 'project_info.json'), 'w', encoding="utf-8", errors="ignore") as f: json.dump(project_info, f) self.sources = [ """ int main() { int i = 1 / 0; sizeof(42); sizeof(42); sizeof(42); }""", """ int main() { int i = 1 / 0; int* p = 0; i = *p + 42; sizeof(42); sizeof(42); sizeof(42); }""", """ int main() { int i = 1 / 2; int* p = 0; i = *p + 42; sizeof(42); sizeof(42); sizeof(42); }""", """ int main() { int i = 1 / 0; int* p = 0; i = *p + 42; sizeof(42); sizeof(42); }""" ]