Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(305)

Side by Side Diff: net/data/parse_certificate_unittest/rebase-errors.py

Issue 2918913002: Add path validation error expectations for PKITS tests. (Closed)
Patch Set: Address Matt's comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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="*ParseCertificate*" | \ 14 $ ./out/Release/net_unittests --gtest_filter="*ParseCertificate*" | \
15 net/data/parse_certificate_unittest/rebase-errors.py 15 net/data/parse_certificate_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 having a
18 comparing "errors.ToDebugString()". The C++ test side should have been 18 particular format. The C++ test side should have been instrumented to dump
19 instrumented to dump out the test file's path on mismatch. 19 out the test file's path on mismatch.
20 20
21 This script will then update the corresponding .pem file 21 This script will then update the corresponding .pem file
22 """ 22 """
23 23
24 import sys 24 import sys
25 sys.path += ['../verify_certificate_chain_unittest'] 25 sys.path += ['../verify_certificate_chain_unittest']
26 26
27 import common 27 import common
28 28
29 import os 29 import os
30 import sys 30 import sys
31 import re 31 import re
32 32
33 33
34 # Regular expression to find the failed errors in test stdout. 34 # Regular expression to find the failed errors in test stdout.
35 # * Group 1 of the match is the actual error text (backslash-escaped) 35 # * Group 1 of the match is file path (relative to //src) where the
36 # * Group 2 of the match is file path (relative to //src) where the expected 36 # expected errors were read from.
37 # errors were read from. 37 # * Group 2 of the match is the actual error text
38 failed_test_regex = re.compile(r""" 38 failed_test_regex = re.compile(r"""
39 Value of: errors.ToDebugString\(\) 39 Cert errors don't match expectations \((.+?)\)
40 Actual: "(.*)" 40
41 (?:.|\n)+? 41 EXPECTED:
42 Test file: (.*[.]pem) 42
43 (?:.|\n)*?
44 ACTUAL:
45
46 ((?:.|\n)*?)
47 ===> Use net/data/parse_certificate_unittest/rebase-errors.py to rebaseline.
43 """, re.MULTILINE) 48 """, re.MULTILINE)
44 49
45 50
46 # Regular expression to find the ERRORS block (and any text above it) in a PEM 51 # Regular expression to find the ERRORS block (and any text above it) in a PEM
47 # file. The assumption is that ERRORS is not the very first block in the file 52 # file. The assumption is that ERRORS is not the very first block in the file
48 # (since it looks for an -----END to precede it). 53 # (since it looks for an -----END to precede it).
49 # * Group 1 of the match is the ERRORS block content and any comments 54 # * Group 1 of the match is the ERRORS block content and any comments
50 # immediately above it. 55 # immediately above it.
51 errors_block_regex = re.compile(r""".* 56 errors_block_regex = re.compile(r""".*
52 -----END .*?----- 57 -----END .*?-----
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 127
123 # Read the input either from a file, or from stdin. 128 # Read the input either from a file, or from stdin.
124 test_stdout = None 129 test_stdout = None
125 if len(sys.argv) == 2: 130 if len(sys.argv) == 2:
126 test_stdout = read_file_to_string(sys.argv[1]) 131 test_stdout = read_file_to_string(sys.argv[1])
127 else: 132 else:
128 print 'Reading input from stdin...' 133 print 'Reading input from stdin...'
129 test_stdout = sys.stdin.read() 134 test_stdout = sys.stdin.read()
130 135
131 for m in failed_test_regex.finditer(test_stdout): 136 for m in failed_test_regex.finditer(test_stdout):
132 actual_errors = m.group(1) 137 src_relative_errors_path = m.group(1)
133 actual_errors = actual_errors.decode('string-escape') 138 errors_path = get_abs_path(src_relative_errors_path)
134 relative_test_path = m.group(2) 139 actual_errors = m.group(2)
135 fixup_pem_file(get_abs_path(relative_test_path), actual_errors) 140
141 fixup_pem_file(errors_path, actual_errors)
136 142
137 143
138 if __name__ == "__main__": 144 if __name__ == "__main__":
139 main() 145 main()
OLDNEW
« no previous file with comments | « net/cert/internal/verify_certificate_chain_unittest.cc ('k') | net/data/verify_certificate_chain_unittest/README » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698