summaryrefslogtreecommitdiffstats
path: root/media/tools/layout_tests/test_expectations.py
blob: b68bc0929871e749d5d7771b227ab5f774f55c69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""A module to analyze test expectations for Webkit layout tests."""

import urllib2

from webkitpy.layout_tests.models.test_expectations import *

# Default location for chromium test expectation file.
# TODO(imasaki): support multiple test expectations files.
DEFAULT_TEST_EXPECTATIONS_LOCATION = (
    'http://src.chromium.org/blink/trunk/LayoutTests/TestExpectations')

# The following is from test expectation syntax. The detail can be found in
# http://www.chromium.org/developers/testing/webkit-layout-tests#TOC-Test-Expectations
# <decision> ::== [SKIP] [WONTFIX] [SLOW]
DECISION_NAMES = ['SKIP', 'WONTFIX', 'SLOW']
# <config> ::== RELEASE | DEBUG
CONFIG_NAMES = ['RELEASE', 'DEBUG']
# Only hard code keywords we don't expect to change.  Determine the rest from
# the format of the status line.
KNOWN_TE_KEYWORDS = DECISION_NAMES + CONFIG_NAMES


class TestExpectations(object):
  """A class to model the content of test expectation file for analysis.

  This class retrieves the TestExpectations file via HTTP from WebKit and uses
  the WebKit layout test processor to process each line.

  The resulting dictionary is stored in |all_test_expectation_info| and looks
  like:

    {'<test name>': [{'<modifier0>': True, '<modifier1>': True, ...,
                     'Platforms: ['<platform0>', ... ], 'Bugs': ['....']}]}

  Duplicate keys are merged (though technically they shouldn't exist).

  Example:
    crbug.com/145590 [ Android ] \
        platform/chromium/media/video-frame-size-change.html [ Timeout ]
    webkit.org/b/84724 [ SnowLeopard ] \
        platform/chromium/media/video-frame-size-change.html \
        [ ImageOnlyFailure Pass ]

  {'platform/chromium/media/video-frame-size-change.html': [{'IMAGE': True,
   'Bugs': ['BUGWK84724', 'BUGCR145590'], 'Comments': '',
   'Platforms': ['SNOWLEOPARD', 'ANDROID'], 'TIMEOUT': True, 'PASS': True}]}
  """

  def __init__(self, url=DEFAULT_TEST_EXPECTATIONS_LOCATION):
    """Read the test expectation file from the specified URL and parse it.

    Args:
      url: A URL string for the test expectation file.

    Raises:
      NameError when the test expectation file cannot be retrieved from |url|.
    """
    self.all_test_expectation_info = {}
    resp = urllib2.urlopen(url)
    if resp.code != 200:
      raise NameError('Test expectation file does not exist in %s' % url)
    # Start parsing each line.
    for line in resp.read().split('\n'):
      line = line.strip()
      # Skip comments.
      if line.startswith('#'):
        continue
      testname, te_info = self.ParseLine(line)
      if not testname or not te_info:
        continue
      if testname in self.all_test_expectation_info:
        # Merge keys if entry already exists.
        for k in te_info.keys():
          if (isinstance(te_info[k], list) and
              k in self.all_test_expectation_info[testname]):
            self.all_test_expectation_info[testname][0][k] += te_info[k]
          else:
            self.all_test_expectation_info[testname][0][k] = te_info[k]
      else:
        self.all_test_expectation_info[testname] = [te_info]

  @staticmethod
  def ParseLine(line):
    """Parses the provided line using WebKit's TextExpecations parser.

    Returns:
      Tuple of test name, test expectations dictionary.  See class documentation
      for the format of the dictionary
    """
    test_expectation_info = {}
    parsed = TestExpectationParser._tokenize_line('TestExpectations', line, 0)
    if parsed.is_invalid():
      return None, None

    test_expectation_info['Comments'] = parsed.comment or ''
    test_expectation_info['Bugs'] = parsed.bugs or [];
    test_expectation_info['Platforms'] =  parsed.specifiers or []
    # Shovel the expectations and modifiers in as "<key>: True" entries.  Ugly,
    # but required by the rest of the pipeline for parsing.
    for m in parsed.expectations:
      test_expectation_info[m] = True

    return parsed.name, test_expectation_info