• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2017 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import logging
6import os
7import subprocess
8
9
10from autotest_lib.client.bin import test
11from autotest_lib.client.common_lib import error
12from autotest_lib.client.cros.video import device_capability
13
14class video_VideoCapability(test.test):
15    """
16    This tests the video static capabilities settings
17    with label detector: "avtest_label_detect."
18    """
19    version = 1
20    avtest_label_to_capability = {
21        'hw_video_acc_h264'    : 'hw_dec_h264_1080_30',
22        'hw_video_acc_vp8'     : 'hw_dec_vp8_1080_30',
23        'hw_video_acc_vp9'     : 'hw_dec_vp9_1080_30',
24        'hw_video_acc_vp9_2'   : 'hw_dec_vp9-2_1080_30',
25        'hw_jpeg_acc_dec'      : 'hw_dec_jpeg',
26        'hw_jpeg_acc_enc'      : 'hw_enc_jpeg',
27        'hw_video_acc_enc_h264': 'hw_enc_h264_1080_30',
28        'hw_video_acc_enc_vp8' : 'hw_enc_vp8_1080_30',
29        'hw_video_acc_enc_vp9' : 'hw_enc_vp9_1080_30',
30        'webcam'               : 'usb_camera',
31    }
32
33
34    def compare_avtest_label_detect(self, dc_results):
35        avtest_label = subprocess.check_output(['avtest_label_detect']).strip()
36        logging.debug("avtest_label_detect result\n%s", avtest_label)
37        mismatch_list = []
38        avtest_detected_labels = set()
39        for line in avtest_label.splitlines():
40            label = line.split(':')[1].strip()
41            if label in video_VideoCapability.avtest_label_to_capability:
42                cap = video_VideoCapability.avtest_label_to_capability[label]
43                avtest_detected_labels.add(cap)
44
45        for cap in video_VideoCapability.avtest_label_to_capability.values():
46            if dc_results[cap] == 'yes' and cap not in avtest_detected_labels:
47                logging.error('Static capability claims %s is available. '
48                              "But avtest_label_detect doesn't detect", cap)
49                mismatch_list.append(cap)
50
51            if dc_results[cap] == 'no' and cap in avtest_detected_labels:
52                logging.error("Static capability claims %s isn't available. "
53                              'But avtest_label_detect detects', cap)
54                mismatch_list.append(cap)
55
56        if mismatch_list:
57            raise error.TestFail("Dynamic capability detection results did not "
58                                 "match static capability configuration. "
59                                 "mismatch_list=%r" % mismatch_list)
60
61
62    def run_once(self):
63        logging.debug('Starting video_VideoCapability')
64        dc = device_capability.DeviceCapability()
65        dc_results = {}
66        for cap in dc.get_managed_caps():
67            ret = dc.get_capability(cap)
68            dc_results[cap] = ret
69
70        self.compare_avtest_label_detect(dc_results)
71