예제 #1
0
    def run_once(self, codec):
        """
        Tests whether VEA works by verifying histogram after MediaRecorder
        records a video.
        """
        with chrome.Chrome(
                extra_browser_args=EXTRA_BROWSER_ARGS +\
                [helper_logger.chrome_vmodule_flag()],
                init_network_controller=True) as cr:
            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)

            # Waits for histogram updated for the test video.
            histogram_verifier.verify(cr, MEDIA_RECORDER_HW_ENC_USED,
                                      MEDIA_RECORDER_HW_ENC_USED_BUCKET)

            # Verify no GPU error happens.
            if histogram_verifier.is_histogram_present(cr,
                                                       MEDIA_RECORDER_ERROR):
                logging.info(
                    histogram_verifier.get_histogram(cr, MEDIA_RECORDER_ERROR))
                raise error.TestError('GPU Video Encoder Error.')
 def run_once(self):
     """Run the test code."""
     # TODO: When we've cloned the sonic test repo get these from their
     # test config files.
     logging.info('Starting sonic client test.')
     kwargs = {
         'extension_paths': [self._extension_dir],
         'is_component': True,
         'extra_chrome_flags': [self._settings['extra_flags']],
     }
     with chromedriver.chromedriver(**kwargs) as chromedriver_instance:
         driver = chromedriver_instance.driver
         extension = chromedriver_instance.get_extension(
             self._extension_dir)
         extension_id = extension.extension_id
         time.sleep(self.wait_time)
         self._test_utils.close_popup_tabs(driver)
         self._test_utils.block_setup_dialog(driver, extension_id)
         test_info = self._get_run_information(driver, self._settings)
         logging.info('Starting tabcast to extension: %s', extension_id)
         self._test_utils.set_mirroring_options(driver, extension_id,
                                                self._settings)
         current_tab_handle = driver.current_window_handle
         self._test_utils.start_v2_mirroring_test_utils(
             driver, extension_id, self._sonic_hostname,
             self._settings['video_site'],
             self._settings['full_screen'] == 'on')
         self._test_utils.set_focus_tab(driver, current_tab_handle)
         driver.switch_to_window(current_tab_handle)
         cpu_usage = self._test_utils.cpu_usage_interval(
             int(self._settings['mirror_duration']))
         self._test_utils.stop_v2_mirroring_test_utils(driver, extension_id)
         crash_id = self._test_utils.upload_v2_mirroring_logs(
             driver, extension_id)
         test_info['crash_id'] = crash_id
         if self._settings.get('sender_root_dir'):
             cpu_bound = self._test_utils.compute_cpu_utilization(cpu_usage)
             info_json_file = os.path.join(
                 self._settings['sender_root_dir'], 'test_information.json')
             cpu_json_file = os.path.join(self._settings['sender_root_dir'],
                                          'cpu_data.json')
             cpu_bound_json_file = os.path.join(
                 self._settings['sender_root_dir'], 'cpu_bound.json')
             json.dump(test_info, open(info_json_file, 'wb'))
             json.dump(cpu_usage, open(cpu_json_file, 'wb'))
             json.dump(cpu_bound, open(cpu_bound_json_file, 'wb'))
         time.sleep(self.wait_time)
         #To cehck encoder acceleration used while casting
         histogram_verifier.verify(chromedriver_instance.chrome_instance,
                                   MEDIA_GVD_INIT_STATUS, MEDIA_GVD_BUCKET)
    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)
예제 #4
0
    def run_once(self, codec, is_mse, video_file, 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.

        """
        if self.is_skipping_test(codec):
            raise error.TestNAError('Skipping test run on this board.')

        with chrome.Chrome(arc_mode=arc_mode,
                           init_network_controller=True) as cr:
            # 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 for histogram updated for the test video.
            histogram_verifier.verify(cr, constants.MEDIA_GVD_INIT_STATUS,
                                      constants.MEDIA_GVD_BUCKET)
    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)
예제 #6
0
    def run_once(self, video_file, video_len):
        """Verify VDA and playback for the video_file.

        @param video_file: test video file.
        @param video_len : test video file length.
        """

        with chrome.Chrome(
                extra_browser_args=helper_logger.chrome_vmodule_flag(),
                init_network_controller=True) as cr:
            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.verify(
                    cr,
                    constants.MEDIA_GVD_INIT_STATUS,
                    constants.MEDIA_GVD_BUCKET)
    def get_record_performance(self, cr, codec, is_hw_encode):
        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.verify(
            cr, constants.MEDIA_RECORDER_VEA_USED_HISTOGRAM,
            constants.MEDIA_RECORDER_VEA_USED_BUCKET
            if is_hw_encode else constants.MEDIA_RECORDER_VEA_NOT_USED_BUCKET)
        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)
예제 #8
0
    def run_once(self, codec, is_mse, video_file, 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.

        """
        if self.is_skipping_test(codec):
            raise error.TestNAError('Skipping test run on this board.')

        with chrome.Chrome(
                extra_browser_args=helper_logger.chrome_vmodule_flag(),
                arc_mode=arc_mode,
                init_network_controller=True) as cr:
            # 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()

            # Waits for histogram updated for the test video.
            histogram_verifier.verify(
                 cr,
                 constants.MEDIA_GVD_INIT_STATUS,
                 constants.MEDIA_GVD_BUCKET)

            # Verify no GPU error happens.
            if histogram_verifier.is_histogram_present(
                    cr,
                    constants.MEDIA_GVD_ERROR):
                logging.info(histogram_verifier.get_histogram(
                             cr, constants.MEDIA_GVD_ERROR))
                raise error.TestError('GPU Video Decoder 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())