Пример #1
0
    def setup(self, context):
        devpath = self.device.path
        if self.setup_required:
            self.revent_setup_file = context.resolver.get(ReventFile(self, 'setup'))
            if self.revent_setup_file:
                self.on_device_setup_revent = devpath.join(self.device.working_directory,
                                                 os.path.split(self.revent_setup_file)[-1])
                duration = ReventRecording(self.revent_setup_file).duration
                self.default_setup_timeout = ceil(duration) + 30
        if not self.idle_time:
            self.revent_run_file = context.resolver.get(ReventFile(self, 'run'))
            if self.revent_run_file:
                self.on_device_run_revent = devpath.join(self.device.working_directory,
                                                 os.path.split(self.revent_run_file)[-1])
                self.default_run_timeout = ceil(ReventRecording(self.revent_run_file).duration) + 30
        if self.teardown_required:
            self.revent_teardown_file = context.resolver.get(ReventFile(self, 'teardown'))
            if self.revent_teardown_file:
                self.on_device_teardown_revent = devpath.join(self.device.working_directory,
                                                 os.path.split(self.revent_teardown_file)[-1])
                duration = ReventRecording(self.revent_teardown_file).duration
                self.default_teardown_timeout = ceil(duration) + 30
        self._check_revent_files(context)

        Workload.setup(self, context)

        if self.revent_setup_file is not None:
            self.setup_timeout = self.setup_timeout or self.default_setup_timeout
            self.device.killall('revent')
            command = '{} replay {}'.format(self.on_device_revent_binary, self.on_device_setup_revent)
            self.device.execute(command, timeout=self.setup_timeout)
            self.logger.debug('Revent setup completed.')
Пример #2
0
 def resolve_resource(self, resource):
     # pylint: disable=too-many-branches
     assets = self.index.get(resource.owner.name, {})
     if not assets:
         return {}
     if resource.name in ['apk', 'jar']:
         paths = [a['path'] for a in assets]
         version = getattr(resource, 'version', None)
         found = get_from_list_by_extension(resource, paths, resource.name,
                                            version)
         if found:
             for a in assets:
                 if a['path'] == found:
                     return a
     elif resource.name == 'revent':
         device_model = resource.owner.device.get_device_model()
         wa_device_name = resource.owner.device.name
         for name in [device_model, wa_device_name]:
             if not name:
                 continue
             filename = '.'.join([name, resource.stage, 'revent']).lower()
             for asset in assets:
                 pathname = os.path.basename(asset['path']).lower()
                 if pathname == filename:
                     try:
                         ReventRecording(
                             asset['path']).close()  # Check valid recording
                         return asset
                     except ValueError as e:
                         self.logger.warning(e.message)
     else:  # file
         for asset in assets:
             if asset['path'].lower() == resource.path.lower():
                 return asset
    def setup(self, context):
        self.revent_setup_file = context.resolver.get(ReventFile(self, 'setup'))
        self.revent_run_file = context.resolver.get(ReventFile(self, 'run'))
        devpath = self.device.path
        self.on_device_setup_revent = devpath.join(self.device.working_directory,
                                                   os.path.split(self.revent_setup_file)[-1])
        self.on_device_run_revent = devpath.join(self.device.working_directory,
                                                 os.path.split(self.revent_run_file)[-1])
        self._check_revent_files(context)
        default_setup_timeout = ceil(ReventRecording(self.revent_setup_file).duration) + 30
        default_run_timeout = ceil(ReventRecording(self.revent_run_file).duration) + 30
        self.setup_timeout = self.setup_timeout or default_setup_timeout
        self.run_timeout = self.run_timeout or default_run_timeout

        Workload.setup(self, context)
        self.device.killall('revent')
        command = '{} replay {}'.format(self.on_device_revent_binary, self.on_device_setup_revent)
        self.device.execute(command, timeout=self.setup_timeout)
Пример #4
0
    def run(self, args):
        self.logger.info("Pushing file to device")
        self.device.push_file(args.revent, self.device.working_directory)
        revent_file = self.device.path.join(self.device.working_directory, os.path.split(args.revent)[1])

        if args.clear:
            self.device.execute("pm clear {}".format(args.package))

        if args.package:
            self.logger.info("Starting {}".format(args.package))
            self.device.execute('monkey -p {} -c android.intent.category.LAUNCHER 1'.format(args.package))

        self.logger.info("Replaying recording")
        command = "{} replay {}".format(self.target_binary, revent_file)
        recording = ReventRecording(args.revent)
        timeout = ceil(recording.duration) + 30
        recording.close()
        self.device.execute(command, timeout=timeout,
                            as_root=(recording.mode == GAMEPAD_MODE))
        self.logger.info("Finished replay")
Пример #5
0
    def run(self, args):
        self.logger.info("Pushing file to device")
        self.device.push_file(args.revent, self.device.working_directory)
        revent_file = self.device.path.join(self.device.working_directory,
                                            os.path.split(args.revent)[1])

        if args.clear:
            self.device.execute("pm clear {}".format(args.package))

        if args.package:
            self.logger.info("Starting {}".format(args.package))
            self.device.execute(
                'monkey -p {} -c android.intent.category.LAUNCHER 1'.format(
                    args.package))

        self.logger.info("Replaying recording")
        command = "{} replay {}".format(self.target_binary, revent_file)
        recording = ReventRecording(args.revent)
        timeout = ceil(recording.duration) + 30
        recording.close()
        self.device.execute(command,
                            timeout=timeout,
                            as_root=(recording.mode == GAMEPAD_MODE))
        self.logger.info("Finished replay")
Пример #6
0
 def get(self, resource, **kwargs):
     device_model = resource.owner.device.get_device_model()
     wa_device_name = resource.owner.device.name
     for name in [device_model, wa_device_name]:
         if not name:
             continue
         filename = '.'.join([name, resource.stage, 'revent']).lower()
         location = _d(
             os.path.join(self.get_base_location(resource), 'revent_files'))
         for candidate in os.listdir(location):
             if candidate.lower() == filename.lower():
                 path = os.path.join(location, candidate)
                 try:
                     ReventRecording(path).close()  # Check valid recording
                     return path
                 except ValueError as e:
                     self.logger.warning(e.message)
Пример #7
0
    def get_from(self, resource, version, location):  # pylint: disable=no-self-use
        # pylint: disable=too-many-branches
        if resource.name in ['apk', 'jar']:
            return get_from_location_by_extension(resource, location,
                                                  resource.name, version)
        elif resource.name == 'file':
            filepath = os.path.join(location, resource.path)
            if os.path.exists(filepath):
                return filepath
        elif resource.name == 'revent':
            device_model = resource.owner.device.get_device_model()
            wa_device_name = resource.owner.device.name
            for name in [device_model, wa_device_name]:
                if not name:
                    continue
                filename = '.'.join([name, resource.stage, 'revent']).lower()
                alternate_location = os.path.join(location, 'revent_files')
                # There tends to be some confusion as to where revent files should
                # be placed. This looks both in the extension's directory, and in
                # 'revent_files' subdirectory under it, if it exists.
                path = None
                if os.path.isdir(alternate_location):
                    for candidate in os.listdir(alternate_location):
                        if candidate.lower() == filename.lower():
                            path = os.path.join(alternate_location, candidate)
                if os.path.isdir(location):
                    for candidate in os.listdir(location):
                        if candidate.lower() == filename.lower():
                            path = os.path.join(location, candidate)
                if path:
                    try:
                        ReventRecording(path).close()  # Check valid recording
                        return path
                    except ValueError as e:
                        self.logger.warning(e.message)

        else:
            raise ValueError('Unexpected resource type: {}'.format(
                resource.name))