def _download_remote_test_file(self, filename, input_type):
        """Download a file from the remote touch playback folder.

        @param filename: string of filename
        @param input_type: device type, e.g. 'touchpad'

        @returns: Path to local file or None if file is not found.

        """
        REMOTE_STORAGE_URL = ('https://storage.googleapis.com/'
                              'chromiumos-test-assets-public/touch_playback')
        filename = urllib.quote(filename)

        if input_type in ['touchpad', 'touchscreen', 'stylus']:
            url = '%s/%s/%s' % (REMOTE_STORAGE_URL, self._platform, filename)
        else:
            url = '%s/TYPE-%s/%s' % (REMOTE_STORAGE_URL, input_type, filename)
        local_file = os.path.join(self.bindir, filename)

        logging.info('Looking for %s', url)
        try:
            file_utils.download_file(url, local_file)
        except urllib2.URLError as e:
            logging.info('File download failed!')
            logging.debug(e.msg)
            return None

        return local_file
Beispiel #2
0
    def run_once(self, test_cases):
        """
        Runs JpegEncodeAcceleratorTest.SimpleEncode on the device and reports
        latency values for HW and SW.
        """

        for (image_path, width, height) in test_cases:
            url = DOWNLOAD_BASE + image_path
            file_name = os.path.basename(image_path)
            input_path = os.path.join(self.bindir, file_name)
            file_utils.download_file(url, input_path)
            test_name = ('%s_%dx%d' % (file_name, width, height))
            output_path = os.path.join(self.tmpdir, TEST_LOG)

            cmd_line_list = [helper_logger.chrome_vmodule_flag()] + [
                '--gtest_filter=JpegEncodeAcceleratorTest.SimpleEncode',
                ('--output_log=%s' % output_path),
                ('--repeat=%d' % REPEAT_TIMES),
                ('--yuv_filenames="%s:%dx%d"' % (input_path, width, height))
            ]
            cmd_line = ' '.join(cmd_line_list)
            try:
                self.run_chrome_test_binary(self.binary, cmd_line)
                self.report_perf_results(test_name, output_path)
            except Exception as last_error:
                # Log the error and continue to the next test case.
                logging.exception(last_error)
            finally:
                self.remove_if_exists(input_path)
                self.remove_if_exists(output_path)
    def run_once(self, args={}):
        self._parse_args(args)

        logging.info("Running crouton test:")
        logging.info(" - repo: %s", self._repo)
        logging.info(" - branch: %s", self._branch)
        logging.info(" - runargs: %s", self._runargs)
        logging.info(" - env:%s", self._env)
        logging.debug(" - resultsdir: %s", self.resultsdir)
        logging.debug(' - tmpdir: %s', self.tmpdir)

        crouton_temp_file = os.path.join(self.tmpdir, "archive.tar.gz")
        crouton_url = 'https://github.com/%s/archive/%s.tar.gz' \
                                            % (self._repo, self._branch)

        logging.info('Downloading crouton tarball: "%s".', crouton_url)
        file_utils.download_file(crouton_url, crouton_temp_file)

        os.chdir(self.tmpdir)
        utils.system('tar xvf %s --strip-components 1' % crouton_temp_file)

        # Set environment. Only allow setting CROUTON_MIRROR_* variables
        for env_pair in self._env.split(";"):
            keyval = env_pair.split("=")
            if len(keyval) == 2 and keyval[0].find("CROUTON_MIRROR_") == 0:
                logging.debug('Setting env %s=%s', keyval[0], keyval[1])
                os.environ[keyval[0]] = keyval[1]

        # Pass arguments separately to avoid problems with Little Bobby Tables.
        args = ['test/run.sh', '-l', self.resultsdir] + self._runargs.split()
        utils.run('sh',
                  args=args,
                  timeout=None,
                  ignore_status=False,
                  stderr_tee=logging_manager.LoggingFile(level=logging.INFO))
Beispiel #4
0
    def run_once(self, video_name, histogram_name, histogram_bucket_val,
                 capability):
        if self.is_skipping_test():
            raise error.TestNAError('Skipping test run on this board.')

        if not device_capability.DeviceCapability().have_capability(
                capability):
            logging.warning("Missing Capability: %s" % capability)
            return

        # Download test video.
        url = DOWNLOAD_BASE + video_name
        local_path = os.path.join(self.bindir, video_name)
        file_utils.download_file(url, local_path)

        # Start chrome with test flags.
        EXTRA_BROWSER_ARGS.append(FAKE_FILE_ARG % local_path)
        EXTRA_BROWSER_ARGS.append(helper_logger.chrome_vmodule_flag())
        with chrome.Chrome(extra_browser_args=EXTRA_BROWSER_ARGS,
                           init_network_controller=True) as cr:
            histogram_differ = histogram_verifier.HistogramDiffer(
                cr, histogram_name)
            # Open WebRTC loopback page.
            cr.browser.platform.SetHTTPServerDirectories(self.bindir)
            self.start_loopback(cr)

            # Make sure decode is hardware accelerated.
            histogram_verifier.expect_sole_bucket(histogram_differ,
                                                  histogram_bucket_val,
                                                  histogram_bucket_val)
    def initialize(self, ppd_file):
        """
        Args:
        @param ppd_file: ppd file name
        """

        # Instantiate Chrome browser.
        with tempfile.NamedTemporaryFile() as cap:
            file_utils.download_file(chrome.CAP_URL, cap.name)
            password = cap.read().rstrip()

        extra_flags = ['--enable-features=CrOSComponent']
        self.browser = chrome.Chrome(gaia_login=False,
                                     username=chrome.CAP_USERNAME,
                                     password=password,
                                     extra_browser_args=extra_flags)
        self.tab = self.browser.browser.tabs[0]

        # Set file path.
        current_dir = os.path.dirname(os.path.realpath(__file__))
        self.pdf_path = os.path.join(current_dir, 'to_print.pdf')
        self.printing_log_path = '/tmp/printing_request.log'

        # Download ppd files
        self.ppd_file = '/tmp/%s' % ppd_file
        file_utils.download_file(
            'https://storage.googleapis.com/chromiumos-test-assets-public'
            '/platform_AddPrinter/%s' % ppd_file, self.ppd_file)

        # Start fake printer.
        printer = FakePrinter()
        self.server_thread = Thread(target=printer.start,
                                    args=(self.printing_log_path, ))
        self.server_thread.start()
    def run_once(self):
        with tempfile.NamedTemporaryFile() as pltp:
            file_utils.download_file(self._PLTP_URL, pltp.name)
            self._password = pltp.read().rstrip()

        with chrome.Chrome(gaia_login=True,
                           username=self._USERNAME,
                           password=self._password) as cr:
            if not cryptohome.is_vault_mounted(user=self._USERNAME):
                raise error.TestFail(
                    'Expected to find a mounted vault for %s' % self._USERNAME)
            tab = cr.browser.tabs.New()
            # TODO(achuith): Use a better signal of being logged in, instead of
            # parsing accounts.google.com.
            tab.Navigate('http://accounts.google.com')
            tab.WaitForDocumentReadyStateToBeComplete()
            res = tab.EvaluateJavaScript('''
                    var res = '',
                        divs = document.getElementsByTagName('div');
                    for (var i = 0; i < divs.length; i++) {
                        res = divs[i].textContent;
                        if (res.search('%s') > 1) {
                            break;
                        }
                    }
                    res;
            ''' % self._USERNAME_DISPLAY)
            if not res:
                raise error.TestFail('No references to %s on accounts page.' %
                                     self._USERNAME_DISPLAY)
            tab.Close()
    def run_once(self, codec, fps, video_file):
        """ Report cpu usage and frame processing time with HW and SW encode.

        Use MediaRecorder to record a videos with HW encode and SW encode, and
        report the frame processing time and CPU usage of both.

        @param codec: a string indicating the codec used to encode video stream,
                ex. 'h264'.
        @param fps: an integer specifying FPS of the fake input video stream.
        @param video_file: a string specifying the name of the video file to be
                used as fake input video stream.
        """
        # Download test video.
        url = DOWNLOAD_BASE + video_file
        local_path = os.path.join(self.bindir, video_file)
        file_utils.download_file(url, local_path)
        fake_file_arg = (FAKE_FILE_ARG % local_path)
        fake_stream_arg = (FAKE_STREAM_ARG % fps)

        processing_time_sw = 0
        processing_time_hw = 0
        cpu_usage_sw = 0
        cpu_usage_hw = 0
        with chrome.Chrome(extra_browser_args=EXTRA_BROWSER_ARGS +
                           [fake_file_arg, fake_stream_arg] +
                           DISABLE_HW_ENCODE_ARGS +
                           [helper_logger.chrome_vmodule_flag()],
                           init_network_controller=True) as cr:
            (processing_time_sw,
             cpu_usage_sw) = self.get_record_performance(cr, codec, False)
            self.output_perf_value(description=(SW_PREFIX +
                                                FRAME_PROCESSING_TIME),
                                   value=processing_time_sw,
                                   units=TIME_UNIT,
                                   higher_is_better=False)
            self.output_perf_value(description=(SW_PREFIX + CPU_USAGE),
                                   value=cpu_usage_sw,
                                   units=PERCENT,
                                   higher_is_better=False)

        with chrome.Chrome(extra_browser_args=EXTRA_BROWSER_ARGS +
                           [fake_file_arg, fake_stream_arg] +
                           [helper_logger.chrome_vmodule_flag()],
                           init_network_controller=True) as cr:
            (processing_time_hw,
             cpu_usage_hw) = self.get_record_performance(cr, codec, True)
            self.output_perf_value(description=(HW_PREFIX +
                                                FRAME_PROCESSING_TIME),
                                   value=processing_time_hw,
                                   units=TIME_UNIT,
                                   higher_is_better=False)
            self.output_perf_value(description=(HW_PREFIX + CPU_USAGE),
                                   value=cpu_usage_hw,
                                   units=PERCENT,
                                   higher_is_better=False)

        log = 'sw processing_time=%f cpu=%d hw processing_time=%f cpu=%d' % (
            processing_time_sw, cpu_usage_sw, processing_time_hw, cpu_usage_hw)
        logging.info(log)
    def _download_video(self, download_path, local_file):
        url = '%s%s' % (DOWNLOAD_BASE, download_path)
        logging.info('download "%s" to "%s"', url, local_file)

        file_utils.download_file(url, local_file)

        with open(local_file, 'r') as r:
            md5sum = hashlib.md5(r.read()).hexdigest()
            if md5sum not in download_path:
                raise error.TestError('unmatched md5 sum: %s' % md5sum)
def _get_content(url):
    """Reads the content of the file at the given |URL|.

    Args:
        url: URL to be fetched.

    Return:
        The content of the fetched file.
    """
    with tempfile.NamedTemporaryFile() as named_file:
        file_utils.download_file(url, named_file.name)
        return named_file.read().rstrip()
    def run_once(self,
                 videos=None,
                 secs_per_video=_MEASUREMENT_DURATION,
                 use_hw_decode=True):
        """run_once method.

        @param videos: list of tuple of tagname and video url to test.
        @param secs_per_video: time in seconds to play video and measure power.
        @param use_hw_decode: if False, disable hw video decoding.
        """
        videos_local = []
        loop = 0

        if not videos:
            videos = self._VIDEOS

        # Download video to ramdisk
        for name, url in videos:
            local_path = os.path.join(self._RAMDISK, os.path.basename(url))
            logging.info('Downloading %s to %s', url, local_path)
            file_utils.download_file(url, local_path)
            videos_local.append((name, local_path))

        extra_browser_args = []
        if not use_hw_decode:
            extra_browser_args.append(self._DISABLE_HW_VIDEO_DECODE_ARGS)

        with chrome.Chrome(extra_browser_args=extra_browser_args,
                           init_network_controller=True) as self.cr:
            self.cr.browser.platform.SetHTTPServerDirectories(self._RAMDISK)
            tab = self.cr.browser.tabs.New()
            tab.Activate()

            # Just measure power in full-screen.
            fullscreen = tab.EvaluateJavaScript('document.webkitIsFullScreen')
            if not fullscreen:
                with keyboard.Keyboard() as keys:
                    keys.press_key('f4')

            time.sleep(self._WAIT_FOR_IDLE)
            self.start_measurements()

            for name, url in videos_local:
                logging.info('Playing video: %s', name)
                self._play_video(self.cr, url)
                tagname = '%s_%s' % (self.tagged_testname, name)
                loop_start = time.time()
                self.loop_sleep(loop, secs_per_video)
                self.keyvals[name + '_dropped_frame_percent'] = \
                        self._calculate_dropped_frame_percent(tab)
                self.checkpoint_measurements(tagname, loop_start)
                loop += 1
Beispiel #11
0
def set_browser_options_for_opt_in(b_options):
    """
    Setup Chrome for gaia login and opt_in.

    @param b_options: browser options object used by chrome.Chrome.

    """
    b_options.username = _USERNAME
    with tempfile.NamedTemporaryFile() as pltp:
        file_utils.download_file(_ARCP_URL, pltp.name)
        b_options.password = pltp.read().rstrip()
    b_options.disable_default_apps = False
    b_options.disable_component_extensions_with_background_pages = False
    b_options.gaia_login = True
Beispiel #12
0
 def run_once(self, test_file, checksum):
     local_path = os.path.join(self.bindir, '%s' % test_file)
     file_utils.download_file(_DOWNLOAD_BASE + test_file, local_path)
     logging.info('Downloaded file: %s. Expected checksum: %s', local_path,
                  checksum)
     with open(local_path, 'r') as r:
         md5sum = hashlib.md5(r.read()).hexdigest()
         if md5sum != checksum:
             raise error.TestError('unmatched md5 sum: %s' % md5sum)
     with chrome.Chrome(init_network_controller=True) as cr:
         cr.browser.platform.SetHTTPServerDirectories(self.bindir)
         url = cr.browser.platform.http_server.UrlOf(local_path)
         self.play_audio(cr.browser.tabs[0], url)
         self.run_power_test(url.split('.')[-1])
Beispiel #13
0
    def _download_extension_crx(self, output_file):
        """Download Cast (Beta) extension from Chrome Web Store to a file.

        @param output_file: The output file of the extension.
        """
        update_check_url = UPDATE_CHECK_URL % EXTENSION_ID_BETA
        response = urllib2.urlopen(update_check_url).read()
        logging.info('Response: %s', response)
        pattern = r'codebase="(.*crx)"'
        regex = re.compile(pattern)
        match = regex.search(response)
        extension_download_url = match.groups()[0]
        logging.info('Extension download link: %s', extension_download_url)
        file_utils.download_file(extension_download_url, output_file)
 def initialize(self):
     self.keyboard = keyboard.Keyboard()
     self.username, password = arc_util.get_test_account_info()
     # Login a user session.
     if utils.is_arc_available():
         super(platform_LogoutPerf,
               self).initialize(gaia_login=True, disable_arc_opt_in=False)
         self.cr = self._chrome
     else:
         with tempfile.NamedTemporaryFile() as cap:
             file_utils.download_file(arc_util._ARCP_URL, cap.name)
             password = cap.read().rstrip()
         self.cr = chrome.Chrome(gaia_login=True,
                                 username=self.username,
                                 password=password)
    def run_once(self, video_name, histogram_name, histogram_bucket_val):
        # Download test video.
        url = DOWNLOAD_BASE + video_name
        local_path = os.path.join(self.bindir, video_name)
        file_utils.download_file(url, local_path)

        # Start chrome with test flags.
        EXTRA_BROWSER_ARGS.append(FAKE_FILE_ARG % local_path)
        with chrome.Chrome(extra_browser_args=EXTRA_BROWSER_ARGS) as cr:
            # Open WebRTC loopback page.
            cr.browser.platform.SetHTTPServerDirectories(self.bindir)
            self.start_loopback(cr)

            # Make sure decode is hardware accelerated.
            histogram_verifier.verify(cr, histogram_name, histogram_bucket_val)
Beispiel #16
0
    def run_once(self):
        # Download test video.
        url = DOWNLOAD_BASE + VIDEO_NAME
        local_path = os.path.join(self.bindir, VIDEO_NAME)
        file_utils.download_file(url, local_path)

        # Start chrome with test flags.
        EXTRA_BROWSER_ARGS.append(FAKE_FILE_ARG % local_path)
        with chrome.Chrome(extra_browser_args=EXTRA_BROWSER_ARGS) as cr:
            # Open WebRTC loopback page.
            cr.browser.platform.SetHTTPServerDirectories(self.bindir)
            self.start_loopback(cr)

            # Make sure decode is hardware accelerated.
            self.assert_hardware_accelerated(cr)
Beispiel #17
0
    def play_and_record(self, recorder_widget):
        """Plays and records audio

        @param recorder_widget: widget to do the recording

        """
        audio_test_utils.dump_cros_audio_logs(
                self.host, self.audio_facade, self.resultsdir,
                'before_playback')

        self.check_correct_audio_node_selected()

        browser_facade = self.factory.create_browser_facade()

        host_file = os.path.join('/tmp',
                os.path.basename(self.test_playback_file))
        with tempfile.NamedTemporaryFile() as tmpfile:
            file_utils.download_file(self.test_playback_file, tmpfile.name)
            os.chmod(tmpfile.name, 0444)
            self.host.send_file(tmpfile.name, host_file)
            logging.debug('Copied the file on the DUT at %s', host_file)

        # Play, wait for some time, and then start recording.
        # This is to avoid artifact caused by codec initialization.
        browser_facade.new_tab('file://' + host_file)
        logging.info('Start playing %s on Cros device', host_file)

        time.sleep(self.SHORT_WAIT)
        logging.debug('Suspend.')
        self.suspend_resume()
        logging.debug('Resume.')
        time.sleep(self.SHORT_WAIT)
        logging.debug('Start recording.')
        recorder_widget.start_recording()

        time.sleep(self.RECORD_SECONDS)

        recorder_widget.stop_recording()
        logging.debug('Stopped recording.')

        audio_test_utils.dump_cros_audio_logs(
                self.host, self.audio_facade, self.resultsdir,
                'after_recording')

        recorder_widget.read_recorded_binary()
    def run_once(self,
                 decode_time_test=False,
                 cpu_test=False,
                 power_test=False,
                 arc_mode=None):
        """
        Runs the video_WebRtcPerf test.

        @param decode_time_test: Pass True to run decode time test.
        @param cpu_test: Pass True to run CPU usage test.
        @param power_test: Pass True to run power consumption test.
        @param arc_mode: if 'enabled', run the test with Android enabled.
        """
        # Download test video.
        url = DOWNLOAD_BASE + VIDEO_NAME
        local_path = os.path.join(self.bindir, VIDEO_NAME)
        file_utils.download_file(url, local_path)
        self.arc_mode = arc_mode

        if decode_time_test:
            keyvals = self.test_decode_time(local_path)
            # The first value is max decode time. The second value is median
            # decode time. Construct a dictionary containing one value to log
            # the result.
            max_decode_time = {
                key: value[0]
                for (key, value) in keyvals.items()
            }
            self.log_result(max_decode_time, MAX_DECODE_TIME_DESCRIPTION,
                            'milliseconds')
            median_decode_time = {
                key: value[1]
                for (key, value) in keyvals.items()
            }
            self.log_result(median_decode_time, MEDIAN_DECODE_TIME_DESCRIPTION,
                            'milliseconds')

        if cpu_test:
            keyvals = self.test_cpu_usage(local_path)
            self.log_result(keyvals, CPU_USAGE_DESCRIPTION, 'percent')

        if power_test:
            keyvals = self.test_power(local_path)
            self.log_result(keyvals, POWER_DESCRIPTION, 'W')
    def run_once(self, video_name, histogram_name, histogram_bucket_val):
        if self.is_skipping_test():
            raise error.TestNAError('Skipping test run on this board.')

        # Download test video.
        url = DOWNLOAD_BASE + video_name
        local_path = os.path.join(self.bindir, video_name)
        file_utils.download_file(url, local_path)

        # Start chrome with test flags.
        EXTRA_BROWSER_ARGS.append(FAKE_FILE_ARG % local_path)
        with chrome.Chrome(extra_browser_args=EXTRA_BROWSER_ARGS,
                           init_network_controller=True) as cr:
            # Open WebRTC loopback page.
            cr.browser.platform.SetHTTPServerDirectories(self.bindir)
            self.start_loopback(cr)

            # Make sure decode is hardware accelerated.
            histogram_verifier.verify(cr, histogram_name, histogram_bucket_val)
Beispiel #20
0
    def _download_single_file(self, remote_path):
        url = DOWNLOAD_BASE + remote_path
        tmp = tempfile.NamedTemporaryFile(delete=False, dir=self._tmpdir)
        logging.info('download "%s" to "%s"', url, tmp.name)

        file_utils.download_file(url, tmp.name)
        md5 = hashlib.md5()
        with open(tmp.name, 'r') as r:
            md5.update(r.read())

        filename = os.path.basename(remote_path)
        m = RE_VERSIONING_FILE.match(filename)
        if m:
            prefix, md5sum, suffix = m.groups()
            if md5.hexdigest() != md5sum:
                raise error.TestError('unmatched md5 sum: %s' %
                                      md5.hexdigest())
            filename = prefix + (suffix or '')
        self._download_map[filename] = tmp.name
Beispiel #21
0
    def run_once(self, video_name, video_description, power_test=False,
                 arc_mode=None):
        """
        Runs the video_PlaybackPerf test.

        @param video_name: the name of video to play in the DOWNLOAD_BASE
        @param video_description: a string describes the video to play which
                will be part of entry name in dashboard.
        @param power_test: True if this is a power test and it would only run
                the power test. If False, it would run the cpu usage test and
                the dropped frame count test.
        @param arc_mode: if 'enabled', run the test with Android enabled.
        """
        # Download test video.
        url = DOWNLOAD_BASE + video_name
        local_path = os.path.join(self.bindir, os.path.basename(video_name))
        logging.info("Downloading %s to %s", url, local_path);
        file_utils.download_file(url, local_path)
        self.arc_mode = arc_mode

        if not power_test:
            # Run the video playback dropped frame tests.
            keyvals = self.test_dropped_frames(local_path)

            # Every dictionary value is a tuple. The first element of the tuple
            # is dropped frames. The second is dropped frames percent.
            keyvals_dropped_frames = {k: v[0] for k, v in keyvals.iteritems()}
            keyvals_dropped_frames_percent = {
                    k: v[1] for k, v in keyvals.iteritems()}

            self.log_result(keyvals_dropped_frames, DROPPED_FRAMES_DESCRIPTION +
                                video_description, 'frames')
            self.log_result(keyvals_dropped_frames_percent,
                            DROPPED_FRAMES_PERCENT_DESCRIPTION +
                                video_description, 'percent')

            # Run the video playback cpu usage tests.
            keyvals = self.test_cpu_usage(local_path)
            self.log_result(keyvals, CPU_USAGE_DESCRIPTION + video_description,
                            'percent')
        else:
            keyvals = self.test_power(local_path)
            self.log_result(keyvals, POWER_DESCRIPTION + video_description, 'W')
    def run_once(self, gtest_filter=None):
        """
        Runs jpeg_encode_accelerator_unittest on the device.

        @param gtest_filter: test case filter.

        @raises: error.TestFail for jpeg_encode_accelerator_unittest failures.
        """
        url = DOWNLOAD_BASE + TEST_IMAGE_PATH
        local_path = os.path.join(self.bindir,
                                  os.path.basename(TEST_IMAGE_PATH))
        file_utils.download_file(url, local_path)

        cmd_line_list = [helper_logger.chrome_vmodule_flag()]
        if gtest_filter:
            cmd_line_list.append('--gtest_filter="%s"' % gtest_filter)

        cmd_line = ' '.join(cmd_line_list)
        self.run_chrome_test_binary(self.binary, cmd_line)
Beispiel #23
0
    def _download_test_video(self):
        """
        Downloads the test video to a temporary directory on host.

        @return the remote path of the downloaded video.
        """
        url = _DOWNLOAD_BASE + _VIDEO_NAME
        local_path = os.path.join(self.tmpdir, _VIDEO_NAME)
        logging.info('Downloading %s to %s', url, local_path)
        file_utils.download_file(url, local_path)
        # The directory returned by get_tmp_dir() is automatically deleted.
        tmp_dir = self._host.get_tmp_dir()
        remote_path = os.path.join(tmp_dir, _VIDEO_NAME)
        # The temporary directory has mode 700 by default. Chrome runs with a
        # different user so cannot access it unless we change the permissions.
        logging.info('chmodding tmpdir %s to 755', tmp_dir)
        self._host.run('chmod 755 %s' % tmp_dir)
        logging.info('Sending %s to %s on DUT', local_path, remote_path)
        self._host.send_file(local_path, remote_path)
        os.remove(local_path)
        return remote_path
Beispiel #24
0
    def initialize(self, ppd_file):
        """
        Args:
        @param ppd_file: ppd file name
        """

        # Set file path.
        current_dir = os.path.dirname(os.path.realpath(__file__))
        self.pdf_path = os.path.join(current_dir, 'to_print.pdf')
        self.printing_log_path = '/tmp/printing_request.log'

        # Download ppd files
        self.ppd_file = '/tmp/%s' % ppd_file
        file_utils.download_file(
            'https://storage.googleapis.com/chromiumos-test-assets-public'
            '/platform_AddPrinter/%s' % ppd_file, self.ppd_file)

        # Start fake printer.
        printer = FakePrinter()
        self.server_thread = Thread(target=printer.start,
                                    args=(self.printing_log_path, ))
        self.server_thread.start()
    def run_once(self, capability, arc_mode=None):
        if not device_capability.DeviceCapability().have_capability(
                capability):
            logging.warning("Missing Capability: %s" % capability)
            return

        # Download test video.
        url = DOWNLOAD_BASE + VIDEO_NAME
        local_path = os.path.join(self.bindir, VIDEO_NAME)
        file_utils.download_file(url, local_path)

        # Start chrome with test flags.
        EXTRA_BROWSER_ARGS.append(FAKE_FILE_ARG % local_path)
        EXTRA_BROWSER_ARGS.append(helper_logger.chrome_vmodule_flag())
        with chrome.Chrome(extra_browser_args=EXTRA_BROWSER_ARGS,
                           arc_mode=arc_mode,
                           init_network_controller=True) as cr:
            # Open WebRTC loopback page.
            cr.browser.platform.SetHTTPServerDirectories(self.bindir)
            self.start_loopback(cr)

            # Make sure decode is hardware accelerated.
            self.assert_hardware_accelerated(cr)
Beispiel #26
0
    def initialize(self):
        # Create a virtual keyboard device for key event playback.
        device_node = input_device.get_device_node(input_device.KEYBOARD_TYPES)
        if not device_node:
            raise error.TestFail('Could not find keyboard device node')
        self.keyboard = input_device.InputDevice(device_node)

        # Instantiate Chrome browser.
        with tempfile.NamedTemporaryFile() as cap:
            file_utils.download_file(chrome.CAP_URL, cap.name)
            password = cap.read().rstrip()

        self.browser = chrome.Chrome(gaia_login=True,
                                     username=chrome.CAP_USERNAME,
                                     password=password)
        self.tab = self.browser.browser.tabs[0]

        # Setup Chrome Tracing.
        config = tracing_config.TracingConfig()
        category_filter = config.chrome_trace_config.category_filter
        category_filter.AddFilterString(_TARGET_TRACING_CATEGORIES)
        config.enable_chrome_trace = True
        self.target_tracing_config = config
def download_and_install_gsutil():
    """Download and install gsutil package."""
    if not os.path.isdir(GSUTIL_PATH):
        print 'Installing %s ...' % GSUTIL

        # Download the gsutil tarball to a temporary directory
        temp_dir = tempfile.mkdtemp()
        gsutil_temp_file = os.path.join(temp_dir, GSUTIL_TAR_NAME)
        print '  Downloading gsutil tarball: "%s".' % GSUTIL_URI
        file_utils.download_file(GSUTIL_URI, gsutil_temp_file)

        # Untar the gsutil tarball
        untar_cmd_str = 'tar xf %s -C %s'
        untar_cmd = untar_cmd_str % (gsutil_temp_file, GSUTIL_INSTALL_DIR)
        print '  Untarring the gsutil tarball.'
        simple_system(untar_cmd)

        # Remove the tarball and the temp directory
        shutil.rmtree(temp_dir)

    # Set the PATH environment variable for gsutil
    PATH = os.environ['PATH']
    os.environ['PATH'] = ':'.join([GSUTIL_PATH, PATH])
Beispiel #28
0
    def run_once(self,
                 source_path,
                 codec,
                 resolution,
                 host,
                 args,
                 collect_only=False):

        board = utils.get_current_board()

        file_utils.make_leaf_dir(constants.TEST_DIR)

        with chrome.Chrome(
                extension_paths=[cros_constants.MULTIMEDIA_TEST_EXTENSION],
                autotest_ext=True) as cr:

            cr.browser.platform.SetHTTPServerDirectories(self.bindir)
            html_fullpath = os.path.join(self.bindir, 'video.html')
            player = native_html5_player.NativeHtml5Player(
                tab=cr.browser.tabs[0],
                full_url=cr.browser.platform.http_server.UrlOf(html_fullpath),
                video_id='video',
                video_src_path=source_path,
                event_timeout=120)

            chameleon_board = chameleon.create_chameleon_board(
                host.hostname, args)
            display_facade = local_facade_factory.LocalFacadeFactory(
                cr).create_display_facade()

            finder = chameleon_port_finder.ChameleonVideoInputFinder(
                chameleon_board, display_facade)

            capturer = chameleon_video_capturer.ChameleonVideoCapturer(
                finder.find_port(interface='hdmi'), display_facade)

            with capturer:
                player.load_video()

                player.verify_video_can_play()

                display_facade.move_to_display(
                    display_facade.get_first_external_display_index())
                display_facade.set_fullscreen(True)
                # HACK: Unset and reset fullscreen. There is a bug in Chrome
                # that fails to move the window to a correct position.
                # Resetting fullscren helps, check http://crbug.com/574284
                display_facade.set_fullscreen(False)
                display_facade.set_fullscreen(True)
                time.sleep(5)

                box = (0, 0, constants.DESIRED_WIDTH, constants.DESIRED_HEIGHT)

                #TODO: mussa, Revisit once crbug/580736 is fixed
                for n in xrange(constants.NUM_CAPTURE_TRIES):
                    logging.debug('Trying to capture frames. TRY #%d', n + 1)
                    raw_test_checksums = capturer.capture_only(
                        player, max_frame_count=constants.FCOUNT, box=box)

                    raw_test_checksums = [
                        tuple(checksum) for checksum in raw_test_checksums
                    ]

                    overreach_counts = self.overreach_frame_counts(
                        raw_test_checksums, constants.MAX_FRAME_REPEAT_COUNT)

                    if not overreach_counts:  # no checksums exceeded threshold
                        break

                    player.pause()
                    player.seek_to(datetime.timedelta(seconds=0))

                else:
                    msg = ('Framecount overreach detected even after %d '
                           'tries. Checksums: %s' %
                           (constants.NUM_CAPTURE_TRIES, overreach_counts))
                    raise error.TestFail(msg)

                # produces unique checksums mapped to their occur. indices
                test_checksum_indices = frame_checksum_utils.checksum_indices(
                    raw_test_checksums)

                test_checksums = test_checksum_indices.keys()

                test_indices = test_checksum_indices.values()

                golden_checksums_filepath = os.path.join(
                    constants.TEST_DIR, constants.GOLDEN_CHECKSUMS_FILENAME)

                if collect_only:
                    capturer.write_images(test_indices, constants.TEST_DIR,
                                          constants.IMAGE_FORMAT)

                    logging.debug("Write golden checksum file to %s",
                                  golden_checksums_filepath)

                    with open(golden_checksums_filepath, "w+") as f:
                        for checksum in test_checksums:
                            f.write(' '.join([str(i)
                                              for i in checksum]) + '\n')
                    return

                golden_checksums_remote_filepath = os.path.join(
                    constants.GOLDEN_CHECKSUM_REMOTE_BASE_DIR, board,
                    codec + '_' + resolution,
                    constants.GOLDEN_CHECKSUMS_FILENAME)

                file_utils.download_file(golden_checksums_remote_filepath,
                                         golden_checksums_filepath)

                golden_checksums = self.read_checksum_file(
                    golden_checksums_filepath)

                golden_checksum_count = len(golden_checksums)
                test_checksum_count = len(test_checksums)

                eps = constants.MAX_DIFF_TOTAL_FCOUNT
                if golden_checksum_count - test_checksum_count > eps:
                    msg = ('Expecting about %d checksums, received %d. '
                           'Allowed delta is %d') % (golden_checksum_count,
                                                     test_checksum_count, eps)
                    raise error.TestFail(msg)

                # Some frames might be missing during either golden frame
                # collection or during a test run. Using LCS ensures we
                # ignore a few missing frames while comparing test vs golden

                lcs_len = sequence_utils.lcs_length(golden_checksums,
                                                    test_checksums)

                missing_frames_count = len(golden_checksums) - lcs_len
                unknown_frames_count = len(test_checksums) - lcs_len

                msg = ('# of matching frames : %d. # of missing frames : %d. '
                       '# of unknown test frames : %d. Max allowed # of '
                       'missing frames : %d. # of golden frames : %d. # of '
                       'test_checksums : %d' %
                       (lcs_len, missing_frames_count,
                        unknown_frames_count, constants.MAX_NONMATCHING_FCOUNT,
                        len(golden_checksums), len(test_checksums)))
                logging.debug(msg)

                if (missing_frames_count + unknown_frames_count >
                        constants.MAX_NONMATCHING_FCOUNT):
                    unknown_frames = set(test_checksums) - set(
                        golden_checksums)

                    store_indices = [
                        test_checksum_indices[c] for c in unknown_frames
                    ]

                    paths = capturer.write_images(store_indices,
                                                  constants.TEST_DIR,
                                                  constants.IMAGE_FORMAT)

                    path_publish = publisher.ImageDiffPublisher(
                        self.resultsdir)
                    path_publish.publish_paths(paths, self.tagged_testname)

                    raise error.TestFail("Too many non-matching frames")
    def run_screenshot_comparison_test(self):
        """
        Template method to run screenshot comparison tests for ui pieces.

        1. Set up test dirs.
        2. Create folder name
        3. Download golden image.
        4. Capture test image.
        5. Compare images locally, if FAIL upload to remote for analysis later.
        6. Clean up test dirs.

        """

        img_comp_conf_path = os.path.join(ui_TestBase.AUTOTEST_CROS_UI_DIR,
                                          ui_TestBase.IMG_COMP_CONF_FILE)

        img_comp_factory = image_comparison_factory.ImageComparisonFactory(
            img_comp_conf_path)

        golden_image_local_dir = os.path.join(ui_TestBase.WORKING_DIR,
                                              'golden_images')

        file_utils.make_leaf_dir(golden_image_local_dir)

        filename = '%s.png' % self.tagged_testname

        golden_image_remote_path = os.path.join(
            ui_TestBase.REMOTE_DIR, 'ui',
            lsbrelease_utils.get_chrome_milestone(), self.folder_name,
            filename)

        golden_image_local_path = os.path.join(golden_image_local_dir,
                                               filename)

        test_image_filepath = os.path.join(ui_TestBase.WORKING_DIR, filename)

        try:
            file_utils.download_file(golden_image_remote_path,
                                     golden_image_local_path)
        except urllib2.HTTPError as e:
            warn = "No screenshot found for {0} on milestone {1}. ".format(
                self.tagged_testname, lsbrelease_utils.get_chrome_milestone())
            warn += e.msg
            raise error.TestWarn(warn)

        self.capture_screenshot(test_image_filepath)

        comparer = img_comp_factory.make_pdiff_comparer()
        comp_res = comparer.compare(golden_image_local_path,
                                    test_image_filepath)

        if comp_res.diff_pixel_count > img_comp_factory.pixel_thres:
            publisher = img_comp_factory.make_imagediff_publisher(
                self.resultsdir)

            # get chrome version
            version_string = utils.system_output(
                constants.CHROME_VERSION_COMMAND, ignore_status=True)
            version_string = utils.parse_chrome_version(version_string)[0]

            # tags for publishing
            tags = {
                'testname': self.tagged_testname,
                'chromeos_version': utils.get_chromeos_release_version(),
                'chrome_version': version_string,
                'board': utils.get_board(),
                'date': datetime.date.today().strftime("%m/%d/%y"),
                'diff_pixels': comp_res.diff_pixel_count
            }

            publisher.publish(golden_image_local_path, test_image_filepath,
                              comp_res.pdiff_image_path, tags)

            raise error.TestFail('Test Failed. Please see image comparison '
                                 'result by opening index.html from the '
                                 'results directory.')

        file_utils.rm_dir_if_exists(ui_TestBase.WORKING_DIR)
    def run_once(self,
                 host,
                 video_hardware_acceleration=True,
                 video_url=DEFAULT_VIDEO_URL,
                 arc=False):
        """Running audio/video synchronization quality measurement

        @param host: A host object representing the DUT.
        @param video_hardware_acceleration: Enables the hardware acceleration
                                            for video decoding.
        @param video_url: The ULR of the test video.
        @param arc: Tests on ARC with an Android Video Player App.
        """
        self.host = host

        factory = remote_facade_factory.RemoteFacadeFactory(
            host, results_dir=self.resultsdir, no_chrome=True)

        chrome_args = {
            'extension_paths':
            [constants.AUDIO_TEST_EXTENSION, constants.DISPLAY_TEST_EXTENSION],
            'extra_browser_args': [],
            'arc_mode':
            arc_common.ARC_MODE_DISABLED,
            'autotest_ext':
            True
        }
        if not video_hardware_acceleration:
            chrome_args['extra_browser_args'].append(
                '--disable-accelerated-video-decode')
        if arc:
            chrome_args['arc_mode'] = arc_common.ARC_MODE_ENABLED
        browser_facade = factory.create_browser_facade()
        browser_facade.start_custom_chrome(chrome_args)
        logging.info("created chrome")
        if arc:
            self.setup_video_app()

        chameleon_board = host.chameleon
        audio_facade = factory.create_audio_facade()
        display_facade = factory.create_display_facade()
        video_facade = factory.create_video_facade()

        audio_port_finder = chameleon_port_finder.ChameleonAudioInputFinder(
            chameleon_board)
        video_port_finder = chameleon_port_finder.ChameleonVideoInputFinder(
            chameleon_board, display_facade)
        audio_port = audio_port_finder.find_port('HDMI')
        video_port = video_port_finder.find_port('HDMI')

        chameleon_board.setup_and_reset(self.outputdir)

        _, ext = os.path.splitext(video_url)
        with tempfile.NamedTemporaryFile(prefix='playback_', suffix=ext) as f:
            # The default permission is 0o600.
            os.chmod(f.name, 0o644)

            file_utils.download_file(video_url, f.name)
            if arc:
                video_facade.prepare_arc_playback(f.name)
            else:
                video_facade.prepare_playback(f.name)

        edid_path = os.path.join(self.bindir,
                                 'test_data/edids/HDMI_DELL_U2410.txt')

        video_port.plug()
        with video_port.use_edid_file(edid_path):
            audio_facade.set_chrome_active_node_type('HDMI', None)
            audio_facade.set_chrome_active_volume(100)
            audio_test_utils.check_audio_nodes(audio_facade, (['HDMI'], None))
            display_facade.set_mirrored(True)
            video_port.start_monitoring_audio_video_capturing_delay()

            time.sleep(self.DELAY_BEFORE_CAPTURING)
            video_port.start_capturing_video((64, 64, 16, 16))
            audio_port.start_capturing_audio()

            time.sleep(self.DELAY_BEFORE_PLAYBACK)
            if arc:
                video_facade.start_arc_playback(blocking_secs=20)
            else:
                video_facade.start_playback(blocking=True)
            time.sleep(self.DELAY_AFTER_PLAYBACK)

            remote_path, _ = audio_port.stop_capturing_audio()
            video_port.stop_capturing_video()
            start_delay = video_port.get_audio_video_capturing_delay()

        local_path = os.path.join(self.resultsdir, 'recorded.raw')
        chameleon_board.host.get_file(remote_path, local_path)

        audio_data = open(local_path).read()
        video_data = video_port.get_captured_checksums()

        logging.info("audio capture %d bytes, %f seconds", len(audio_data),
                     len(audio_data) / float(self.AUDIO_CAPTURE_RATE) / 32)
        logging.info("video capture %d frames, %f seconds", len(video_data),
                     len(video_data) / float(self.VIDEO_CAPTURE_RATE))

        key_audio = self.compute_audio_keypoint(audio_data)
        key_video = self.compute_video_keypoint(video_data)
        # Use the capturing delay to align A/V
        key_video = map(lambda x: x + start_delay, key_video)

        dropped_frame_count = None
        if not arc:
            video_facade.dropped_frame_count()

        prefix = ''
        if arc:
            prefix = 'arc_'
        elif video_hardware_acceleration:
            prefix = 'hw_'
        else:
            prefix = 'sw_'

        self.log_result(prefix, key_audio, key_video, dropped_frame_count)