Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 24d59ab6 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Make sure DisabledOnRavenwood on unloadable tests works

Fix: 367694651
Test: $ANDROID_BUILD_TOP/frameworks/base/ravenwood/scripts/run-ravenwood-tests.sh
Test: mkdir -p frameworks/base/packages/SystemUI/multivalentTests/src/com/android/systemui/privacy/ &&
    mv fameworks/base/packages/SystemUI/tests/src/com/android/systemui/privacy/PrivacyDialogControllerTest.kt \
      frameworks/base/packages/SystemUI/multivalentTests/src/com/android/systemui/privacy/ &&
    atest SystemUiRavenTests

Flag: EXEMPT host test change only
Change-Id: If5166537febae5c3af46474a2b65da0b7ea16fec
parent 82fc0100
Loading
Loading
Loading
Loading
+12 −13
Original line number Diff line number Diff line
@@ -195,23 +195,25 @@ public final class RavenwoodAwareTestRunner extends Runner implements Filterable
        try {
            performGlobalInitialization();

            mTestClass = new TestClass(testClass);

            Log.v(TAG, "RavenwoodAwareTestRunner starting for " + testClass.getCanonicalName());

            onRunnerInitializing();

            /*
             * If the class has @DisabledOnRavenwood, then we'll delegate to
             * ClassSkippingTestRunner, which simply skips it.
             *
             * We need to do it before instantiating TestClass for b/367694651.
             */
            if (isOnRavenwood() && !RavenwoodAwareTestRunnerHook.shouldRunClassOnRavenwood(
                    mTestClass.getJavaClass())) {
                mRealRunner = new ClassSkippingTestRunner(mTestClass);
                    testClass)) {
                mRealRunner = new ClassSkippingTestRunner(testClass);
                mDescription = mRealRunner.getDescription();
                return;
            }

            mTestClass = new TestClass(testClass);

            Log.v(TAG, "RavenwoodAwareTestRunner starting for " + testClass.getCanonicalName());

            onRunnerInitializing();

            // Find the real runner.
            final Class<? extends Runner> realRunnerClass;
            final InnerRunner innerRunnerAnnotation = mTestClass.getAnnotation(InnerRunner.class);
@@ -444,14 +446,11 @@ public final class RavenwoodAwareTestRunner extends Runner implements Filterable
     * filter.
     */
    private static class ClassSkippingTestRunner extends Runner implements Filterable {
        private final TestClass mTestClass;
        private final Description mDescription;
        private boolean mFilteredOut;

        ClassSkippingTestRunner(TestClass testClass) {
            mTestClass = testClass;
            mDescription = Description.createTestDescription(
                    testClass.getJavaClass(), testClass.getJavaClass().getSimpleName());
        ClassSkippingTestRunner(Class<?> testClass) {
            mDescription = Description.createTestDescription(testClass, testClass.getSimpleName());
            mFilteredOut = false;
        }

+32 −0
Original line number Diff line number Diff line
@@ -17,12 +17,14 @@ package com.android.ravenwoodtest.runnercallbacktests;

import static org.junit.Assume.assumeTrue;

import android.platform.test.annotations.DisabledOnRavenwood;
import android.platform.test.annotations.NoRavenizer;
import android.platform.test.ravenwood.RavenwoodAwareTestRunner;

import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.ClassRule;
@@ -353,4 +355,34 @@ public class RavenwoodRunnerCallbackTest extends RavenwoodRunnerTestBase {
        public void test2() {
        }
    }

    /**
     * The test class is unloadable, but has a @DisabledOnRavenwood.
     */
    @RunWith(AndroidJUnit4.class)
    @DisabledOnRavenwood
    // CHECKSTYLE:OFF
    @Expected("""
    testRunStarted: classes
    testSuiteStarted: classes
    testSuiteStarted: ClassUnloadbleTest(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerCallbackTest$ClassUnloadbleTest)
    testIgnored: ClassUnloadbleTest(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerCallbackTest$ClassUnloadbleTest)
    testSuiteFinished: ClassUnloadbleTest(com.android.ravenwoodtest.runnercallbacktests.RavenwoodRunnerCallbackTest$ClassUnloadbleTest)
    testSuiteFinished: classes
    testRunFinished: 0,0,0,1
    """)
    // CHECKSTYLE:ON
    public static class ClassUnloadbleTest {
        static {
            Assert.fail("Class unloadable!");
        }

        @Test
        public void test1() {
        }

        @Test
        public void test2() {
        }
    }
}