Enable a subset of error prone rules for hostside tests
Enable couple of rules for CTS host sides tests and fix
the errors.
- TryFailThrowable: fail() is throwing and AssertionError
that was caught resulting in the check always passing.
Test: make cts javac-check -j76 TARGET_PRODUCT=aosp_arm64
WITH_DEXPREOPT=false RUN_ERROR_PRONE=true
Bug: 37854485
Change-Id: I99319c3e3083cc01b5be18fb33c6ae2a30ee9c30
diff --git a/build/config.mk b/build/config.mk
index 573dc7b..159dc8d 100644
--- a/build/config.mk
+++ b/build/config.mk
@@ -20,7 +20,7 @@
BUILD_COMPATIBILITY_SUITE := cts/build/compatibility_test_suite.mk
BUILD_CTS_EXECUTABLE := cts/build/test_executable.mk
BUILD_CTS_PACKAGE := cts/build/test_package.mk
-BUILD_CTS_HOST_JAVA_LIBRARY := $(BUILD_HOST_JAVA_LIBRARY)
+BUILD_CTS_HOST_JAVA_LIBRARY := cts/build/host_java_library.mk
BUILD_CTS_TARGET_JAVA_LIBRARY := cts/build/test_target_java_library.mk
BUILD_CTS_SUPPORT_PACKAGE := cts/build/support_package.mk
BUILD_CTS_DEVICE_INFO_PACKAGE := cts/build/device_info_package.mk
diff --git a/build/host_java_library.mk b/build/host_java_library.mk
new file mode 100644
index 0000000..303527e
--- /dev/null
+++ b/build/host_java_library.mk
@@ -0,0 +1,22 @@
+# Copyright (C) 2017 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Builds a java library (jar)
+#
+# Replace "include $(BUILD_HOST_JAVA_LIBRARY) with "include $(BUILD_CTS_HOST_JAVA_LIBRARY)
+#
+
+-include cts/error_prone_rules_tests.mk
+
+include $(BUILD_HOST_JAVA_LIBRARY)
diff --git a/error_prone_rules_tests.mk b/error_prone_rules_tests.mk
new file mode 100644
index 0000000..78cb3a0
--- /dev/null
+++ b/error_prone_rules_tests.mk
@@ -0,0 +1,21 @@
+# Copyright (C) 2017 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Set of error prone rules to ensure code quality of tests
+
+# Goal is to eventually merge with error_prone_rules.mk
+LOCAL_ERROR_PRONE_FLAGS:= -Xep:JUnit3TestNotRun:ERROR \
+ -Xep:JUnitAmbiguousTestClass:ERROR \
+ -Xep:TryFailThrowable:ERROR
+
diff --git a/hostsidetests/appsecurity/src/android/appsecurity/cts/AdoptableHostTest.java b/hostsidetests/appsecurity/src/android/appsecurity/cts/AdoptableHostTest.java
index 16e2765..78b03e4 100644
--- a/hostsidetests/appsecurity/src/android/appsecurity/cts/AdoptableHostTest.java
+++ b/hostsidetests/appsecurity/src/android/appsecurity/cts/AdoptableHostTest.java
@@ -269,10 +269,14 @@
// Kick through a remount cycle, which should purge the adopted app
getDevice().executeShellCommand("sm mount " + vol.volId);
runDeviceTests(PKG, CLASS, "testDataInternal");
+ boolean didThrow = false;
try {
runDeviceTests(PKG, CLASS, "testDataRead");
- fail("Unexpected data from adopted volume picked up");
} catch (AssertionError expected) {
+ didThrow = true;
+ }
+ if (!didThrow) {
+ fail("Unexpected data from adopted volume picked up");
}
getDevice().executeShellCommand("sm unmount " + vol.volId);
diff --git a/hostsidetests/appsecurity/src/android/appsecurity/cts/PermissionsHostTest.java b/hostsidetests/appsecurity/src/android/appsecurity/cts/PermissionsHostTest.java
index b7f7f88..79f838c 100644
--- a/hostsidetests/appsecurity/src/android/appsecurity/cts/PermissionsHostTest.java
+++ b/hostsidetests/appsecurity/src/android/appsecurity/cts/PermissionsHostTest.java
@@ -76,22 +76,30 @@
public void testFail() throws Exception {
// Sanity check that remote failure is host failure
assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false));
+ boolean didThrow = false;
try {
runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23",
"testFail");
- fail("Expected remote failure");
} catch (AssertionError expected) {
+ didThrow = true;
+ }
+ if (!didThrow) {
+ fail("Expected remote failure");
}
}
public void testKill() throws Exception {
// Sanity check that remote kill is host failure
assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false));
+ boolean didThrow = false;
try {
runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23",
"testKill");
- fail("Expected remote failure");
} catch (AssertionError expected) {
+ didThrow = true;
+ }
+ if (!didThrow) {
+ fail("Expected remote failure");
}
}
@@ -103,11 +111,15 @@
public void testCompatRevoked22() throws Exception {
assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_22), false, false));
+ boolean didThrow = false;
try {
runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest22",
"testCompatRevoked_part1");
- fail("App must be killed on a permission revoke");
} catch (AssertionError expected) {
+ didThrow = true;
+ }
+ if (!didThrow) {
+ fail("App must be killed on a permission revoke");
}
runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest22",
"testCompatRevoked_part2");
@@ -169,10 +181,15 @@
public void testRevokeAffectsWholeGroup23() throws Exception {
assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false));
+ boolean didThrow = false;
try {
runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23",
"testRevokeAffectsWholeGroup_part1");
} catch (AssertionError expected) {
+ didThrow = true;
+ }
+ if (!didThrow) {
+ fail("Should have thrown an exception.");
}
runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23",
"testRevokeAffectsWholeGroup_part2");
@@ -180,11 +197,15 @@
public void testGrantPreviouslyRevokedWithPrejudiceShowsPrompt23() throws Exception {
assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false));
+ boolean didThrow = false;
try {
runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23",
"testGrantPreviouslyRevokedWithPrejudiceShowsPrompt_part1");
- fail("App must be killed on a permission revoke");
} catch (Throwable expected) {
+ didThrow = true;
+ }
+ if (!didThrow) {
+ fail("App must be killed on a permission revoke");
}
runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23",
"testGrantPreviouslyRevokedWithPrejudiceShowsPrompt_part2");
@@ -225,10 +246,14 @@
public void testNoDowngradePermissionModel() throws Exception {
assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), false, false));
+ boolean didThrow = false;
try {
assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_22), true, false));
- fail("Permission mode downgrade not allowed");
} catch (AssertionError expected) {
+ didThrow = true;
+ }
+ if (!didThrow) {
+ fail("Permission mode downgrade not allowed");
}
}
@@ -244,11 +269,15 @@
public void testRevokePropagatedOnUpgradeOldToNewModel() throws Exception {
assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_22), false, false));
+ boolean didThrow = false;
try {
runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest22",
"testRevokePropagatedOnUpgradeOldToNewModel_part1");
- fail("App must be killed on a permission revoke");
} catch (AssertionError expected) {
+ didThrow = true;
+ }
+ if (!didThrow) {
+ fail("App must be killed on a permission revoke");
}
assertNull(getDevice().installPackage(mBuildHelper.getTestFile(APK_23), true, false));
runDeviceTests(USES_PERMISSION_PKG, "com.android.cts.usepermission.UsePermissionTest23",