summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-06-01 23:19:44 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-06-01 23:19:44 +0000
commit49baeff9b0fe2ccd29521a6d53f9224a2150d39f (patch)
tree9c23b7aabf3a64542bf8398e513cdf4bf7fbe8b0
parentbd7681d55a8e992bee0f11de868024d1b27ec269 (diff)
parente9e4899984d3e43568c67851d4d34d86eef26bbf (diff)
Snap for 8671908 from e9e4899984d3e43568c67851d4d34d86eef26bbf to tm-d1-release
Change-Id: Ic9af803c99ec4040c62fa2eb9eef0e01b2478b76
-rw-r--r--common/device/com/android/net/module/util/FdEventsReader.java2
-rw-r--r--common/testutils/devicetests/com/android/testutils/DevSdkIgnoreRule.kt28
-rw-r--r--common/testutils/devicetests/com/android/testutils/filters/CtsNetTestCasesMaxTargetSdk31.kt22
3 files changed, 46 insertions, 6 deletions
diff --git a/common/device/com/android/net/module/util/FdEventsReader.java b/common/device/com/android/net/module/util/FdEventsReader.java
index 71ae13d..ecf8e77 100644
--- a/common/device/com/android/net/module/util/FdEventsReader.java
+++ b/common/device/com/android/net/module/util/FdEventsReader.java
@@ -211,7 +211,7 @@ public abstract class FdEventsReader<BufferType> {
return true;
}
- private boolean isRunning() {
+ protected boolean isRunning() {
return (mFd != null) && mFd.valid();
}
diff --git a/common/testutils/devicetests/com/android/testutils/DevSdkIgnoreRule.kt b/common/testutils/devicetests/com/android/testutils/DevSdkIgnoreRule.kt
index 8b58e71..2d2f5a6 100644
--- a/common/testutils/devicetests/com/android/testutils/DevSdkIgnoreRule.kt
+++ b/common/testutils/devicetests/com/android/testutils/DevSdkIgnoreRule.kt
@@ -17,16 +17,21 @@
package com.android.testutils
import android.os.Build
+import androidx.test.InstrumentationRegistry
import com.android.modules.utils.build.SdkLevel
import kotlin.test.fail
import org.junit.Assume.assumeTrue
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
+import java.util.regex.Pattern
// TODO: Remove it when Build.VERSION_CODES.SC_V2 is available
const val SC_V2 = 32
+private val MAX_TARGET_SDK_ANNOTATION_RE = Pattern.compile("MaxTargetSdk([0-9]+)$")
+private val targetSdk = InstrumentationRegistry.getContext().applicationInfo.targetSdkVersion
+
/**
* Returns true if the development SDK version of the device is in the provided range.
*
@@ -67,6 +72,14 @@ private fun isDevSdkUpTo(maxInclusive: Int): Boolean {
}
}
+private fun getMaxTargetSdk(description: Description): Int? {
+ return description.annotations.firstNotNullOfOrNull {
+ MAX_TARGET_SDK_ANNOTATION_RE.matcher(it::class.simpleName).let { m ->
+ if (m.find()) m.group(1).toIntOrNull() else null
+ }
+ }
+}
+
/**
* A test rule to ignore tests based on the development SDK level.
*
@@ -108,11 +121,16 @@ class DevSdkIgnoreRule @JvmOverloads constructor(
val ignoreAfter = description.getAnnotation(IgnoreAfter::class.java)
val ignoreUpTo = description.getAnnotation(IgnoreUpTo::class.java)
- val message = "Skipping test for build ${Build.VERSION.CODENAME} " +
+ val devSdkMessage = "Skipping test for build ${Build.VERSION.CODENAME} " +
"with SDK ${Build.VERSION.SDK_INT}"
- assumeTrue(message, isDevSdkInRange(ignoreClassUpTo, ignoreClassAfter))
- assumeTrue(message, isDevSdkInRange(ignoreUpTo?.value, ignoreAfter?.value))
- base.evaluate()
+ assumeTrue(devSdkMessage, isDevSdkInRange(ignoreClassUpTo, ignoreClassAfter))
+ assumeTrue(devSdkMessage, isDevSdkInRange(ignoreUpTo?.value, ignoreAfter?.value))
+
+ val maxTargetSdk = getMaxTargetSdk(description)
+ if (maxTargetSdk != null) {
+ assumeTrue("Skipping test, target SDK $targetSdk greater than $maxTargetSdk",
+ targetSdk <= maxTargetSdk)
+ }
}
}
-} \ No newline at end of file
+}
diff --git a/common/testutils/devicetests/com/android/testutils/filters/CtsNetTestCasesMaxTargetSdk31.kt b/common/testutils/devicetests/com/android/testutils/filters/CtsNetTestCasesMaxTargetSdk31.kt
new file mode 100644
index 0000000..be0103d
--- /dev/null
+++ b/common/testutils/devicetests/com/android/testutils/filters/CtsNetTestCasesMaxTargetSdk31.kt
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2020 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.
+ */
+
+package com.android.testutils.filters
+
+/**
+ * Only run this test in the CtsNetTestCasesMaxTargetSdk31 suite.
+ */
+annotation class CtsNetTestCasesMaxTargetSdk31(val reason: String)