Chromium Code Reviews| Index: Tools/Scripts/webkitpy/layout_tests/models/testharness_results.py |
| diff --git a/Tools/Scripts/webkitpy/layout_tests/models/testharness_results.py b/Tools/Scripts/webkitpy/layout_tests/models/testharness_results.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..511431a59136ff501e0c6e84593035dc24d22a00 |
| --- /dev/null |
| +++ b/Tools/Scripts/webkitpy/layout_tests/models/testharness_results.py |
| @@ -0,0 +1,76 @@ |
| +# Copyright 2014 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. |
| + |
| +"""Utility module for testharness.""" |
| + |
| + |
| +# const definitions |
| +TESTHARNESSREPORT_HEADER = 'This is a testharness.js-based test.' |
| +TESTHARNESSREPORT_FOOTER = 'Harness: the test ran to completion.' |
| + |
| + |
| +def is_testharness_output(content_text): |
| + """Returns whether the content_text in parameter is a testharness output. |
| + |
| + Returns: |
| + True if content_text is a valid testharness output. False otherwise. |
| + """ |
|
Dirk Pranke
2014/09/02 23:48:17
I would just use the first line of the docstring,
mlamouri (slow - plz ping)
2014/09/03 10:53:46
Done.
|
| + |
| + # Leading and trailing white spaces are accepted. |
| + lines = content_text.strip().splitlines() |
| + lines = [line.strip() for line in lines] |
| + |
| + # A testharness output is defined as containing the header and the footer. |
| + found_header = False |
| + found_footer = False |
| + for line in lines: |
| + if line == TESTHARNESSREPORT_HEADER: |
| + found_header = True |
| + elif line == TESTHARNESSREPORT_FOOTER: |
| + found_footer = True |
| + |
| + return found_header and found_footer |
| + |
| + |
| +def is_testharness_output_passing(content_text): |
| + """Returns whether the content_text in parameter is a passing testharness output. |
| + |
| + Note: |
| + It is expected that the |content_text| is a testharness output. |
| + |
| + Returns: |
| + True if content_text is a passing testharness output. False otherwise. |
|
Dirk Pranke
2014/09/02 23:48:17
Same thing, I would delete lines 41-30 (but keep t
mlamouri (slow - plz ping)
2014/09/03 10:53:46
Done. I assumed that you meant 41-43.
|
| + """ |
| + |
| + # Leading and trailing white spaces are accepted. |
| + lines = content_text.strip().splitlines() |
| + lines = [line.strip() for line in lines] |
| + |
| + # The check is very conservative and reject any unexpected content in the output. |
|
Dirk Pranke
2014/09/02 23:48:17
nit: grammar: "rejects", not "reject".
mlamouri (slow - plz ping)
2014/09/03 10:53:46
Done.
|
| + for line in lines: |
| + # There should be no empty lines. |
| + if len(line) == 0: |
| + return False |
| + |
| + # Those lines are expected to be exactly equivalent. |
| + if line == TESTHARNESSREPORT_HEADER or \ |
| + line == TESTHARNESSREPORT_FOOTER: |
| + continue |
| + |
| + # Those are expected passing output. |
| + if line.startswith('CONSOLE') or \ |
| + line.startswith('PASS'): |
| + continue |
| + |
| + # Those are expected failing outpu. |
|
Dirk Pranke
2014/09/02 23:48:17
Nit: typo: "output", not "outpu"
mlamouri (slow - plz ping)
2014/09/03 10:53:46
Done.
|
| + if line.startswith('FAIL') or \ |
| + line.startswith('TIMEOUT') or \ |
| + line.startswith('NOTRUN') or \ |
| + line.startswith('Harness Error. harness_status = '): |
| + return False |
| + |
| + # Unexpected output should be considered as a failure. |
| + return False |
| + |
| + return True |