OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 # This is used to test the findbugs plugin, it calls | 7 # This is used to test the findbugs plugin, it calls |
8 # build/android/pylib/utils/findbugs.py to analyze the classes in | 8 # build/android/pylib/utils/findbugs.py to analyze the classes in |
9 # org.chromium.tools.findbugs.plugin package, and expects to get the same | 9 # org.chromium.tools.findbugs.plugin package, and expects to get the same |
10 # issue with those in expected_result.txt. | 10 # issue with those in expected_result.txt. |
11 # | 11 # |
12 # Useful command line: | 12 # Useful command line: |
13 # --rebaseline to generate the expected_result.txt, please make sure don't | 13 # --rebaseline to generate the expected_result.txt, please make sure don't |
14 # remove the expected result of exsting tests. | 14 # remove the expected result of exsting tests. |
15 | 15 |
16 | 16 |
17 import optparse | 17 import argparse |
18 import os | 18 import os |
19 import sys | 19 import sys |
20 | 20 |
21 sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), | 21 sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), |
22 '..', '..', '..', '..', | 22 '..', '..', '..', '..', |
23 'build', 'android'))) | 23 'build', 'android'))) |
24 | 24 |
25 from pylib import constants | 25 from pylib import constants |
26 from pylib.utils import findbugs | 26 from pylib.utils import findbugs |
27 | 27 |
28 | 28 |
| 29 _EXPECTED_WARNINGS = set([ |
| 30 findbugs.FindBugsWarning( |
| 31 bug_type='CHROMIUM_SYNCHRONIZED_THIS', |
| 32 start_line=15, |
| 33 end_line=15, |
| 34 file_name='SimpleSynchronizedThis.java', |
| 35 message=( |
| 36 "Shouldn't use synchronized(this)", |
| 37 'In class org.chromium.tools.findbugs.plugin.' |
| 38 + 'SimpleSynchronizedThis', |
| 39 'In method org.chromium.tools.findbugs.plugin.' |
| 40 + 'SimpleSynchronizedThis.synchronizedThis()', |
| 41 'At SimpleSynchronizedThis.java:[line 15]', |
| 42 )), |
| 43 findbugs.FindBugsWarning( |
| 44 bug_type='CHROMIUM_SYNCHRONIZED_METHOD', |
| 45 start_line=14, |
| 46 end_line=14, |
| 47 file_name='SimpleSynchronizedStaticMethod.java', |
| 48 message=( |
| 49 "Shouldn't use synchronized method", |
| 50 'In class org.chromium.tools.findbugs.plugin.' |
| 51 + 'SimpleSynchronizedStaticMethod', |
| 52 'In method org.chromium.tools.findbugs.plugin.' |
| 53 + 'SimpleSynchronizedStaticMethod.synchronizedStaticMethod()', |
| 54 'At SimpleSynchronizedStaticMethod.java:[line 14]', |
| 55 )), |
| 56 findbugs.FindBugsWarning( |
| 57 bug_type='CHROMIUM_SYNCHRONIZED_METHOD', |
| 58 start_line=15, |
| 59 end_line=15, |
| 60 file_name='SimpleSynchronizedMethod.java', |
| 61 message=( |
| 62 "Shouldn't use synchronized method", |
| 63 'In class org.chromium.tools.findbugs.plugin.' |
| 64 + 'SimpleSynchronizedMethod', |
| 65 'In method org.chromium.tools.findbugs.plugin.' |
| 66 + 'SimpleSynchronizedMethod.synchronizedMethod()', |
| 67 'At SimpleSynchronizedMethod.java:[line 15]', |
| 68 )), |
| 69 ]) |
| 70 |
| 71 |
29 def main(argv): | 72 def main(argv): |
30 parser = findbugs.GetCommonParser() | |
31 | 73 |
32 options, _ = parser.parse_args() | 74 parser = argparse.ArgumentParser() |
| 75 parser.add_argument( |
| 76 '-l', '--release-build', action='store_true', dest='release', |
| 77 help='Run the release build of the findbugs plugin test.') |
| 78 args = parser.parse_args() |
33 | 79 |
34 if not options.known_bugs: | 80 test_jar_path = os.path.join( |
35 options.known_bugs = os.path.join(constants.DIR_SOURCE_ROOT, 'tools', | 81 constants.GetOutDirectory( |
36 'android', 'findbugs_plugin', 'test', | 82 'Release' if args.release else 'Debug'), |
37 'expected_result.txt') | 83 'lib.java', 'findbugs_plugin_test.jar') |
38 | 84 |
39 if not options.only_analyze: | 85 findbugs_command, findbugs_warnings = findbugs.Run( |
40 options.only_analyze = 'org.chromium.tools.findbugs.plugin.*' | 86 None, 'org.chromium.tools.findbugs.plugin.*', None, None, None, |
| 87 [test_jar_path]) |
41 | 88 |
42 # crbug.com/449101 | 89 missing_warnings = _EXPECTED_WARNINGS.difference(findbugs_warnings) |
43 # Temporary workaround to have the Android Clang Builder (dbg) bot | 90 if missing_warnings: |
44 # pass the findbugs_tests step. | 91 print 'Missing warnings:' |
45 if not options.exclude: | 92 for w in missing_warnings: |
46 options.exclude = os.path.join(constants.DIR_SOURCE_ROOT, 'build', | 93 print '%s' % str(w) |
47 'android', 'findbugs_filter', | |
48 'findbugs_exclude.xml') | |
49 | 94 |
50 return findbugs.Run(options) | 95 unexpected_warnings = findbugs_warnings.difference(_EXPECTED_WARNINGS) |
| 96 if unexpected_warnings: |
| 97 print 'Unexpected warnings:' |
| 98 for w in unexpected_warnings: |
| 99 print '%s' % str(w) |
| 100 |
| 101 return len(unexpected_warnings) + len(missing_warnings) |
51 | 102 |
52 if __name__ == '__main__': | 103 if __name__ == '__main__': |
53 sys.exit(main(sys.argv)) | 104 sys.exit(main(sys.argv)) |
OLD | NEW |