| # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| """Test to verify formats availability for hardware offload.""" |
| import logging, os |
| from autotest_lib.client.bin import test, utils |
| from autotest_lib.client.common_lib import error |
| |
| try: |
| import v4l2 |
| except ImportError: |
| # v4l2 module is generated by setup. It will fail when setup runs and succeed |
| # when run_once runs. |
| pass |
| |
| |
| class audiovideo_Formats(test.test): |
| """Test class to verify formats availability for hardware offload.""" |
| |
| version = 1 |
| preserve_srcdir = False |
| |
| |
| def setup(self): |
| os.chdir(self.srcdir) |
| utils.make() |
| |
| |
| def _enum_formats(self, video_device): |
| """Use the v4l2 binary to enum formats. |
| |
| Runs the embedded v4l2 binary to enumerate supported |
| capture formats and output formats. |
| |
| @param video_device: device interrogated (e.g. /dev/mfc-dec). |
| |
| @return a dict of keyvals reflecting the formats supported. |
| """ |
| capture_formats = v4l2.enum_capture_formats(video_device) |
| logging.info('Capture formats=%s', capture_formats) |
| output_formats = v4l2.enum_output_formats(video_device) |
| logging.info('Output formats=%s', output_formats) |
| |
| capture_keyvals = [('cap_fmt_%s' % c, True) for c in capture_formats] |
| output_keyvals = [('out_fmt_%s' % o, True) for o in output_formats] |
| # Underlying eval command requires True definition included. |
| return dict(capture_keyvals + output_keyvals + [('True', True)]) |
| |
| |
| def run_once(self, video_device=None): |
| """Emit supported image formats as keyvals. |
| |
| @param video_device: used by v4l2 binary to enum formats. |
| """ |
| if not video_device: |
| raise error.TestError('no video_device supplied to check') |
| self.write_perf_keyval(self._enum_formats(video_device)) |