def testConfigureEmulator_defaultSdCard(self): device = emulated_device.EmulatedDevice() device.Configure(fake_android_platform_util.GetSystemImageDir(), '480x800', 1024, 133, 36, source_properties={ 'systemimage.abi': 'x86', 'androidversion.apilevel': '15' }) self.assertEquals(256, device._metadata_pb.sdcard_size_mb) device = emulated_device.EmulatedDevice() device.Configure(fake_android_platform_util.GetSystemImageDir(), '480x800', 1024, 133, 36, default_properties={'some_other_key': 'foo'}, source_properties={ 'systemimage.abi': 'x86', 'androidversion.apilevel': '10' }) self.assertEquals(256, device._metadata_pb.sdcard_size_mb)
def testStartEmulator_EmulatorDies(self): platform = fake_android_platform_util.BuildAndroidPlatform() platform.adb = '/bin/echo' device = emulated_device.EmulatedDevice( android_platform=fake_android_platform_util.BuildAndroidPlatform()) with tempfile.NamedTemporaryFile(delete=False) as f: device._emulator_log_file = f.name device.Configure(fake_android_platform_util.GetSystemImageDir(), '480x800', 1024, 133, 36, source_properties={ 'systemimage.abi': 'x86', 'androidversion.apilevel': '10' }, system_image_path=os.path.join( fake_android_platform_util.GetSystemImageDir(), 'system.img')) try: device.StartDevice(False, 0) self.fail('Device couldn\'t possibly launch - bad arch') except Exception as e: if 'has died' not in e.message: raise e
def testConfigureEmulator_useAdbdPipe(self): device = emulated_device.EmulatedDevice() device.Configure(fake_android_platform_util.GetSystemImageDir(), '480x800', 1024, 133, 36, source_properties={ 'systemimage.abi': 'x86', 'androidversion.apilevel': '15' }) self.assertEquals(False, device._metadata_pb.with_adbd_pipe) self.assertEquals(False, device._metadata_pb.with_patched_adbd) device = emulated_device.EmulatedDevice() device.Configure(fake_android_platform_util.GetSystemImageDir(), '480x800', 1024, 133, 36, source_properties={ 'systemimage.abi': 'x86', 'androidversion.apilevel': '10' }) self.assertEquals(False, device._metadata_pb.with_adbd_pipe) self.assertEquals(False, device._metadata_pb.with_patched_adbd) device = emulated_device.EmulatedDevice() device.Configure(fake_android_platform_util.GetSystemImageDir(), '480x800', 1024, 133, 36, source_properties={ 'systemimage.abi': 'armeabi', 'androidversion.apilevel': '10' }) self.assertEquals(False, device._metadata_pb.with_adbd_pipe) self.assertEquals(False, device._metadata_pb.with_patched_adbd) device = emulated_device.EmulatedDevice() device.Configure(fake_android_platform_util.GetSystemImageDir(), '480x800', 1024, 133, 36, source_properties={ 'systemimage.abi': 'armeabi-v7a', 'androidversion.apilevel': '15' }) self.assertEquals(False, device._metadata_pb.with_adbd_pipe) self.assertEquals(False, device._metadata_pb.with_patched_adbd)
def testStartEmulator_arm_source_properties(self): attempts = 0 last_err = None while attempts < 4: attempts += 1 try: device = emulated_device.EmulatedDevice( android_platform=fake_android_platform_util. BuildAndroidPlatform()) device.Configure(fake_android_platform_util.GetSystemImageDir( SYSTEM_IMG_DIR), '800x480', '512', 233, 36, source_properties={ 'systemimage.abi': 'armeabi', 'androidversion.apilevel': '19' }) device.StartDevice(False, 0) device.KillEmulator(politely=True) return except emulated_device.TransientEmulatorFailure as e: last_err = e self.fail(last_err)
def testBroadcastDeviceReady_action(self): device = emulated_device.EmulatedDevice( android_platform=fake_android_platform_util.BuildAndroidPlatform()) device._CanConnect = lambda: True device.Configure(fake_android_platform_util.GetSystemImageDir(), '480x800', 1024, 133, 36, default_properties={'some_other_key': 'foo'}, source_properties={ 'systemimage.abi': 'x86', 'androidversion.apilevel': '15' }) called_with = [] def StubExecOnEmulator(args, **unused_kwds): called_with.extend(args) device.ExecOnDevice = StubExecOnEmulator extras = collections.OrderedDict() extras['hello'] = 'world' extras['something'] = 'new' action = 'com.google.android.apps.common.testing.services.TEST_ACTION' device.BroadcastDeviceReady(extras, action) self.assertEquals([ 'am', 'broadcast', '-a', action, '-f', '268435488', '-e', 'hello', 'world', '-e', 'something', 'new' ], called_with)
def testBroadcastDeviceReady_booleanExtras(self): device = emulated_device.EmulatedDevice( android_platform=fake_android_platform_util.BuildAndroidPlatform()) device._CanConnect = lambda: True device.Configure(fake_android_platform_util.GetSystemImageDir(), '480x800', 1024, 133, 36, default_properties={'some_other_key': 'foo'}, source_properties={ 'systemimage.abi': 'x86', 'androidversion.apilevel': '15' }) called_with = [] def StubExecOnEmulator(args, **unused_kwds): called_with.extend(args) device.ExecOnDevice = StubExecOnEmulator extras = collections.OrderedDict() extras['boolkey'] = True device.BroadcastDeviceReady(extras) self.assertEquals([ 'am', 'broadcast', '-a', 'ACTION_MOBILE_NINJAS_START', '-f', '268435488', '--ez', 'boolkey', 'true', 'com.google.android.apps.common.testing.services.bootstrap' ], called_with)
def testConfigureEmulator_avdProps(self): device = emulated_device.EmulatedDevice() device.Configure( fake_android_platform_util.GetSystemImageDir(), '480x800', 1024, 133, 36, default_properties={'avd_config_ini.hw.mainkeys': 'no'}, source_properties={ 'avd_config_ini.hw.keyboard.lid': 'no', 'systemimage.abi': 'x86', 'androidversion.apilevel': '10' }) found = set() for prop in device._metadata_pb.avd_config_property: if prop.name == 'hw.mainKeys': found.add(prop.name) self.assertEquals('no', prop.value) elif prop.name == 'hw.keyboard.lid': found.add(prop.name) self.assertEquals('no', prop.value) elif prop.name == 'hw.keyboard': found.add(prop.name) self.assertEquals('yes', prop.value) self.assertEquals(3, len(found))
def _Test(self, start_vnc_on_port): device = None attempts = 0 last_err = None while attempts < 1 and not device: try: attempts += 1 device = emulated_device.EmulatedDevice( android_platform=fake_android_platform_util. BuildAndroidPlatform()) default_props = { 'ro.product.model': 'SuperAwesomePhone 3000', 'ro.mobile_ninjas.emulator_type': 'qemu2', } if int(FLAGS.api_level) > 19: default_props['ro.initial_se_linux_mode'] = 'disabled' device.Configure( fake_android_platform_util.GetSystemImageDir(), '800x480', '1024', 233, 36, kvm_present=True, source_properties={ 'systemimage.abi': 'x86', 'androidversion.apilevel': FLAGS.api_level, 'systemimage.gpusupport': 'yes' }, default_properties=default_props) device.StartDevice(False, start_vnc_on_port, open_gl_driver='mesa') get_prop_output = device.ExecOnDevice(['getprop']) device.KillEmulator(politely=True) device.CleanUp() except emulated_device.TransientEmulatorFailure as e: device = None last_err = e if not device: self.fail(last_err) # Vals for this flag: -1 not an emulator, 0 emulator which doesn't support # open gl, 1 emulator which supports opengl. print get_prop_output self.assertTrue('[ro.kernel.qemu.gles]: [1]' in get_prop_output)