def run_once(self, codec, capability):
        """
        Tests whether VEA works by verifying histogram after MediaRecorder
        records a video.
        """
        device_capability.DeviceCapability().ensure_capability(capability)

        with chrome.Chrome(
                extra_browser_args=EXTRA_BROWSER_ARGS +\
                [helper_logger.chrome_vmodule_flag()],
                init_network_controller=True) as cr:
            hw_enc_used_differ = histogram_verifier.HistogramDiffer(
                cr, MEDIA_RECORDER_HW_ENC_USED)
            recorder_error_differ = histogram_verifier.HistogramDiffer(
                cr, MEDIA_RECORDER_ERROR)
            cr.browser.platform.SetHTTPServerDirectories(self.bindir)
            self.tab = cr.browser.tabs.New()
            self.tab.Navigate(cr.browser.platform.http_server.UrlOf(
                    os.path.join(self.bindir, 'loopback_mediarecorder.html')))
            self.tab.WaitForDocumentReadyStateToBeComplete()
            self.tab.EvaluateJavaScript(JS_INVOCATION % codec)
            if not self.is_test_completed():
                logging.error('%s did not complete', test_name)
                raise error.TestFail('Failed %s' % test_name)
            histogram_verifier.expect_sole_bucket(
                hw_enc_used_differ, MEDIA_RECORDER_HW_ENC_USED_BUCKET,
                'HW encoder used (1)')

            has_error, diff_error = histogram_verifier.poll_histogram_grow(
                recorder_error_differ)
            if has_error:
                raise error.TestError(
                    'GPU Video Encoder Error. Histogram diff: %r' % diff_error)
Exemplo n.º 2
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 test_init(self):
     """
     Tests __init__().
     """
     differ = histogram_verifier.HistogramDiffer(None, self.HISTOGRAM_NAME,
                                                 begin=False)
     self.assertEqual(self.HISTOGRAM_NAME, differ.histogram_name)
     self.assertDictEqual({}, differ.begin_histogram)
     self.assertDictEqual({}, differ.end_histogram)
    def setUp(self):
        self.histogram_name = 'mock_histogram'
        self.bucket_name = 'mock_bucket'
        self.differ = histogram_verifier.HistogramDiffer(
            None, self.histogram_name, begin=False)
        self.differ.end = mock.Mock()

        self.time_patcher = mock.patch.object(histogram_verifier.utils.Timer,
                                              'sleep')
        # Timeout at the third call of sleep().
        self.sleep_mock = self.time_patcher.start()
        self.sleep_mock.side_effect = [True, True, False]
    def test_histogram_unchange(self):
        """
        Tests HistogramDiffer with histogram unchanged.

        Expects no difference.
        """
        differ = histogram_verifier.HistogramDiffer(None, self.HISTOGRAM_NAME,
                                                    begin=False)
        differ._get_histogram = mock.Mock(
            side_effect = [
                (histogram_verifier.parse_histogram(self.HISTOGRAM_BEGIN),
                 self.HISTOGRAM_BEGIN),
                (histogram_verifier.parse_histogram(self.HISTOGRAM_BEGIN),
                 self.HISTOGRAM_BEGIN)])
        differ.begin()
        self.assertDictEqual({}, differ.end())
    def test_begin_end(self):
        """
        Tests HistogramDiffer's begin() and end().

        Mocks out HistogramDiffer.get_histogram() to simplify test.
        """

        differ = histogram_verifier.HistogramDiffer(None, self.HISTOGRAM_NAME,
                                                    begin=False)
        differ._get_histogram = mock.Mock(
            side_effect = [
                (histogram_verifier.parse_histogram(self.HISTOGRAM_BEGIN),
                 self.HISTOGRAM_BEGIN),
                (histogram_verifier.parse_histogram(self.HISTOGRAM_END),
                 self.HISTOGRAM_END)])
        differ.begin()
        self.assertDictEqual({0: 1}, differ.end())
Exemplo n.º 7
0
    def run_once(self, video_file, video_len, capability):
        """Verify VDA and playback for the video_file.

        @param video_file: test video file.
        @param video_len : test video file length.
        """
        device_capability.DeviceCapability().ensure_capability(capability)

        with chrome.Chrome(
                extra_browser_args=helper_logger.chrome_vmodule_flag(),
                init_network_controller=True) as cr:
            init_status_differ = histogram_verifier.HistogramDiffer(
                cr, constants.MEDIA_GVD_INIT_STATUS)
            shutil.copy2(constants.VIDEO_HTML_FILEPATH, self.bindir)
            cr.browser.platform.SetHTTPServerDirectories(self.bindir)
            tab1 = cr.browser.tabs[0]
            html_fullpath = os.path.join(self.bindir, 'video.html')
            url = cr.browser.platform.http_server.UrlOf(html_fullpath)
            logging.info("full url is %s", url)
            player = native_html5_player.NativeHtml5Player(
                tab1,
                full_url=url,
                video_id='video',
                video_src_path=video_file,
                event_timeout=120)
            player.load_video()
            player.play()

            # Verify the video playback.
            for i in range(1, video_len / 2):
                if (player.paused() or player.ended()):
                    raise error.TestError('Video either stopped or ended.')
                time.sleep(1)

            # Verify that video ends successfully.
            utils.poll_for_condition(
                lambda: player.ended(),
                timeout=video_len,
                exception=error.TestError('Video did not end successfully'),
                sleep_interval=1)

            # Make sure decode is hardware accelerated.
            histogram_verifier.expect_sole_bucket(init_status_differ,
                                                  constants.MEDIA_GVD_BUCKET,
                                                  'OK (0)')
    def get_record_performance(self, cr, codec, is_hw_encode):
        histogram_differ = histogram_verifier.HistogramDiffer(
            cr, constants.MEDIA_RECORDER_VEA_USED_HISTOGRAM)
        self.wait_for_idle_cpu()
        cr.browser.platform.SetHTTPServerDirectories(self.bindir)
        self.tab = cr.browser.tabs.New()
        self.tab.Navigate(
            cr.browser.platform.http_server.UrlOf(
                os.path.join(self.bindir, LOOPBACK_PAGE)))
        self.tab.WaitForDocumentReadyStateToBeComplete()
        self.tab.EvaluateJavaScript(JS_INVOCATION % codec)
        cpu_usage = self.compute_cpu_usage()
        if not self.video_record_completed():
            raise error.TestFail('Video record did not complete')

        histogram_verifier.expect_sole_bucket(
            histogram_differ, constants.MEDIA_RECORDER_VEA_USED_BUCKET
            if is_hw_encode else constants.MEDIA_RECORDER_VEA_NOT_USED_BUCKET,
            'VEA used (1)' if is_hw_encode else 'VEA not used (0)')

        video_buffer = self.tab.EvaluateJavaScript(JS_VIDEO_BUFFER)
        elapsed_time = self.tab.EvaluateJavaScript(ELAPSED_TIME)
        video_buffer_size = self.tab.EvaluateJavaScript(JS_VIDEO_BUFFER_SIZE)
        video_buffer = video_buffer.encode('ascii', 'ignore')
        if video_buffer_size != len(video_buffer):
            raise error.TestFail('Video buffer from JS is truncated: Was %d.\
                    Got %d' % (video_buffer_size, len(video_buffer)))

        import mkvparse
        video_byte_array = bytearray(base64.b64decode(video_buffer))
        mkv_listener = self.get_mkv_result_listener()
        with tempfile.TemporaryFile() as video_file:
            video_file.write(video_byte_array)
            video_file.seek(0)
            mkvparse.mkvparse(video_file, mkv_listener)
            logging.info('(%s) Number of frames: %d time: %d',
                         'hw' if is_hw_encode else 'sw',
                         mkv_listener.get_num_frames(), elapsed_time)
        return (elapsed_time / mkv_listener.get_num_frames(), cpu_usage)
    def run_once(self, codec, is_mse, video_file, capability, arc_mode=None):
        """
        Tests whether VDA works by verifying histogram for the loaded video.

        @param is_mse: bool, True if the content uses MSE, False otherwise.
        @param video_file: Sample video file to be loaded in Chrome.
        @param capability: Capability required for executing this test.
        """
        if self.is_skipping_test(codec):
            raise error.TestNAError('Skipping test run on this board.')

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

        with chrome.Chrome(
                extra_browser_args=helper_logger.chrome_vmodule_flag(),
                arc_mode=arc_mode,
                init_network_controller=True) as cr:
            init_status_differ = histogram_verifier.HistogramDiffer(
                cr, constants.MEDIA_GVD_INIT_STATUS)
            error_differ = histogram_verifier.HistogramDiffer(
                cr, constants.MEDIA_GVD_ERROR)

            # This will execute for MSE video by accesing shaka player
            if is_mse:
                tab1 = cr.browser.tabs.New()
                tab1.Navigate(video_file)
                tab1.WaitForDocumentReadyStateToBeComplete()
                # Running the test longer to check errors and longer playback
                # for MSE videos.
                time.sleep(30)
            else:
                #This execute for normal video for downloading html file
                shutil.copy2(constants.VIDEO_HTML_FILEPATH, self.bindir)
                video_path = os.path.join(constants.CROS_VIDEO_DIR, 'files',
                                          video_file)
                shutil.copy2(video_path, self.bindir)

                cr.browser.platform.SetHTTPServerDirectories(self.bindir)
                tab = cr.browser.tabs.New()
                html_fullpath = os.path.join(self.bindir, 'video.html')
                url = cr.browser.platform.http_server.UrlOf(html_fullpath)

                player = native_html5_player.NativeHtml5Player(
                    tab,
                    full_url=url,
                    video_id='video',
                    video_src_path=video_file,
                    event_timeout=120)
                player.load_video()
                player.play()
                # Waits until the video ends or an error happens.
                player.wait_ended_or_error()

            # Wait for histogram updated for the test video.
            histogram_verifier.expect_sole_bucket(init_status_differ,
                                                  constants.MEDIA_GVD_BUCKET,
                                                  'OK (0)')

            # Check if there's GPU Video Error for a period of time.
            has_error, diff_error = histogram_verifier.poll_histogram_grow(
                error_differ)
            if has_error:
                raise error.TestError(
                    'GPU Video Decoder Error. Histogram diff: %r' % diff_error)

            # Verify the video ends successully for normal videos.
            if not is_mse and player.check_error():
                raise error.TestError('player did not end successully '\
                                      '(HTML5 Player Error %s: %s)'
                                      % player.get_error_info())