def testStopDeviceAndOutputState(self): mock_device = emulated_device.EmulatedDevice() self.mox.StubOutWithMock(mock_device, 'TakeSnapshot') self.mox.StubOutWithMock(mock_device, 'KillEmulator') self.mox.StubOutWithMock(mock_device, 'StoreAndCompressUserdata') self.mox.StubOutWithMock(mock_device, 'GetEmulatorMetadataProto') mock_device.KillEmulator(politely=True) output_dir = tempfile.mkdtemp() mock_device.StoreAndCompressUserdata( os.path.join(output_dir, 'userdata_images.dat')) mock_device.GetEmulatorMetadataProto().AndReturn(self._test_proto) self.mox.ReplayAll() unified_launcher._StopDeviceAndOutputState(mock_device, output_dir) self.assertTrue( os.path.exists( os.path.join(output_dir, unified_launcher._METADATA_FILE_NAME))) written_file = open( os.path.join(output_dir, unified_launcher._METADATA_FILE_NAME), 'rb') written_proto = emulator_meta_data_pb2.EmulatorMetaDataPb() written_proto.ParseFromString(written_file.read()) written_file.close() self.assertEquals(written_proto, self._test_proto)
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 VerifyDisableSideLoading(self, api_level, table_name): device = emulated_device.EmulatedDevice() device._metadata_pb = emulator_meta_data_pb2.EmulatorMetaDataPb( api_name=api_level) called_with = [] def StubTestAdbCall(args): called_with.extend(args) device.ExecOnDevice = StubTestAdbCall device._DisableSideloading() self.assertSideLoading(api_level, table_name, called_with)
def _PrintInfo(metadata_path, output_format, out=None): """Prints out the info contained in the metadata protobuf.""" out = out or sys.stdout proto = emulator_meta_data_pb2.EmulatorMetaDataPb() with open(metadata_path, 'rb') as proto_file: proto.ParseFromString(proto_file.read()) if output_format == 'text': text_format.PrintMessage(proto, out, indent=2) else: out.write(proto.SerializeToString())
def setUp(self): super(UnifiedLauncherTest, self).setUp() base_temp = tempfile.mkdtemp() self._tempdir = os.path.join(base_temp, 'android_test_support') os.mkdir(self._tempdir) FLAGS.flag_configured_android_tools = False FLAGS.enable_gms_usage_reporting = True self._test_proto = emulator_meta_data_pb2.EmulatorMetaDataPb() self._test_proto.skin = '800x900' self._test_proto.memory_mb = 1024 self._test_proto.density = 133 self._test_proto.vm_heap = 36 self._test_proto.net_type = 'fastnet' self._test_proto.sdcard_size_mb = 256
def testExecOnEmulator_NormalBoot(self): self.mox.ReplayAll() test_plat = emulated_device.AndroidPlatform() test_plat.adb = '/bin/echo' test_plat.real_adb = '/bin/echo' mock_device = emulated_device.EmulatedDevice( android_platform=test_plat, emulator_adb_port=1234, emulator_telnet_port=4567, device_serial='localhost:1234') mock_device._metadata_pb = emulator_meta_data_pb2.EmulatorMetaDataPb() self.assertEquals('-s localhost:1234 shell echo hello\n', mock_device.ExecOnDevice(['echo', 'hello']))
def testSanityTestOpenGL_supportedChecking(self): device = emulated_device.EmulatedDevice() device._metadata_pb = emulator_meta_data_pb2.EmulatorMetaDataPb( supported_open_gl_drivers=[emulated_device.MESA_OPEN_GL]) self.assertRaises(AssertionError, device._SanityCheckOpenGLDriver, emulated_device.HOST_OPEN_GL, False) self.assertRaises(AssertionError, device._SanityCheckOpenGLDriver, emulated_device.NO_OPEN_GL, False) device._SanityCheckOpenGLDriver(emulated_device.MESA_OPEN_GL, False) device._SanityCheckOpenGLDriver(emulated_device.MESA_OPEN_GL, True) device._SanityCheckOpenGLDriver(emulated_device.HOST_OPEN_GL, True) device._SanityCheckOpenGLDriver(emulated_device.NO_OPEN_GL, True)
def _RestartDevice(device, enable_display, start_vnc_on_port, net_type, system_image_files, input_image_file, proto_filepath, new_process_group=False, window_scale=None, with_audio=False, with_boot_anim=False, emulator_tmp_dir=None, open_gl_driver=None, experimental_open_gl=False): """Restarts a emulated device from persisted images and snapshots. Args: device: an unstarted emulated_device.EmulatedDevice enable_display: if true emulator starts in display mode start_vnc_on_port: if a port is specified, starts vnc server at that port. net_type: the type of network to use while starting the emulator. system_image_files: list of system image files and other support files. input_image_file: a tar gz archive of the userdata dir. proto_filepath: (optional) a path to the emulator metadata proto. new_process_group: (optional) launches emulator in a new process group. window_scale: (optional) Scale factor of emulator window in percent. with_audio: (optional) indicates the emulator should turn on audio. with_boot_anim: (optional) Enables boot animation. emulator_tmp_dir: temporary directory where system_images/sockets/ramdisk files are placed while starting the emulator open_gl_driver: (optional) name of opengl driver to use. experimental_open_gl: (optional) if true - disables many opengl checks Raises: Exception: if the emulated device cannot be started. """ assert proto_filepath and os.path.exists( proto_filepath), 'No metadata found!' system_images_dir = _FindSystemImagesDir(system_image_files) proto_file = open(proto_filepath, 'rb') proto = emulator_meta_data_pb2.EmulatorMetaDataPb() proto.ParseFromString(proto_file.read()) proto_file.close() assert not (proto.with_kvm and not _IsKvmPresent()), ( 'Try to run snapshot images with KVM support on non-KVM machine.') if 'x86' == proto.emulator_architecture: if not _IsKvmPresent(): print '' print '=' * 80 print( '= By activating KVM on your local host you can increase the ' 'speed of the emulator. =') print '=' * 80 elif not proto.with_kvm: print '' print '=' * 80 print( '= Please add --no to your bazel command line, to create ' 'snapshot images =') print( '= local with KVM support. This will increase the speed of the ' 'emulator. =') print '=' * 80 else: print '' print '=' * 80 print( '= By using x86 with KVM on your local host you can increase the ' 'speed of the emulator.') print '=' * 80 proto.system_image_dir = system_images_dir sysimg = (_ExtractSuffixFile(system_image_files, 'system.img.tar.gz') or _ExtractSuffixFile(system_image_files, 'system.img')) dataimg = (_ExtractSuffixFile(system_image_files, 'userdata.img.tar.gz') or _ExtractSuffixFile(system_image_files, 'userdata.img')) vendorimg_path = _ExtractSuffixFile(system_image_files, 'vendor.img.tar.gz') encryptionkeyimg_path = _ExtractSuffixFile(system_image_files, 'encryptionkey.img') advanced_features_ini = _ExtractSuffixFile(system_image_files, 'advancedFeatures.ini') # TODO: Move data to another field in the proto. images_dict = device.BuildImagesDict(sysimg, dataimg, vendorimg_path, encryptionkeyimg_path, advanced_features_ini) proto.system_image_path = json.dumps(images_dict) device._metadata_pb = proto device.StartDevice(enable_display, start_vnc_on_port=start_vnc_on_port, net_type=net_type, userdata_tarball=input_image_file, new_process_group=new_process_group, window_scale=window_scale, with_audio=with_audio, with_boot_anim=with_boot_anim, emulator_tmp_dir=emulator_tmp_dir, open_gl_driver=open_gl_driver, allow_experimental_open_gl=experimental_open_gl)