コード例 #1
0
    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)
コード例 #2
0
    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 testBoot_display(self):
    self.mox.StubOutClassWithMocks(emulated_device, 'EmulatedDevice')
    initial_boot_device = emulated_device.EmulatedDevice(
        android_platform=mox.IsA(emulated_device.AndroidPlatform),
        qemu_gdb_port=0,
        enable_single_step=False)
    self.mox.StubOutWithMock(initial_boot_device, 'Configure')
    self.mox.StubOutWithMock(initial_boot_device, 'StartDevice')
    skin = 'rabbit_fur'
    memory = '42'
    initial_boot_device.Configure(
        self._tempdir,
        skin,
        memory,
        133,
        36,
        source_properties=None,
        default_properties=None,
        kvm_present=mox.IsA(bool),
        system_image_path=os.path.join(self._tempdir, 'system.img'),
        data_image_path=os.path.join(self._tempdir, 'userdata.img'),
        vendor_img_path=None,
        encryptionkey_img_path=None,
        advanced_features_ini=None,
        build_prop_path=os.path.join(self._tempdir, 'build.prop'))

    initial_boot_device.StartDevice(enable_display=False,
                                    start_vnc_on_port=0,
                                    emulator_tmp_dir=None,
                                    build_time_only_no_op_rendering=True)

    self.mox.StubOutWithMock(initial_boot_device, 'InstallApk')
    self.mox.StubOutWithMock(initial_boot_device, 'KillEmulator')
    self.mox.StubOutWithMock(initial_boot_device, 'IsInstalled')
    self.mox.StubOutWithMock(unified_launcher, '_StopDeviceAndOutputState')

    initial_boot_device.LogToDevice('Device booted.')
    initial_boot_device.InstallApk('hello_world.apk')
    unified_launcher._StopDeviceAndOutputState(initial_boot_device, '/foobar')
    initial_boot_device.CleanUp()

    self.mox.ReplayAll()

    unified_launcher._FirstBootAtBuildTimeOnly(
        [
            os.path.join(self._tempdir, 'system.img'),
            os.path.join(self._tempdir, 'userdata.img'),
            os.path.join(self._tempdir, 'build.prop')
        ],
        skin,
        133,
        memory,
        '/foobar',
        vm_size=36,
        source_properties=None,
        default_properties=None,
        qemu_gdb_port=0,
        enable_single_step=False,
        emulator_tmp_dir=None,
        boot_time_apks=['hello_world.apk'])
コード例 #4
0
    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)
コード例 #5
0
    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)
コード例 #6
0
    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 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)
コード例 #8
0
 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
コード例 #9
0
    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)
コード例 #10
0
    def testSanityTestOpenGL_bogusDriver(self):
        device = emulated_device.EmulatedDevice()

        self.assertRaises(AssertionError, device._SanityCheckOpenGLDriver,
                          'bacon', False)

        self.assertRaises(AssertionError, device._SanityCheckOpenGLDriver,
                          'Reinheitsgebot', True)
コード例 #11
0
    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())
コード例 #12
0
    def testMapToSupportedDensity(self):
        device = emulated_device.EmulatedDevice()

        self.assertEquals(120, device._MapToSupportedDensity(1))
        self.assertEquals(213, device._MapToSupportedDensity(213))
        self.assertEquals(240, device._MapToSupportedDensity(214))
        self.assertEquals(280, device._MapToSupportedDensity(270))
        self.assertEquals(360, device._MapToSupportedDensity(370))
        self.assertEquals(640, device._MapToSupportedDensity(1000))
コード例 #13
0
def _Kill(adb_server_port, emulator_port, adb_port):
    """Shuts down an emulator using the telnet interface."""
    device = emulated_device.EmulatedDevice(
        adb_server_port=adb_server_port,
        emulator_telnet_port=emulator_port,
        emulator_adb_port=adb_port,
        android_platform=_MakeAndroidPlatform())
    device._pipe_traversal_running = True  # pylint: disable=protected-access
    device.KillEmulator()
コード例 #14
0
 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.')
コード例 #15
0
    def testNoAuth(self):
        device = emulated_device.EmulatedDevice()

        mock_sock = self.mox.CreateMockAnything()
        mock_sock.read_until('OK', 1.0).AndReturn('OK')

        self.mox.ReplayAll()
        device._TryAuth(mock_sock)
        self.mox.VerifyAll()
コード例 #16
0
def _Ping(adb_server_port, emulator_port, adb_port):
    """Ensures device is running."""
    device = emulated_device.EmulatedDevice(
        adb_server_port=adb_server_port,
        emulator_telnet_port=emulator_port,
        emulator_adb_port=adb_port,
        device_serial='localhost:%s' % adb_port,
        android_platform=_MakeAndroidPlatform())
    device._pipe_traversal_running = True  # pylint: disable=protected-access
    assert device.Ping() or device.Ping() or device.Ping()
コード例 #17
0
  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)
コード例 #18
0
    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'])
コード例 #19
0
    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'])
コード例 #20
0
  def testBroadcastDeviceReady_withNoArgs(self):
    device = emulated_device.EmulatedDevice()
    device._CanConnect = lambda: True
    called_with = []

    def StubTestAdbCall(args):
      called_with.extend(args)
    device.ExecOnDevice = StubTestAdbCall
    device.BroadcastDeviceReady()
    # do not broadcast!
    self.assertEquals([], called_with)
コード例 #21
0
 def testStartEmulator_NoInitialData(self):
     device = emulated_device.EmulatedDevice()
     device.Configure(tempfile.mkdtemp(),
                      '480x800',
                      '1024',
                      '130',
                      '64',
                      source_properties={
                          'systemimage.abi': 'x86',
                          'androidversion.apilevel': '10'
                      })
     self.assertRaises(AssertionError, device.StartDevice, False, 0)
コード例 #22
0
    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())
コード例 #23
0
 def testStartEmulator_BadSystemDir(self):
     device = emulated_device.EmulatedDevice()
     self.assertRaises(AssertionError,
                       device.Configure,
                       'foo/bar/baz/1234',
                       '480x800',
                       '1024',
                       '130',
                       '64',
                       source_properties={
                           'systemimage.abi': 'x86',
                           'androidversion.apilevel': '10'
                       })
コード例 #24
0
    def testDetermineQemuArgs_FromSourceProperties(self):
        props = {'systemimage.abi': 'armeabi-v7a'}
        device = emulated_device.EmulatedDevice()

        props = {'systemimage.abi': 'armeabi'}
        self.assertEquals([], device._DetermineQemuArgs(props, False))
        self.assertEquals([], device._DetermineQemuArgs(props, True))

        props = {'systemimage.abi': 'x86'}
        self.assertEquals(['-disable-kvm'],
                          device._DetermineQemuArgs(props, False))
        self.assertEquals(['-enable-kvm', '-append', 'nopat'],
                          device._DetermineQemuArgs(props, True))
コード例 #25
0
    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']))
コード例 #26
0
    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 _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)
コード例 #28
0
    def testKill(self):
        self.mox.StubOutClassWithMocks(emulated_device, 'EmulatedDevice')
        adb_server_port = 1
        adb_port = 2
        emulator_port = 3

        mock_device = emulated_device.EmulatedDevice(
            android_platform=mox.IsA(emulated_device.AndroidPlatform),
            adb_server_port=adb_server_port,
            emulator_telnet_port=emulator_port,
            emulator_adb_port=adb_port)
        self.mox.StubOutWithMock(mock_device, 'KillEmulator')
        mock_device.KillEmulator()

        self.mox.ReplayAll()

        unified_launcher._Kill(adb_server_port, emulator_port, adb_port)
コード例 #29
0
    def testPing_live(self):
        self.mox.StubOutClassWithMocks(emulated_device, 'EmulatedDevice')
        adb_server_port = 1
        adb_port = 2
        emulator_port = 3

        mock_device = emulated_device.EmulatedDevice(
            android_platform=mox.IsA(emulated_device.AndroidPlatform),
            adb_server_port=adb_server_port,
            emulator_telnet_port=emulator_port,
            emulator_adb_port=adb_port,
            device_serial='localhost:%s' % adb_port)
        self.mox.StubOutWithMock(mock_device, 'Ping')
        mock_device.Ping().AndReturn(True)

        self.mox.ReplayAll()

        unified_launcher._Ping(adb_server_port, emulator_port, adb_port)
コード例 #30
0
    def testAuth(self):
        device = emulated_device.EmulatedDevice()

        base_dir = tempfile.mkdtemp()
        fname = os.path.join(base_dir, '.emulator_auth_token')
        with open(fname, 'w') as f:
            f.write('123\n')

        mock_sock = self.mox.CreateMockAnything()
        mock_sock.read_until('OK', 1.0).AndReturn(
            'Android Console: Authentication required\n'
            'Android Console: type \'auth <auth_token>\' to authenticate\n'
            'Android Console: you can find your <auth_token> in\n'
            '\'%s\'\nOK' % fname)
        mock_sock.write('auth 123\n')
        mock_sock.read_until('\n', 1.0).AndReturn('OK')

        self.mox.ReplayAll()
        device._TryAuth(mock_sock)
        self.mox.VerifyAll()