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 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 testBiosDir_NoExplicitFiles(self): android_platform = fake_android_platform_util.BuildAndroidPlatform() bios_dir = android_platform.MakeBiosDir(tempfile.mkdtemp()) self.assertTrue(os.path.exists(bios_dir), 'pc-bios dir doesnt exist: %s' % bios_dir) self.assertTrue(os.listdir(bios_dir), 'pc-bios dir is empty! %s' % bios_dir)
def testAdbEnv_NoPort(self): device = emulated_device.EmulatedDevice( android_platform=fake_android_platform_util.BuildAndroidPlatform()) env = device._AdbEnv() self.assertIsNotNone(device.adb_server_port, 'Adb Server Port should ' 'auto assign') self.assertEquals( str(device.adb_server_port), env['ANDROID_ADB_SERVER_PORT'], 'Adb port mismatches between class and environment.')
def testEmulatorPing_noConnect(self): mock_device = emulated_device.EmulatedDevice( android_platform=fake_android_platform_util.BuildAndroidPlatform()) self.mox.StubOutWithMock(mock_device, '_CanConnect') mock_device._CanConnect().AndReturn(False) self.mox.ReplayAll() self.assertFalse(mock_device.Ping())
def testBiosDir_ExplicitFiles(self): android_platform = fake_android_platform_util.BuildAndroidPlatform() temp = tempfile.NamedTemporaryFile() android_platform.bios_files = [temp.name] bios_dir = android_platform.MakeBiosDir(tempfile.mkdtemp()) bios_contents = os.listdir(bios_dir) self.assertTrue( os.path.basename(temp.name) in bios_contents, 'bios dir missing: %s, has: %s' % (temp.name, bios_contents))
def testExecOnEmulator_RestoreFromSnapshot(self): self.mox.ReplayAll() mock_device = emulated_device.EmulatedDevice( android_platform=fake_android_platform_util.BuildAndroidPlatform(), emulator_adb_port=1234, emulator_telnet_port=4567, device_serial='localhost:1234') mock_device._metadata_pb = emulator_meta_data_pb2.EmulatorMetaDataPb() mock_device._SnapshotPresent().value = 'True' self.assertRaises(AssertionError, mock_device.ExecOnDevice, ['ls'])
def testExecOnEmulator_ToggledOff(self): self.mox.ReplayAll() mock_device = emulated_device.EmulatedDevice( android_platform=fake_android_platform_util.BuildAndroidPlatform(), emulator_adb_port=1234, emulator_telnet_port=4567, device_serial='localhost:1234') mock_device._metadata_pb = emulator_meta_data_pb2.EmulatorMetaDataPb() mock_device._pipe_traversal_running = False self.assertRaises(AssertionError, mock_device.ExecOnDevice, ['ls'])
def testEmulatorPing_healthy(self): mock_device = emulated_device.EmulatedDevice( android_platform=fake_android_platform_util.BuildAndroidPlatform()) self.mox.StubOutWithMock(mock_device, '_CanConnect') self.mox.StubOutWithMock(mock_device, '_CheckSystemServerProcess') self.mox.StubOutWithMock(mock_device, '_CheckPackageManagerRunning') mock_device._CanConnect().AndReturn(True) mock_device._CheckSystemServerProcess().AndReturn(True) mock_device._CheckPackageManagerRunning().AndReturn(True) self.mox.ReplayAll() self.assertTrue(mock_device.Ping())
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'} 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)
def testAdbEnv_AssignedPort(self): device = emulated_device.EmulatedDevice( adb_server_port=1234, android_platform=fake_android_platform_util.BuildAndroidPlatform()) self.assertEquals(str(1234), device._AdbEnv()['ANDROID_ADB_SERVER_PORT'])