summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/harness/docs/expectation.rst
blob: 6a0c77684a3b83aba88436e84b399fd8fb64e325 (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
Expectation Data
================

Introduction
------------

For use in continuous integration systems, and other scenarios where
regression tracking is required, wptrunner supports storing and
loading the expected result of each test in a test run. Typically
these expected results will initially be generated by running the
testsuite in a baseline build. They may then be edited by humans as
new features are added to the product that change the expected
results. The expected results may also vary for a single product
depending on the platform on which it is run. Therefore, the raw
structured log data is not a suitable format for storing these
files. Instead something is required that is:

 * Human readable

 * Human editable

 * Machine readable / writable

 * Capable of storing test id / result pairs

 * Suitable for storing in a version control system (i.e. text-based)

The need for different results per platform means either having
multiple expectation files for each platform, or having a way to
express conditional values within a certain file. The former would be
rather cumbersome for humans updating the expectation files, so the
latter approach has been adopted, leading to the requirement:

 * Capable of storing result values that are conditional on the platform.

There are few extant formats that meet these requirements, so
wptrunner uses a bespoke ``expectation manifest`` format, which is
closely based on the standard ``ini`` format.

Directory Layout
----------------

Expectation manifest files must be stored under the ``metadata``
directory passed to the test runner. The directory layout follows that
of web-platform-tests with each test path having a corresponding
manifest file. Tests that differ only by query string, or reftests
with the same test path but different ref paths share the same
reference file. The file name is taken from the last /-separated part
of the path, suffixed with ``.ini``.

As an optimisation, files which produce only default results
(i.e. ``PASS`` or ``OK``) don't require a corresponding manifest file.

For example a test with url::

  /spec/section/file.html?query=param

would have an expectation file ::

  metadata/spec/section/file.html.ini


.. _wptupdate-label:

Generating Expectation Files
----------------------------

wptrunner provides the tool ``wptupdate`` to generate expectation
files from the results of a set of baseline test runs. The basic
syntax for this is::

  wptupdate [options] [logfile]...

Each ``logfile`` is a structured log file from a previous run. These
can be generated from wptrunner using the ``--log-raw`` option
e.g. ``--log-raw=structured.log``. The default behaviour is to update
all the test data for the particular combination of hardware and OS
used in the run corresponding to the log data, whilst leaving any
other expectations untouched.

wptupdate takes several useful options:

``--sync``
  Pull the latest version of web-platform-tests from the
  upstream specified in the config file. If this is specified in
  combination with logfiles, it is assumed that the results in the log
  files apply to the post-update tests.

``--no-check-clean``
  Don't attempt to check if the working directory is clean before
  doing the update (assuming that the working directory is a git or
  mercurial tree).

``--patch``
  Create a a git commit, or a mq patch, with the changes made by wptupdate.

``--ignore-existing``
  Overwrite all the expectation data for any tests that have a result
  in the passed log files, not just data for the same platform.

Examples
~~~~~~~~

Update the local copy of web-platform-tests without changing the
expectation data and commit (or create a mq patch for) the result::

  wptupdate --patch --sync

Update all the expectations from a set of cross-platform test runs::

  wptupdate --no-check-clean --patch osx.log linux.log windows.log

Add expectation data for some new tests that are expected to be
platform-independent::

  wptupdate --no-check-clean --patch --ignore-existing tests.log

Manifest Format
---------------
The format of the manifest files is based on the ini format. Files are
divided into sections, each (apart from the root section) having a
heading enclosed in square braces. Within each section are key-value
pairs. There are several notable differences from standard .ini files,
however:

 * Sections may be hierarchically nested, with significant whitespace
   indicating nesting depth.

 * Only ``:`` is valid as a key/value separator

A simple example of a manifest file is::

  root_key: root_value

  [section]
    section_key: section_value

    [subsection]
       subsection_key: subsection_value

  [another_section]
    another_key: another_value

Conditional Values
~~~~~~~~~~~~~~~~~~

In order to support values that depend on some external data, the
right hand side of a key/value pair can take a set of conditionals
rather than a plain value. These values are placed on a new line
following the key, with significant indentation. Conditional values
are prefixed with ``if`` and terminated with a colon, for example::

  key:
    if cond1: value1
    if cond2: value2
    value3

In this example, the value associated with ``key`` is determined by
first evaluating ``cond1`` against external data. If that is true,
``key`` is assigned the value ``value1``, otherwise ``cond2`` is
evaluated in the same way. If both ``cond1`` and ``cond2`` are false,
the unconditional ``value3`` is used.

Conditions themselves use a Python-like expression syntax. Operands
can either be variables, corresponding to data passed in, numbers
(integer or floating point; exponential notation is not supported) or
quote-delimited strings. Equality is tested using ``==`` and
inequality by ``!=``. The operators ``and``, ``or`` and ``not`` are
used in the expected way. Parentheses can also be used for
grouping. For example::

  key:
    if (a == 2 or a == 3) and b == "abc": value1
    if a == 1 or b != "abc": value2
    value3

Here ``a`` and ``b`` are variables, the value of which will be
supplied when the manifest is used.

Expectation Manifests
---------------------

When used for expectation data, manifests have the following format:

 * A section per test URL described by the manifest, with the section
   heading being the part of the test URL following the last ``/`` in
   the path (this allows multiple tests in a single manifest file with
   the same path part of the URL, but different query parts).

 * A subsection per subtest, with the heading being the title of the
   subtest.

 * A key ``type`` indicating the test type. This takes the values
   ``testharness`` and ``reftest``.

 * For reftests, keys ``reftype`` indicating the reference type
   (``==`` or ``!=``) and ``refurl`` indicating the URL of the
   reference.

 * A key ``expected`` giving the expectation value of each (sub)test.

 * A key ``disabled`` which can be set to any value to indicate that
   the (sub)test is disabled and should either not be run (for tests)
   or that its results should be ignored (subtests).

 * A key ``restart-after`` which can be set to any value to indicate that
   the runner should restart the browser after running this test (e.g. to
   clear out unwanted state).

 * Variables ``debug``, ``os``, ``version``, ``processor`` and
   ``bits`` that describe the configuration of the browser under
   test. ``debug`` is a boolean indicating whether a build is a debug
   build. ``os`` is a string indicating the operating system, and
   ``version`` a string indicating the particular version of that
   operating system. ``processor`` is a string indicating the
   processor architecture and ``bits`` an integer indicating the
   number of bits. This information is typically provided by
   :py:mod:`mozinfo`.

 * Top level keys are taken as defaults for the whole file. So, for
   example, a top level key with ``expected: FAIL`` would indicate
   that all tests and subtests in the file are expected to fail,
   unless they have an ``expected`` key of their own.

An simple example manifest might look like::

  [test.html?variant=basic]
    type: testharness

    [Test something unsupported]
       expected: FAIL

  [test.html?variant=broken]
    expected: ERROR

  [test.html?variant=unstable]
    disabled: http://test.bugs.example.org/bugs/12345

A more complex manifest with conditional properties might be::

  [canvas_test.html]
    expected:
      if os == "osx": FAIL
      if os == "windows" and version == "XP": FAIL
      PASS

Note that ``PASS`` in the above works, but is unnecessary; ``PASS``
(or ``OK``) is always the default expectation for (sub)tests.