Exemple #1
0
    def setup(self):
        if self.restart:
            self.logger.debug('Stopping B2G')
            self.device.stop_b2g()

        if self.reset:
            self.logger.debug('Removing persistent storage')
            self.device.file_manager.remove('/data/local/storage/persistent')
            self.device.file_manager.remove('/data/local/indexedDB')

            self.logger.debug('Removing profile')
            self.device.file_manager.remove('/data/b2g/mozilla')

            self.logger.debug('Removing files from storage')
            # TODO: Remove hard-coded paths once bug 1018079 is resolved
            for path in [
                    '/mnt/sdcard', '/mnt/extsdcard', '/storage/sdcard',
                    '/storage/sdcard0', '/storage/sdcard1'
            ]:
                if self.device.file_manager.dir_exists(path):
                    for item in self.device.file_manager.list_items(path):
                        self.device.file_manager.remove('/'.join([path, item]))

        self.logger.debug('Populating databases')
        self.populate_databases()

        if self.restart:
            self.logger.debug('Starting B2G')
            self.device.start_b2g(self.start_timeout)

        self.apps = gaiatest.GaiaApps(self.marionette)
        self.data_layer = gaiatest.GaiaData(self.marionette)

        self.logger.debug('Populating files')
        self.populate_files()

        self.logger.debug('Settling for %d seconds' % self.settle_time)
        time.sleep(self.settle_time)

        self.marionette.switch_to_frame()

        safe_volume = 5
        self.logger.debug('Setting content volume to %d' % safe_volume)
        self.data_layer.set_setting('audio.volume.content', safe_volume)

        self.logger.debug('Switching off keyboard first time use screen')
        self.data_layer.set_setting('keyboard.ftu.enabled', False)

        self.logger.debug('Unlocking device')
        self.device.unlock()

        self.logger.debug('Killing all running apps')
        self.apps.kill_all()

        self.logger.debug('Returning to home screen')
        self.marionette.execute_script(
            'window.wrappedJSObject.dispatchEvent(new Event("home"));')
Exemple #2
0
    def __init__(self, marionette, datazilla_config=None, sources=None):
        self.marionette = marionette

        settings = gaiatest.GaiaData(self.marionette).all_settings  # get all settings
        mac_address = self.marionette.execute_script('return navigator.mozWifiManager && navigator.mozWifiManager.macAddress;')

        self.submit_report = True
        self.ancillary_data = {}

        if gaiatest.GaiaDevice(self.marionette).is_android_build:
            # get gaia, gecko and build revisions
            try:
                device_manager = mozdevice.DeviceManagerADB()
                app_zip = device_manager.pullFile('/data/local/webapps/settings.gaiamobile.org/application.zip')
                with zipfile.ZipFile(StringIO(app_zip)).open('resources/gaia_commit.txt') as f:
                    self.ancillary_data['gaia_revision'] = f.read().splitlines()[0]
            except zipfile.BadZipfile:
                # the zip file will not exist if Gaia has not been flashed to
                # the device, so we fall back to the sources file
                pass

            try:
                sources_xml = sources and xml.dom.minidom.parse(sources) or xml.dom.minidom.parseString(device_manager.catFile('system/sources.xml'))
                for element in sources_xml.getElementsByTagName('project'):
                    path = element.getAttribute('path')
                    revision = element.getAttribute('revision')
                    if not self.ancillary_data.get('gaia_revision') and path in 'gaia':
                        self.ancillary_data['gaia_revision'] = revision
                    if path in ['gecko', 'build']:
                        self.ancillary_data['_'.join([path, 'revision'])] = revision
            except:
                pass

        self.required = {
            'gaia revision': self.ancillary_data.get('gaia_revision'),
            'gecko revision': self.ancillary_data.get('gecko_revision'),
            'build revision': self.ancillary_data.get('build_revision'),
            'protocol': datazilla_config['protocol'],
            'host': datazilla_config['host'],
            'project': datazilla_config['project'],
            'branch': datazilla_config['branch'],
            'oauth key': datazilla_config['oauth_key'],
            'oauth secret': datazilla_config['oauth_secret'],
            'machine name': mac_address or 'unknown',
            'device name': datazilla_config['device_name'],
            'os version': settings.get('deviceinfo.os'),
            'id': settings.get('deviceinfo.platform_build_id')}

        for key, value in self.required.items():
            if not value:
                self.submit_report = False
                print '\nMissing required DataZilla field: %s' % key

        if not self.submit_report:
            print '\n***Reports will not be submitted to DataZilla***'
Exemple #3
0
    def run(self, args=sys.argv[1:]):
        args = self.parser.parse_args()

        host, port = args.address.split(':')
        self.marionette = Marionette(host=host, port=int(port))
        self.marionette.start_session()

        self.apps = gaiatest.GaiaApps(self.marionette)
        self.data_layer = gaiatest.GaiaData(self.marionette)
        self.device = gaiatest.GaiaDevice(self.marionette)

        ret = args.func(args)
        if ret is None:
            ret = 0

        self.marionette.delete_session()

        sys.exit(ret)
Exemple #4
0
    def test_scrollfps(self):
        requires_connection = ['browser']
        self.marionette.set_context(self.marionette.CONTEXT_CONTENT)
        caught_exception = False

        if not self.restart:
            time.sleep(self.settle_time)

        for app_name in self.app_names:
            progress = ProgressBar(widgets=[
                '%s: ' % app_name, '[',
                Counter(),
                '/%d] ' % self.iterations
            ],
                                   maxval=self.iterations)
            progress.start()

            if self.restart:
                self.device.restart_b2g()
                time.sleep(self.settle_time)

            apps = gaiatest.GaiaApps(self.marionette)
            data_layer = gaiatest.GaiaData(self.marionette)
            gaiatest.LockScreen(self.marionette).unlock()  # unlock
            apps.kill_all()  # kill all running apps
            self.marionette.execute_script(
                'window.wrappedJSObject.dispatchEvent(new Event("home"));'
            )  # return to home screen
            self.marionette.import_script(
                pkg_resources.resource_filename(__name__, 'scrollapp.js'))

            try:
                results = {}
                success_counter = 0
                fail_counter = 0
                fail_threshold = int(self.iterations * 0.2)
                for i in range(self.iterations + fail_threshold):
                    if success_counter == self.iterations:
                        break
                    else:
                        try:
                            self.marionette.set_script_timeout(60000)
                            time.sleep(self.delay)
                            period = 5000  # ms
                            sample_hz = 100

                            if self.testvars.get(
                                    'wifi'
                            ) and self.marionette.execute_script(
                                    'return window.navigator.mozWifiManager !== undefined'
                            ):
                                if app_name.lower() in requires_connection:
                                    data_layer.enable_wifi()
                                    data_layer.connect_to_wifi(
                                        self.testvars.get('wifi'))
                                else:
                                    data_layer.disable_wifi()

                            app = apps.launch(app_name, switch_to_frame=False)

                            # Turn on FPS
                            self.marionette.set_script_timeout(period + 1000)
                            result = self.marionette.execute_async_script(
                                'window.wrappedJSObject.fps = new fps_meter("%s", %d, %d); window.wrappedJSObject.fps.start_fps();'
                                % (app_name, period, sample_hz))
                            if not result:
                                raise Exception(
                                    'Error turning on fps measurement')

                            # Do scroll
                            self.marionette.set_script_timeout(60000)
                            self.marionette.switch_to_frame(app.frame)
                            self.marionette.execute_script(
                                'window.addEventListener("touchend", function() { window.wrappedJSObject.touchend = true; }, false);',
                                new_sandbox=False)
                            self.scroll_app(app_name)
                            MarionetteWait(
                                self.marionette,
                                30).until(lambda m: m.execute_script(
                                    'return window.wrappedJSObject.touchend;',
                                    new_sandbox=False))
                            self.marionette.switch_to_frame()
                            fps = self.marionette.execute_script(
                                'return window.wrappedJSObject.fps.stop_fps();'
                            )
                            for metric in ['fps']:
                                if fps.get(metric):
                                    results.setdefault(metric, []).append(
                                        fps.get(metric))
                                else:
                                    raise Exception(
                                        '%s missing %s metric in iteration %s'
                                        % (app_name, metric, i + 1))

                            if fps:
                                gaiatest.GaiaApps(self.marionette).kill(
                                    gaiatest.GaiaApp(origin=fps.get(
                                        'origin')))  # kill application
                            success_counter += 1
                        except Exception:
                            traceback.print_exc()
                            fail_counter += 1
                            if fail_counter > fail_threshold:
                                progress.maxval = success_counter
                                progress.finish()
                                raise Exception(
                                    'Exceeded failure threshold for gathering results!'
                                )
                        finally:
                            progress.update(success_counter)
                            apps.kill_all()
                progress.finish()

                # TODO: This is where you submit to datazilla
                print "DBG: This is the FPS object: %s" % fps
                print "DBG: This is the results object %s" % results
                if self.submit_report:
                    self.post_to_datazilla(results, app_name)
                else:
                    print 'Results: %s' % results

            except Exception:
                traceback.print_exc()
                caught_exception = True
        if caught_exception:
            sys.exit(1)
Exemple #5
0
    def test_startup(self):
        requires_connection = ['marketplace']
        caught_exception = False

        self.marionette.set_script_timeout(60000)

        if not self.restart:
            time.sleep(self.settle_time)

        for app_name in self.app_names:
            progress = ProgressBar(widgets=[
                '%s: ' % app_name, '[',
                Counter(),
                '/%d] ' % self.iterations
            ],
                                   maxval=self.iterations)
            progress.start()

            if self.restart:
                self.device.restart_b2g()
                time.sleep(self.settle_time)

            apps = gaiatest.GaiaApps(self.marionette)
            data_layer = gaiatest.GaiaData(self.marionette)
            data_layer.set_setting('audio.volume.content', 5)  # set volume
            gaiatest.LockScreen(self.marionette).unlock()  # unlock
            apps.kill_all()  # kill all running apps
            self.marionette.execute_script(
                'window.wrappedJSObject.dispatchEvent(new Event("home"));'
            )  # return to home screen
            self.marionette.import_script(
                pkg_resources.resource_filename(__name__, 'launchapp.js'))

            try:
                results = {}
                success_counter = 0
                fail_counter = 0
                fail_threshold = int(self.iterations * 0.2)
                for i in range(self.iterations + fail_threshold):
                    if success_counter == self.iterations:
                        break
                    else:
                        try:
                            if self.testvars.get(
                                    'wifi'
                            ) and self.marionette.execute_script(
                                    'return window.navigator.mozWifiManager !== undefined'
                            ):
                                if app_name.lower() in requires_connection:
                                    data_layer.enable_wifi()
                                    data_layer.connect_to_wifi(
                                        self.testvars.get('wifi'))
                                else:
                                    data_layer.disable_wifi()
                            time.sleep(self.delay)
                            result = self.marionette.execute_async_script(
                                'launch_app("%s")' % app_name)
                            if not result:
                                raise Exception('Error launching app')
                            for metric in ['cold_load_time']:
                                if result.get(metric):
                                    results.setdefault(metric, []).append(
                                        result.get(metric))
                                else:
                                    raise Exception(
                                        '%s missing %s metric in iteration %s'
                                        % (app_name, metric, i + 1))
                            apps.kill(
                                gaiatest.GaiaApp(origin=result.get(
                                    'origin')))  # kill application
                            success_counter += 1
                        except Exception:
                            traceback.print_exc()
                            fail_counter += 1
                            if fail_counter > fail_threshold:
                                progress.maxval = success_counter
                                progress.finish()
                                raise Exception(
                                    'Exceeded failure threshold for gathering results!'
                                )
                        finally:
                            try:
                                apps.kill_all()
                            except:
                                pass
                            progress.update(success_counter)
                progress.finish()
                if self.submit_report:
                    self.post_to_datazilla(results, app_name)
                else:
                    print 'Results for %s:' % app_name
                    for key, values in results.iteritems():
                        print '* %s: avg:%s, max:%s, min:%s, all:%s' % (
                            key, sum(values) / len(values), max(values),
                            min(values), ','.join(str(x) for x in values))

            except Exception:
                traceback.print_exc()
                caught_exception = True

        if caught_exception:
            sys.exit(1)
Exemple #6
0
    def __init__(self,
                 marionette,
                 datazilla_config=None,
                 sources=None,
                 log_level='INFO',
                 device_serial=None):
        # Set up logging
        handler = mozlog.StreamHandler()
        handler.setFormatter(mozlog.MozFormatter(include_timestamp=True))
        self.logger = mozlog.getLogger(self.__class__.__name__, handler)
        self.logger.setLevel(getattr(mozlog, log_level.upper()))

        self.device_serial = device_serial
        self.marionette = marionette

        settings = gaiatest.GaiaData(self.marionette).all_settings
        mac_address = self.marionette.execute_script(
            'return navigator.mozWifiManager && '
            'navigator.mozWifiManager.macAddress;')

        self.submit_report = True
        self.ancillary_data = {
            'generated_by': 'b2gperf %s' % __version__,
            'build_url': datazilla_config['build_url']
        }

        dm = mozdevice.DeviceManagerADB(deviceSerial=self.device_serial)
        self.device = gaiatest.GaiaDevice(self.marionette, manager=dm)

        version = mozversion.get_version(sources=sources,
                                         dm_type='adb',
                                         device_serial=self.device_serial)
        self.ancillary_data['build_revision'] = version.get('build_changeset')
        self.ancillary_data['gaia_revision'] = version.get('gaia_changeset')
        self.ancillary_data['gecko_repository'] = version.get(
            'application_repository')
        self.ancillary_data['gecko_revision'] = version.get(
            'application_changeset')
        self.ancillary_data['ro.build.version.incremental'] = version.get(
            'device_firmware_version_incremental')
        self.ancillary_data['ro.build.version.release'] = version.get(
            'device_firmware_version_release')
        self.ancillary_data['ro.build.date.utc'] = version.get(
            'device_firmware_date')

        self.required = {
            'generated_by': self.ancillary_data.get('generated_by'),
            'gaia_revision': self.ancillary_data.get('gaia_revision'),
            'gecko_repository': self.ancillary_data.get('gecko_repository'),
            'gecko_revision': self.ancillary_data.get('gecko_revision'),
            'build_revision': self.ancillary_data.get('build_revision'),
            'protocol': datazilla_config['protocol'],
            'host': datazilla_config['host'],
            'project': datazilla_config['project'],
            'branch': datazilla_config['branch'],
            'oauth_key': datazilla_config['oauth_key'],
            'oauth_secret': datazilla_config['oauth_secret'],
            'machine_name': datazilla_config['machine_name'] or mac_address,
            'device_name': datazilla_config['device_name'],
            'os_version': settings.get('deviceinfo.os'),
            'id': settings.get('deviceinfo.platform_build_id')
        }

        for key, value in self.required.items():
            if value:
                self.logger.debug('DataZilla field: %s (%s)' % (key, value))
            if not value:
                self.submit_report = False
                self.logger.warn('Missing required DataZilla field: %s' % key)

        for key, value in self.ancillary_data.items():
            if value and key not in self.required.keys():
                self.logger.debug('Ancillary field: %s (%s)' % (key, value))

        if not self.submit_report:
            self.logger.info('Reports will not be submitted to DataZilla')