summaryrefslogtreecommitdiffstats
path: root/tools/android
diff options
context:
space:
mode:
authormichaelbai@chromium.org <michaelbai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-01 18:24:28 +0000
committermichaelbai@chromium.org <michaelbai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-01 18:24:28 +0000
commitb9c9f20c55fdf632dd5a1840356c6c6f3f10a9fb (patch)
tree3d16ec77e967cb1f334a5434c89115b383f9d6f5 /tools/android
parent6e76b73ebfade134c07c7f83ee6ddfb34e2553e7 (diff)
downloadchromium_src-b9c9f20c55fdf632dd5a1840356c6c6f3f10a9fb.zip
chromium_src-b9c9f20c55fdf632dd5a1840356c6c6f3f10a9fb.tar.gz
chromium_src-b9c9f20c55fdf632dd5a1840356c6c6f3f10a9fb.tar.bz2
Added test for findbugs plugin.
- The java files had the issue that findbugd plugin need to find out, they compiled with the same configuration as chrome for android's. - The run_findbugs_plugin_tests.py runs the findbugs against the above Java classes, and expects to find the same issues as those in expected_result.txt. BUG=143971, 157970 Review URL: https://chromiumcodereview.appspot.com/11343057 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165442 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/android')
-rw-r--r--tools/android/findbugs_plugin/test/expected_result.txt3
-rw-r--r--tools/android/findbugs_plugin/test/java/src/org/chromium/tools/findbugs/plugin/SimpleSynchronizedMethod.java16
-rw-r--r--tools/android/findbugs_plugin/test/java/src/org/chromium/tools/findbugs/plugin/SimpleSynchronizedStaticMethod.java15
-rw-r--r--tools/android/findbugs_plugin/test/java/src/org/chromium/tools/findbugs/plugin/SimpleSynchronizedThis.java19
-rwxr-xr-xtools/android/findbugs_plugin/test/run_findbugs_plugin_tests.py48
5 files changed, 101 insertions, 0 deletions
diff --git a/tools/android/findbugs_plugin/test/expected_result.txt b/tools/android/findbugs_plugin/test/expected_result.txt
new file mode 100644
index 0000000..076b007
--- /dev/null
+++ b/tools/android/findbugs_plugin/test/expected_result.txt
@@ -0,0 +1,3 @@
+M C CSM: Shouldn't use synchronized method, please narrow down the synchronization scope. At SimpleSynchronizedMethod.java
+M C CSM: Shouldn't use synchronized method, please narrow down the synchronization scope. At SimpleSynchronizedStaticMethod.java
+M C CST: Shouldn't use synchronized(this), please narrow down the synchronization scope. At SimpleSynchronizedThis.java
diff --git a/tools/android/findbugs_plugin/test/java/src/org/chromium/tools/findbugs/plugin/SimpleSynchronizedMethod.java b/tools/android/findbugs_plugin/test/java/src/org/chromium/tools/findbugs/plugin/SimpleSynchronizedMethod.java
new file mode 100644
index 0000000..c04a35c
--- /dev/null
+++ b/tools/android/findbugs_plugin/test/java/src/org/chromium/tools/findbugs/plugin/SimpleSynchronizedMethod.java
@@ -0,0 +1,16 @@
+// Copyright (c) 2012 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.
+
+package org.chromium.tools.findbugs.plugin;
+
+/**
+ * This class has synchronized method and is used to test
+ * SynchronizedMethodDetector.
+ */
+class SimpleSynchronizedMethod {
+ private int i = 0;
+ synchronized void synchronizedMethod() {
+ i++;
+ }
+}
diff --git a/tools/android/findbugs_plugin/test/java/src/org/chromium/tools/findbugs/plugin/SimpleSynchronizedStaticMethod.java b/tools/android/findbugs_plugin/test/java/src/org/chromium/tools/findbugs/plugin/SimpleSynchronizedStaticMethod.java
new file mode 100644
index 0000000..0af6582
--- /dev/null
+++ b/tools/android/findbugs_plugin/test/java/src/org/chromium/tools/findbugs/plugin/SimpleSynchronizedStaticMethod.java
@@ -0,0 +1,15 @@
+// Copyright (c) 2012 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.
+
+package org.chromium.tools.findbugs.plugin;
+
+/**
+ * This class is used to test SynchronizedMethodDetector
+ */
+class SimpleSynchronizedStaticMethod {
+ private static int i = 0;
+ synchronized static void synchronizedStaticMethod() {
+ i++;
+ }
+}
diff --git a/tools/android/findbugs_plugin/test/java/src/org/chromium/tools/findbugs/plugin/SimpleSynchronizedThis.java b/tools/android/findbugs_plugin/test/java/src/org/chromium/tools/findbugs/plugin/SimpleSynchronizedThis.java
new file mode 100644
index 0000000..2c7e6fd
--- /dev/null
+++ b/tools/android/findbugs_plugin/test/java/src/org/chromium/tools/findbugs/plugin/SimpleSynchronizedThis.java
@@ -0,0 +1,19 @@
+// Copyright (c) 2012 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.
+
+package org.chromium.tools.findbugs.plugin;
+
+/**
+ * This class has synchronized(this) statement and is used to test
+ * SynchronizedThisDetector.
+ */
+class SimpleSynchronizedThis {
+ private int i = 0;
+
+ void synchronizedThis() {
+ synchronized(this) {
+ i++;
+ }
+ }
+}
diff --git a/tools/android/findbugs_plugin/test/run_findbugs_plugin_tests.py b/tools/android/findbugs_plugin/test/run_findbugs_plugin_tests.py
new file mode 100755
index 0000000..1115192
--- /dev/null
+++ b/tools/android/findbugs_plugin/test/run_findbugs_plugin_tests.py
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2012 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.
+
+# This is used to test the findbugs plugin, it calls
+# build/android/pylib/findbugs.py to analyze the classes in
+# org.chromium.tools.findbugs.plugin package, and expects to get the same
+# issue with those in expected_result.txt.
+#
+# Useful command line:
+# --rebaseline to generate the expected_result.txt, please make sure don't
+# remove the expected result of exsting tests.
+
+
+import optparse
+import os
+import sys
+
+lib_folder = os.path.join(os.getenv('CHROME_SRC'), 'build', 'android', 'pylib')
+if lib_folder not in sys.path:
+ sys.path.append(lib_folder)
+
+import findbugs
+
+
+def main(argv):
+ if not findbugs.CheckEnvironment():
+ return 1
+
+ parser = findbugs.GetCommonParser()
+
+ options, _ = parser.parse_args()
+
+ chrome_src = os.getenv('CHROME_SRC')
+
+ if not options.known_bugs:
+ options.known_bugs = os.path.join(chrome_src, 'tools', 'android',
+ 'findbugs_plugin', 'test',
+ 'expected_result.txt')
+ if not options.only_analyze:
+ options.only_analyze = 'org.chromium.tools.findbugs.plugin.*'
+
+ return findbugs.Run(options)
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))