diff options
88 files changed, 969 insertions, 236 deletions
diff --git a/core/java/android/os/Binder.java b/core/java/android/os/Binder.java index 0ccc485a34f4..02e40cfbecaa 100644 --- a/core/java/android/os/Binder.java +++ b/core/java/android/os/Binder.java @@ -396,6 +396,7 @@ public class Binder implements IBinder { * This is Test API which will be used to override output of isDirectlyHandlingTransactionNative * @hide */ + @android.ravenwood.annotation.RavenwoodKeep public static void setIsDirectlyHandlingTransactionOverride(boolean isInTransaction) { sIsHandlingBinderTransaction = isInTransaction; } @@ -1068,6 +1069,7 @@ public class Binder implements IBinder { * * @hide */ + @android.ravenwood.annotation.RavenwoodKeep public @Nullable String getTransactionName(int transactionCode) { return null; } @@ -1076,6 +1078,7 @@ public class Binder implements IBinder { * @hide */ @VisibleForTesting + @android.ravenwood.annotation.RavenwoodKeep public final @Nullable String getTransactionTraceName(int transactionCode) { final boolean isInterfaceUserDefined = getMaxTransactionId() == 0; if (mTransactionTraceNames == null) { @@ -1113,6 +1116,7 @@ public class Binder implements IBinder { return transactionTraceName; } + @android.ravenwood.annotation.RavenwoodKeep private @NonNull String getSimpleDescriptor() { String descriptor = mDescriptor; if (descriptor == null) { @@ -1132,6 +1136,7 @@ public class Binder implements IBinder { * @return The highest user-defined transaction id of all transactions. * @hide */ + @android.ravenwood.annotation.RavenwoodKeep public int getMaxTransactionId() { return 0; } diff --git a/core/java/android/os/Broadcaster.java b/core/java/android/os/Broadcaster.java index 88760b0b6828..17cf69296015 100644 --- a/core/java/android/os/Broadcaster.java +++ b/core/java/android/os/Broadcaster.java @@ -19,6 +19,7 @@ package android.os; import android.compat.annotation.UnsupportedAppUsage; /** @hide */ +@android.ravenwood.annotation.RavenwoodKeepWholeClass public class Broadcaster { @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) diff --git a/core/java/android/os/BundleMerger.java b/core/java/android/os/BundleMerger.java index 857aaf57f640..dc243a5e9c08 100644 --- a/core/java/android/os/BundleMerger.java +++ b/core/java/android/os/BundleMerger.java @@ -48,6 +48,7 @@ import java.util.function.BinaryOperator; * * @hide */ +@android.ravenwood.annotation.RavenwoodKeepWholeClass public class BundleMerger implements Parcelable { private static final String TAG = "BundleMerger"; diff --git a/core/java/android/os/PackageTagsList.java b/core/java/android/os/PackageTagsList.java index df99074a851f..cbc427207ccf 100644 --- a/core/java/android/os/PackageTagsList.java +++ b/core/java/android/os/PackageTagsList.java @@ -41,6 +41,7 @@ import java.util.Set; */ @TestApi @Immutable +@android.ravenwood.annotation.RavenwoodKeepWholeClass public final class PackageTagsList implements Parcelable { // an empty set value matches any attribution tag (ie, wildcard) diff --git a/core/java/android/os/TimestampedValue.java b/core/java/android/os/TimestampedValue.java index 3d8a5504b56d..e514d63aa147 100644 --- a/core/java/android/os/TimestampedValue.java +++ b/core/java/android/os/TimestampedValue.java @@ -35,6 +35,7 @@ import java.util.Objects; * @param <T> the type of the value with an associated timestamp * @hide */ +@android.ravenwood.annotation.RavenwoodKeepWholeClass public final class TimestampedValue<T> implements Parcelable { private final long mReferenceTimeMillis; @Nullable diff --git a/core/java/android/os/WorkSource.java b/core/java/android/os/WorkSource.java index bc80c8b20b86..6d4e28403908 100644 --- a/core/java/android/os/WorkSource.java +++ b/core/java/android/os/WorkSource.java @@ -23,6 +23,7 @@ import java.util.Objects; * Currently the public representation of what a work source is not * defined; this is an opaque container. */ +@android.ravenwood.annotation.RavenwoodKeepWholeClass public class WorkSource implements Parcelable { static final String TAG = "WorkSource"; static final boolean DEBUG = false; @@ -141,11 +142,17 @@ public class WorkSource implements Parcelable { * * @hide */ + @android.ravenwood.annotation.RavenwoodReplace public static boolean isChainedBatteryAttributionEnabled(Context context) { return Settings.Global.getInt(context.getContentResolver(), Global.CHAINED_BATTERY_ATTRIBUTION_ENABLED, 0) == 1; } + /** @hide */ + public static boolean isChainedBatteryAttributionEnabled$ravenwood(Context context) { + return false; + } + /** * Returns the number of uids in this work source. * @hide diff --git a/core/java/com/android/internal/os/BinderCallHeavyHitterWatcher.java b/core/java/com/android/internal/os/BinderCallHeavyHitterWatcher.java index 7701761baac8..00043cfcd56b 100644 --- a/core/java/com/android/internal/os/BinderCallHeavyHitterWatcher.java +++ b/core/java/com/android/internal/os/BinderCallHeavyHitterWatcher.java @@ -33,6 +33,7 @@ import java.util.List; * A watcher which makes stats on the incoming binder transaction, if the amount of some type of * transactions exceeds the threshold, the listener will be notified. */ +@android.ravenwood.annotation.RavenwoodKeepWholeClass public final class BinderCallHeavyHitterWatcher { private static final String TAG = "BinderCallHeavyHitterWatcher"; diff --git a/core/java/com/android/internal/os/BinderDeathDispatcher.java b/core/java/com/android/internal/os/BinderDeathDispatcher.java index 8ca6241e63c6..e7abe2a83ad8 100644 --- a/core/java/com/android/internal/os/BinderDeathDispatcher.java +++ b/core/java/com/android/internal/os/BinderDeathDispatcher.java @@ -36,6 +36,7 @@ import com.android.internal.annotations.VisibleForTesting; * * test with: atest FrameworksCoreTests:BinderDeathDispatcherTest */ +@android.ravenwood.annotation.RavenwoodKeepWholeClass public class BinderDeathDispatcher<T extends IInterface> { private static final String TAG = "BinderDeathDispatcher"; diff --git a/core/java/com/android/internal/os/BinderLatencyBuckets.java b/core/java/com/android/internal/os/BinderLatencyBuckets.java index d7d2d6a8f9dd..5679bc778eee 100644 --- a/core/java/com/android/internal/os/BinderLatencyBuckets.java +++ b/core/java/com/android/internal/os/BinderLatencyBuckets.java @@ -26,6 +26,7 @@ import java.util.Arrays; * Generates the bucket thresholds (with a custom logarithmic scale) for a histogram to store * latency samples in. */ +@android.ravenwood.annotation.RavenwoodKeepWholeClass public class BinderLatencyBuckets { private static final String TAG = "BinderLatencyBuckets"; private final int[] mBuckets; diff --git a/core/java/com/android/internal/os/BinderfsStatsReader.java b/core/java/com/android/internal/os/BinderfsStatsReader.java index 9cc4a35b5c65..66f91e192a88 100644 --- a/core/java/com/android/internal/os/BinderfsStatsReader.java +++ b/core/java/com/android/internal/os/BinderfsStatsReader.java @@ -43,6 +43,7 @@ import java.util.function.Predicate; * free async space 520192 * ... */ +@android.ravenwood.annotation.RavenwoodKeepWholeClass public class BinderfsStatsReader { private final String mPath; diff --git a/core/java/com/android/internal/os/CachedDeviceState.java b/core/java/com/android/internal/os/CachedDeviceState.java index 334cca317c30..ac92f866eb7e 100644 --- a/core/java/com/android/internal/os/CachedDeviceState.java +++ b/core/java/com/android/internal/os/CachedDeviceState.java @@ -30,6 +30,7 @@ import java.util.ArrayList; * * @hide */ +@android.ravenwood.annotation.RavenwoodKeepWholeClass public class CachedDeviceState { private volatile boolean mScreenInteractive; private volatile boolean mCharging; diff --git a/core/java/com/android/internal/os/Clock.java b/core/java/com/android/internal/os/Clock.java index 45007c48777f..c2403d1e9f89 100644 --- a/core/java/com/android/internal/os/Clock.java +++ b/core/java/com/android/internal/os/Clock.java @@ -21,6 +21,7 @@ import android.os.SystemClock; /** * A wrapper for SystemClock, intended for mocking in unit tests. */ +@android.ravenwood.annotation.RavenwoodKeepWholeClass public abstract class Clock { /** Elapsed Realtime, see SystemClock.elapsedRealtime() */ public long elapsedRealtime() { diff --git a/core/java/com/android/internal/os/CpuScalingPolicies.java b/core/java/com/android/internal/os/CpuScalingPolicies.java index 6dbe8ab5f567..f61cf97c3277 100644 --- a/core/java/com/android/internal/os/CpuScalingPolicies.java +++ b/core/java/com/android/internal/os/CpuScalingPolicies.java @@ -27,6 +27,7 @@ import java.util.Arrays; * CPU scaling policies: the policy IDs and corresponding supported scaling for those * policies. */ +@android.ravenwood.annotation.RavenwoodKeepWholeClass public class CpuScalingPolicies { private final SparseArray<int[]> mCpusByPolicy; private final SparseArray<int[]> mFreqsByPolicy; diff --git a/core/java/com/android/internal/os/CpuScalingPolicyReader.java b/core/java/com/android/internal/os/CpuScalingPolicyReader.java index c96089a5c9c9..0d272fdd1578 100644 --- a/core/java/com/android/internal/os/CpuScalingPolicyReader.java +++ b/core/java/com/android/internal/os/CpuScalingPolicyReader.java @@ -40,6 +40,7 @@ import java.util.regex.Pattern; * href="https://www.kernel.org/doc/html/latest/admin-guide/pm/cpufreq.html * #policy-interface-in-sysfs">Policy Interface in sysfs</a> */ +@android.ravenwood.annotation.RavenwoodKeepWholeClass public class CpuScalingPolicyReader { private static final String TAG = "CpuScalingPolicyReader"; private static final String CPUFREQ_DIR = "/sys/devices/system/cpu/cpufreq"; diff --git a/core/java/com/android/internal/os/KernelCpuThreadReader.java b/core/java/com/android/internal/os/KernelCpuThreadReader.java index 0843741d237c..5b6d1b63a42f 100644 --- a/core/java/com/android/internal/os/KernelCpuThreadReader.java +++ b/core/java/com/android/internal/os/KernelCpuThreadReader.java @@ -244,7 +244,8 @@ public class KernelCpuThreadReader { } /** Set the UID predicate for {@link #getProcessCpuUsage} */ - void setUidPredicate(Predicate<Integer> uidPredicate) { + @VisibleForTesting + public void setUidPredicate(Predicate<Integer> uidPredicate) { mUidPredicate = uidPredicate; } diff --git a/core/java/com/android/internal/os/LoggingPrintStream.java b/core/java/com/android/internal/os/LoggingPrintStream.java index d27874cd3be2..4bf92bb5e256 100644 --- a/core/java/com/android/internal/os/LoggingPrintStream.java +++ b/core/java/com/android/internal/os/LoggingPrintStream.java @@ -36,6 +36,7 @@ import com.android.internal.annotations.VisibleForTesting; * {@hide} */ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) +@android.ravenwood.annotation.RavenwoodKeepWholeClass public abstract class LoggingPrintStream extends PrintStream { private final StringBuilder builder = new StringBuilder(); diff --git a/core/java/com/android/internal/os/LooperStats.java b/core/java/com/android/internal/os/LooperStats.java index 0645eb7f0835..bbcea8af2b87 100644 --- a/core/java/com/android/internal/os/LooperStats.java +++ b/core/java/com/android/internal/os/LooperStats.java @@ -36,6 +36,7 @@ import java.util.concurrent.ThreadLocalRandom; * * @hide Only for use within the system server. */ +@android.ravenwood.annotation.RavenwoodKeepWholeClass public class LooperStats implements Looper.Observer { public static final String DEBUG_ENTRY_PREFIX = "__DEBUG_"; private static final int SESSION_POOL_SIZE = 50; diff --git a/core/java/com/android/internal/os/MonotonicClock.java b/core/java/com/android/internal/os/MonotonicClock.java index 661628a8c148..c3bcfa6b2cc2 100644 --- a/core/java/com/android/internal/os/MonotonicClock.java +++ b/core/java/com/android/internal/os/MonotonicClock.java @@ -40,6 +40,7 @@ import java.nio.charset.StandardCharsets; * A clock that is similar to SystemClock#elapsedRealtime(), except that it is not reset * on reboot, but keeps going. */ +@android.ravenwood.annotation.RavenwoodKeepWholeClass public class MonotonicClock { private static final String TAG = "MonotonicClock"; diff --git a/core/java/com/android/internal/os/ProcLocksReader.java b/core/java/com/android/internal/os/ProcLocksReader.java index 9ddb8c75f5c8..6b85e08877ae 100644 --- a/core/java/com/android/internal/os/ProcLocksReader.java +++ b/core/java/com/android/internal/os/ProcLocksReader.java @@ -34,6 +34,7 @@ import java.io.IOException; * 3: POSIX ADVISORY READ 3888 fd:09:13992 128 128 * 4: POSIX ADVISORY READ 3888 fd:09:14230 1073741826 1073742335 */ +@android.ravenwood.annotation.RavenwoodKeepWholeClass public class ProcLocksReader { private final String mPath; private ProcFileReader mReader = null; diff --git a/core/java/com/android/internal/os/ProcStatsUtil.java b/core/java/com/android/internal/os/ProcStatsUtil.java index 0002447fda2a..b67190bc7e88 100644 --- a/core/java/com/android/internal/os/ProcStatsUtil.java +++ b/core/java/com/android/internal/os/ProcStatsUtil.java @@ -30,6 +30,7 @@ import java.io.IOException; * Utility functions for reading {@code proc} files */ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PROTECTED) +@android.ravenwood.annotation.RavenwoodKeepWholeClass public final class ProcStatsUtil { private static final boolean DEBUG = false; @@ -92,10 +93,24 @@ public final class ProcStatsUtil { * seen, or at the end of the file */ @Nullable + @android.ravenwood.annotation.RavenwoodReplace public static String readTerminatedProcFile(String path, byte terminator) { // Permit disk reads here, as /proc isn't really "on disk" and should be fast. // TODO: make BlockGuard ignore /proc/ and /sys/ files perhaps? final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads(); + try { + return readTerminatedProcFileInternal(path, terminator); + } finally { + StrictMode.setThreadPolicy(savedPolicy); + } + } + + public static String readTerminatedProcFile$ravenwood(String path, byte terminator) { + // No StrictMode under Ravenwood + return readTerminatedProcFileInternal(path, terminator); + } + + private static String readTerminatedProcFileInternal(String path, byte terminator) { try (FileInputStream is = new FileInputStream(path)) { ByteArrayOutputStream byteStream = null; final byte[] buffer = new byte[READ_SIZE]; @@ -147,8 +162,6 @@ public final class ProcStatsUtil { Slog.d(TAG, "Failed to open proc file", e); } return null; - } finally { - StrictMode.setThreadPolicy(savedPolicy); } } } diff --git a/core/java/com/android/internal/os/StoragedUidIoStatsReader.java b/core/java/com/android/internal/os/StoragedUidIoStatsReader.java index 9b0346923cd3..2d485dac4859 100644 --- a/core/java/com/android/internal/os/StoragedUidIoStatsReader.java +++ b/core/java/com/android/internal/os/StoragedUidIoStatsReader.java @@ -38,6 +38,7 @@ import java.nio.file.Files; * This provides the number of bytes/chars read/written in foreground/background for each uid. * The file contains a monotonically increasing count of bytes/chars for a single boot. */ +@android.ravenwood.annotation.RavenwoodKeepWholeClass public class StoragedUidIoStatsReader { private static final String TAG = StoragedUidIoStatsReader.class.getSimpleName(); @@ -73,8 +74,21 @@ public class StoragedUidIoStatsReader { * * @param callback The callback to invoke for each line of the proc file. */ + @android.ravenwood.annotation.RavenwoodReplace public void readAbsolute(Callback callback) { final int oldMask = StrictMode.allowThreadDiskReadsMask(); + try { + readAbsoluteInternal(callback); + } finally { + StrictMode.setThreadPolicyMask(oldMask); + } + } + + public void readAbsolute$ravenwood(Callback callback) { + readAbsoluteInternal(callback); + } + + private void readAbsoluteInternal(Callback callback) { File file = new File(sUidIoFile); try (BufferedReader reader = Files.newBufferedReader(file.toPath())) { String line; @@ -106,8 +120,6 @@ public class StoragedUidIoStatsReader { } } catch (IOException e) { Slog.e(TAG, "Failed to read " + sUidIoFile + ": " + e.getMessage()); - } finally { - StrictMode.setThreadPolicyMask(oldMask); } } } diff --git a/core/tests/coretests/Android.bp b/core/tests/coretests/Android.bp index 6706c916a0e2..1a3ec27418a6 100644 --- a/core/tests/coretests/Android.bp +++ b/core/tests/coretests/Android.bp @@ -7,19 +7,35 @@ package { default_applicable_licenses: ["frameworks_base_license"], } -android_test { - name: "FrameworksCoreTests", - +filegroup { + name: "FrameworksCoreTests-aidl", srcs: [ - "src/**/*.java", - "src/**/*.kt", "src/**/I*.aidl", + "aidl/**/I*.aidl", + ], + visibility: ["//visibility:private"], +} + +filegroup { + name: "FrameworksCoreTests-helpers", + srcs: [ "DisabledTestApp/src/**/*.java", "EnabledTestApp/src/**/*.java", "BinderProxyCountingTestApp/src/**/*.java", "BinderProxyCountingTestService/src/**/*.java", "BinderDeathRecipientHelperApp/src/**/*.java", - "aidl/**/I*.aidl", + ], + visibility: ["//visibility:private"], +} + +android_test { + name: "FrameworksCoreTests", + + srcs: [ + "src/**/*.java", + "src/**/*.kt", + ":FrameworksCoreTests-aidl", + ":FrameworksCoreTests-helpers", ":FrameworksCoreTestDoubles-sources", ], @@ -177,17 +193,29 @@ android_ravenwood_test { "androidx.annotation_annotation", "androidx.test.rules", "androidx.test.ext.junit", + "androidx.test.uiautomator_uiautomator", + "compatibility-device-util-axt", + "flag-junit", "mockito_ravenwood", "platform-test-annotations", "flag-junit", + "testng", ], srcs: [ - "src/android/os/BuildTest.java", - "src/android/os/FileUtilsTest.java", + "src/android/os/**/*.java", + "src/com/android/internal/os/**/*.java", "src/android/util/**/*.java", "src/com/android/internal/os/LongArrayMultiStateCounterTest.java", "src/com/android/internal/util/**/*.java", - "testdoubles/src/com/android/internal/util/**/*.java", + "src/com/android/internal/power/EnergyConsumerStatsTest.java", + ":FrameworksCoreTests{.aapt.srcjar}", + ":FrameworksCoreTests-aidl", + ":FrameworksCoreTests-helpers", + ":FrameworksCoreTestDoubles-sources", ], + aidl: { + generate_get_transaction_name: true, + local_include_dirs: ["aidl"], + }, auto_gen_config: true, } diff --git a/core/tests/coretests/src/android/app/PropertyInvalidatedCacheTests.java b/core/tests/coretests/src/android/app/PropertyInvalidatedCacheTests.java index 3768063f2a91..cd6abddc20a1 100644 --- a/core/tests/coretests/src/android/app/PropertyInvalidatedCacheTests.java +++ b/core/tests/coretests/src/android/app/PropertyInvalidatedCacheTests.java @@ -20,9 +20,13 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; + import androidx.test.filters.SmallTest; import org.junit.After; +import org.junit.Rule; import org.junit.Test; /** @@ -35,7 +39,10 @@ import org.junit.Test; * atest FrameworksCoreTests:PropertyInvalidatedCacheTests */ @SmallTest +@IgnoreUnderRavenwood(blockedBy = PropertyInvalidatedCache.class) public class PropertyInvalidatedCacheTests { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); // Configuration for creating caches private static final String MODULE = PropertyInvalidatedCache.MODULE_TEST; diff --git a/core/tests/coretests/src/android/os/AidlTest.java b/core/tests/coretests/src/android/os/AidlTest.java index d0c3470c4c1f..006828f12156 100644 --- a/core/tests/coretests/src/android/os/AidlTest.java +++ b/core/tests/coretests/src/android/os/AidlTest.java @@ -16,23 +16,36 @@ package android.os; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; + import androidx.test.filters.SmallTest; import com.google.android.collect.Lists; -import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; import java.util.List; -public class AidlTest extends TestCase { +@IgnoreUnderRavenwood(blockedBy = Parcel.class) +public class AidlTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); private IAidlTest mRemote; private AidlObject mLocal; private NonAutoGeneratedObject mNonAutoGenerated; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { mLocal = new AidlObject(); mRemote = IAidlTest.Stub.asInterface(mLocal); mNonAutoGenerated = new NonAutoGeneratedObject("NonAutoGeneratedObject"); @@ -212,12 +225,14 @@ public class AidlTest extends TestCase { } } + @Test @SmallTest public void testInt() throws Exception { int result = mRemote.intMethod(42); assertEquals(42, result); } + @Test @SmallTest public void testParcelableIn() throws Exception { TestParcelable arg = new TestParcelable(43, "hi"); @@ -228,6 +243,7 @@ public class AidlTest extends TestCase { assertEquals(44, result.mAnInt); } + @Test @SmallTest public void testParcelableOut() throws Exception { TestParcelable arg = new TestParcelable(43, "hi"); @@ -236,6 +252,7 @@ public class AidlTest extends TestCase { assertEquals(44, arg.mAnInt); } + @Test @SmallTest public void testParcelableInOut() throws Exception { TestParcelable arg = new TestParcelable(43, "hi"); @@ -244,6 +261,7 @@ public class AidlTest extends TestCase { assertEquals(44, arg.mAnInt); } + @Test @SmallTest public void testListParcelableLonger() throws Exception { List<TestParcelable> list = Lists.newArrayList(); @@ -268,6 +286,7 @@ public class AidlTest extends TestCase { assertNotSame(list.get(1), list.get(2)); } + @Test @SmallTest public void testListParcelableShorter() throws Exception { List<TestParcelable> list = Lists.newArrayList(); @@ -290,6 +309,7 @@ public class AidlTest extends TestCase { assertNotSame(list.get(0), list.get(1)); } + @Test @SmallTest public void testArrays() throws Exception { // boolean @@ -363,14 +383,14 @@ public class AidlTest extends TestCase { float[] fr = mRemote.floatArray(f0, f1, f2); assertEquals(1, fr.length); - assertEquals(90.1f, fr[0]); + assertEquals(90.1f, fr[0], 0.0f); - assertEquals(90.1f, f1[0]); + assertEquals(90.1f, f1[0], 0.0f); assertEquals(0f, f1[1], 0.0f); - assertEquals(90.1f, f2[0]); - assertEquals(90.5f, f2[1]); - assertEquals(90.6f, f2[2]); + assertEquals(90.1f, f2[0], 0.0f); + assertEquals(90.5f, f2[1], 0.0f); + assertEquals(90.6f, f2[2], 0.0f); // double double[] d0 = new double[]{100.1}; @@ -379,14 +399,14 @@ public class AidlTest extends TestCase { double[] dr = mRemote.doubleArray(d0, d1, d2); assertEquals(1, dr.length); - assertEquals(100.1, dr[0]); + assertEquals(100.1, dr[0], 0.0); - assertEquals(100.1, d1[0]); + assertEquals(100.1, d1[0], 0.0); assertEquals(0, d1[1], 0.0); - assertEquals(100.1, d2[0]); - assertEquals(100.5, d2[1]); - assertEquals(100.6, d2[2]); + assertEquals(100.1, d2[0], 0.0); + assertEquals(100.5, d2[1], 0.0); + assertEquals(100.6, d2[2], 0.0); // String String[] s0 = new String[]{"s0[0]"}; @@ -405,6 +425,7 @@ public class AidlTest extends TestCase { assertEquals("s2[2]", s2[2]); } + @Test @SmallTest public void testVoidSecurityException() throws Exception { boolean good = false; @@ -416,6 +437,7 @@ public class AidlTest extends TestCase { assertEquals(good, true); } + @Test @SmallTest public void testIntSecurityException() throws Exception { boolean good = false; @@ -427,6 +449,7 @@ public class AidlTest extends TestCase { assertEquals(good, true); } + @Test @SmallTest public void testGetTransactionNameAutoGenerated() throws Exception { assertEquals(15, mLocal.getMaxTransactionId()); @@ -446,6 +469,7 @@ public class AidlTest extends TestCase { mLocal.getTransactionTraceName(IAidlTest.Stub.TRANSACTION_parcelableIn)); } + @Test @SmallTest public void testGetTransactionNameNonAutoGenerated() throws Exception { assertEquals(0, mNonAutoGenerated.getMaxTransactionId()); diff --git a/core/tests/coretests/src/android/os/BinderDeathRecipientTest.java b/core/tests/coretests/src/android/os/BinderDeathRecipientTest.java index 2cce43f70774..eff52f0dc4e2 100644 --- a/core/tests/coretests/src/android/os/BinderDeathRecipientTest.java +++ b/core/tests/coretests/src/android/os/BinderDeathRecipientTest.java @@ -25,6 +25,8 @@ import android.app.ActivityManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import android.util.ArraySet; import android.util.Log; import android.util.Pair; @@ -36,6 +38,7 @@ import com.android.frameworks.coretests.bdr_helper_app.TestCommsReceiver; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -52,6 +55,7 @@ import java.util.concurrent.atomic.AtomicReference; * Tests functionality of {@link android.os.IBinder.DeathRecipient} callbacks. */ @RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(blockedBy = ActivityManager.class) public class BinderDeathRecipientTest { private static final String TAG = BinderDeathRecipientTest.class.getSimpleName(); private static final String TEST_PACKAGE_NAME_1 = @@ -59,6 +63,9 @@ public class BinderDeathRecipientTest { private static final String TEST_PACKAGE_NAME_2 = "com.android.frameworks.coretests.bdr_helper_app2"; + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + private Context mContext; private Handler mHandler; private ActivityManager mActivityManager; diff --git a/core/tests/coretests/src/android/os/BinderProxyCountingTest.java b/core/tests/coretests/src/android/os/BinderProxyCountingTest.java index 2089c6cf89c9..bcd9521019e4 100644 --- a/core/tests/coretests/src/android/os/BinderProxyCountingTest.java +++ b/core/tests/coretests/src/android/os/BinderProxyCountingTest.java @@ -24,6 +24,8 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import android.util.Log; import androidx.test.InstrumentationRegistry; @@ -35,7 +37,8 @@ import com.android.frameworks.coretests.aidl.IBpcCallbackObserver; import com.android.frameworks.coretests.aidl.IBpcTestAppCmdService; import com.android.frameworks.coretests.aidl.IBpcTestServiceCmdService; -import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -71,6 +74,7 @@ import java.util.function.Consumer; */ @LargeTest @RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(blockedBy = ActivityManager.class) public class BinderProxyCountingTest { private static final String TAG = BinderProxyCountingTest.class.getSimpleName(); @@ -107,11 +111,14 @@ public class BinderProxyCountingTest { }; private static int sTestPkgUid; + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + /** * Setup any common data for the upcoming tests. */ - @BeforeClass - public static void setUpOnce() throws Exception { + @Before + public void setUp() throws Exception { sContext = InstrumentationRegistry.getContext(); sTestPkgUid = sContext.getPackageManager().getPackageUid(TEST_APP_PKG, 0); ((ActivityManager) sContext.getSystemService(Context.ACTIVITY_SERVICE)).killUid(sTestPkgUid, diff --git a/core/tests/coretests/src/android/os/BinderProxyTest.java b/core/tests/coretests/src/android/os/BinderProxyTest.java index 3567d17ea874..a903ed91cb3d 100644 --- a/core/tests/coretests/src/android/os/BinderProxyTest.java +++ b/core/tests/coretests/src/android/os/BinderProxyTest.java @@ -16,19 +16,34 @@ package android.os; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import android.annotation.Nullable; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; -import android.test.AndroidTestCase; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; +import androidx.test.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.MediumTest; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -public class BinderProxyTest extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(blockedBy = PowerManager.class) +public class BinderProxyTest { private static class CountingListener implements Binder.ProxyTransactListener { int mStartedCount; int mEndedCount; @@ -43,17 +58,22 @@ public class BinderProxyTest extends AndroidTestCase { } }; + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + + private Context mContext; private PowerManager mPowerManager; /** * Setup any common data for the upcoming tests. */ - @Override + @Before public void setUp() throws Exception { - super.setUp(); + mContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); } + @Test @MediumTest public void testNoListener() throws Exception { CountingListener listener = new CountingListener(); @@ -66,6 +86,7 @@ public class BinderProxyTest extends AndroidTestCase { assertEquals(0, listener.mEndedCount); } + @Test @MediumTest public void testListener() throws Exception { CountingListener listener = new CountingListener(); @@ -77,6 +98,7 @@ public class BinderProxyTest extends AndroidTestCase { assertEquals(1, listener.mEndedCount); } + @Test @MediumTest public void testSessionPropagated() throws Exception { Binder.setProxyTransactListener(new Binder.ProxyTransactListener() { @@ -95,6 +117,7 @@ public class BinderProxyTest extends AndroidTestCase { private IBinder mRemoteBinder = null; + @Test @MediumTest public void testGetExtension() throws Exception { final CountDownLatch bindLatch = new CountDownLatch(1); diff --git a/core/tests/coretests/src/android/os/BinderTest.java b/core/tests/coretests/src/android/os/BinderTest.java index 02f87901318d..6c8b69fc9c5c 100644 --- a/core/tests/coretests/src/android/os/BinderTest.java +++ b/core/tests/coretests/src/android/os/BinderTest.java @@ -16,21 +16,35 @@ package android.os; -import androidx.test.filters.SmallTest; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.testng.Assert.assertThrows; -import junit.framework.TestCase; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; -import static org.testng.Assert.assertThrows; +import androidx.test.filters.SmallTest; + +import org.junit.Rule; +import org.junit.Test; -public class BinderTest extends TestCase { +@IgnoreUnderRavenwood(blockedBy = WorkSource.class) +public class BinderTest { private static final int UID = 100; + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + + @Test @SmallTest public void testSetWorkSource() throws Exception { Binder.setCallingWorkSourceUid(UID); assertEquals(UID, Binder.getCallingWorkSourceUid()); } + @Test @SmallTest public void testClearWorkSource() throws Exception { Binder.setCallingWorkSourceUid(UID); @@ -38,6 +52,7 @@ public class BinderTest extends TestCase { assertEquals(-1, Binder.getCallingWorkSourceUid()); } + @Test @SmallTest public void testRestoreWorkSource() throws Exception { Binder.setCallingWorkSourceUid(UID); @@ -46,11 +61,13 @@ public class BinderTest extends TestCase { assertEquals(UID, Binder.getCallingWorkSourceUid()); } + @Test @SmallTest public void testGetCallingUidOrThrow_throws() throws Exception { assertThrows(IllegalStateException.class, () -> Binder.getCallingUidOrThrow()); } + @Test @SmallTest public void testGetExtension() throws Exception { Binder binder = new Binder(); diff --git a/core/tests/coretests/src/android/os/BinderThreadPriorityTest.java b/core/tests/coretests/src/android/os/BinderThreadPriorityTest.java index 48c9df65da61..4172bffe100c 100644 --- a/core/tests/coretests/src/android/os/BinderThreadPriorityTest.java +++ b/core/tests/coretests/src/android/os/BinderThreadPriorityTest.java @@ -16,21 +16,42 @@ package android.os; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import android.app.ActivityManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; -import android.test.AndroidTestCase; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import android.util.Log; +import androidx.test.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + import java.io.File; import java.io.IOException; /** * Test whether Binder calls inherit thread priorities correctly. */ -public class BinderThreadPriorityTest extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(blockedBy = ActivityManager.class) +public class BinderThreadPriorityTest { private static final String TAG = "BinderThreadPriorityTest"; + + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + + private Context mContext; private IBinderThreadPriorityService mService; private int mSavedPriority; @@ -55,12 +76,11 @@ public class BinderThreadPriorityTest extends AndroidTestCase { private static void fail() { throw new RuntimeException("unimplemented"); } } - @Override - protected void setUp() throws Exception { - super.setUp(); - - getContext().bindService( - new Intent(getContext(), BinderThreadPriorityService.class), + @Before + public void setUp() throws Exception { + mContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + mContext.bindService( + new Intent(mContext, BinderThreadPriorityService.class), mConnection, Context.BIND_AUTO_CREATE); synchronized (this) { @@ -80,8 +100,8 @@ public class BinderThreadPriorityTest extends AndroidTestCase { Log.i(TAG, "Saved priority: " + mSavedPriority); } - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { // HACK -- see bug 2665914 -- setThreadPriority() doesn't always set the // scheduler group reliably unless we start out with background priority. Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); @@ -89,8 +109,7 @@ public class BinderThreadPriorityTest extends AndroidTestCase { assertEquals(mSavedPriority, Process.getThreadPriority(Process.myTid())); assertEquals(expectedSchedulerGroup(mSavedPriority), getSchedulerGroup()); - getContext().unbindService(mConnection); - super.tearDown(); + mContext.unbindService(mConnection); } public static String getSchedulerGroup() { @@ -111,6 +130,7 @@ public class BinderThreadPriorityTest extends AndroidTestCase { return "/"; } + @Test public void testPassPriorityToService() throws Exception { for (int prio = 19; prio >= -20; prio--) { Process.setThreadPriority(prio); @@ -125,6 +145,7 @@ public class BinderThreadPriorityTest extends AndroidTestCase { } } + @Test public void testCallBackFromServiceWithPriority() throws Exception { for (int prio = -20; prio <= 19; prio++) { final int expected = prio; diff --git a/core/tests/coretests/src/android/os/BinderWorkSourceTest.java b/core/tests/coretests/src/android/os/BinderWorkSourceTest.java index b14c88f7341e..552066c92931 100644 --- a/core/tests/coretests/src/android/os/BinderWorkSourceTest.java +++ b/core/tests/coretests/src/android/os/BinderWorkSourceTest.java @@ -19,11 +19,14 @@ package android.os; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import android.app.ActivityManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; +import android.platform.test.annotations.IgnoreUnderRavenwood; import android.platform.test.annotations.Presubmit; +import android.platform.test.ravenwood.RavenwoodRule; import androidx.test.InstrumentationRegistry; import androidx.test.filters.LargeTest; @@ -33,6 +36,7 @@ import androidx.test.runner.AndroidJUnit4; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -42,12 +46,16 @@ import org.junit.runner.RunWith; @LargeTest @Presubmit @RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(blockedBy = ActivityManager.class) public class BinderWorkSourceTest { private static Context sContext; private static final int UID = 100; private static final int SECOND_UID = 200; private static final int UID_NONE = ThreadLocalWorkSource.UID_NONE; + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + private IBinderWorkSourceService mService; private IBinderWorkSourceNestedService mNestedService; @@ -71,13 +79,9 @@ public class BinderWorkSourceTest { } }; - @BeforeClass - public static void setUpOnce() throws Exception { - sContext = InstrumentationRegistry.getContext(); - } - @Before public void setUp() throws Exception { + sContext = InstrumentationRegistry.getContext(); sContext.bindService( new Intent(sContext, BinderWorkSourceService.class), mConnection, Context.BIND_AUTO_CREATE); diff --git a/core/tests/coretests/src/android/os/BroadcasterTest.java b/core/tests/coretests/src/android/os/BroadcasterTest.java index b4c47af93355..7829457109cd 100644 --- a/core/tests/coretests/src/android/os/BroadcasterTest.java +++ b/core/tests/coretests/src/android/os/BroadcasterTest.java @@ -16,16 +16,26 @@ package android.os; +import android.platform.test.ravenwood.RavenwoodRule; + import androidx.test.filters.MediumTest; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; -import junit.framework.TestCase; +@RunWith(AndroidJUnit4.class) +public class BroadcasterTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); -public class BroadcasterTest extends TestCase { private static final int MESSAGE_A = 23234; private static final int MESSAGE_B = 3; private static final int MESSAGE_C = 14; private static final int MESSAGE_D = 95; + @Test @MediumTest public void test1() throws Exception { /* @@ -103,6 +113,7 @@ public class BroadcasterTest extends TestCase { } } + @Test @MediumTest public void test2() throws Exception { /* @@ -112,6 +123,7 @@ public class BroadcasterTest extends TestCase { tester.doTest(1000); } + @Test @MediumTest public void test3() throws Exception { /* @@ -121,6 +133,7 @@ public class BroadcasterTest extends TestCase { tester.doTest(1000); } + @Test @MediumTest public void test4() throws Exception { /* @@ -156,6 +169,7 @@ public class BroadcasterTest extends TestCase { tester.doTest(1000); } + @Test @MediumTest public void test5() throws Exception { /* @@ -191,6 +205,7 @@ public class BroadcasterTest extends TestCase { tester.doTest(1000); } + @Test @MediumTest public void test6() throws Exception { /* diff --git a/core/tests/coretests/src/android/os/BundleTest.java b/core/tests/coretests/src/android/os/BundleTest.java index a3bda8b23f30..8c231de5598f 100644 --- a/core/tests/coretests/src/android/os/BundleTest.java +++ b/core/tests/coretests/src/android/os/BundleTest.java @@ -23,13 +23,16 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; +import android.platform.test.annotations.IgnoreUnderRavenwood; import android.platform.test.annotations.Presubmit; +import android.platform.test.ravenwood.RavenwoodRule; import android.util.Log; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; import org.junit.After; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -45,6 +48,9 @@ import java.util.Objects; @Presubmit @RunWith(AndroidJUnit4.class) public class BundleTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + private Log.TerribleFailureHandler mWtfHandler; @After @@ -115,6 +121,7 @@ public class BundleTest { } @Test + @IgnoreUnderRavenwood(blockedBy = ParcelFileDescriptor.class) public void testCreateFromParcel() throws Exception { boolean withFd; Parcel p; @@ -190,6 +197,7 @@ public class BundleTest { } @Test + @IgnoreUnderRavenwood(blockedBy = Parcel.class) public void kindofEquals_bothParcelled_same() { Bundle bundle1 = new Bundle(); bundle1.putString("StringKey", "S"); @@ -207,6 +215,7 @@ public class BundleTest { } @Test + @IgnoreUnderRavenwood(blockedBy = Parcel.class) public void kindofEquals_bothParcelled_different() { Bundle bundle1 = new Bundle(); bundle1.putString("StringKey", "S"); @@ -238,6 +247,7 @@ public class BundleTest { } @Test + @IgnoreUnderRavenwood(blockedBy = Parcel.class) public void kindofEquals_lazyValues() { Parcelable p1 = new CustomParcelable(13, "Tiramisu"); Parcelable p2 = new CustomParcelable(13, "Tiramisu"); @@ -271,6 +281,7 @@ public class BundleTest { } @Test + @IgnoreUnderRavenwood(blockedBy = Parcel.class) public void kindofEquals_lazyValuesWithIdenticalParcels_returnsTrue() { Parcelable p1 = new CustomParcelable(13, "Tiramisu"); Parcelable p2 = new CustomParcelable(13, "Tiramisu"); @@ -295,6 +306,7 @@ public class BundleTest { } @Test + @IgnoreUnderRavenwood(blockedBy = Parcel.class) public void kindofEquals_lazyValuesAndDifferentClassLoaders_returnsFalse() { Parcelable p1 = new CustomParcelable(13, "Tiramisu"); Parcelable p2 = new CustomParcelable(13, "Tiramisu"); @@ -350,6 +362,7 @@ public class BundleTest { } @Test + @IgnoreUnderRavenwood(blockedBy = Parcel.class) public void readWriteLengthMismatch_logsWtf() throws Exception { mWtfHandler = Log.setWtfHandler((tag, e, system) -> { throw new RuntimeException(e); @@ -364,6 +377,7 @@ public class BundleTest { } @Test + @IgnoreUnderRavenwood(blockedBy = Parcel.class) public void getParcelable_whenThrowingAndNotDefusing_throws() throws Exception { Bundle.setShouldDefuse(false); Bundle bundle = new Bundle(); @@ -376,6 +390,7 @@ public class BundleTest { } @Test + @IgnoreUnderRavenwood(blockedBy = Parcel.class) public void getParcelable_whenThrowingAndDefusing_returnsNull() throws Exception { Bundle.setShouldDefuse(true); Bundle bundle = new Bundle(); @@ -391,6 +406,7 @@ public class BundleTest { } @Test + @IgnoreUnderRavenwood(blockedBy = Parcel.class) public void getParcelable_whenThrowingAndDefusing_leavesElement() throws Exception { Bundle.setShouldDefuse(true); Bundle bundle = new Bundle(); diff --git a/core/tests/coretests/src/android/os/CancellationSignalBeamerTest.java b/core/tests/coretests/src/android/os/CancellationSignalBeamerTest.java index 42c97f3876a6..c2cea0a2c286 100644 --- a/core/tests/coretests/src/android/os/CancellationSignalBeamerTest.java +++ b/core/tests/coretests/src/android/os/CancellationSignalBeamerTest.java @@ -22,6 +22,8 @@ import static com.google.common.truth.Truth.assertThat; import android.content.Context; import android.os.CancellationSignalBeamer.Receiver; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import android.util.PollingCheck; import android.util.PollingCheck.PollingCheckCondition; @@ -29,6 +31,8 @@ import androidx.test.filters.SmallTest; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; +import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -40,11 +44,20 @@ import java.util.concurrent.CountDownLatch; @RunWith(AndroidJUnit4.class) @SmallTest +@IgnoreUnderRavenwood(blockedBy = CancellationSignalBeamer.class) public class CancellationSignalBeamerTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); - private CancellationSignal mSenderSignal = new CancellationSignal(); + private CancellationSignal mSenderSignal; private CancellationSignal mReceivedSignal; - private Context mContext = InstrumentationRegistry.getInstrumentation().getContext(); + private Context mContext; + + @Before + public void setUp() { + mSenderSignal = new CancellationSignal(); + mContext = InstrumentationRegistry.getInstrumentation().getContext(); + } @Test public void testBeam_null() { @@ -208,17 +221,22 @@ public class CancellationSignalBeamerTest { mReceivedSignal = mReceiver.unbeam(cancellationSignalToken); } - private final Sender mSender = new Sender() { - @Override - public void onCancel(IBinder token) { - mReceiver.cancel(token); - } + private Sender mSender; + private Receiver mReceiver; - @Override - public void onForget(IBinder token) { - mReceiver.forget(token); - } - }; + @Before + public void setUpSenderReceiver() { + mSender = new Sender() { + @Override + public void onCancel(IBinder token) { + mReceiver.cancel(token); + } - private final Receiver mReceiver = new Receiver(false); + @Override + public void onForget(IBinder token) { + mReceiver.forget(token); + } + }; + mReceiver = new Receiver(false); + } } diff --git a/core/tests/coretests/src/android/os/EnvironmentTest.java b/core/tests/coretests/src/android/os/EnvironmentTest.java index ef38cdec0d63..1aa263f13d92 100644 --- a/core/tests/coretests/src/android/os/EnvironmentTest.java +++ b/core/tests/coretests/src/android/os/EnvironmentTest.java @@ -28,12 +28,15 @@ import static org.junit.Assert.assertEquals; import android.content.Context; import android.os.storage.StorageManager; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import androidx.test.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -43,7 +46,11 @@ import java.util.UUID; import java.util.function.BiFunction; @RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(blockedBy = Environment.class) public class EnvironmentTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + private File dir; private static Context getContext() { diff --git a/core/tests/coretests/src/android/os/FileBridgeTest.java b/core/tests/coretests/src/android/os/FileBridgeTest.java index 708bfa6ece2e..726670b4d625 100644 --- a/core/tests/coretests/src/android/os/FileBridgeTest.java +++ b/core/tests/coretests/src/android/os/FileBridgeTest.java @@ -19,12 +19,25 @@ package android.os; import static android.os.ParcelFileDescriptor.MODE_CREATE; import static android.os.ParcelFileDescriptor.MODE_READ_WRITE; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import android.os.FileBridge.FileBridgeOutputStream; -import android.test.AndroidTestCase; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import android.test.MoreAsserts; +import androidx.test.ext.junit.runners.AndroidJUnit4; + import libcore.io.Streams; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; @@ -32,18 +45,20 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.Random; -public class FileBridgeTest extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(blockedBy = ParcelFileDescriptor.class) +public class FileBridgeTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); private File file; private ParcelFileDescriptor outputFile; private FileBridge bridge; private FileBridgeOutputStream client; - @Override - protected void setUp() throws Exception { - super.setUp(); - - file = getContext().getFileStreamPath("meow.dat"); + @Before + public void setUp() throws Exception { + file = File.createTempFile("meow", "dat"); file.delete(); outputFile = ParcelFileDescriptor.open(file, MODE_CREATE | MODE_READ_WRITE); @@ -54,8 +69,8 @@ public class FileBridgeTest extends AndroidTestCase { client = new FileBridgeOutputStream(bridge.getClientSocket()); } - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { outputFile.close(); file.delete(); } @@ -76,17 +91,20 @@ public class FileBridgeTest extends AndroidTestCase { MoreAsserts.assertEquals(expected, Streams.readFully(new FileInputStream(file))); } + @Test public void testNoWriteNoSync() throws Exception { assertOpen(); closeAndAssertClosed(); } + @Test public void testNoWriteSync() throws Exception { assertOpen(); client.flush(); closeAndAssertClosed(); } + @Test public void testWriteNoSync() throws Exception { assertOpen(); client.write("meow".getBytes(StandardCharsets.UTF_8)); @@ -94,6 +112,7 @@ public class FileBridgeTest extends AndroidTestCase { assertContents("meow".getBytes(StandardCharsets.UTF_8)); } + @Test public void testWriteSync() throws Exception { assertOpen(); client.write("cake".getBytes(StandardCharsets.UTF_8)); @@ -102,6 +121,7 @@ public class FileBridgeTest extends AndroidTestCase { assertContents("cake".getBytes(StandardCharsets.UTF_8)); } + @Test public void testWriteSyncWrite() throws Exception { assertOpen(); client.write("meow".getBytes(StandardCharsets.UTF_8)); @@ -111,6 +131,7 @@ public class FileBridgeTest extends AndroidTestCase { assertContents("meowcake".getBytes(StandardCharsets.UTF_8)); } + @Test public void testEmptyWrite() throws Exception { assertOpen(); client.write(new byte[0]); @@ -118,6 +139,7 @@ public class FileBridgeTest extends AndroidTestCase { assertContents(new byte[0]); } + @Test public void testWriteAfterClose() throws Exception { assertOpen(); client.write("meow".getBytes(StandardCharsets.UTF_8)); @@ -130,6 +152,7 @@ public class FileBridgeTest extends AndroidTestCase { assertContents("meow".getBytes(StandardCharsets.UTF_8)); } + @Test public void testRandomWrite() throws Exception { final Random r = new Random(); final ByteArrayOutputStream result = new ByteArrayOutputStream(); @@ -146,6 +169,7 @@ public class FileBridgeTest extends AndroidTestCase { assertContents(result.toByteArray()); } + @Test public void testGiantWrite() throws Exception { final byte[] test = new byte[263401]; new Random().nextBytes(test); diff --git a/core/tests/coretests/src/android/os/FileObserverTest.java b/core/tests/coretests/src/android/os/FileObserverTest.java index ece7645b7389..3cd8045c32cb 100644 --- a/core/tests/coretests/src/android/os/FileObserverTest.java +++ b/core/tests/coretests/src/android/os/FileObserverTest.java @@ -16,21 +16,37 @@ package android.os; -import android.test.AndroidTestCase; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import android.util.Log; +import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.MediumTest; import com.google.android.collect.Lists; import com.google.android.collect.Maps; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + import java.io.File; import java.io.FileOutputStream; import java.util.Iterator; import java.util.List; import java.util.Map; -public class FileObserverTest extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(blockedBy = FileObserver.class) +public class FileObserverTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + private Observer mObserver; private File mTestFile; @@ -57,18 +73,19 @@ public class FileObserverTest extends AndroidTestCase { } } - @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { mTestFile = File.createTempFile(".file_observer_test", ".txt"); } - @Override - protected void tearDown() throws Exception { + @After + public void tearDown() throws Exception { if (mTestFile != null && mTestFile.exists()) { mTestFile.delete(); } } + @Test @MediumTest public void testRun() throws Exception { // make file changes and wait for them diff --git a/core/tests/coretests/src/android/os/HandlerThreadTest.java b/core/tests/coretests/src/android/os/HandlerThreadTest.java index 93cfc40d555e..0bac1c728f3b 100644 --- a/core/tests/coretests/src/android/os/HandlerThreadTest.java +++ b/core/tests/coretests/src/android/os/HandlerThreadTest.java @@ -16,18 +16,35 @@ package android.os; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import android.platform.test.ravenwood.RavenwoodRule; + import androidx.test.filters.MediumTest; +import androidx.test.runner.AndroidJUnit4; -import junit.framework.TestCase; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; -public class HandlerThreadTest extends TestCase { +@RunWith(AndroidJUnit4.class) +public class HandlerThreadTest { private static final int TEST_WHAT = 1; + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + private boolean mGotMessage = false; private int mGotMessageWhat = -1; private volatile boolean mDidSetup = false; private volatile int mLooperTid = -1; - + + @Test @MediumTest public void testHandlerThread() throws Exception { HandlerThread th1 = new HandlerThread("HandlerThreadTest") { diff --git a/core/tests/coretests/src/android/os/IdleHandlerTest.java b/core/tests/coretests/src/android/os/IdleHandlerTest.java index d8886c97838e..864466329389 100644 --- a/core/tests/coretests/src/android/os/IdleHandlerTest.java +++ b/core/tests/coretests/src/android/os/IdleHandlerTest.java @@ -17,12 +17,19 @@ package android.os; import android.os.MessageQueue.IdleHandler; +import android.platform.test.ravenwood.RavenwoodRule; import androidx.test.filters.MediumTest; +import androidx.test.runner.AndroidJUnit4; -import junit.framework.TestCase; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; -public class IdleHandlerTest extends TestCase { +@RunWith(AndroidJUnit4.class) +public class IdleHandlerTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); private static class BaseTestHandler extends TestHandlerThread { Handler mHandler; @@ -54,6 +61,7 @@ public class IdleHandlerTest extends TestCase { } } + @Test @MediumTest public void testOneShotFirst() throws Exception { TestHandlerThread tester = new BaseTestHandler() { @@ -88,6 +96,7 @@ public class IdleHandlerTest extends TestCase { tester.doTest(1000); } + @Test @MediumTest public void testOneShotLater() throws Exception { TestHandlerThread tester = new BaseTestHandler() { @@ -125,6 +134,7 @@ public class IdleHandlerTest extends TestCase { } + @Test @MediumTest public void testRepeatedFirst() throws Exception { TestHandlerThread tester = new BaseTestHandler() { @@ -159,6 +169,7 @@ public class IdleHandlerTest extends TestCase { tester.doTest(1000); } + @Test @MediumTest public void testRepeatedLater() throws Exception { TestHandlerThread tester = new BaseTestHandler() { diff --git a/core/tests/coretests/src/android/os/IpcDataCacheTest.java b/core/tests/coretests/src/android/os/IpcDataCacheTest.java index 34712ce54e0f..b03fd6485786 100644 --- a/core/tests/coretests/src/android/os/IpcDataCacheTest.java +++ b/core/tests/coretests/src/android/os/IpcDataCacheTest.java @@ -17,12 +17,14 @@ package android.os; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; + +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import androidx.test.filters.SmallTest; import org.junit.After; +import org.junit.Rule; import org.junit.Test; /** @@ -35,7 +37,10 @@ import org.junit.Test; * atest FrameworksCoreTests:IpcDataCacheTest */ @SmallTest +@IgnoreUnderRavenwood(blockedBy = IpcDataCache.class) public class IpcDataCacheTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); // Configuration for creating caches private static final String MODULE = IpcDataCache.MODULE_TEST; diff --git a/core/tests/coretests/src/android/os/LocaleListTest.java b/core/tests/coretests/src/android/os/LocaleListTest.java index 88fc8267f5b2..0025e3a3c454 100644 --- a/core/tests/coretests/src/android/os/LocaleListTest.java +++ b/core/tests/coretests/src/android/os/LocaleListTest.java @@ -16,13 +16,29 @@ package android.os; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.fail; + +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; + import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; -import junit.framework.TestCase; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; import java.util.Locale; -public class LocaleListTest extends TestCase { +@RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(blockedBy = LocaleList.class) +public class LocaleListTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + + @Test @SmallTest public void testConstructor() throws Exception { LocaleList ll; @@ -51,6 +67,7 @@ public class LocaleListTest extends TestCase { assertEquals("fr,de", ll.toLanguageTags()); } + @Test @SmallTest public void testConstructor_nullThrows() throws Exception { try { @@ -61,6 +78,7 @@ public class LocaleListTest extends TestCase { } } + @Test @SmallTest public void testGetDefault_localeSetDefaultCalledButNoChangeNecessary() throws Exception { final Locale originalLocale = Locale.getDefault(); @@ -82,6 +100,7 @@ public class LocaleListTest extends TestCase { LocaleList.setDefault(originalLocaleList, originalLocaleIndex); } + @Test @SmallTest public void testIntersection() { LocaleList localesWithN = new LocaleList( diff --git a/core/tests/coretests/src/android/os/MemoryFileTest.java b/core/tests/coretests/src/android/os/MemoryFileTest.java index 05c2995fa158..a69542479afc 100644 --- a/core/tests/coretests/src/android/os/MemoryFileTest.java +++ b/core/tests/coretests/src/android/os/MemoryFileTest.java @@ -16,11 +16,21 @@ package android.os; -import android.test.AndroidTestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; + +import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.LargeTest; import androidx.test.filters.SmallTest; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -29,7 +39,11 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -public class MemoryFileTest extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(blockedBy = MemoryFile.class) +public class MemoryFileTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); private void compareBuffers(byte[] buffer1, byte[] buffer2, int length) throws Exception { for (int i = 0; i < length; i++) { @@ -44,6 +58,8 @@ public class MemoryFileTest extends AndroidTestCase { */ // Flaky test - temporarily suppress from large suite for now // @LargeTest + @Test + @Ignore("Flaky test") public void testPurge() throws Exception { List<MemoryFile> files = new ArrayList<MemoryFile>(); try { @@ -70,6 +86,7 @@ public class MemoryFileTest extends AndroidTestCase { } } + @Test @SmallTest public void testRun() throws Exception { MemoryFile file = new MemoryFile("MemoryFileTest", 1000000); @@ -102,6 +119,7 @@ public class MemoryFileTest extends AndroidTestCase { } // http://code.google.com/p/android/issues/detail?id=11415 + @Test public void testOutputStreamAdvances() throws IOException { MemoryFile file = new MemoryFile("MemoryFileTest", 10); @@ -142,24 +160,28 @@ public class MemoryFileTest extends AndroidTestCase { } } + @Test @SmallTest public void testReadNegativeOffset() throws Exception { readIndexOutOfBoundsException(-1, 5, "read() with negative offset should throw IndexOutOfBoundsException"); } + @Test @SmallTest public void testReadNegativeCount() throws Exception { readIndexOutOfBoundsException(5, -1, "read() with negative length should throw IndexOutOfBoundsException"); } + @Test @SmallTest public void testReadOffsetOverflow() throws Exception { readIndexOutOfBoundsException(testString.length + 10, 5, "read() with offset outside buffer should throw IndexOutOfBoundsException"); } + @Test @SmallTest public void testReadOffsetCountOverflow() throws Exception { readIndexOutOfBoundsException(testString.length, 11, @@ -167,6 +189,7 @@ public class MemoryFileTest extends AndroidTestCase { } // Test behavior of read() at end of file + @Test @SmallTest public void testReadEOF() throws Exception { MemoryFile file = new MemoryFile("MemoryFileTest", testString.length); @@ -189,6 +212,7 @@ public class MemoryFileTest extends AndroidTestCase { } // Tests that close() is idempotent + @Test @SmallTest public void testCloseClose() throws Exception { MemoryFile file = new MemoryFile("MemoryFileTest", 1000000); @@ -199,6 +223,7 @@ public class MemoryFileTest extends AndroidTestCase { } // Tests that we can't read from a closed memory file + @Test @SmallTest public void testCloseRead() throws Exception { MemoryFile file = new MemoryFile("MemoryFileTest", 1000000); @@ -214,6 +239,7 @@ public class MemoryFileTest extends AndroidTestCase { } // Tests that we can't write to a closed memory file + @Test @SmallTest public void testCloseWrite() throws Exception { MemoryFile file = new MemoryFile("MemoryFileTest", 1000000); @@ -229,6 +255,7 @@ public class MemoryFileTest extends AndroidTestCase { } // Tests that we can't call allowPurging() after close() + @Test @SmallTest public void testCloseAllowPurging() throws Exception { MemoryFile file = new MemoryFile("MemoryFileTest", 1000000); @@ -245,6 +272,7 @@ public class MemoryFileTest extends AndroidTestCase { } // Tests that we don't leak file descriptors or mmap areas + @Test @LargeTest public void testCloseLeak() throws Exception { // open enough memory files that we should run out of diff --git a/core/tests/coretests/src/android/os/MessageQueueTest.java b/core/tests/coretests/src/android/os/MessageQueueTest.java index 2c5588e6ed0d..8cd6773936ef 100644 --- a/core/tests/coretests/src/android/os/MessageQueueTest.java +++ b/core/tests/coretests/src/android/os/MessageQueueTest.java @@ -16,13 +16,21 @@ package android.os; +import android.platform.test.ravenwood.RavenwoodRule; + import androidx.test.filters.MediumTest; import androidx.test.filters.Suppress; +import androidx.test.runner.AndroidJUnit4; -import junit.framework.TestCase; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; @Suppress // Failing. -public class MessageQueueTest extends TestCase { +@RunWith(AndroidJUnit4.class) +public class MessageQueueTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); private static class BaseTestHandler extends TestHandlerThread { Handler mHandler; @@ -61,6 +69,7 @@ public class MessageQueueTest extends TestCase { } } + @Test @MediumTest public void testMessageOrder() throws Exception { TestHandlerThread tester = new BaseTestHandler() { @@ -80,6 +89,7 @@ public class MessageQueueTest extends TestCase { tester.doTest(1000); } + @Test @MediumTest public void testAtFrontOfQueue() throws Exception { TestHandlerThread tester = new BaseTestHandler() { @@ -141,6 +151,7 @@ public class MessageQueueTest extends TestCase { } } + @Test @MediumTest public void testFieldIntegrity() throws Exception { @@ -157,7 +168,7 @@ public class MessageQueueTest extends TestCase { public void handleMessage(Message msg) { super.handleMessage(msg); if (msg.what == 0) { - msg.flags = -1; + msg.flags = Message.FLAGS_TO_CLEAR_ON_COPY_FROM; msg.what = 1; msg.arg1 = 456; msg.arg2 = 789; diff --git a/core/tests/coretests/src/android/os/MessengerTest.java b/core/tests/coretests/src/android/os/MessengerTest.java index 9143ff1d1017..eb6263fe8053 100644 --- a/core/tests/coretests/src/android/os/MessengerTest.java +++ b/core/tests/coretests/src/android/os/MessengerTest.java @@ -16,15 +16,31 @@ package android.os; +import android.app.ActivityManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; -import android.test.AndroidTestCase; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; +import androidx.test.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.MediumTest; -public class MessengerTest extends AndroidTestCase { +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(blockedBy = ActivityManager.class) +public class MessengerTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + + private Context mContext; private Messenger mServiceMessenger; private ServiceConnection mConnection = new ServiceConnection() { @@ -86,10 +102,10 @@ public class MessengerTest extends AndroidTestCase { } }; - @Override - protected void setUp() throws Exception { - super.setUp(); - getContext().bindService(new Intent(mContext, MessengerService.class), + @Before + public void setUp() throws Exception { + mContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + mContext.bindService(new Intent(mContext, MessengerService.class), mConnection, Context.BIND_AUTO_CREATE); synchronized (this) { while (mServiceMessenger == null) { @@ -101,15 +117,14 @@ public class MessengerTest extends AndroidTestCase { } } - @Override - protected void tearDown() throws Exception { - super.tearDown(); - getContext().unbindService(mConnection); + @After + public void tearDown() throws Exception { + mContext.unbindService(mConnection); } + @Test @MediumTest public void testSend() { (new TestThread()).doTest(1000); - } } diff --git a/core/tests/coretests/src/android/os/OsTests.java b/core/tests/coretests/src/android/os/OsTests.java deleted file mode 100644 index 08fb945857e9..000000000000 --- a/core/tests/coretests/src/android/os/OsTests.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2006 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 android.os; - -import junit.framework.TestSuite; - -public class OsTests { - public static TestSuite suite() { - TestSuite suite = new TestSuite(OsTests.class.getName()); - - suite.addTestSuite(AidlTest.class); - suite.addTestSuite(BroadcasterTest.class); - suite.addTestSuite(FileObserverTest.class); - suite.addTestSuite(IdleHandlerTest.class); - suite.addTestSuite(MessageQueueTest.class); - suite.addTestSuite(MessengerTest.class); - suite.addTestSuite(PatternMatcherTest.class); - - return suite; - } -} diff --git a/core/tests/coretests/src/android/os/ParcelNullabilityTest.java b/core/tests/coretests/src/android/os/ParcelNullabilityTest.java index b4e180cf647c..ffeab291e49f 100644 --- a/core/tests/coretests/src/android/os/ParcelNullabilityTest.java +++ b/core/tests/coretests/src/android/os/ParcelNullabilityTest.java @@ -20,11 +20,14 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import android.util.ArrayMap; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -36,6 +39,9 @@ import java.util.Map; @SmallTest @RunWith(AndroidJUnit4.class) public final class ParcelNullabilityTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + @Test public void nullByteArray() { Parcel p = Parcel.obtain(); @@ -61,6 +67,7 @@ public final class ParcelNullabilityTest { } @Test + @IgnoreUnderRavenwood(blockedBy = Parcel.class) public void nullCharSequence() { Parcel p = Parcel.obtain(); p.writeCharSequence(null); @@ -69,6 +76,7 @@ public final class ParcelNullabilityTest { } @Test + @IgnoreUnderRavenwood(blockedBy = Parcel.class) public void nullStrongBinder() { Parcel p = Parcel.obtain(); p.writeStrongBinder(null); @@ -77,6 +85,7 @@ public final class ParcelNullabilityTest { } @Test + @IgnoreUnderRavenwood(blockedBy = Parcel.class) public void nullStringInterface() { Parcel p = Parcel.obtain(); p.writeStrongInterface(null); diff --git a/core/tests/coretests/src/android/os/ParcelTest.java b/core/tests/coretests/src/android/os/ParcelTest.java index 4b993fadc1e0..5bbd2219e2f0 100644 --- a/core/tests/coretests/src/android/os/ParcelTest.java +++ b/core/tests/coretests/src/android/os/ParcelTest.java @@ -21,22 +21,29 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; +import android.platform.test.annotations.IgnoreUnderRavenwood; import android.platform.test.annotations.Presubmit; +import android.platform.test.ravenwood.RavenwoodRule; import androidx.test.runner.AndroidJUnit4; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @Presubmit @RunWith(AndroidJUnit4.class) public class ParcelTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + private static final int WORK_SOURCE_1 = 1000; private static final int WORK_SOURCE_2 = 1002; private static final String INTERFACE_TOKEN_1 = "IBinder interface token"; private static final String INTERFACE_TOKEN_2 = "Another IBinder interface token"; @Test + @IgnoreUnderRavenwood(blockedBy = Parcel.class) public void testIsForRpc() { Parcel p = Parcel.obtain(); assertEquals(false, p.isForRpc()); @@ -44,6 +51,7 @@ public class ParcelTest { } @Test + @IgnoreUnderRavenwood(blockedBy = Parcel.class) public void testCallingWorkSourceUidAfterWrite() { Parcel p = Parcel.obtain(); // Method does not throw if replaceCallingWorkSourceUid is called before requests headers @@ -64,6 +72,7 @@ public class ParcelTest { } @Test + @IgnoreUnderRavenwood(blockedBy = Parcel.class) public void testCallingWorkSourceUidAfterEnforce() { Parcel p = Parcel.obtain(); p.writeInterfaceToken(INTERFACE_TOKEN_1); @@ -81,6 +90,7 @@ public class ParcelTest { } @Test + @IgnoreUnderRavenwood(blockedBy = Parcel.class) public void testParcelWithMultipleHeaders() { Parcel p = Parcel.obtain(); Binder.setCallingWorkSourceUid(WORK_SOURCE_1); @@ -122,6 +132,7 @@ public class ParcelTest { } @Test + @IgnoreUnderRavenwood(blockedBy = Parcel.class) public void testCompareDataInRange_whenSameData() { Parcel pA = Parcel.obtain(); int iA = pA.dataPosition(); @@ -138,6 +149,7 @@ public class ParcelTest { } @Test + @IgnoreUnderRavenwood(blockedBy = Parcel.class) public void testCompareDataInRange_whenSameDataWithBinder() { Binder binder = new Binder(); Parcel pA = Parcel.obtain(); @@ -157,6 +169,7 @@ public class ParcelTest { } @Test + @IgnoreUnderRavenwood(blockedBy = Parcel.class) public void testCompareDataInRange_whenDifferentData() { Parcel pA = Parcel.obtain(); int iA = pA.dataPosition(); @@ -173,6 +186,7 @@ public class ParcelTest { } @Test + @IgnoreUnderRavenwood(blockedBy = Parcel.class) public void testCompareDataInRange_whenLimitOutOfBounds_throws() { Parcel pA = Parcel.obtain(); int iA = pA.dataPosition(); @@ -199,6 +213,7 @@ public class ParcelTest { } @Test + @IgnoreUnderRavenwood(blockedBy = Parcel.class) public void testCompareDataInRange_whenLengthZero() { Parcel pA = Parcel.obtain(); int iA = pA.dataPosition(); @@ -217,6 +232,7 @@ public class ParcelTest { } @Test + @IgnoreUnderRavenwood(blockedBy = Parcel.class) public void testCompareDataInRange_whenNegativeLength_throws() { Parcel pA = Parcel.obtain(); int iA = pA.dataPosition(); @@ -232,6 +248,7 @@ public class ParcelTest { } @Test + @IgnoreUnderRavenwood(blockedBy = Parcel.class) public void testCompareDataInRange_whenNegativeOffset_throws() { Parcel pA = Parcel.obtain(); int iA = pA.dataPosition(); @@ -297,6 +314,7 @@ public class ParcelTest { * and 1M length for complex objects are allowed. */ @Test + @IgnoreUnderRavenwood(blockedBy = Parcel.class) public void testAllocations_whenWithinLimit() { Binder.setIsDirectlyHandlingTransactionOverride(true); Parcel p = Parcel.obtain(); diff --git a/core/tests/coretests/src/android/os/PatternMatcherTest.java b/core/tests/coretests/src/android/os/PatternMatcherTest.java index 82350cd5ffdf..a5e036de6f20 100644 --- a/core/tests/coretests/src/android/os/PatternMatcherTest.java +++ b/core/tests/coretests/src/android/os/PatternMatcherTest.java @@ -16,9 +16,10 @@ package android.os; -import androidx.test.filters.SmallTest; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; -import junit.framework.TestCase; +import androidx.test.filters.SmallTest; import org.junit.Test; import org.junit.runner.RunWith; @@ -26,7 +27,7 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) @SmallTest -public class PatternMatcherTest extends TestCase{ +public class PatternMatcherTest { @Test public void testAdvancedPatternMatchesAnyToken() { diff --git a/core/tests/coretests/src/android/os/PerformanceCollectorTest.java b/core/tests/coretests/src/android/os/PerformanceCollectorTest.java index 38ad90f11a23..46f1706c47c7 100644 --- a/core/tests/coretests/src/android/os/PerformanceCollectorTest.java +++ b/core/tests/coretests/src/android/os/PerformanceCollectorTest.java @@ -16,33 +16,48 @@ package android.os; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import android.os.PerformanceCollector.PerformanceResultsWriter; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import androidx.test.filters.MediumTest; import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Random; -public class PerformanceCollectorTest extends TestCase { +@RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(blockedBy = PerformanceCollector.class) +public class PerformanceCollectorTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); private PerformanceCollector mPerfCollector; - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { mPerfCollector = new PerformanceCollector(); } - @Override - protected void tearDown() throws Exception { - super.tearDown(); + @After + public void tearDown() throws Exception { mPerfCollector = null; } + @Test @SmallTest public void testBeginSnapshotNoWriter() throws Exception { mPerfCollector.beginSnapshot("testBeginSnapshotNoWriter"); @@ -54,6 +69,7 @@ public class PerformanceCollectorTest extends TestCase { assertEquals(2, snapshot.size()); } + @Test @MediumTest public void testEndSnapshotNoWriter() throws Exception { mPerfCollector.beginSnapshot("testEndSnapshotNoWriter"); @@ -63,6 +79,7 @@ public class PerformanceCollectorTest extends TestCase { verifySnapshotBundle(snapshot); } + @Test @SmallTest public void testStartTimingNoWriter() throws Exception { mPerfCollector.startTiming("testStartTimingNoWriter"); @@ -74,6 +91,7 @@ public class PerformanceCollectorTest extends TestCase { verifyTimingBundle(measurement, new ArrayList<String>()); } + @Test @SmallTest public void testAddIterationNoWriter() throws Exception { mPerfCollector.startTiming("testAddIterationNoWriter"); @@ -83,6 +101,7 @@ public class PerformanceCollectorTest extends TestCase { verifyIterationBundle(iteration, "timing1"); } + @Test @SmallTest public void testStopTimingNoWriter() throws Exception { mPerfCollector.startTiming("testStopTimingNoWriter"); @@ -100,6 +119,7 @@ public class PerformanceCollectorTest extends TestCase { verifyTimingBundle(timing, labels); } + @Test @SmallTest public void testBeginSnapshot() throws Exception { MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter(); @@ -114,6 +134,7 @@ public class PerformanceCollectorTest extends TestCase { assertEquals(2, snapshot.size()); } + @Test @MediumTest public void testEndSnapshot() throws Exception { MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter(); @@ -127,6 +148,7 @@ public class PerformanceCollectorTest extends TestCase { verifySnapshotBundle(snapshot1); } + @Test @SmallTest public void testStartTiming() throws Exception { MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter(); @@ -141,6 +163,7 @@ public class PerformanceCollectorTest extends TestCase { verifyTimingBundle(measurement, new ArrayList<String>()); } + @Test @SmallTest public void testAddIteration() throws Exception { mPerfCollector.startTiming("testAddIteration"); @@ -150,6 +173,7 @@ public class PerformanceCollectorTest extends TestCase { verifyIterationBundle(iteration, "timing5"); } + @Test @SmallTest public void testStopTiming() throws Exception { mPerfCollector.startTiming("testStopTiming"); @@ -167,6 +191,7 @@ public class PerformanceCollectorTest extends TestCase { verifyTimingBundle(timing, labels); } + @Test @SmallTest public void testAddMeasurementLong() throws Exception { MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter(); @@ -188,6 +213,7 @@ public class PerformanceCollectorTest extends TestCase { assertEquals(-19354, results.getLong("testAddMeasurementLongNeg")); } + @Test @SmallTest public void testAddMeasurementFloat() throws Exception { MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter(); @@ -202,13 +228,14 @@ public class PerformanceCollectorTest extends TestCase { Bundle results = writer.timingResults; assertEquals(4, results.size()); assertTrue(results.containsKey("testAddMeasurementFloatZero")); - assertEquals(0.0f, results.getFloat("testAddMeasurementFloatZero")); + assertEquals(0.0f, results.getFloat("testAddMeasurementFloatZero"), 0.0f); assertTrue(results.containsKey("testAddMeasurementFloatPos")); - assertEquals(348573.345f, results.getFloat("testAddMeasurementFloatPos")); + assertEquals(348573.345f, results.getFloat("testAddMeasurementFloatPos"), 0.0f); assertTrue(results.containsKey("testAddMeasurementFloatNeg")); - assertEquals(-19354.093f, results.getFloat("testAddMeasurementFloatNeg")); + assertEquals(-19354.093f, results.getFloat("testAddMeasurementFloatNeg"), 0.0f); } + @Test @SmallTest public void testAddMeasurementString() throws Exception { MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter(); @@ -230,6 +257,7 @@ public class PerformanceCollectorTest extends TestCase { assertEquals("Hello World", results.getString("testAddMeasurementStringNonEmpty")); } + @Test @MediumTest public void testSimpleSequence() throws Exception { MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter(); @@ -262,6 +290,7 @@ public class PerformanceCollectorTest extends TestCase { verifyTimingBundle(timing, labels); } + @Test @MediumTest public void testLongSequence() throws Exception { MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter(); @@ -348,6 +377,7 @@ public class PerformanceCollectorTest extends TestCase { * Verify that snapshotting and timing do not interfere w/ each other, * by staggering calls to snapshot and timing functions. */ + @Test @MediumTest public void testOutOfOrderSequence() { MockPerformanceResultsWriter writer = new MockPerformanceResultsWriter(); diff --git a/core/tests/coretests/src/android/os/PerformanceHintManagerTest.java b/core/tests/coretests/src/android/os/PerformanceHintManagerTest.java index 9b4dec4118a1..12a28446b0e1 100644 --- a/core/tests/coretests/src/android/os/PerformanceHintManagerTest.java +++ b/core/tests/coretests/src/android/os/PerformanceHintManagerTest.java @@ -24,18 +24,25 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeNotNull; import android.os.PerformanceHintManager.Session; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import androidx.test.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(blockedBy = PerformanceHintManager.class) public class PerformanceHintManagerTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + private static final long RATE_1000 = 1000L; private static final long TARGET_166 = 166L; private static final long DEFAULT_TARGET_NS = 16666666L; diff --git a/core/tests/coretests/src/android/os/PowerManagerTest.java b/core/tests/coretests/src/android/os/PowerManagerTest.java index 5d213caf61e6..cb281ff8a6a7 100644 --- a/core/tests/coretests/src/android/os/PowerManagerTest.java +++ b/core/tests/coretests/src/android/os/PowerManagerTest.java @@ -17,7 +17,9 @@ package android.os; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; @@ -26,28 +28,34 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; -import android.os.Flags; +import android.platform.test.annotations.IgnoreUnderRavenwood; import android.platform.test.annotations.RequiresFlagsEnabled; import android.platform.test.flag.junit.CheckFlagsRule; import android.platform.test.flag.junit.DeviceFlagsValueProvider; -import android.test.AndroidTestCase; +import android.platform.test.ravenwood.RavenwoodRule; import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; import androidx.test.uiautomator.UiDevice; import org.junit.After; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.util.concurrent.Executor; import java.util.concurrent.Executors; -public class PowerManagerTest extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(blockedBy = PowerManager.class) +public class PowerManagerTest { private static final String TAG = "PowerManagerTest"; + private Context mContext; private PowerManager mPm; private UiDevice mUiDevice; private Executor mExec = Executors.newSingleThreadExecutor(); @@ -68,21 +76,27 @@ public class PowerManagerTest extends AndroidTestCase { String[] keys, String[] values); static { - System.loadLibrary("powermanagertest_jni"); + if (!RavenwoodRule.isUnderRavenwood()) { + System.loadLibrary("powermanagertest_jni"); + } } + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + // Required for RequiresFlagsEnabled and RequiresFlagsDisabled annotations to take effect. @Rule - public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule(); + public final CheckFlagsRule mCheckFlagsRule = RavenwoodRule.isUnderRavenwood() ? null + : DeviceFlagsValueProvider.createCheckFlagsRule(); /** * Setup any common data for the upcoming tests. */ - @Override + @Before public void setUp() throws Exception { - super.setUp(); MockitoAnnotations.initMocks(this); mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()); + mContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); mPm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); mUiDevice.executeShellCommand("cmd thermalservice override-status 0"); } @@ -100,6 +114,7 @@ public class PowerManagerTest extends AndroidTestCase { * * @throws Exception */ + @Test @SmallTest public void testPreconditions() throws Exception { assertNotNull(mPm); @@ -110,6 +125,7 @@ public class PowerManagerTest extends AndroidTestCase { * * @throws Exception */ + @Test @SmallTest public void testNewWakeLock() throws Exception { PowerManager.WakeLock wl = mPm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "FULL_WAKE_LOCK"); @@ -133,6 +149,7 @@ public class PowerManagerTest extends AndroidTestCase { * * @throws Exception */ + @Test @SmallTest public void testBadNewWakeLock() throws Exception { final int badFlags = PowerManager.SCREEN_BRIGHT_WAKE_LOCK @@ -152,6 +169,7 @@ public class PowerManagerTest extends AndroidTestCase { * * @throws Exception */ + @Test @SmallTest public void testWakeLockWithWorkChains() throws Exception { PowerManager.WakeLock wakeLock = mPm.newWakeLock( diff --git a/core/tests/coretests/src/android/os/ProcessTest.java b/core/tests/coretests/src/android/os/ProcessTest.java index b2ffdc035e8b..310baa371163 100644 --- a/core/tests/coretests/src/android/os/ProcessTest.java +++ b/core/tests/coretests/src/android/os/ProcessTest.java @@ -17,12 +17,23 @@ package android.os; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; -public class ProcessTest extends TestCase { +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; + +import org.junit.Rule; +import org.junit.Test; + +@IgnoreUnderRavenwood(blockedBy = Process.class) +public class ProcessTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); private static final int BAD_PID = 0; + @Test public void testProcessGetUidFromName() throws Exception { assertEquals(android.os.Process.SYSTEM_UID, Process.getUidForName("system")); assertEquals(Process.BLUETOOTH_UID, Process.getUidForName("bluetooth")); @@ -36,6 +47,7 @@ public class ProcessTest extends TestCase { Process.getUidForName("u3_a100")); } + @Test public void testProcessGetUidFromNameFailure() throws Exception { // Failure cases assertEquals(-1, Process.getUidForName("u2a_foo")); @@ -51,6 +63,7 @@ public class ProcessTest extends TestCase { * Tests getUidForPid() by ensuring that it returns the correct value when the process queried * doesn't exist. */ + @Test public void testGetUidForPidInvalidPid() { assertEquals(-1, Process.getUidForPid(BAD_PID)); } @@ -59,6 +72,7 @@ public class ProcessTest extends TestCase { * Tests getParentPid() by ensuring that it returns the correct value when the process queried * doesn't exist. */ + @Test public void testGetParentPidInvalidPid() { assertEquals(-1, Process.getParentPid(BAD_PID)); } @@ -67,11 +81,13 @@ public class ProcessTest extends TestCase { * Tests getThreadGroupLeader() by ensuring that it returns the correct value when the * thread queried doesn't exist. */ + @Test public void testGetThreadGroupLeaderInvalidTid() { // This function takes a TID instead of a PID but BAD_PID should also be a bad TID. assertEquals(-1, Process.getThreadGroupLeader(BAD_PID)); } + @Test public void testGetAdvertisedMem() { assertTrue(Process.getAdvertisedMem() > 0); assertTrue(Process.getTotalMemory() <= Process.getAdvertisedMem()); diff --git a/core/tests/coretests/src/android/os/RedactingFileDescriptorTest.java b/core/tests/coretests/src/android/os/RedactingFileDescriptorTest.java index eff4826040f4..25ce240d1fb3 100644 --- a/core/tests/coretests/src/android/os/RedactingFileDescriptorTest.java +++ b/core/tests/coretests/src/android/os/RedactingFileDescriptorTest.java @@ -24,6 +24,8 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import android.content.Context; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import android.system.Os; import androidx.test.InstrumentationRegistry; @@ -31,6 +33,7 @@ import androidx.test.runner.AndroidJUnit4; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -41,7 +44,11 @@ import java.io.FileOutputStream; import java.util.Arrays; @RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(blockedBy = RedactingFileDescriptor.class) public class RedactingFileDescriptorTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + private Context mContext; private File mFile; diff --git a/core/tests/coretests/src/android/os/TraceTest.java b/core/tests/coretests/src/android/os/TraceTest.java index d07187c2c9d8..593833ec96a7 100644 --- a/core/tests/coretests/src/android/os/TraceTest.java +++ b/core/tests/coretests/src/android/os/TraceTest.java @@ -16,24 +16,36 @@ package android.os; -import android.test.AndroidTestCase; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import android.util.Log; import androidx.test.filters.LargeTest; import androidx.test.filters.SmallTest; import androidx.test.filters.Suppress; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; /** * This class is used to test the native tracing support. Run this test * while tracing on the emulator and then run traceview to view the trace. */ -public class TraceTest extends AndroidTestCase -{ +@RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(blockedBy = Trace.class) +public class TraceTest { private static final String TAG = "TraceTest"; + + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + private int eMethodCalls = 0; private int fMethodCalls = 0; private int gMethodCalls = 0; + @Test public void testNullStrings() { Trace.traceCounter(Trace.TRACE_TAG_ACTIVITY_MANAGER, null, 42); Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, null); @@ -48,6 +60,7 @@ public class TraceTest extends AndroidTestCase Trace.instantForTrack(Trace.TRACE_TAG_ACTIVITY_MANAGER, null, null); } + @Test @SmallTest public void testNativeTracingFromJava() { @@ -80,7 +93,8 @@ public class TraceTest extends AndroidTestCase native void nativeMethod(); native void nativeMethodAndStartTracing(); - + + @Test @LargeTest @Suppress // Failing. public void testMethodTracing() diff --git a/core/tests/coretests/src/android/os/VintfObjectTest.java b/core/tests/coretests/src/android/os/VintfObjectTest.java index ae6e79a040f7..f34b8fd358d9 100644 --- a/core/tests/coretests/src/android/os/VintfObjectTest.java +++ b/core/tests/coretests/src/android/os/VintfObjectTest.java @@ -16,12 +16,27 @@ package android.os; -import junit.framework.TestCase; +import static org.junit.Assert.assertTrue; + +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; + +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(blockedBy = VintfObject.class) +public class VintfObjectTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); -public class VintfObjectTest extends TestCase { /** * Quick check for {@link VintfObject#report VintfObject.report()}. */ + @Test public void testReport() { String[] xmls = VintfObject.report(); assertTrue(xmls.length > 0); diff --git a/core/tests/coretests/src/android/os/WorkSourceParcelTest.java b/core/tests/coretests/src/android/os/WorkSourceParcelTest.java index 483160687723..5f49186df0f5 100644 --- a/core/tests/coretests/src/android/os/WorkSourceParcelTest.java +++ b/core/tests/coretests/src/android/os/WorkSourceParcelTest.java @@ -16,17 +16,25 @@ package android.os; +import static org.junit.Assert.assertEquals; + +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; + import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SmallTest; -import static org.junit.Assert.assertEquals; - +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(AndroidJUnit4.class) @SmallTest +@IgnoreUnderRavenwood(reason = "JNI") public class WorkSourceParcelTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + /** * END_OF_PARCEL_MARKER is added at the end of Parcel on native or java side on write and * then read on java or native side on read. This way we can ensure that no extra data @@ -41,8 +49,11 @@ public class WorkSourceParcelTest { String[] names, int parcelEndMarker); static { - System.loadLibrary("worksourceparceltest_jni"); + if (!RavenwoodRule.isUnderRavenwood()) { + System.loadLibrary("worksourceparceltest_jni"); + } } + /** * Confirm that we can pass WorkSource from native to Java. */ diff --git a/core/tests/coretests/src/android/os/WorkSourceTest.java b/core/tests/coretests/src/android/os/WorkSourceTest.java index 4206fd239528..85dc1277f14f 100644 --- a/core/tests/coretests/src/android/os/WorkSourceTest.java +++ b/core/tests/coretests/src/android/os/WorkSourceTest.java @@ -16,9 +16,19 @@ package android.os; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + import android.os.WorkSource.WorkChain; -import junit.framework.TestCase; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; import java.util.ArrayList; import java.util.List; @@ -28,7 +38,9 @@ import java.util.List; * * These tests will be moved to CTS when finalized. */ -public class WorkSourceTest extends TestCase { +@RunWith(AndroidJUnit4.class) +public class WorkSourceTest { + @Test public void testWorkChain_add() { WorkChain wc1 = new WorkChain(); wc1.addNode(56, null); @@ -46,6 +58,7 @@ public class WorkSourceTest extends TestCase { assertEquals(2, wc1.getSize()); } + @Test public void testWorkChain_equalsHashCode() { WorkChain wc1 = new WorkChain(); WorkChain wc2 = new WorkChain(); @@ -78,6 +91,7 @@ public class WorkSourceTest extends TestCase { assertFalse(wc1.hashCode() == wc2.hashCode()); } + @Test public void testWorkChain_constructor() { WorkChain wc1 = new WorkChain(); wc1.addNode(1, "foo") @@ -91,6 +105,7 @@ public class WorkSourceTest extends TestCase { assertFalse(wc1.equals(wc2)); } + @Test public void testDiff_workChains() { WorkSource ws1 = new WorkSource(); ws1.add(50); @@ -104,6 +119,7 @@ public class WorkSourceTest extends TestCase { assertFalse(ws2.diff(ws1)); } + @Test public void testEquals_workChains() { WorkSource ws1 = new WorkSource(); ws1.add(50); @@ -128,6 +144,7 @@ public class WorkSourceTest extends TestCase { assertFalse(ws3.equals(ws1)); } + @Test public void testEquals_workChains_nullEmptyAreEquivalent() { // Construct a WorkSource that has no WorkChains, but whose workChains list // is non-null. @@ -145,6 +162,7 @@ public class WorkSourceTest extends TestCase { assertFalse(ws1.equals(ws2)); } + @Test public void testWorkSourceParcelling() { WorkSource ws = new WorkSource(); @@ -164,6 +182,7 @@ public class WorkSourceTest extends TestCase { assertEquals(unparcelled, ws); } + @Test public void testSet_workChains() { WorkSource ws1 = new WorkSource(); ws1.add(50); @@ -193,6 +212,7 @@ public class WorkSourceTest extends TestCase { assertEquals(1, ws1.getWorkChains().get(0).getSize()); } + @Test public void testSet_nullWorkChain() { WorkSource ws = new WorkSource(); ws.add(60); @@ -203,6 +223,7 @@ public class WorkSourceTest extends TestCase { assertEquals(0, ws.getWorkChains().size()); } + @Test public void testAdd_workChains() { WorkSource ws = new WorkSource(); ws.createWorkChain().addNode(70, "foo"); @@ -224,6 +245,7 @@ public class WorkSourceTest extends TestCase { assertEquals(2, workChains.size()); } + @Test public void testSet_noWorkChains() { WorkSource ws = new WorkSource(); ws.set(10); @@ -237,6 +259,7 @@ public class WorkSourceTest extends TestCase { assertEquals("foo", ws2.getPackageName(0)); } + @Test public void testDiffChains_noChanges() { // WorkSources with no chains. assertEquals(null, WorkSource.diffChains(new WorkSource(), new WorkSource())); @@ -254,6 +277,7 @@ public class WorkSourceTest extends TestCase { assertEquals(null, WorkSource.diffChains(ws2, ws1)); } + @Test public void testDiffChains_noChains() { // Diffs against a worksource with no chains. WorkSource ws1 = new WorkSource(); @@ -276,6 +300,7 @@ public class WorkSourceTest extends TestCase { assertEquals(ws2.getWorkChains(), diffs[1]); } + @Test public void testDiffChains_onlyAdditionsOrRemovals() { WorkSource ws1 = new WorkSource(); WorkSource ws2 = new WorkSource(); @@ -302,6 +327,7 @@ public class WorkSourceTest extends TestCase { } + @Test public void testDiffChains_generalCase() { WorkSource ws1 = new WorkSource(); WorkSource ws2 = new WorkSource(); @@ -340,6 +366,7 @@ public class WorkSourceTest extends TestCase { assertEquals(new WorkChain().addNode(2, "tag2"), diffs[1].get(1)); } + @Test public void testGetAttributionId() { WorkSource ws = new WorkSource(); WorkChain wc1 = ws.createWorkChain(); @@ -355,6 +382,7 @@ public class WorkSourceTest extends TestCase { assertEquals(100, ws.getAttributionUid()); } + @Test public void testGetAttributionIdWithoutWorkChain() { WorkSource ws1 = new WorkSource(100); ws1.add(200); @@ -365,6 +393,7 @@ public class WorkSourceTest extends TestCase { assertEquals(100, ws2.getAttributionUid()); } + @Test public void testGetAttributionWhenEmpty() { WorkSource ws = new WorkSource(); assertEquals(-1, ws.getAttributionUid()); @@ -374,6 +403,7 @@ public class WorkSourceTest extends TestCase { assertNull(wc.getAttributionTag()); } + @Test public void testGetAttributionTag() { WorkSource ws1 = new WorkSource(); WorkChain wc = ws1.createWorkChain(); @@ -383,6 +413,7 @@ public class WorkSourceTest extends TestCase { assertEquals("tag", wc.getAttributionTag()); } + @Test public void testRemove_fromChainedWorkSource() { WorkSource ws1 = new WorkSource(); ws1.createWorkChain().addNode(50, "foo"); @@ -403,6 +434,7 @@ public class WorkSourceTest extends TestCase { assertEquals(75, ws1.getWorkChains().get(0).getAttributionUid()); } + @Test public void testRemove_fromSameWorkSource() { WorkSource ws1 = new WorkSource(50, "foo"); WorkSource ws2 = ws1; @@ -414,6 +446,7 @@ public class WorkSourceTest extends TestCase { assertEquals("foo", ws1.getPackageName(0)); } + @Test public void testTransferWorkChains() { WorkSource ws1 = new WorkSource(); WorkChain wc1 = ws1.createWorkChain().addNode(100, "tag"); diff --git a/core/tests/coretests/src/com/android/internal/os/BinderCallsStatsTest.java b/core/tests/coretests/src/com/android/internal/os/BinderCallsStatsTest.java index 8207c9ee5ff3..b70f29038b31 100644 --- a/core/tests/coretests/src/com/android/internal/os/BinderCallsStatsTest.java +++ b/core/tests/coretests/src/com/android/internal/os/BinderCallsStatsTest.java @@ -29,7 +29,9 @@ import android.os.Looper; import android.os.Message; import android.os.Process; import android.os.SystemClock; +import android.platform.test.annotations.IgnoreUnderRavenwood; import android.platform.test.annotations.Presubmit; +import android.platform.test.ravenwood.RavenwoodRule; import android.util.ArrayMap; import android.util.SparseArray; @@ -39,6 +41,8 @@ import androidx.test.runner.AndroidJUnit4; import com.android.internal.os.BinderInternal.CallSession; import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -55,13 +59,22 @@ import java.util.Set; @SmallTest @RunWith(AndroidJUnit4.class) @Presubmit +@IgnoreUnderRavenwood(blockedBy = BinderCallsStats.class) public class BinderCallsStatsTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + private static final int WORKSOURCE_UID = Process.FIRST_APPLICATION_UID; private static final int CALLING_UID = 2; private static final int REQUEST_SIZE = 2; private static final int REPLY_SIZE = 3; private final CachedDeviceState mDeviceState = new CachedDeviceState(false, true); - private final TestHandler mHandler = new TestHandler(); + private TestHandler mHandler; + + @Before + public void setUp() { + mHandler = new TestHandler(); + } @Test public void testDetailedOff() { diff --git a/core/tests/coretests/src/com/android/internal/os/BinderHeavyHitterTest.java b/core/tests/coretests/src/com/android/internal/os/BinderHeavyHitterTest.java index e4597b53b1a3..a1b80d24c48f 100644 --- a/core/tests/coretests/src/com/android/internal/os/BinderHeavyHitterTest.java +++ b/core/tests/coretests/src/com/android/internal/os/BinderHeavyHitterTest.java @@ -16,11 +16,19 @@ package com.android.internal.os; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import android.os.Binder; +import androidx.test.runner.AndroidJUnit4; + import com.android.internal.os.BinderCallHeavyHitterWatcher.HeavyHitterContainer; -import junit.framework.TestCase; +import org.junit.Test; +import org.junit.runner.RunWith; import java.util.ArrayList; import java.util.List; @@ -29,7 +37,8 @@ import java.util.Random; /** * Tests for {@link BinderCallHeavyHitterWatcher}. */ -public final class BinderHeavyHitterTest extends TestCase { +@RunWith(AndroidJUnit4.class) +public final class BinderHeavyHitterTest { private boolean mListenerNotified = false; @@ -114,6 +123,7 @@ public final class BinderHeavyHitterTest extends TestCase { } } + @Test public void testPositive() throws Exception { BinderCallHeavyHitterWatcher watcher = BinderCallHeavyHitterWatcher.getInstance(); try { @@ -142,6 +152,7 @@ public final class BinderHeavyHitterTest extends TestCase { } } + @Test public void testNegative() throws Exception { BinderCallHeavyHitterWatcher watcher = BinderCallHeavyHitterWatcher.getInstance(); try { diff --git a/core/tests/coretests/src/com/android/internal/os/BinderLatencyObserverTest.java b/core/tests/coretests/src/com/android/internal/os/BinderLatencyObserverTest.java index 7bd53b9d4fcc..31b55e69cf20 100644 --- a/core/tests/coretests/src/com/android/internal/os/BinderLatencyObserverTest.java +++ b/core/tests/coretests/src/com/android/internal/os/BinderLatencyObserverTest.java @@ -23,7 +23,9 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import android.os.Binder; +import android.platform.test.annotations.IgnoreUnderRavenwood; import android.platform.test.annotations.Presubmit; +import android.platform.test.ravenwood.RavenwoodRule; import android.util.ArrayMap; import android.util.proto.ProtoOutputStream; @@ -36,6 +38,7 @@ import com.android.internal.os.BinderLatencyProto.ApiStats; import com.android.internal.os.BinderLatencyProto.Dims; import com.android.internal.os.BinderLatencyProto.RepeatedApiStats; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -47,7 +50,11 @@ import java.util.Random; @SmallTest @RunWith(AndroidJUnit4.class) @Presubmit +@IgnoreUnderRavenwood(blockedBy = BinderLatencyObserver.class) public class BinderLatencyObserverTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + @Test public void testLatencyCollectionWithMultipleClasses() { TestBinderLatencyObserver blo = new TestBinderLatencyObserver(); diff --git a/core/tests/coretests/src/com/android/internal/os/BinderfsStatsReaderTest.java b/core/tests/coretests/src/com/android/internal/os/BinderfsStatsReaderTest.java index e9f6450c13aa..5f02f046a647 100644 --- a/core/tests/coretests/src/com/android/internal/os/BinderfsStatsReaderTest.java +++ b/core/tests/coretests/src/com/android/internal/os/BinderfsStatsReaderTest.java @@ -20,11 +20,9 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import android.content.Context; import android.os.FileUtils; import android.util.IntArray; -import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; @@ -102,9 +100,8 @@ public class BinderfsStatsReaderTest { private boolean mHasError; @Before - public void setUp() { - Context context = InstrumentationRegistry.getContext(); - mStatsDirectory = context.getDir("binder_logs", Context.MODE_PRIVATE); + public void setUp() throws Exception { + mStatsDirectory = Files.createTempDirectory("BinderfsStatsReaderTest").toFile(); mFreezerBinderAsyncThreshold = 1024; mValidPids = IntArray.fromArray(new int[]{14505, 14461, 542, 540}, 4); mStatsPids = new IntArray(); diff --git a/core/tests/coretests/src/com/android/internal/os/CpuScalingPolicyReaderTest.java b/core/tests/coretests/src/com/android/internal/os/CpuScalingPolicyReaderTest.java index 7f054d136639..2da3873341bb 100644 --- a/core/tests/coretests/src/com/android/internal/os/CpuScalingPolicyReaderTest.java +++ b/core/tests/coretests/src/com/android/internal/os/CpuScalingPolicyReaderTest.java @@ -16,11 +16,8 @@ package com.android.internal.os; -import static androidx.test.InstrumentationRegistry.getContext; - import static com.google.common.truth.Truth.assertThat; -import android.content.Context; import android.os.FileUtils; import androidx.test.runner.AndroidJUnit4; @@ -31,6 +28,7 @@ import org.junit.runner.RunWith; import java.io.File; import java.io.IOException; +import java.nio.file.Files; @RunWith(AndroidJUnit4.class) public class CpuScalingPolicyReaderTest { @@ -38,7 +36,7 @@ public class CpuScalingPolicyReaderTest { @Before public void setup() throws IOException { - File testDir = getContext().getDir("test", Context.MODE_PRIVATE); + File testDir = Files.createTempDirectory("CpuScalingPolicyReaderTest").toFile(); FileUtils.deleteContents(testDir); File policy0 = new File(testDir, "policy0"); diff --git a/core/tests/coretests/src/com/android/internal/os/DebugTest.java b/core/tests/coretests/src/com/android/internal/os/DebugTest.java index 2a8a8571c882..4371f2699d4f 100644 --- a/core/tests/coretests/src/com/android/internal/os/DebugTest.java +++ b/core/tests/coretests/src/com/android/internal/os/DebugTest.java @@ -16,14 +16,22 @@ package com.android.internal.os; +import static org.junit.Assert.assertTrue; + import android.os.Debug; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import androidx.test.filters.SmallTest; -import junit.framework.TestCase; +import org.junit.Rule; +import org.junit.Test; @SmallTest -public class DebugTest extends TestCase { +@IgnoreUnderRavenwood(reason = "Requires ART support") +public class DebugTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); private final static String EXPECTED_GET_CALLER = "com\\.android\\.internal\\.os\\.DebugTest\\.testGetCaller:\\d\\d"; @@ -39,6 +47,7 @@ public class DebugTest extends TestCase { return Debug.getCaller(); } + @Test public void testGetCaller() { assertTrue(callDepth0().matches(EXPECTED_GET_CALLER)); } @@ -62,6 +71,7 @@ public class DebugTest extends TestCase { return callDepth2(); } + @Test public void testGetCallers() { assertTrue(callDepth1().matches(EXPECTED_GET_CALLERS)); } @@ -69,6 +79,7 @@ public class DebugTest extends TestCase { /** * Regression test for b/31943543. Note: must be run under CheckJNI to detect the issue. */ + @Test public void testGetMemoryInfo() { Debug.MemoryInfo info = new Debug.MemoryInfo(); Debug.getMemoryInfo(-1, info); diff --git a/core/tests/coretests/src/com/android/internal/os/KernelCpuProcStringReaderTest.java b/core/tests/coretests/src/com/android/internal/os/KernelCpuProcStringReaderTest.java index cbd2ba4eeabc..1d8628d2ee55 100644 --- a/core/tests/coretests/src/com/android/internal/os/KernelCpuProcStringReaderTest.java +++ b/core/tests/coretests/src/com/android/internal/os/KernelCpuProcStringReaderTest.java @@ -24,6 +24,8 @@ import static org.junit.Assert.assertTrue; import android.content.Context; import android.os.FileUtils; import android.os.SystemClock; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; @@ -31,6 +33,7 @@ import androidx.test.runner.AndroidJUnit4; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -57,7 +60,11 @@ import java.util.stream.IntStream; */ @SmallTest @RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(reason = "Needs kernel support") public class KernelCpuProcStringReaderTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + private File mRoot; private File mTestDir; private File mTestFile; diff --git a/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderDiffTest.java b/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderDiffTest.java index b45f8d2733db..a57a40046a84 100644 --- a/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderDiffTest.java +++ b/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderDiffTest.java @@ -24,13 +24,16 @@ import static org.testng.Assert.assertThrows; import static java.util.stream.Collectors.toList; +import android.platform.test.annotations.IgnoreUnderRavenwood; import android.platform.test.annotations.Presubmit; +import android.platform.test.ravenwood.RavenwoodRule; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -44,7 +47,10 @@ import java.util.Collections; @Presubmit @SmallTest @RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(reason = "Needs kernel support") public class KernelCpuThreadReaderDiffTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); private MockitoSession mMockingSessions; @Mock KernelCpuThreadReader mMockReader; diff --git a/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderEndToEndTest.java b/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderEndToEndTest.java index d43989c06a72..8c5e3d0e0724 100644 --- a/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderEndToEndTest.java +++ b/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderEndToEndTest.java @@ -22,6 +22,8 @@ import static org.junit.Assert.assertTrue; import android.os.Process; import android.os.SystemClock; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.LargeTest; @@ -29,6 +31,7 @@ import androidx.test.filters.LargeTest; import com.android.internal.os.KernelCpuThreadReader.ProcessCpuUsage; import com.android.internal.os.KernelCpuThreadReader.ThreadCpuUsage; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -47,7 +50,10 @@ import java.util.stream.Collectors; */ @RunWith(AndroidJUnit4.class) @LargeTest +@IgnoreUnderRavenwood(reason = "Needs kernel support") public class KernelCpuThreadReaderEndToEndTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); private static final int TIMED_NUM_SAMPLES = 5; private static final int TIMED_START_MILLIS = 500; diff --git a/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderTest.java b/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderTest.java index c3e4014bf29a..7eac2a31bee0 100644 --- a/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderTest.java +++ b/core/tests/coretests/src/com/android/internal/os/KernelCpuThreadReaderTest.java @@ -25,7 +25,9 @@ import static org.testng.Assert.assertThrows; import android.content.Context; import android.os.FileUtils; +import android.platform.test.annotations.IgnoreUnderRavenwood; import android.platform.test.annotations.Presubmit; +import android.platform.test.ravenwood.RavenwoodRule; import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; @@ -33,6 +35,7 @@ import androidx.test.runner.AndroidJUnit4; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -48,7 +51,11 @@ import java.util.function.Predicate; @Presubmit @SmallTest @RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(reason = "Needs kernel support") public class KernelCpuThreadReaderTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + private File mProcDirectory; @Before diff --git a/core/tests/coretests/src/com/android/internal/os/KernelCpuUidActiveTimeReaderTest.java b/core/tests/coretests/src/com/android/internal/os/KernelCpuUidActiveTimeReaderTest.java index 2ccd74e99116..d35e0fc95aa1 100644 --- a/core/tests/coretests/src/com/android/internal/os/KernelCpuUidActiveTimeReaderTest.java +++ b/core/tests/coretests/src/com/android/internal/os/KernelCpuUidActiveTimeReaderTest.java @@ -21,6 +21,8 @@ import static org.junit.Assert.assertTrue; import android.content.Context; import android.os.FileUtils; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import android.util.SparseArray; import android.util.SparseLongArray; @@ -31,6 +33,7 @@ import com.android.internal.os.KernelCpuUidTimeReader.KernelCpuUidActiveTimeRead import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -51,7 +54,11 @@ import java.util.Random; */ @SmallTest @RunWith(Parameterized.class) +@IgnoreUnderRavenwood(reason = "Needs kernel support") public class KernelCpuUidActiveTimeReaderTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + private File mTestDir; private File mTestFile; private KernelCpuUidActiveTimeReader mReader; diff --git a/core/tests/coretests/src/com/android/internal/os/KernelCpuUidBpfMapReaderTest.java b/core/tests/coretests/src/com/android/internal/os/KernelCpuUidBpfMapReaderTest.java index bda21c61375e..610e6aeb210d 100644 --- a/core/tests/coretests/src/com/android/internal/os/KernelCpuUidBpfMapReaderTest.java +++ b/core/tests/coretests/src/com/android/internal/os/KernelCpuUidBpfMapReaderTest.java @@ -23,11 +23,15 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import android.content.Context; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import android.util.SparseArray; import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; + +import org.junit.Rule; import org.junit.runner.RunWith; import com.android.internal.os.KernelCpuUidBpfMapReader.BpfMapIterator; @@ -50,7 +54,11 @@ import java.util.stream.IntStream; @SmallTest @RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(reason = "Needs kernel support") public class KernelCpuUidBpfMapReaderTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + private Random mRand = new Random(12345); private KernelCpuUidTestBpfMapReader mReader; diff --git a/core/tests/coretests/src/com/android/internal/os/KernelCpuUidClusterTimeReaderTest.java b/core/tests/coretests/src/com/android/internal/os/KernelCpuUidClusterTimeReaderTest.java index a0dab28a6da5..8807de089864 100644 --- a/core/tests/coretests/src/com/android/internal/os/KernelCpuUidClusterTimeReaderTest.java +++ b/core/tests/coretests/src/com/android/internal/os/KernelCpuUidClusterTimeReaderTest.java @@ -23,6 +23,8 @@ import static org.junit.Assert.assertTrue; import android.content.Context; import android.os.FileUtils; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import android.util.SparseArray; import androidx.test.InstrumentationRegistry; @@ -32,6 +34,7 @@ import com.android.internal.os.KernelCpuUidTimeReader.KernelCpuUidClusterTimeRea import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -52,7 +55,11 @@ import java.util.Random; */ @SmallTest @RunWith(Parameterized.class) +@IgnoreUnderRavenwood(reason = "Needs kernel support") public class KernelCpuUidClusterTimeReaderTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + private File mTestDir; private File mTestFile; private KernelCpuUidClusterTimeReader mReader; diff --git a/core/tests/coretests/src/com/android/internal/os/KernelCpuUidFreqTimeReaderTest.java b/core/tests/coretests/src/com/android/internal/os/KernelCpuUidFreqTimeReaderTest.java index 783f264d6772..b73034437350 100644 --- a/core/tests/coretests/src/com/android/internal/os/KernelCpuUidFreqTimeReaderTest.java +++ b/core/tests/coretests/src/com/android/internal/os/KernelCpuUidFreqTimeReaderTest.java @@ -24,6 +24,8 @@ import static org.mockito.Mockito.when; import android.content.Context; import android.os.FileUtils; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import android.util.SparseArray; import androidx.test.InstrumentationRegistry; @@ -33,6 +35,7 @@ import com.android.internal.os.KernelCpuUidTimeReader.KernelCpuUidFreqTimeReader import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -55,7 +58,11 @@ import java.util.Random; */ @SmallTest @RunWith(Parameterized.class) +@IgnoreUnderRavenwood(reason = "Needs kernel support") public class KernelCpuUidFreqTimeReaderTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + private File mTestDir; private File mTestFile; private KernelCpuUidFreqTimeReader mReader; diff --git a/core/tests/coretests/src/com/android/internal/os/KernelCpuUidUserSysTimeReaderTest.java b/core/tests/coretests/src/com/android/internal/os/KernelCpuUidUserSysTimeReaderTest.java index 1da1a9095d87..65072262c30f 100644 --- a/core/tests/coretests/src/com/android/internal/os/KernelCpuUidUserSysTimeReaderTest.java +++ b/core/tests/coretests/src/com/android/internal/os/KernelCpuUidUserSysTimeReaderTest.java @@ -23,6 +23,8 @@ import static org.junit.Assert.assertTrue; import android.content.Context; import android.os.FileUtils; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import android.util.SparseArray; import androidx.test.InstrumentationRegistry; @@ -33,6 +35,7 @@ import com.android.internal.os.KernelCpuUidTimeReader.KernelCpuUidUserSysTimeRea import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -49,7 +52,11 @@ import java.util.Random; */ @SmallTest @RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(reason = "Needs kernel support") public class KernelCpuUidUserSysTimeReaderTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + private File mTestDir; private File mTestFile; private KernelCpuUidTimeReader.KernelCpuUidUserSysTimeReader mReader; diff --git a/core/tests/coretests/src/com/android/internal/os/KernelMemoryBandwidthStatsTest.java b/core/tests/coretests/src/com/android/internal/os/KernelMemoryBandwidthStatsTest.java index 60dac8520d14..ad5186e8e3c7 100644 --- a/core/tests/coretests/src/com/android/internal/os/KernelMemoryBandwidthStatsTest.java +++ b/core/tests/coretests/src/com/android/internal/os/KernelMemoryBandwidthStatsTest.java @@ -16,12 +16,18 @@ package com.android.internal.os; +import static org.junit.Assert.assertEquals; + +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import android.util.LongSparseLongArray; import androidx.test.filters.SmallTest; +import androidx.test.runner.AndroidJUnit4; -import junit.framework.TestCase; - +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mockito; import java.io.BufferedReader; @@ -29,12 +35,17 @@ import java.io.BufferedReader; /** * Tests for KernelMemoryBandwidthStats parsing and delta calculation, based on memory_state_time. */ -public class KernelMemoryBandwidthStatsTest extends TestCase { +@RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(reason = "Needs kernel support") +public class KernelMemoryBandwidthStatsTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); /** * Standard example of parsing stats. * @throws Exception */ + @Test @SmallTest public void testParseStandard() throws Exception { KernelMemoryBandwidthStats stats = new KernelMemoryBandwidthStats(); @@ -68,6 +79,7 @@ public class KernelMemoryBandwidthStatsTest extends TestCase { * zero. * @throws Exception */ + @Test @SmallTest public void testParseBackwards() throws Exception { KernelMemoryBandwidthStats zeroStats = new KernelMemoryBandwidthStats(); diff --git a/core/tests/coretests/src/com/android/internal/os/KernelSingleProcessCpuThreadReaderTest.java b/core/tests/coretests/src/com/android/internal/os/KernelSingleProcessCpuThreadReaderTest.java index 2de800bb6d00..f42d26de9847 100644 --- a/core/tests/coretests/src/com/android/internal/os/KernelSingleProcessCpuThreadReaderTest.java +++ b/core/tests/coretests/src/com/android/internal/os/KernelSingleProcessCpuThreadReaderTest.java @@ -19,9 +19,13 @@ package com.android.internal.os; import static com.google.common.truth.Truth.assertThat; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; + import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -31,7 +35,10 @@ import java.util.List; @SmallTest @RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(reason = "Needs kernel support") public class KernelSingleProcessCpuThreadReaderTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); @Test public void getProcessCpuUsage() throws IOException { diff --git a/core/tests/coretests/src/com/android/internal/os/KernelSingleUidTimeReaderTest.java b/core/tests/coretests/src/com/android/internal/os/KernelSingleUidTimeReaderTest.java index 74ab644f1376..120a4de54427 100644 --- a/core/tests/coretests/src/com/android/internal/os/KernelSingleUidTimeReaderTest.java +++ b/core/tests/coretests/src/com/android/internal/os/KernelSingleUidTimeReaderTest.java @@ -23,6 +23,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import android.util.SparseArray; import androidx.test.filters.SmallTest; @@ -30,6 +32,7 @@ import androidx.test.filters.SmallTest; import com.android.internal.os.KernelSingleUidTimeReader.Injector; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -43,7 +46,11 @@ import java.util.Collection; @SmallTest @RunWith(Parameterized.class) +@IgnoreUnderRavenwood(reason = "Needs kernel support") public class KernelSingleUidTimeReaderTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + private final static int TEST_UID = 2222; private final static int TEST_FREQ_COUNT = 5; diff --git a/core/tests/coretests/src/com/android/internal/os/LoggingPrintStreamTest.java b/core/tests/coretests/src/com/android/internal/os/LoggingPrintStreamTest.java index cb8a62c0936c..632dce0fdc8b 100644 --- a/core/tests/coretests/src/com/android/internal/os/LoggingPrintStreamTest.java +++ b/core/tests/coretests/src/com/android/internal/os/LoggingPrintStreamTest.java @@ -16,9 +16,13 @@ package com.android.internal.os; -import androidx.test.filters.Suppress; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; -import junit.framework.TestCase; +import androidx.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; import java.io.PrintWriter; import java.io.StringWriter; @@ -28,11 +32,12 @@ import java.util.Collections; import java.util.List; // this test causes a IllegalAccessError: superclass not accessible -@Suppress -public class LoggingPrintStreamTest extends TestCase { +@RunWith(AndroidJUnit4.class) +public class LoggingPrintStreamTest { TestPrintStream out = new TestPrintStream(); + @Test public void testPrintException() { @SuppressWarnings("ThrowableInstanceNeverThrown") Throwable t = new Throwable("Ignore me."); @@ -47,6 +52,7 @@ public class LoggingPrintStreamTest extends TestCase { assertEquals(Arrays.asList(lines), out.lines); } + @Test public void testPrintObject() { Object o = new Object(); out.print(4); @@ -56,6 +62,7 @@ public class LoggingPrintStreamTest extends TestCase { assertEquals(Arrays.asList("4" + o + "2"), out.lines); } + @Test public void testPrintlnObject() { Object o = new Object(); out.print(4); @@ -65,6 +72,7 @@ public class LoggingPrintStreamTest extends TestCase { assertEquals(Arrays.asList("4" + o, "2"), out.lines); } + @Test public void testPrintf() { out.printf("Name: %s\nEmployer: %s", "Bob", "Google"); assertEquals(Arrays.asList("Name: Bob"), out.lines); @@ -72,6 +80,7 @@ public class LoggingPrintStreamTest extends TestCase { assertEquals(Arrays.asList("Name: Bob", "Employer: Google"), out.lines); } + @Test public void testPrintInt() { out.print(4); out.print(2); @@ -80,12 +89,14 @@ public class LoggingPrintStreamTest extends TestCase { assertEquals(Collections.singletonList("42"), out.lines); } + @Test public void testPrintlnInt() { out.println(4); out.println(2); assertEquals(Arrays.asList("4", "2"), out.lines); } + @Test public void testPrintCharArray() { out.print("Foo\nBar\nTee".toCharArray()); assertEquals(Arrays.asList("Foo", "Bar"), out.lines); @@ -93,6 +104,7 @@ public class LoggingPrintStreamTest extends TestCase { assertEquals(Arrays.asList("Foo", "Bar", "Tee"), out.lines); } + @Test public void testPrintString() { out.print("Foo\nBar\nTee"); assertEquals(Arrays.asList("Foo", "Bar"), out.lines); @@ -100,22 +112,26 @@ public class LoggingPrintStreamTest extends TestCase { assertEquals(Arrays.asList("Foo", "Bar", "Tee"), out.lines); } + @Test public void testPrintlnCharArray() { out.println("Foo\nBar\nTee".toCharArray()); assertEquals(Arrays.asList("Foo", "Bar", "Tee"), out.lines); } + @Test public void testPrintlnString() { out.println("Foo\nBar\nTee"); assertEquals(Arrays.asList("Foo", "Bar", "Tee"), out.lines); } + @Test public void testPrintlnStringWithBufferedData() { out.print(5); out.println("Foo\nBar\nTee"); assertEquals(Arrays.asList("5Foo", "Bar", "Tee"), out.lines); } + @Test public void testAppend() { out.append("Foo\n") .append('4') @@ -125,6 +141,7 @@ public class LoggingPrintStreamTest extends TestCase { assertEquals(Arrays.asList("Foo", "4", "a"), out.lines); } + @Test public void testMultiByteCharactersSpanningBuffers() throws Exception { // assume 3*1000 bytes won't fit in LoggingPrintStream's internal buffer StringBuilder builder = new StringBuilder(); @@ -138,6 +155,7 @@ public class LoggingPrintStreamTest extends TestCase { assertEquals(Arrays.asList(expected), out.lines); } + @Test public void testWriteOneByteAtATimeMultibyteCharacters() throws Exception { String expected = " \u20AC \u20AC \u20AC \u20AC "; for (byte b : expected.getBytes()) { @@ -147,6 +165,7 @@ public class LoggingPrintStreamTest extends TestCase { assertEquals(Arrays.asList(expected), out.lines); } + @Test public void testWriteByteArrayAtATimeMultibyteCharacters() throws Exception { String expected = " \u20AC \u20AC \u20AC \u20AC "; out.write(expected.getBytes()); @@ -154,6 +173,7 @@ public class LoggingPrintStreamTest extends TestCase { assertEquals(Arrays.asList(expected), out.lines); } + @Test public void testWriteWithOffsetsMultibyteCharacters() throws Exception { String expected = " \u20AC \u20AC \u20AC \u20AC "; byte[] bytes = expected.getBytes(); @@ -167,6 +187,7 @@ public class LoggingPrintStreamTest extends TestCase { assertEquals(Arrays.asList(expected), out.lines); } + @Test public void testWriteFlushesOnNewlines() throws Exception { String a = " \u20AC \u20AC "; String b = " \u20AC \u20AC "; diff --git a/core/tests/coretests/src/com/android/internal/os/LongArrayMultiStateCounterTest.java b/core/tests/coretests/src/com/android/internal/os/LongArrayMultiStateCounterTest.java index faccf1ad19a1..f34b185b1c5a 100644 --- a/core/tests/coretests/src/com/android/internal/os/LongArrayMultiStateCounterTest.java +++ b/core/tests/coretests/src/com/android/internal/os/LongArrayMultiStateCounterTest.java @@ -22,16 +22,22 @@ import static org.junit.Assert.assertThrows; import android.os.BadParcelableException; import android.os.Parcel; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(AndroidJUnit4.class) @SmallTest +@IgnoreUnderRavenwood(blockedBy = LongArrayMultiStateCounter.class) public class LongArrayMultiStateCounterTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); @Test public void setStateAndUpdateValue() { diff --git a/core/tests/coretests/src/com/android/internal/os/LongMultiStateCounterTest.java b/core/tests/coretests/src/com/android/internal/os/LongMultiStateCounterTest.java index 341375357902..e064e7483bfa 100644 --- a/core/tests/coretests/src/com/android/internal/os/LongMultiStateCounterTest.java +++ b/core/tests/coretests/src/com/android/internal/os/LongMultiStateCounterTest.java @@ -22,16 +22,22 @@ import static org.junit.Assert.assertThrows; import android.os.BadParcelableException; import android.os.Parcel; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(AndroidJUnit4.class) @SmallTest +@IgnoreUnderRavenwood(blockedBy = LongMultiStateCounterTest.class) public class LongMultiStateCounterTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); @Test public void setStateAndUpdateValue() { diff --git a/core/tests/coretests/src/com/android/internal/os/LooperStatsTest.java b/core/tests/coretests/src/com/android/internal/os/LooperStatsTest.java index 48baf09f5e10..dfb5cc35c5bc 100644 --- a/core/tests/coretests/src/com/android/internal/os/LooperStatsTest.java +++ b/core/tests/coretests/src/com/android/internal/os/LooperStatsTest.java @@ -23,6 +23,7 @@ import android.os.HandlerThread; import android.os.Looper; import android.os.Message; import android.platform.test.annotations.Presubmit; +import android.platform.test.ravenwood.RavenwoodRule; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; @@ -30,6 +31,7 @@ import androidx.test.runner.AndroidJUnit4; import org.junit.After; import org.junit.Assert; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -40,6 +42,9 @@ import java.util.List; @RunWith(AndroidJUnit4.class) @Presubmit public final class LooperStatsTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + private HandlerThread mThreadFirst; private HandlerThread mThreadSecond; private Handler mHandlerFirst; diff --git a/core/tests/coretests/src/com/android/internal/os/MonotonicClockTest.java b/core/tests/coretests/src/com/android/internal/os/MonotonicClockTest.java index 7951270461d7..0742052cce53 100644 --- a/core/tests/coretests/src/com/android/internal/os/MonotonicClockTest.java +++ b/core/tests/coretests/src/com/android/internal/os/MonotonicClockTest.java @@ -43,14 +43,12 @@ public class MonotonicClockTest { assertThat(monotonicClock.monotonicTime()).isEqualTo(1234); ByteArrayOutputStream out = new ByteArrayOutputStream(); - monotonicClock.writeXml(out, Xml.newFastSerializer()); - String xml = out.toString(); - assertThat(xml).contains("timeshift=\"1234\""); + monotonicClock.writeXml(out, Xml.newBinarySerializer()); mClock.realtime = 42; MonotonicClock newMonotonicClock = new MonotonicClock(0, mClock); - newMonotonicClock.readXml(new ByteArrayInputStream(out.toByteArray()), - Xml.newFastPullParser()); + ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); + newMonotonicClock.readXml(in, Xml.newBinaryPullParser()); mClock.realtime = 2000; assertThat(newMonotonicClock.monotonicTime()).isEqualTo(1234 - 42 + 2000); diff --git a/core/tests/coretests/src/com/android/internal/os/PowerProfileTest.java b/core/tests/coretests/src/com/android/internal/os/PowerProfileTest.java index 77202d1faa31..c0f0714e52cc 100644 --- a/core/tests/coretests/src/com/android/internal/os/PowerProfileTest.java +++ b/core/tests/coretests/src/com/android/internal/os/PowerProfileTest.java @@ -27,6 +27,8 @@ import android.annotation.XmlRes; import android.content.Context; import android.content.res.Resources; import android.content.res.XmlResourceParser; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; @@ -38,6 +40,7 @@ import com.android.internal.util.XmlUtils; import org.junit.Assert; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -50,7 +53,10 @@ import org.junit.runner.RunWith; */ @SmallTest @RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(blockedBy = PowerProfile.class) public class PowerProfileTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); static final String TAG_TEST_MODEM = "test-modem"; static final String ATTR_NAME = "name"; diff --git a/core/tests/coretests/src/com/android/internal/os/PowerStatsTest.java b/core/tests/coretests/src/com/android/internal/os/PowerStatsTest.java index 29da2319adc2..b99e2026ef26 100644 --- a/core/tests/coretests/src/com/android/internal/os/PowerStatsTest.java +++ b/core/tests/coretests/src/com/android/internal/os/PowerStatsTest.java @@ -21,17 +21,23 @@ import static com.google.common.truth.Truth.assertThat; import android.os.BatteryConsumer; import android.os.Parcel; import android.os.PersistableBundle; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(AndroidJUnit4.class) @SmallTest +@IgnoreUnderRavenwood(reason = "Needs kernel support") public class PowerStatsTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); private PowerStats.DescriptorRegistry mRegistry; private PowerStats.Descriptor mDescriptor; diff --git a/core/tests/coretests/src/com/android/internal/os/ProcLocksReaderTest.java b/core/tests/coretests/src/com/android/internal/os/ProcLocksReaderTest.java index c3d40eb09237..f61fc7c33eb3 100644 --- a/core/tests/coretests/src/com/android/internal/os/ProcLocksReaderTest.java +++ b/core/tests/coretests/src/com/android/internal/os/ProcLocksReaderTest.java @@ -18,11 +18,9 @@ package com.android.internal.os; import static org.junit.Assert.assertTrue; -import android.content.Context; import android.os.FileUtils; import android.util.IntArray; -import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; @@ -45,9 +43,8 @@ public class ProcLocksReaderTest implements private ArrayList<int[]> mPids = new ArrayList<>(); @Before - public void setUp() { - Context context = InstrumentationRegistry.getContext(); - mProcDirectory = context.getDir("proc", Context.MODE_PRIVATE); + public void setUp() throws Exception { + mProcDirectory = Files.createTempDirectory("ProcLocksReaderTest").toFile(); } @After diff --git a/core/tests/coretests/src/com/android/internal/os/ProcStatsUtilTest.java b/core/tests/coretests/src/com/android/internal/os/ProcStatsUtilTest.java index e97caf8c0631..3e4f34d71f5f 100644 --- a/core/tests/coretests/src/com/android/internal/os/ProcStatsUtilTest.java +++ b/core/tests/coretests/src/com/android/internal/os/ProcStatsUtilTest.java @@ -18,10 +18,8 @@ package com.android.internal.os; import static org.junit.Assert.assertEquals; -import android.content.Context; import android.os.FileUtils; -import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; @@ -41,9 +39,8 @@ public class ProcStatsUtilTest { private File mProcDirectory; @Before - public void setUp() { - Context context = InstrumentationRegistry.getContext(); - mProcDirectory = context.getDir("proc", Context.MODE_PRIVATE); + public void setUp() throws Exception { + mProcDirectory = Files.createTempDirectory("ProcStatsUtilTest").toFile(); } @After diff --git a/core/tests/coretests/src/com/android/internal/os/ProcTimeInStateReaderTest.java b/core/tests/coretests/src/com/android/internal/os/ProcTimeInStateReaderTest.java index 9db3f8a6e187..a706350c71a5 100644 --- a/core/tests/coretests/src/com/android/internal/os/ProcTimeInStateReaderTest.java +++ b/core/tests/coretests/src/com/android/internal/os/ProcTimeInStateReaderTest.java @@ -20,15 +20,16 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; -import android.content.Context; import android.os.FileUtils; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; -import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -39,14 +40,16 @@ import java.nio.file.Path; @SmallTest @RunWith(AndroidJUnit4.class) +@IgnoreUnderRavenwood(blockedBy = ProcTimeInStateReader.class) public class ProcTimeInStateReaderTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); private File mProcDirectory; @Before - public void setUp() { - Context context = InstrumentationRegistry.getContext(); - mProcDirectory = context.getDir("proc", Context.MODE_PRIVATE); + public void setUp() throws Exception { + mProcDirectory = Files.createTempDirectory("ProcTimeInStateReaderTest").toFile(); } @After diff --git a/core/tests/coretests/src/com/android/internal/os/ProcessCpuTrackerTest.java b/core/tests/coretests/src/com/android/internal/os/ProcessCpuTrackerTest.java index 81cc9d830228..d11c500b055a 100644 --- a/core/tests/coretests/src/com/android/internal/os/ProcessCpuTrackerTest.java +++ b/core/tests/coretests/src/com/android/internal/os/ProcessCpuTrackerTest.java @@ -18,15 +18,23 @@ package com.android.internal.os; import static com.google.common.truth.Truth.assertThat; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; + import androidx.test.filters.SmallTest; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @SmallTest @RunWith(JUnit4.class) +@IgnoreUnderRavenwood(reason = "Needs kernel support") public class ProcessCpuTrackerTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); + @Test public void testGetCpuTime() throws Exception { final ProcessCpuTracker tracker = new ProcessCpuTracker(false); diff --git a/core/tests/coretests/src/com/android/internal/os/StoragedUidIoStatsReaderTest.java b/core/tests/coretests/src/com/android/internal/os/StoragedUidIoStatsReaderTest.java index 85eafc57acc3..84c93c232d9f 100644 --- a/core/tests/coretests/src/com/android/internal/os/StoragedUidIoStatsReaderTest.java +++ b/core/tests/coretests/src/com/android/internal/os/StoragedUidIoStatsReaderTest.java @@ -20,10 +20,8 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; -import android.content.Context; import android.os.FileUtils; -import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; @@ -48,7 +46,6 @@ import java.nio.file.Files; @RunWith(AndroidJUnit4.class) public class StoragedUidIoStatsReaderTest { - private File mRoot; private File mTestDir; private File mTestFile; // private Random mRand = new Random(); @@ -57,15 +54,10 @@ public class StoragedUidIoStatsReaderTest { @Mock private StoragedUidIoStatsReader.Callback mCallback; - private Context getContext() { - return InstrumentationRegistry.getContext(); - } - @Before - public void setUp() { + public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - mTestDir = getContext().getDir("test", Context.MODE_PRIVATE); - mRoot = getContext().getFilesDir(); + mTestDir = Files.createTempDirectory("StoragedUidIoStatsReaderTest").toFile(); mTestFile = new File(mTestDir, "test.file"); mStoragedUidIoStatsReader = new StoragedUidIoStatsReader(mTestFile.getAbsolutePath()); } @@ -73,10 +65,8 @@ public class StoragedUidIoStatsReaderTest { @After public void tearDown() throws Exception { FileUtils.deleteContents(mTestDir); - FileUtils.deleteContents(mRoot); } - /** * Tests that reading will never call the callback. */ diff --git a/core/tests/coretests/src/com/android/internal/power/EnergyConsumerStatsTest.java b/core/tests/coretests/src/com/android/internal/power/EnergyConsumerStatsTest.java index e09cfd21e605..ae2ef0cb4e51 100644 --- a/core/tests/coretests/src/com/android/internal/power/EnergyConsumerStatsTest.java +++ b/core/tests/coretests/src/com/android/internal/power/EnergyConsumerStatsTest.java @@ -34,10 +34,13 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import android.os.Parcel; +import android.platform.test.annotations.IgnoreUnderRavenwood; +import android.platform.test.ravenwood.RavenwoodRule; import android.view.Display; import androidx.test.filters.SmallTest; +import org.junit.Rule; import org.junit.Test; import java.util.Arrays; @@ -46,7 +49,10 @@ import java.util.Arrays; * Test class for {@link EnergyConsumerStats}. */ @SmallTest +@IgnoreUnderRavenwood(reason = "Needs kernel support") public class EnergyConsumerStatsTest { + @Rule + public final RavenwoodRule mRavenwood = new RavenwoodRule(); @Test public void testConstruction() { diff --git a/ravenwood/ravenwood-annotation-allowed-classes.txt b/ravenwood/ravenwood-annotation-allowed-classes.txt index 2ba5f6b05e26..9fcabd67f9dd 100644 --- a/ravenwood/ravenwood-annotation-allowed-classes.txt +++ b/ravenwood/ravenwood-annotation-allowed-classes.txt @@ -27,6 +27,8 @@ android.util.Xml android.os.BatteryConsumer android.os.Binder android.os.Binder$IdentitySupplier +android.os.Broadcaster +android.os.BundleMerger android.os.FileUtils android.os.FileUtils$MemoryPipe android.os.Handler @@ -36,12 +38,15 @@ android.os.IBinder android.os.Looper android.os.Message android.os.MessageQueue +android.os.PackageTagsList android.os.Parcel android.os.Parcelable android.os.Process android.os.SystemClock android.os.ThreadLocalWorkSource +android.os.TimestampedValue android.os.UserHandle +android.os.WorkSource android.content.ClipData android.content.ClipData$Item @@ -95,8 +100,6 @@ android.content.ContentProvider com.android.server.LocalServices -com.android.internal.os.SomeArgs - com.android.internal.util.BitUtils com.android.internal.util.BitwiseInputStream com.android.internal.util.BitwiseOutputStream @@ -118,6 +121,23 @@ com.android.internal.util.QuickSelect com.android.internal.util.RingBuffer com.android.internal.util.StringPool +com.android.internal.os.BinderCallHeavyHitterWatcher +com.android.internal.os.BinderDeathDispatcher +com.android.internal.os.BinderfsStatsReader +com.android.internal.os.BinderLatencyBuckets +com.android.internal.os.CachedDeviceState +com.android.internal.os.Clock +com.android.internal.os.CpuScalingPolicies +com.android.internal.os.CpuScalingPolicyReader +com.android.internal.os.KernelCpuThreadReader +com.android.internal.os.LoggingPrintStream +com.android.internal.os.LooperStats +com.android.internal.os.MonotonicClock +com.android.internal.os.ProcLocksReader +com.android.internal.os.ProcStatsUtil +com.android.internal.os.SomeArgs +com.android.internal.os.StoragedUidIoStatsReader + com.google.android.collect.Lists com.google.android.collect.Maps com.google.android.collect.Sets |