| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2016 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Helper script to update the test error expectations based on actual results. | 6 """Helper script to update the test error expectations based on actual results. |
| 7 | 7 |
| 8 This is useful for regenerating test expectations after making changes to the | 8 This is useful for regenerating test expectations after making changes to the |
| 9 error format. | 9 error format. |
| 10 | 10 |
| 11 To use this run the affected tests, and then pass the input to this script | 11 To use this run the affected tests, and then pass the input to this script |
| 12 (either via stdin, or as the first argument). For instance: | 12 (either via stdin, or as the first argument). For instance: |
| 13 | 13 |
| 14 $ ./out/Release/net_unittests --gtest_filter="*VerifyCertificateChain*" | \ | 14 $ ./out/Release/net_unittests --gtest_filter="*VerifyCertificateChain*" | \ |
| 15 net/data/verify_certificate_chain_unittest/rebase-errors.py | 15 net/data/verify_certificate_chain_unittest/rebase-errors.py |
| 16 | 16 |
| 17 The script works by scanning the stdout looking for gtest failures when | 17 The script works by scanning the stdout looking for gtest failures when |
| 18 comparing "errors.ToDebugString()". The C++ test side should have been | 18 comparing "errors.ToDebugString(chain)". The C++ test side should have been |
| 19 instrumented to dump out the test file's path on mismatch. | 19 instrumented to dump out the test file's path on mismatch. |
| 20 | 20 |
| 21 This script will then update the corresponding file(s) -- a .pem file, and | 21 This script will then update the corresponding file(s) -- a .pem file, and |
| 22 possibly an accompanying .py file. | 22 possibly an accompanying .py file. |
| 23 """ | 23 """ |
| 24 | 24 |
| 25 import common | 25 import common |
| 26 import os | 26 import os |
| 27 import sys | 27 import sys |
| 28 import re | 28 import re |
| 29 | 29 |
| 30 | 30 |
| 31 # Regular expression to find the failed errors in test stdout. | 31 # Regular expression to find the failed errors in test stdout. |
| 32 # * Group 1 of the match is the actual error text (backslash-escaped) | 32 # * Group 1 of the match is the actual error text (backslash-escaped) |
| 33 # * Group 2 of the match is file path (relative to //src) where the expected | 33 # * Group 2 of the match is file path (relative to //src) where the expected |
| 34 # errors were read from. | 34 # errors were read from. |
| 35 failed_test_regex = re.compile(r""" | 35 failed_test_regex = re.compile(r""" |
| 36 Value of: errors.ToDebugString\(\) | 36 Value of: errors.ToDebugString\((?:chain)?\) |
| 37 Actual: "(.*)" | 37 Actual: "(.*)" |
| 38 (?:.|\n)+? | 38 (?:.|\n)+? |
| 39 Test file: (.*) | 39 Test file: (.*) |
| 40 """, re.MULTILINE) | 40 """, re.MULTILINE) |
| 41 | 41 |
| 42 | 42 |
| 43 # Regular expression to find the ERRORS block (and any text above it) in a PEM | 43 # Regular expression to find the ERRORS block (and any text above it) in a PEM |
| 44 # file. The assumption is that ERRORS is not the very first block in the file | 44 # file. The assumption is that ERRORS is not the very first block in the file |
| 45 # (since it looks for an -----END to precede it). | 45 # (since it looks for an -----END to precede it). |
| 46 # * Group 1 of the match is the ERRORS block content and any comments | 46 # * Group 1 of the match is the ERRORS block content and any comments |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 168 |
| 169 for m in failed_test_regex.finditer(test_stdout): | 169 for m in failed_test_regex.finditer(test_stdout): |
| 170 actual_errors = m.group(1) | 170 actual_errors = m.group(1) |
| 171 actual_errors = actual_errors.decode('string-escape') | 171 actual_errors = actual_errors.decode('string-escape') |
| 172 relative_test_path = m.group(2) | 172 relative_test_path = m.group(2) |
| 173 fixup_errors_for_file(actual_errors, get_abs_path(relative_test_path)) | 173 fixup_errors_for_file(actual_errors, get_abs_path(relative_test_path)) |
| 174 | 174 |
| 175 | 175 |
| 176 if __name__ == "__main__": | 176 if __name__ == "__main__": |
| 177 main() | 177 main() |
| OLD | NEW |