def is_integer(number, minimum=0): if not isinstance(number, (int, long)): raise ConfigError('%s is not an integer' % number) if number < minimum: raise ConfigError('%s should be equal or larger than %i' % (number, minimum)) return number
def __init__(self, config, progress, restart): self.logger = logging.getLogger(self.__class__.__name__) self.progress = progress self.basedir = None self.random = config.get('randomization', False) if 'devices' not in config: raise ConfigError('"device" is required in the configuration') adb_path = config.get('adb_path', 'adb') self.devices = Devices(config['devices'], adb_path=adb_path, devices_spec=config.get('devices_spec')) self.replications = Tests.is_integer(config.get('replications', 1)) self.paths = config.get('paths', []) self.profilers = Profilers(config.get('profilers', {}), config) monkeyrunner_path = config.get('monkeyrunner_path', 'monkeyrunner') self.scripts = Scripts(config.get('scripts', {}), monkeyrunner_path=monkeyrunner_path) self.time_between_run = Tests.is_integer( config.get('time_between_run', 0)) Tests.check_dependencies(self.devices, self.profilers.dependencies()) self.output_root = paths.OUTPUT_DIR self.result_file_structure = None if restart: for device in self.devices: self.prepare_device(device, restart=True)
def __init__(self, config, monkeyrunner_path='monkeyrunner'): self.logger = logging.getLogger(self.__class__.__name__) self.scripts = {} for name, script in config.items(): self.scripts[name] = [] if isinstance(script, basestring): path = op.join(paths.CONFIG_DIR, script) self.scripts[name].append(Python2(path)) continue for s in script: path = op.join(paths.CONFIG_DIR, s['path']) timeout = s.get('timeout', 0) logcat_regex = s.get('logcat_regex', None) if s['type'] == 'python2': script = Python2(path, timeout, logcat_regex) elif s['type'] == 'monkeyreplay': script = MonkeyReplay(path, timeout, logcat_regex, monkeyrunner_path) elif s['type'] == 'monkeyrunner': script = MonkeyRunner(path, timeout, logcat_regex, monkeyrunner_path) else: raise ConfigError('Unknown script type: {}'.format( s['type'])) self.scripts[name].append(script)
def __init__(self, config): self.package = None self.duration = Tests.is_integer(config.get('duration', 0)) / 1000 super(NativeExperiment, self).__init__(config) for apk in config.get('paths', []): if not op.isfile(apk): raise ConfigError('File %s not found' % apk)
def __init__(self, names, adb_path='adb'): Adb.setup(adb_path) mapping_file = load_json(op.join(ROOT_DIR, 'devices.json')) self._device_map = {n: mapping_file.get(n, None) for n in names} for name, device_id in self._device_map.items(): if not device_id: raise ConfigError(name) self.devices = [Device(name, device_id) for name, device_id in self._device_map.items()]
def check_dependencies(devices, dependencies): for device in devices: installed_apps = device.is_installed(dependencies) not_installed_apps = [ name for name, installed in installed_apps.items() if not installed ] if not_installed_apps: for name in not_installed_apps: logging.error('%s: Required package %s is not installed' % (device.id, name)) raise ConfigError( 'Required packages %s are not installed on device %s' % (not_installed_apps, device.id))
def __init__(self, devices, adb_path='adb', devices_spec=None): if devices_spec is None: devices_spec = op.join(ROOT_DIR, 'devices.json') Adb.setup(adb_path) mapping_file = load_json(devices_spec) self._device_map = {n: mapping_file.get(n, None) for n in devices} for name, device_id in self._device_map.items(): if not device_id: raise ConfigError(name) self.devices = [ Device(name, device_id, devices[name]) for name, device_id in self._device_map.items() ]
def su_unplug(self, restart): """Root unplugs the device""" self.root_plug_value = Adb.shell_su(self.id, 'cat %s' % self.root_unplug_file) if 'su: not found' in self.root_plug_value: raise AdbError("%s %s: is not rooted" % (self.id, self.name)) if 'No such file or directory' in self.root_plug_value: raise ConfigError( '%s %s: the root unplug file seems to be invalid' % (self.id, self.name)) if restart: self.check_plug_value() Adb.shell_su( self.id, 'echo %s > %s' % (self.root_unplug_value, self.root_unplug_file))
def __init__(self, config): self.logger = logging.getLogger(self.__class__.__name__) self.basedir = None if 'devices' not in config: raise ConfigError('"device" is required in the configuration') adb_path = config.get('adb_path', 'adb') self.devices = Devices(config['devices'], adb_path=adb_path) self.replications = Tests.is_integer(config.get('replications', 1)) self.paths = config.get('paths', []) self.profilers = Profilers(config.get('profilers', {})) monkeyrunner_path = config.get('monkeyrunner_path', 'monkeyrunner') self.scripts = Scripts(config.get('scripts', {}), monkeyrunner_path=monkeyrunner_path) self.time_between_run = Tests.is_integer( config.get('time_between_run', 0)) Tests.check_dependencies(self.devices, self.profilers.dependencies()) self.output_root = paths.OUTPUT_DIR
def is_string(string): if not isinstance(string, basestring): raise ConfigError('String expected, got %s' % type(string)) return string
def __init__(self, config): self.package = None super(NativeExperiment, self).__init__(config) for apk in config.get('paths', []): if not op.isfile(apk): raise ConfigError('File %s not found' % apk)