def run_once(self, test_cases, required_cap):
        """
        Tests ChromeOS video hardware encoder performance.
        """
        last_error = None
        device_capability.DeviceCapability().ensure_capability(required_cap)
        for (path, on_cloud, width, height, requested_bit_rate, profile,
             requested_frame_rate) in test_cases:
            try:
                test_name, output_name = self._convert_test_name(
                    path, on_cloud, profile)
                if on_cloud:
                    input_path = os.path.join(self.tmpdir,
                                              os.path.basename(path))
                    self._download_video(path, input_path)
                else:
                    input_path = os.path.join(self.cr_source_dir, path)
                output_path = os.path.join(self.tmpdir, output_name)
                test_stream_data = '%s:%s:%s:%s:%s:%s:%s' % (
                    input_path, width, height, profile, output_path,
                    requested_bit_rate, requested_frame_rate)
                self._run_test_case(test_name, test_stream_data)
            except Exception as last_error:
                # Log the error and continue to the next test case.
                logging.exception(last_error)
            finally:
                if on_cloud:
                    _remove_if_exists(input_path)
                _remove_if_exists(output_path)

        if last_error:
            raise last_error
Esempio 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)
Esempio n. 3
0
    def run_once(self, test_cases, capability):
        """
        Runs JpegEncodeAcceleratorTest.SimpleEncode on the device and reports
        latency values for HW and SW.

        @param capability: Capability required for executing this test.
        """
        device_capability.DeviceCapability().ensure_capability(capability)

        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, 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)
    def run_once(self, test_cases):
        self._perf_keyvals = {}
        video_path = None
        last_error = None
        dc = device_capability.DeviceCapability()
        for (path, width, height, frame_num, frag_num, profile,
             fps, required_cap)  in test_cases:
            try:
                name = self._get_test_case_name(path)
                if not dc.have_capability(required_cap):
                    logging.info("%s is unavailable. Skip %s",
                                 required_cap, name)
                    continue
                video_path = os.path.join(self.bindir, '%s.download' % name)
                test_video_data = '%s:%s:%s:%s:%s:%s:%s:%s' % (video_path,
                    width, height, frame_num, frag_num, 0, 0, profile)
                self._download_video(path, video_path)
                self._run_test_case(name, test_video_data, frame_num, fps)
            except Exception as last_error:
                # log the error and continue to the next test case.
                logging.exception(last_error)
            finally:
                _remove_if_exists(video_path)

        self.write_perf_keyval(self._perf_keyvals)

        if last_error:
            raise # the last error
    def run_once(self):
        logging.debug('Starting video_VideoCapability')
        dc = device_capability.DeviceCapability()
        dc_results = {}
        for cap in dc.get_managed_caps():
            ret = dc.get_capability(cap)
            dc_results[cap] = ret

        self.compare_avtest_label_detect(dc_results)
Esempio n. 7
0
 def run_once(self, test_cases, capability):
     device_capability.DeviceCapability().ensure_capability(capability)
     for (path, width, height, frame_num, frag_num, profile) in test_cases:
         video_path = os.path.join(self.bindir, 'video.download')
         test_video_data = '%s:%d:%d:%d:%d:%d:%d:%d' % (
             video_path, width, height, frame_num, frag_num, 0, 0, profile)
         try:
             self._download_video(path, video_path)
             self._run_test_case(test_video_data)
         finally:
             self._remove_if_exists(video_path)
    def run_once(self, capability, save_images=False):
        device_capability.DeviceCapability().ensure_capability(capability)
        # open the camera via opencv
        cam_name, cam_index = camera_utils.find_camera()
        if cam_index is None:
            raise error.TestError('no camera found')
        cam = cv2.VideoCapture(cam_index)

        # kick off async suspend
        logging.info('starting subprocess to suspend system')
        pool = multiprocessing.Pool(processes=1)
        # TODO(spang): Move async suspend to library.
        result = pool.apply_async(async_suspend)

        # capture images concurrently with suspend
        capture_start = time.time()
        logging.info('start capturing at %d', capture_start)
        image_count = 0
        resume_count = None
        last_image = None

        while True:
            # terminate if we've captured a few frames after resume
            if result.ready() and resume_count is None:
                result.get() # reraise exception, if any
                resume_count = image_count
                logging.info('suspend task finished')
            if resume_count is not None and image_count - resume_count >= 10:
                break

            # capture one frame
            image_ok, image = cam.read()
            image_count += 1
            if not image_ok:
                logging.error('failed capture at image %d', image_count)
                raise error.TestFail('image capture failed from %s', cam_name)

            # write image to disk, if requested
            if save_images and image_count <= 200:
                path = os.path.join(self.outputdir, '%03d.jpg' % image_count)
                cv2.imwrite(path, image)

            # verify camera produces a unique image on each capture
            if last_image is not None and numpy.array_equal(image, last_image):
                raise error.TestFail('camera produced two identical images')
            last_image = image

        capture_end = time.time()
        logging.info('done capturing at %d', capture_end)

        logging.info('captured %d frames in %d seconds',
                     image_count, capture_end - capture_start)
    def run_once(self, capability):
        """
        Runs jpeg_decode_accelerator_unittest on the device.

        @param capability: Capability required for executing this test.
        @param gtest_filter: test case filter.

        @raises: error.TestFail for jpeg_decode_accelerator_unittest failures.
        """
        device_capability.DeviceCapability().ensure_capability(capability)
        logging.debug('Starting video_JpegDecodeAccelerator')

        cmd_line = helper_logger.chrome_vmodule_flag()
        self.run_chrome_test_binary(self.binary, cmd_line)
Esempio n. 10
0
    def run_once(self,
                 videos,
                 capability,
                 import_mode=False,
                 use_cr_source_dir=True):
        """
        Runs video_decode_accelerator_unittest on the videos.

        @param videos: The test videos for video_decode_accelerator_unittest.
        @param use_cr_source_dir:  Videos are under chrome source directory.
        @param gtest_filter: test case filter.

        @raises: error.TestFail for video_decode_accelerator_unittest failures.
        """
        device_capability.DeviceCapability().ensure_capability(capability)
        logging.debug('Starting video_VideoDecodeAccelerator: %s', videos)

        if use_cr_source_dir:
            path = os.path.join(self.cr_source_dir, 'media', 'test', 'data',
                                '')
        else:
            path = ''

        last_test_failure = None
        for video in videos:
            cmd_line_list = ['--test_video_data="%s%s"' % (path, video)]

            # While thumbnail test fails, write thumbnail image to results
            # directory so that it will be accessible to host and packed
            # along with test logs.
            cmd_line_list.append('--thumbnail_output_dir="%s"' %
                                 self.resultsdir)
            cmd_line_list.append(helper_logger.chrome_vmodule_flag())
            cmd_line_list.append('--ozone-platform=gbm')

            if import_mode:
                cmd_line_list.append('--test_import')
                cmd_line_list.append('--frame_validator=check')

            cmd_line = ' '.join(cmd_line_list)
            try:
                self.run_chrome_test_binary(self.binary, cmd_line)
            except error.TestFail as test_failure:
                # Continue to run the remaining test videos and raise
                # the last failure after finishing all videos.
                logging.error('%s: %s', video, test_failure.message)
                last_test_failure = test_failure

        if last_test_failure:
            raise last_test_failure
Esempio n. 11
0
    def run_once(self, capability, power_test=False):
        """
        Runs the video_JDAPerf test.

        @param capability: Capability required for executing this test.
        @param power_test: True for power consumption test.
                           False for cpu usage test.
        """
        device_capability.DeviceCapability().ensure_capability(capability)

        if power_test:
            keyvals = self.test_power()
            self.log_result(keyvals, 'jpeg_decode_energy', 'W')
        else:
            keyvals = self.test_cpu_usage()
            self.log_result(keyvals, 'jpeg_decode_cpu', 'percent')
Esempio n. 12
0
    def run_once(self, codec, is_switchres, video, capability):
        """Tests whether video seek works by random seeks forward and backward.

        @param codec: the codec to be tested, ex. 'vp8', 'vp9', 'h264'.
        @param is_switchres: bool, True if using switch resolution video.
        @param video: Sample video file to be seeked in Chrome.
        @param capability: The capability required for executing the test.
        """
        if self.is_skipping_test(codec, is_switchres):
            logging.info('Skipping test run on this board.')
            return  # return immediately to pass this test

        device_capability.DeviceCapability().ensure_capability(capability)

        with chrome.Chrome(
                extra_browser_args=helper_logger.chrome_vmodule_flag(),
                init_network_controller=True) as cr:
            cr.browser.platform.SetHTTPServerDirectories(self.bindir)
            tab = cr.browser.tabs[0]
            tab.Navigate(
                cr.browser.platform.http_server.UrlOf(
                    os.path.join(self.bindir, 'video.html')))
            tab.WaitForDocumentReadyStateToBeComplete()

            tab.EvaluateJavaScript('loadSourceAndRunSeekTest("%s")' % video)

            def get_seek_test_status():
                seek_test_status = tab.EvaluateJavaScript(
                    'getSeekTestStatus()')
                logging.info('Seeking: %s', seek_test_status)
                return seek_test_status

            # Wait until we get the 'pass' status, meaning the test has been
            # successful. Also timeout and fail the test if we stay on the same
            # seek for more than WAIT_TIMEOUT_S.
            cur_status = get_seek_test_status()
            while True:
                utils.poll_for_condition(
                    lambda: get_seek_test_status() != cur_status,
                    exception=error.TestError(
                        'Seek test is stuck and timeout'),
                    timeout=WAIT_TIMEOUT_S,
                    sleep_interval=1)
                cur_status = get_seek_test_status()
                if cur_status == 'pass': break
Esempio n. 13
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 run_once(self, capability):
        """Runs the test.

        @param capability: Capability required for executing this test.
        """
        device_capability.DeviceCapability().ensure_capability(capability)

        self.board = utils.get_current_board()
        with chrome.Chrome(extra_browser_args=EXTRA_BROWSER_ARGS +\
                           [helper_logger.chrome_vmodule_flag()],
                           init_network_controller=True) as cr:

            # TODO(keiichiw): vivid should be loaded in self.setup() after
            # crbug.com/871185 is fixed
            if utils.is_virtual_machine():
                try:
                    utils.run('sudo modprobe vivid n_devs=1 node_types=0x1')
                except Exception as e:
                    raise error.TestFail('Failed to load vivid', e)

            self.start_getusermedia(cr)
            self.print_perf_results()
    def run_once(self, video_codec, capability):
        """Runs the video_WebRtcPeerConnectionWithCamera test.

        @param video_codec: video codec to use.
        @param capability: Capability required for executing this test.
        """
        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:

            # TODO(keiichiw): vivid should be loaded in self.setup() after
            # crbug.com/871185 is fixed
            if utils.is_virtual_machine():
                try:
                    utils.run('sudo modprobe vivid n_devs=1 node_types=0x1')
                except Exception as e:
                    raise error.TestFail('Failed to load vivid', e)

            self.start_loopback(cr, video_codec)
            self.wait_test_completed(TIMEOUT)
            self.print_loopback_result(video_codec)
    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)
    def run_once(self,
                 resources,
                 decode_videos,
                 encode_videos,
                 measurement,
                 capabilities,
                 decode_threads=1,
                 encode_threads=1):
        dc = device_capability.DeviceCapability()
        for cap in capabilities:
            dc.ensure_capability(cap)

        self._downloads = DownloadManager(tmpdir=self.tmpdir)
        try:
            self._downloads.download_all(resources)
            if measurement == 'cpu':
                with CpuUsageMeasurer() as measurer:
                    value = self.simulate_hangout(decode_videos, encode_videos,
                                                  measurer, decode_threads,
                                                  encode_threads)
                    self.output_perf_value(description='cpu_usage',
                                           value=value * 100,
                                           units=UNIT_PERCENT,
                                           higher_is_better=False)
            elif measurement == 'power':
                with PowerMeasurer() as measurer:
                    value = self.simulate_hangout(decode_videos, encode_videos,
                                                  measurer, decode_threads,
                                                  encode_threads)
                    self.output_perf_value(description='power_usage',
                                           value=value,
                                           units=UNIT_WATT,
                                           higher_is_better=False)
            else:
                raise error.TestError('Unknown measurement: ' + measurement)
        finally:
            self._downloads.clear()
Esempio n. 18
0
def has_builtin_usb_camera():
    """Check if there is a built-in USB camera by capability."""
    return device_capability.DeviceCapability().have_capability('usb_camera')
    def run_once(self, in_cloud, streams, profile, capability):
        """Runs video_encode_accelerator_unittest on the streams.

        @param in_cloud: Input file needs to be downloaded first.
        @param streams: The test streams for video_encode_accelerator_unittest.
        @param profile: The profile to encode into.

        @raises error.TestFail for video_encode_accelerator_unittest failures.
        """
        device_capability.DeviceCapability().ensure_capability(capability)

        last_test_failure = None
        for (path, width, height, bit_rate, frame_rate, subsequent_bit_rate,
             subsequent_frame_rate, pixel_format) in streams:
            # Skip the bitrate test if the board cannot switch bitrate.
            if subsequent_bit_rate is not None and not _can_switch_bitrate():
                logging.info('Skip the bitrate switch test: %s => %s',
                             bit_rate, subsequent_bit_rate)
                continue

            if pixel_format == PIXEL_FORMAT_NV12 and not _can_encode_nv12():
                logging.info('Skip the NV12 input buffer case.')
                continue

            # Set the default value for None.
            frame_rate = frame_rate or DEFAULT_FRAME_RATE
            subsequent_bit_rate = (subsequent_bit_rate or bit_rate *
                                   DEFAULT_SUBSEQUENT_BIT_RATE_RATIO)
            subsequent_frame_rate = subsequent_frame_rate or DEFAULT_FRAME_RATE

            if in_cloud:
                input_path = os.path.join(self.tmpdir, path.split('/')[-1])
                _download_video(path, input_path)
            else:
                input_path = os.path.join(self.cr_source_dir, path)

            output_path = os.path.join(self.tmpdir,
                                       '%s.out' % input_path.split('/')[-1])

            test_stream_list = map(str, [
                input_path, width, height, profile, output_path, bit_rate,
                frame_rate, subsequent_bit_rate, subsequent_frame_rate,
                pixel_format
            ])
            cmd_line_list = [
                '--test_stream_data="%s"' % ':'.join(test_stream_list),
                '--ozone-platform=gbm',
                helper_logger.chrome_vmodule_flag()
            ]

            # Command line |gtest_filter| can override get_filter_option().
            predefined_filter = self.get_filter_option(profile,
                                                       (width, height))
            if predefined_filter:
                cmd_line_list.append('--gtest_filter="%s"' % predefined_filter)

            cmd_line = ' '.join(cmd_line_list)
            logging.debug('Executing with argument: %s', cmd_line)
            try:
                self.run_chrome_test_binary(BINARY, cmd_line, as_chronos=False)
            except error.TestFail as test_failure:
                # Continue to run the remaining test streams and raise
                # the last failure after finishing all streams.
                logging.exception('error while encoding %s', input_path)
                last_test_failure = test_failure
            finally:
                # Remove the downloaded video
                if in_cloud:
                    _remove_if_exists(input_path)
                _remove_if_exists(output_path)

        if last_test_failure:
            raise last_test_failure
    def run_once(self, codec, fps, video_file, capability):
        """ 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.
        @param capability: The capability required for running this test.
        """
        device_capability.DeviceCapability().ensure_capability(capability)

        # 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 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())
Esempio n. 22
0
    def run_once(self,
                 cmd_timeout=600,
                 camera_hals=None,
                 options=None,
                 capability=None,
                 test_config=None):
        """
        Entry point of this test.

        @param cmd_timeout: Seconds. Timeout for running the test command.
        @param camera_hals: The camera HALs to be tested. e.g. ['usb.so']
        @param options: Option strings passed to test command. e.g. ['--v=1']
        @param capability: Capability required for executing this test.
        """
        if options is None:
            options = []

        if test_config is None:
            test_config = {}

        if capability:
            device_capability.DeviceCapability().ensure_capability(capability)

        self.job.install_pkg(self.dep, 'dep', self.dep_dir)

        camera_hal_paths = camera_utils.get_camera_hal_paths_for_test()
        if camera_hals is not None:
            name_map = dict(
                (os.path.basename(path), path) for path in camera_hal_paths)
            camera_hal_paths = []
            for name in camera_hals:
                path = name_map.get(name)
                if path is None:
                    msg = 'HAL %r is not available for test' % name
                    raise error.TestNAError(msg)
                camera_hal_paths.append(path)

        binary_path = os.path.join(self.dep_dir, 'bin', self.test_binary)

        with service_stopper.ServiceStopper([self.cros_camera_service]), \
                self.set_test_config(test_config):
            has_facing_option = False
            cmd = [binary_path]
            for option in options:
                if 'gtest_filter' in option:
                    filters = option.split('=')[1]
                    if 'Camera3DeviceTest' in filters.split('-')[0]:
                        if utils.get_current_board() in self.tablet_board_list:
                            option += (':' if '-' in filters else '-')
                            option += '*SensorOrientationTest/*'
                    if any(name in filters.split('-')[0]
                           for name in ('Camera3ModuleFixture',
                                        'Camera3RecordingFixture')):
                        cmd.append(self.get_recording_params())
                elif 'camera_facing' in option:
                    has_facing_option = True
                cmd.append(option)

            if has_facing_option:
                utils.system(cmd, timeout=cmd_timeout)
            else:
                for camera_hal_path in camera_hal_paths:
                    logging.info('Run test with %r', camera_hal_path)
                    cmd.append('--camera_hal_path=%s' % camera_hal_path)
                    utils.system(cmd, timeout=cmd_timeout)
                    cmd.pop()