def main(): parser = argparse.ArgumentParser(description='CodeChecker tester script', formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('-p', '--package', required=True, action='store', dest='pkg_root', help='Path of the package to test.') parser.add_argument('-v', '--clang_version', default='stable', action='store', choices={'stable', 'trunk'}, dest='clang_version', help='Version of the used clang.') parser.add_argument('-t', '--test_modules', default='tests/regression_test', action='store', dest='test_modules', help='The directory containing the test files.') parser.add_argument('--project', default='tests/test_projects/bzip2', action='store', dest='test_project', help='Project to run the test checks on.') parser.add_argument('--project-config', action='store', dest='test_project_config', help='Test project config. By default tries to use from the test_project.') parser.add_argument('--sqlite', dest="sqlite", action='store_true', required=False, help='Use sqlite database.') parser.add_argument('--dbaddress', type=str, dest="dbaddress", default='localhost', help='Postgres database server address.') parser.add_argument('--dbport', type=int, dest="dbport", default=get_free_port(), help='Postgres database server port.') parser.add_argument('--dbname', type=str, dest="dbname", default='testDb', help='Name of the database.') parser.add_argument('--dbusername', type=str, dest="dbusername", default='testUser', help='Database user name.') args = parser.parse_args() args.pkg_root = os.path.realpath(args.pkg_root) args.test_modules = os.path.realpath(args.test_modules) args.test_project = os.path.realpath(args.test_project) database = {k: vars(args)[k] for k in ('dbaddress', 'dbport', 'dbname', 'dbusername')} LOG.info('Initializing new package tester') package_tester = GenericPackageTester(args.pkg_root, database, args.test_project, args.test_project_config, args.test_modules, args.clang_version, LOG, args) LOG.info('Running tests') package_tester.run_test()
def main(): parser = argparse.ArgumentParser( description='CodeChecker tester script', formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('-p', '--package', required=True, action='store', dest='pkg_root', help='Path of the package to test.') parser.add_argument('-v', '--clang_version', default='stable', action='store', choices={'stable', 'trunk'}, dest='clang_version', help='Version of the used clang.') parser.add_argument('-t', '--test_modules', default='tests/regression_test', action='store', dest='test_modules', help='The directory containing the test files.') parser.add_argument('--project', default='tests/test_projects/test_files', action='store', dest='test_project', help='Project to run the test checks on.') parser.add_argument( '--project-config', action='store', dest='test_project_config', help= 'Test project config. By default tries to use from the test_project.') parser.add_argument('--postgresql', dest="postgresql", action='store_true', default=False, help='Use PostgreSQL database.') parser.add_argument('--dbaddress', type=str, dest="dbaddress", default='localhost', help='Postgres database server address.') parser.add_argument('--dbport', type=int, dest="dbport", default=get_free_port(), help='Postgres database server port.') parser.add_argument('--dbname', type=str, dest="dbname", default='testDb', help='Name of the database.') parser.add_argument('--dbusername', type=str, dest="dbusername", default='testUser', help='Database user name.') args = parser.parse_args() args.pkg_root = os.path.realpath(args.pkg_root) args.test_modules = os.path.realpath(args.test_modules) args.test_project = os.path.realpath(args.test_project) database = { k: vars(args)[k] for k in ('dbaddress', 'dbport', 'dbname', 'dbusername') } LOG.info('Initializing new package tester') package_tester = GenericPackageTester(args.pkg_root, database, args.test_project, args.test_project_config, args.test_modules, args.clang_version, LOG, args) LOG.info('Running tests') package_tester.run_test()
def run_test(self): db = self.database test_config = {} test_config['CC_TEST_SERVER_PORT'] = get_free_port() test_config['CC_TEST_SERVER_HOST'] = 'localhost' test_config['CC_TEST_VIEWER_PORT'] = get_free_port() test_config['CC_TEST_VIEWER_HOST'] = 'localhost' test_project_path = self.test_proj_path test_project_clean_cmd = self.project_info['clean_cmd'] test_project_build_cmd = self.project_info['build_cmd'] codechecker_workspace = self.workspace self.env['CODECHECKER_VERBOSE'] = 'debug' # self.env['CODECHECKER_ALCHEMY_LOG'] = '2' def run_check(suppress_file): check_cmd = [] check_cmd.append('CodeChecker') check_cmd.append('check') if self.use_sqlite: check_cmd.append('--sqlite') else: check_cmd.append('--dbaddress') check_cmd.append(db['dbaddress']) check_cmd.append('--dbport') check_cmd.append(str(db['dbport'])) check_cmd.append('--dbname') check_cmd.append(db['dbname']) check_cmd.append('--dbusername') check_cmd.append(db['dbusername']) check_cmd.append('-w') check_cmd.append(codechecker_workspace) check_cmd.append('--suppress') check_cmd.append(suppress_file) unique_id = uuid.uuid4().hex check_cmd.append('-n') check_cmd.append(self.project_info['name'] + '_' + unique_id) check_cmd.append('-b') check_cmd.append(test_project_build_cmd) self.log.info(' '.join(check_cmd)) try: subprocess.check_call(check_cmd, cwd=test_project_path, env=self.env) self.log.info('Checking the test project is done.') except subprocess.CalledProcessError as perr: self.log.error(str(perr)) self.log.error('Failed to run command: ' + ' '.join(check_cmd)) raise perr def start_server(): server_cmd = [] server_cmd.append('CodeChecker') server_cmd.append('server') server_cmd.append('--check-port') server_cmd.append(str(test_config['CC_TEST_SERVER_PORT'])) if self.use_sqlite: server_cmd.append('--sqlite') else: server_cmd.append('--dbaddress') server_cmd.append(db['dbaddress']) server_cmd.append('--dbport') server_cmd.append(str(db['dbport'])) server_cmd.append('--dbname') server_cmd.append(db['dbname']) server_cmd.append('--dbusername') server_cmd.append(db['dbusername']) server_cmd.append('--view-port') server_cmd.append(str(test_config['CC_TEST_VIEWER_PORT'])) server_cmd.append('-w') server_cmd.append(codechecker_workspace) server_cmd.append('--suppress') server_cmd.append(suppress_file) self.log.info('Starting server.') self.log.info(' '.join(server_cmd)) w2 = multiprocessing.Process(name='server', target=start_test_server, args=(stop_server, server_cmd, self.env)) w2.start() # wait for server to start and connect to database time.sleep(15) manager = multiprocessing.Manager() err = manager.dict() fail = manager.dict() skipp = manager.dict() self.log.info('STARTING CLIENT TESTS...') w1 = multiprocessing.Process( name='test_client', target=self.start_test_client, args=(stop_server, err, fail, skipp, test_config['CC_TEST_VIEWER_PORT'], test_config['CC_TEST_SERVER_PORT'], test_module_error)) w1.start() # wait for test to finish w1.join() return err, fail, skipp self.log.info('Cleaning checker workspace') # generate suppress file suppress_file_fd, suppress_file = tempfile.mkstemp() self._generate_suppress_file(suppress_file) # end ------------------ self.log.info('Cleaning test project') # fist check self._clean_test_project(test_project_path, test_project_clean_cmd) run_check(suppress_file) time.sleep(5) stop_server = multiprocessing.Event() test_module_error = multiprocessing.Event() # second check self._clean_test_project(test_project_path, test_project_clean_cmd) run_check(suppress_file) time.sleep(5) stop_server = multiprocessing.Event() err, fail, skipp = start_server() # delete suppress file os.close(suppress_file_fd) os.remove(suppress_file) if test_module_error.is_set(): LOG.error('Test module error') sys.exit(1) self.log.info('CLIENT TESTS DONE.') self.log.info('=====================================') self.log.info('TEST RESULTS:') self.log.info('=====================================') self.log.info('=====================================') self.log.info('TestCase errors: ' + str(len(err))) if err: self.log.info('=====================================') for id, msg in err.items(): LOG.info(id) LOG.info(msg) self.log.info('=====================================') self.log.info('Failed TestCases: ' + str(len(fail))) if fail: self.log.info('=====================================') for id, msg in fail.items(): LOG.info(id) LOG.info(msg) self.log.info('=====================================') self.log.info('Skipped TestCases: ' + str(len(skipp))) if skipp: self.log.info('=====================================') for id, msg in skipp.items(): LOG.info(id) LOG.info(msg) self.log.info('=====================================') if fail or err: LOG.error('Some tests have failed!') sys.exit(1)
def run_test(self): db = self.database test_config = {} test_config['CC_TEST_SERVER_PORT'] = get_free_port() test_config['CC_TEST_SERVER_HOST'] = 'localhost' test_config['CC_TEST_VIEWER_PORT'] = get_free_port() test_config['CC_TEST_VIEWER_HOST'] = 'localhost' test_project_path = self.test_proj_path test_project_clean_cmd = self.project_info['clean_cmd'] test_project_build_cmd = self.project_info['build_cmd'] codechecker_workspace = self.workspace #self.env['CODECHECKER_VERBOSE'] = 'debug' # self.env['CODECHECKER_ALCHEMY_LOG'] = '2' def run_check(suppress_file, skip_list_file): check_cmd = [] check_cmd.append('CodeChecker') check_cmd.append('check') if self.use_postgresql: check_cmd.append('--postgresql') check_cmd.append('--dbaddress') check_cmd.append(db['dbaddress']) check_cmd.append('--dbport') check_cmd.append(str(db['dbport'])) check_cmd.append('--dbname') check_cmd.append(db['dbname']) check_cmd.append('--dbusername') check_cmd.append(db['dbusername']) check_cmd.append('-w') check_cmd.append(codechecker_workspace) check_cmd.append('--suppress') check_cmd.append(suppress_file) check_cmd.append('--skip') check_cmd.append(skip_list_file) unique_id = uuid.uuid4().hex check_cmd.append('-n') check_cmd.append(self.project_info['name'] + '_' + unique_id) check_cmd.append('-b') check_cmd.append(test_project_build_cmd) check_cmd.append('--analyzers') check_cmd.append('clangsa') self.log.info(' '.join(check_cmd)) try: subprocess.check_call(check_cmd, cwd=test_project_path, env=self.env) self.log.info('Checking the test project is done.') except subprocess.CalledProcessError as perr: self.log.error(str(perr)) self.log.error('Failed to run command: ' + ' '.join(check_cmd)) raise perr def start_server(): server_cmd = [] server_cmd.append('CodeChecker') server_cmd.append('server') server_cmd.append('--check-port') server_cmd.append(str(test_config['CC_TEST_SERVER_PORT'])) if self.use_postgresql: server_cmd.append('--postgresql') server_cmd.append('--dbaddress') server_cmd.append(db['dbaddress']) server_cmd.append('--dbport') server_cmd.append(str(db['dbport'])) server_cmd.append('--dbname') server_cmd.append(db['dbname']) server_cmd.append('--dbusername') server_cmd.append(db['dbusername']) server_cmd.append('--view-port') server_cmd.append(str(test_config['CC_TEST_VIEWER_PORT'])) server_cmd.append('-w') server_cmd.append(codechecker_workspace) server_cmd.append('--suppress') server_cmd.append(suppress_file) self.log.info('Starting server.') self.log.info(' '.join(server_cmd)) w2 = multiprocessing.Process(name='server', target=start_test_server, args=(stop_server, server_cmd, self.env)) w2.start() # wait for server to start and connect to database time.sleep(15) manager = multiprocessing.Manager() err = manager.dict() fail = manager.dict() skipp = manager.dict() self.log.info('STARTING CLIENT TESTS...') w1 = multiprocessing.Process( name='test_client', target=self.start_test_client, args=(stop_server, err, fail, skipp, test_config['CC_TEST_VIEWER_PORT'], test_config['CC_TEST_SERVER_PORT'], test_module_error)) w1.start() # wait for test to finish w1.join() return err, fail, skipp self.log.info('Cleaning checker workspace') # generate suppress file suppress_file_fd, suppress_file = tempfile.mkstemp() self._generate_suppress_file(suppress_file) skip_list_file_fd, skip_list_file = tempfile.mkstemp() self._generate_skip_list_file(skip_list_file) # end ------------------ self.log.info('Cleaning test project') # fist check self._clean_test_project(test_project_path, test_project_clean_cmd) run_check(suppress_file, skip_list_file) time.sleep(5) stop_server = multiprocessing.Event() test_module_error = multiprocessing.Event() # second check self._clean_test_project(test_project_path, test_project_clean_cmd) run_check(suppress_file, skip_list_file) time.sleep(5) stop_server = multiprocessing.Event() err, fail, skipp = start_server() # delete suppress file os.close(suppress_file_fd) os.remove(suppress_file) if test_module_error.is_set(): LOG.error('Test module error') sys.exit(1) self.log.info('CLIENT TESTS DONE.') self.log.info('=====================================') self.log.info('TEST RESULTS:') self.log.info('=====================================') self.log.info('=====================================') self.log.info('TestCase errors: ' + str(len(err))) if err: self.log.info('=====================================') for id, msg in err.items(): LOG.info(id) LOG.info(msg) self.log.info('=====================================') self.log.info('Failed TestCases: ' + str(len(fail))) if fail: self.log.info('=====================================') for id, msg in fail.items(): LOG.info(id) LOG.info(msg) self.log.info('=====================================') self.log.info('Skipped TestCases: ' + str(len(skipp))) if skipp: self.log.info('=====================================') for id, msg in skipp.items(): LOG.info(id) LOG.info(msg) self.log.info('=====================================') if fail or err: LOG.error('Some tests have failed!') sys.exit(1)