def execute(argv=None): """The main entry point.""" local_logging.start_loggers() logger.info('Version: %s', common.get_version()) logger.info('Path: %s', __file__) parser = argparse.ArgumentParser(description='ClusterFuzz tools') subparsers = parser.add_subparsers(dest='command') subparsers.add_parser('supported_job_types', help='List all supported job types') reproduce = subparsers.add_parser('reproduce', help='Reproduce a crash.') reproduce.add_argument('testcase_id', help='The testcase ID.') reproduce.add_argument( '-c', '--current', action='store_true', default=False, help=('Use the current tree; On the other hand, without --current, ' 'the Chrome repository will be switched to the commit specified in ' 'the testcase.')) reproduce.add_argument( '-b', '--build', action='store', default='chromium', choices=['download', 'chromium', 'standalone'], help='Select which type of build to run the testcase against.') reproduce.add_argument( '--disable-goma', action='store_true', default=False, help='Disable GOMA when building binaries locally.') reproduce.add_argument( '-j', '--goma-threads', action='store', default=None, type=int, help='Manually specify the number of concurrent jobs for a ninja build.') reproduce.add_argument( '-i', '--iterations', action='store', default=10, type=int, help='Specify the number of times to attempt reproduction.') reproduce.add_argument( '-dx', '--disable-xvfb', action='store_true', default=False, help='Disable running testcases in a virtual frame buffer.') reproduce.add_argument( '--target-args', action='store', default='', help='Additional arguments for the target (e.g. chrome).') reproduce.add_argument( '--edit-mode', action='store_true', default=False, help='Edit args.gn before building and target arguments before running.') reproduce.add_argument( '--disable-gclient', action='store_true', default=False, help='Disable running gclient commands (e.g. sync, runhooks).') reproduce.add_argument( '--enable-debug', action='store_true', default=False, help=( 'Build Chrome with full debug symbols by injecting ' '`sanitizer_keep_symbols = true` and `is_debug = true` to args.gn. ' 'Ready to debug with GDB.')) args = parser.parse_args(argv) command = importlib.import_module('clusterfuzz.commands.%s' % args.command) arg_dict = {k: v for k, v in vars(args).items()} del arg_dict['command'] command.execute(**arg_dict)
def send_log(params, stacktrace=None): """Joins the params dict with info like user id and then sends logs.""" scopes = ['https://www.googleapis.com/auth/logging.write'] filename = common.get_resource(0640, 'resources', 'clusterfuzz-tools-logging.json') credentials = ServiceAccountCredentials.from_json_keyfile_name( filename, scopes=scopes) http_auth = credentials.authorize(Http()) params['version'] = common.get_version() params['user'] = os.environ.get('USER') params['sessionId'] = get_session_id() if 'success' in params: prefix = ('successfully finished' if params['success'] else 'unsuccessfully finished') else: prefix = 'started' params['message'] = ( '%s %s running %s with testcase=%s, build_type=%s, ' 'current=%s, and goma=%s' % (params['user'], prefix, params['command'], params['testcase_id'], params['build'], params['current'], 'disabled' if params['disable_goma'] else 'enabled')) if stacktrace: params['message'] += '\n%s' % stacktrace structure = { 'logName': 'projects/clusterfuzz-tools/logs/client', 'resource': { 'type': 'project', 'labels': { 'project_id': 'clusterfuzz-tools' } }, 'entries': [{ 'jsonPayload': params, 'severity': 'ERROR' if stacktrace else 'INFO' }] } http_auth.request(uri='https://logging.googleapis.com/v2/entries:write', method='POST', body=json.dumps(structure))
def test_get_version(self): """Test get_version.""" version_path = os.path.join(os.path.dirname(common.__file__), 'resources', 'VERSION') self.fs.CreateFile(version_path, contents='vvv') self.assertEqual('vvv', common.get_version())