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
5 # found in the LICENSE file.
7 # This is used to test the findbugs plugin, it calls
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
10 # issue with those in expected_result.txt.
12 # Useful command line:
13 # --rebaseline to generate the expected_result.txt, please make sure don't
14 # remove the expected result of exsting tests.
21 sys
.path
.append(os
.path
.abspath(os
.path
.join(os
.path
.dirname(__file__
),
22 '..', '..', '..', '..',
25 from pylib
import constants
26 from pylib
.utils
import findbugs
29 _EXPECTED_WARNINGS
= set([
30 findbugs
.FindBugsWarning(
31 bug_type
='CHROMIUM_SYNCHRONIZED_THIS',
34 file_name
='SimpleSynchronizedThis.java',
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]',
43 findbugs
.FindBugsWarning(
44 bug_type
='CHROMIUM_SYNCHRONIZED_METHOD',
47 file_name
='SimpleSynchronizedStaticMethod.java',
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]',
56 findbugs
.FindBugsWarning(
57 bug_type
='CHROMIUM_SYNCHRONIZED_METHOD',
60 file_name
='SimpleSynchronizedMethod.java',
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]',
74 parser
= argparse
.ArgumentParser()
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()
80 test_jar_path
= os
.path
.join(
81 constants
.GetOutDirectory(
82 'Release' if args
.release
else 'Debug'),
83 'lib.java', 'findbugs_plugin_test.jar')
85 findbugs_command
, findbugs_warnings
= findbugs
.Run(
86 None, 'org.chromium.tools.findbugs.plugin.*', None, None, None,
89 missing_warnings
= _EXPECTED_WARNINGS
.difference(findbugs_warnings
)
91 print 'Missing warnings:'
92 for w
in missing_warnings
:
95 unexpected_warnings
= findbugs_warnings
.difference(_EXPECTED_WARNINGS
)
96 if unexpected_warnings
:
97 print 'Unexpected warnings:'
98 for w
in unexpected_warnings
:
101 return len(unexpected_warnings
) + len(missing_warnings
)
103 if __name__
== '__main__':
104 sys
.exit(main(sys
.argv
))