Exemplo n.º 1
0
def get_content_protection(output_name):
    """
    Gets the state of the content protection.

    @param output_name: The output name as a string.
    @return: A string of the state, like 'Undesired', 'Desired', or 'Enabled'.
             False if not supported.

    """
    if utils.is_freon():
        raise error.TestFail('freon: get_content_protection not implemented')

    output = call_xrandr('--verbose').split('\n')
    current_output_name = ''

    # Parse output of xrandr, line by line.
    for line in output:
        # If the line contains 'connected', it is a connected display.
        if line.find(' connected') != -1:
            current_output_name = line.split()[0]
            continue
        if current_output_name != output_name:
            continue
        # Search the line like: 'Content Protection:     Undesired'
        match = re.search(r'Content Protection:\t(\w+)', line)
        if match:
            return match.group(1)

    return False
Exemplo n.º 2
0
    def run_once(self, videos, 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: gtest_filter parameter for the unittest.

        @raises: error.TestFail for video_decode_accelerator_unittest failures.
        """
        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 = ('--test_video_data="%s%s"' % (path, video))

            if utils.is_freon():
                cmd_line += ' --ozone-platform=gbm'

            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
Exemplo n.º 3
0
def hide_typing_cursor():
    """Hides typing cursor."""
    # Press the tab key to move outside the typing bar.
    if utils.is_freon():
        press_keys(['KEY_TAB'])
    else:
        press_key_X('Tab')
    def run_chrome_test_binary(self, binary_to_run, extra_params='', prefix='',
                               as_chronos=True):
        """
        Run chrome test binary.

        @param binary_to_run: The name of the browser test binary.
        @param extra_params: Arguments for the browser test binary.
        @param prefix: Prefix to the command that invokes the test binary.
        @param as_chronos: Boolean indicating if the tests should run in a
            chronos shell.

        @raises: error.TestFail if there is error running the command.
        """
        binary = self.get_chrome_binary_path(binary_to_run)
        cmd = '%s/%s %s' % (self.test_binary_dir, binary_to_run, extra_params)
        env_vars = 'HOME=%s CR_SOURCE_ROOT=%s CHROME_DEVEL_SANDBOX=%s' % (
                self.home_dir, self.cr_source_dir, self.CHROME_SANDBOX)
        cmd = '%s %s' % (env_vars, prefix + cmd)

        try:
            if utils.is_freon():
                if as_chronos:
                    utils.system('su %s -c \'%s\'' % ('chronos', cmd))
                else:
                    utils.system(cmd)
            else:
                if as_chronos:
                    graphics_utils.xsystem(cmd, user='******')
                else:
                    graphics_utils.xsystem(cmd)
        except error.CmdError as e:
            raise error.TestFail('%s failed! %s' % (binary_to_run, e))
Exemplo n.º 5
0
def hide_cursor():
    """Hides mouse cursor."""
    # Send a keystroke to hide the cursor.
    if utils.is_freon():
        press_keys(['KEY_UP'])
    else:
        press_key_X('Up')
Exemplo n.º 6
0
def screen_disable_blanking():
    """ Called from power_Backlight to disable screen blanking. """
    if utils.is_freon():
        # We don't have to worry about unexpected screensavers or DPMS here.
        return
    xsystem(XSET + ' s off')
    xsystem(XSET + ' dpms 0 0 0')
    xsystem(XSET + ' -dpms')
Exemplo n.º 7
0
def press_key_X(key_str):
    """Presses the given keys as one combination.
    @param key: A string of keys, e.g. 'ctrl+F4'.
    """
    if utils.is_freon():
        raise error.TestFail('freon: press_key_X not implemented')
    command = 'xdotool key %s' % key_str
    xsystem(command)
Exemplo n.º 8
0
def screen_wakeup():
    """Wake up the screen if it is dark."""
    # Move the mouse a little bit to wake up the screen.
    if utils.is_freon():
        device = _get_uinput_device_mouse_rel()
        _uinput_emit(device, 'REL_X', 1)
        _uinput_emit(device, 'REL_X', -1)
    else:
        xsystem('xdotool mousemove_relative 1 1')
Exemplo n.º 9
0
    def run_in_parallel(self, *commands):
        env = os.environ.copy()

        # To clear the temparory files created by vea_unittest.
        env['TMPDIR'] = self.tmpdir
        if not utils.is_freon():
            env['DISPLAY'] = ':0'
            env['XAUTHORITY'] = '/home/chronos/.Xauthority'
        return map(lambda c: cmd_utils.popen(c, env=env), commands)
Exemplo n.º 10
0
def get_display_output_state():
    """
    Retrieves output status of connected display(s).

    Return value: dictionary of connected display states.
    """
    if utils.is_freon():
        return get_modetest_output_state()
    else:
        return get_xrandr_output_state()
Exemplo n.º 11
0
    def run_once(self):
        # TODO(ihf): Remove this once GLES2ConformChrome works on freon.
        if utils.is_freon():
            raise error.TestNAError(
                'Test needs work on Freon. See crbug.com/484463.')

        if not os.path.exists(self.get_chrome_binary_path(self.BINARY)):
            raise error.TestFail('%s not found. Use internal Chrome sources!' %
                                 self.BINARY)

        self.run_chrome_test_binary(self.BINARY)
Exemplo n.º 12
0
def get_internal_resolution():
    if utils.is_freon():
        if has_internal_display():
            crtcs = get_modetest_crtcs()
            if len(crtcs) > 0:
                return crtcs[0].size
        return (-1, -1)
    else:
        connector = get_internal_connector_name()
        width, height, _, _ = get_output_rect_x(connector)
        return (width, height)
Exemplo n.º 13
0
def set_content_protection(output_name, state):
    """
    Sets the content protection to the given state.

    @param output_name: The output name as a string.
    @param state: One of the states 'Undesired', 'Desired', or 'Enabled'

    """
    if utils.is_freon():
        raise error.TestFail('freon: set_content_protection not implemented')
    call_xrandr('--output %s --set "Content Protection" %s' %
                (output_name, state))
    def take_external_screenshot(self, path):
        """Takes external screenshot.

        @param path: path to image file.
        """
        if utils.is_freon():
            self.take_screenshot_crtc(path, self.get_external_crtc())
        else:
            output = self.get_external_connector_name()
            box = self.get_output_rect(output)
            graphics_utils.take_screenshot_crop_x(path, box)
            return output, box  # for logging/debugging
 def cleanup(self):
     if utils.is_freon() and self._services:
         self._services.restore_services()
     if self.GSC:
         keyvals = self.GSC.get_memory_keyvals()
         for key, val in keyvals.iteritems():
             self.output_perf_value(description=key,
                                    value=val,
                                    units='bytes',
                                    higher_is_better=False)
         self.GSC.finalize()
         self.write_perf_keyval(keyvals)
Exemplo n.º 16
0
    def run_once(self):
        if utils.is_freon():
            if not self.__check_wflinfo():
                raise error.TestFail('Failed: GLES API insufficient:' +
                                     self.error_message)
            return

        # TODO(ihf): Remove this once all boards are switched to freon.
        cmd_gl = os.path.join(self.bindir, 'gl_APICheck')
        cmd_gles = os.path.join(self.bindir, 'gles_APICheck')
        exist_gl = os.path.isfile(cmd_gl)
        exist_gles = os.path.isfile(cmd_gles)
        if not exist_gl and not exist_gles:
            raise error.TestFail(
                'Failed: Found neither gl_APICheck nor gles_APICheck. '
                'Test setup error.')
        elif exist_gl and exist_gles:
            raise error.TestFail(
                'Failed: Found both gl_APICheck and gles_APICheck. '
                'Test setup error.')
        elif exist_gl:
            self.error_message = ''
            result = self.__run_x_cmd(cmd_gl)
            errors = re.findall(r'ERROR: ', result)
            run_through = re.findall(r'SUCCEED: run to the end', result)
            if not errors and run_through:
                check_result = self.__check_gl(result)
                if not check_result:
                    raise error.TestFail('Failed: GL API insufficient:' +
                                         self.error_message)
            else:
                raise error.TestFail('Failed: gl_APICheck error: ' + result)
        else:
            self.error_message = ''
            # TODO(zmo@): smarter mechanism with GLES & EGL library names.
            result = self.__run_x_cmd(cmd_gles + ' libGLESv2.so libEGL.so')
            errors = re.findall(r'ERROR: ', result)
            run_through = re.findall(r'SUCCEED: run to the end', result)
            if not errors and run_through:
                check_result = self.__check_gles(result)
                if not check_result:
                    raise error.TestFail('Failed: GLES API insufficient:' +
                                         self.error_message)
            else:
                raise error.TestFail('Failed: gles_APICheck error: ' + result)

        # Check X11 extensions.
        self.error_message = ''
        check_result = self.__check_x_extensions(result)
        if not check_result:
            raise error.TestFail('Failed: X extensions insufficient:' +
                                 self.error_message)
Exemplo n.º 17
0
def get_display_resolution():
    """
    Parses output of modetest to determine the display resolution of the dut.
    @return: tuple, (w,h) resolution of device under test.
    """
    if not utils.is_freon():
        return _get_display_resolution_x()

    connectors = get_modetest_connectors()
    for connector in connectors:
        if connector.connected:
            return connector.size
    return None
Exemplo n.º 18
0
    def run_once(self):
        # TODO(ihf): Remove this once KhronosGLCTSChrome works on freon.
        if utils.is_freon():
            raise error.TestNAError(
                'Test needs work on Freon. See crbug.com/484467.')

        if not os.path.exists(self.get_chrome_binary_path(self.BINARY)):
            raise error.TestFail('%s not found. Use internal Chrome sources!' %
                                 self.BINARY)

        log_file = os.path.join(self.resultsdir, self.BINARY + ".xml")
        bin_args = '--gtest_output=xml:%s %s' % (log_file, self.resultsdir)

        self.run_chrome_test_binary(self.BINARY, bin_args)
Exemplo n.º 19
0
def screen_disable_energy_saving():
    """ Called from power_Consumption to immediately disable energy saving. """
    if utils.is_freon():
        # All we need to do here is enable displays via Chrome.
        power_utils.set_display_power(power_utils.DISPLAY_POWER_ALL_ON)
        return
    # Disable X screen saver
    xsystem(XSET + ' s 0 0')
    # Disable DPMS Standby/Suspend/Off
    xsystem(XSET + ' dpms 0 0 0')
    # Force monitor on
    screen_switch_on(on=1)
    # Save off X settings
    xsystem(XSET + ' q')
Exemplo n.º 20
0
def xcommand(cmd, user=None):
    """
    Add the necessary X setup to a shell command that needs to connect to the X
    server.
    @param cmd: the command line string
    @param user: if not None su command to desired user.
    @return a modified command line string with necessary X setup
    """
    logging.warning('xcommand will be deprecated under freon!')
    #traceback.print_stack()
    if user is not None:
        cmd = 'su %s -c \'%s\'' % (user, cmd)
    if not utils.is_freon():
        cmd = 'DISPLAY=:0 XAUTHORITY=/home/chronos/.Xauthority ' + cmd
    return cmd
Exemplo n.º 21
0
def take_screenshot_crop(fullpath, box=None, crtc_id=None):
    """
    Take a screenshot using import tool, crop according to dim given by the box.
    @param fullpath: path, full path to save the image to.
    @param box: 4-tuple giving the upper left and lower right pixel coordinates.
    """
    if not utils.is_freon():
        return take_screenshot_crop_x(fullpath, box)
    if crtc_id is not None:
        image = drm.crtcScreenshot(crtc_id)
    else:
        image = drm.crtcScreenshot(get_internal_crtc())
    if box:
        image = image.crop(box)
    image.save(fullpath)
    return fullpath
Exemplo n.º 22
0
def get_external_resolution():
    """Gets the resolution of the external display.

    @return A tuple of (width, height) or None if no external display is
            connected.
    """
    if utils.is_freon():
        offset = 1 if has_internal_display() else 0
        crtcs = get_modetest_crtcs()
        if len(crtcs) > offset and crtcs[offset].size != (0, 0):
            return crtcs[offset].size
        return None
    else:
        connector = get_external_connector_name()
        width, height, _, _ = get_output_rect_x(connector)
        if width == 0 and height == 0:
            return None
        return (width, height)
    def run_once(self, process_path=None, crash_extensions=None):
        if process_path:
            self._test_process(process_path, crash_extensions)
            return

        with chrome.Chrome():
            if not utils.is_freon():
                process_path = '/usr/bin/X'
                crash_extensions = ['.core', '.dmp', '.meta']
                self.job.run_test("logging_CrashServices",
                                  process_path=process_path,
                                  crash_extensions=crash_extensions,
                                  tag=os.path.basename(process_path))
            for process_path in self.process_list.keys():
                self.job.run_test(
                    "logging_CrashServices",
                    process_path=process_path,
                    crash_extensions=self.process_list.get(process_path),
                    tag=os.path.basename(process_path))
Exemplo n.º 24
0
    def check_file(self, basename):
        match_func = getattr(self, 'match_%s' % basename)
        success = True

        expected_entries = self.load_path(
            os.path.join(self.bindir, 'baseline.%s' % basename))

        # TODO(spang): Remove this once per-board baselines are supported
        # (crbug.com/406013).
        if utils.is_freon():
            extra_baseline = 'baseline.%s.freon' % basename
        else:
            extra_baseline = 'baseline.%s.x11' % basename

        expected_entries += self.load_path(
            os.path.join(self.bindir, extra_baseline))

        actual_entries = self.load_path('/etc/%s' % basename)

        if len(actual_entries) > len(expected_entries):
            success = False
            logging.error('%s baseline mismatch: expected %d entries, got %d.',
                          basename, len(expected_entries), len(actual_entries))

        for actual in actual_entries:
            expected = [x for x in expected_entries if x[0] == actual[0]]
            if not expected:
                success = False
                logging.error("Unexpected %s entry for '%s'.", basename,
                              actual[0])
                continue
            expected = expected[0]
            match_res = match_func(expected, actual)
            success = success and match_res

        for expected in expected_entries:
            actual = [x for x in actual_entries if x[0] == expected[0]]
            if not actual:
                logging.info("Ignoring missing %s entry for '%s'.", basename,
                             expected[0])

        return success
    def run_once_vaapi(self):
        sys.path.append(self.bindir)
        import vaapi

        if not utils.is_freon():
            # Set the XAUTHORITY for connecting to the X server
            utils.assert_has_X_server()
            os.environ.setdefault('XAUTHORITY', '/home/chronos/.Xauthority')

            display = vaapi.create_display(':0.0')
        else:
            display = vaapi.create_display('/dev/dri/card0')

        supported_profiles = vaapi.query_profiles(display)
        logging.info('Vaapi Profiles: %s', supported_profiles)

        for profile in self.REQUESTED_VAAPI_PROFILES:
            self.assertTrue(profile in supported_profiles,
                            'Profile:%s is not supported', profile)
            self.verifyProfile(vaapi, display, profile)
Exemplo n.º 26
0
 def get_vda_unittest_cmd_line(self, decode_videos):
     test_video_data = []
     for v in decode_videos:
         assert len(v) == 6
         # Convert to strings, also make a copy of the list.
         v = map(str, v)
         v[0] = self._downloads.get_path(v[0])
         v[-1:-1] = ['0', '0']  # no fps requirements
         test_video_data.append(':'.join(v))
     cmd_line = [
         self.get_chrome_binary_path(VDA_BINARY),
         '--gtest_filter=DecodeVariations/*/0',
         '--test_video_data=%s' % ';'.join(test_video_data),
         '--rendering_warm_up=%d' % RENDERING_WARM_UP,
         '--rendering_fps=%f' % RENDERING_FPS,
         '--num_play_throughs=%d' % MAX_INT
     ]
     if utils.is_freon():
         cmd_line.append('--ozone-platform=gbm')
     return cmd_line
    def run_once(self, in_cloud, streams, profile):
        """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.
        """

        last_test_failure = None
        for path, width, height, bit_rate in streams:
            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])

            cmd_line = '--test_stream_data="%s:%s:%s:%s:%s:%s"' % (
                input_path, width, height, profile, output_path, bit_rate)
            if utils.is_freon():
                cmd_line += ' --ozone-platform=gbm'
            cmd_line += self.get_filter_option()
            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
Exemplo n.º 28
0
 def get_vea_unittest_cmd_line(self, encode_videos):
     test_stream_data = []
     for v in encode_videos:
         assert len(v) == 5
         # Convert to strings, also make a copy of the list.
         v = map(str, v)
         v[0] = self._downloads.get_path(v[0])
         # The output destination, ignore the output.
         v.insert(4, '/dev/null')
         # Insert the FPS requirement
         v.append(str(INPUT_FPS))
         test_stream_data.append(':'.join(v))
     cmd_line = [
         self.get_chrome_binary_path(VEA_BINARY),
         '--gtest_filter=SimpleEncode/*/0',
         '--test_stream_data=%s' % ';'.join(test_stream_data),
         '--run_at_fps',
         '--num_frames_to_encode=%d' % MAX_INT
     ]
     if utils.is_freon():
         cmd_line.append('--ozone-platform=gbm')
     return cmd_line
    def run_once(self, test_slice):
        # TODO(ihf): Remove this once Piglit works on freon.
        if utils.is_freon():
            return

        gpu_family = utils.get_gpu_family()
        family = gpu_family
        logging.info('Detected gpu family %s.', gpu_family)

        # TODO(ihf): Delete this once we have a piglit that runs on ARM.
        if gpu_family in ['mali', 'tegra']:
            logging.info('Not running any tests, passing by default.')
            return

        scripts_dir = os.path.join(self.bindir, self.test_scripts)
        family_dir = os.path.join(scripts_dir, family)
        # We don't want to introduce too many combinations, so fall back.
        if not os.path.isdir(family_dir):
            family = 'other'
            family_dir = os.path.join(scripts_dir, family)
        logging.info('Using scripts for gpu family %s.', family)
        scripts_dir = os.path.join(self.bindir, self.test_scripts)
        # Mark scripts executable if they are not.
        utils.system('chmod +x ' + scripts_dir + '*/graphics_PiglitBVT_*.sh')

        # Kick off test script.
        cmd = (
            'source ' +
            os.path.join(family_dir, 'graphics_PiglitBVT_%d.sh' % test_slice))
        logging.info('Executing cmd = %s', cmd)
        result = utils.run(cmd,
                           stdout_tee=utils.TEE_TO_LOGS,
                           stderr_tee=utils.TEE_TO_LOGS,
                           ignore_status=True)
        tests_failed = result.exit_status
        if tests_failed:
            reason = '%d tests failed on "%s" in slice %d' % (
                tests_failed, gpu_family, test_slice)
            raise error.TestError(reason)
 def _append_freon_switch_if_needed(self, cmd_line):
     if utils.is_freon():
         cmd_line.append('--ozone-platform=gbm')