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

Commit 5bf79a4f authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Remove @DisabledOnNonRavenwood

I added it "just in case we need it", but it was a weird annotation
because it'll only affect device side behavior yet it'll require a
RavenwoodRule to take effect.

With Ravenizer, it'd be even more weird because now all other annotations
would be handled by the implicit test runner, but @DisabledOnNonRavenwood
would still need an explicit @DisabledOnNonRavenwood.

So let's just remove it. It's not used anywhere yet.

With Ravenizer, we could do it differently -- for example, we could
add an @UnIgnoreOnRavenwood, which is to be used with @Ignore,
and have Ravenizer remove the @Ignore.

Flag: EXEMPT host test change only
Bug: 292141694
Test: $ANDROID_BUILD_TOP/frameworks/base/ravenwood/scripts/run-ravenwood-tests.sh
Change-Id: Icfd5e33f07e217a95012164dc8fa28f7d0ba6daa
parent 41ade60e
Loading
Loading
Loading
Loading
+0 −43
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.ravenwoodtest.bivalenttest;

import android.platform.test.ravenwood.RavenwoodClassRule;
import android.platform.test.ravenwood.RavenwoodRule;

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

import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
// TODO: atest RavenwoodBivalentTest_device fails with the following message.
// `RUNNER ERROR: Instrumentation reported numtests=7 but only ran 6`
// @android.platform.test.annotations.DisabledOnNonRavenwood
// Figure it out and then make DisabledOnNonRavenwood support TYPEs as well.
@Ignore
public class RavenwoodClassRuleRavenwoodOnlyTest {
    @ClassRule
    public static final RavenwoodClassRule sRavenwood = new RavenwoodClassRule();

    @Test
    public void testRavenwoodOnly() {
        Assert.assertTrue(RavenwoodRule.isOnRavenwood());
    }
}
+0 −7
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@
 */
package com.android.ravenwoodtest.bivalenttest;

import android.platform.test.annotations.DisabledOnNonRavenwood;
import android.platform.test.annotations.DisabledOnRavenwood;
import android.platform.test.ravenwood.RavenwoodRule;
import android.util.Log;
@@ -38,12 +37,6 @@ public class RavenwoodRuleTest {
        Assert.assertFalse(RavenwoodRule.isOnRavenwood());
    }

    @Test
    @DisabledOnNonRavenwood
    public void testRavenwoodOnly() {
        Assert.assertTrue(RavenwoodRule.isOnRavenwood());
    }

    @Test
    public void testDumpSystemProperties() {
        Log.w("XXX", "System properties");
+0 −51
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.platform.test.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * Tests marked with this annotation are only executed when running on Ravenwood, but not
 * on a device.
 *
 * This is basically equivalent to the opposite of {@link DisabledOnRavenwood}, but in order to
 * avoid complex structure, and there's no equivalent to the opposite {@link EnabledOnRavenwood},
 * which means if a test class has this annotation, you can't negate it in subclasses or
 * on a per-method basis.
 *
 * THIS ANNOTATION CANNOT BE ADDED TO CLASSES AT THIS PONINT.
 * See {@link com.android.ravenwoodtest.bivalenttest.RavenwoodClassRuleRavenwoodOnlyTest}
 * for the reason.
 *
 * The {@code RAVENWOOD_RUN_DISABLED_TESTS} environmental variable won't work because it won't be
 * propagated to the device. (We may support it in the future, possibly using a debug. sysprop.)
 *
 * @hide
 */
@Inherited
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface DisabledOnNonRavenwood {
    /**
     * General free-form description of why this test is being ignored.
     */
    String reason() default "";
}
+1 −6
Original line number Diff line number Diff line
@@ -18,14 +18,12 @@ package android.platform.test.ravenwood;

import static android.platform.test.ravenwood.RavenwoodRule.ENABLE_PROBE_IGNORED;
import static android.platform.test.ravenwood.RavenwoodRule.IS_ON_RAVENWOOD;
import static android.platform.test.ravenwood.RavenwoodRule.shouldEnableOnDevice;
import static android.platform.test.ravenwood.RavenwoodRule.shouldEnableOnRavenwood;
import static android.platform.test.ravenwood.RavenwoodRule.shouldStillIgnoreInProbeIgnoreMode;

import android.platform.test.annotations.DisabledOnRavenwood;
import android.platform.test.annotations.EnabledOnRavenwood;

import org.junit.Assert;
import org.junit.Assume;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
@@ -43,10 +41,7 @@ public class RavenwoodClassRule implements TestRule {
    @Override
    public Statement apply(Statement base, Description description) {
        if (!IS_ON_RAVENWOOD) {
            // This should be "Assume", not Assert, but if we use assume here, the device side
            // test runner would complain.
            // See the TODO comment in RavenwoodClassRuleRavenwoodOnlyTest.
            Assert.assertTrue(shouldEnableOnDevice(description));
            // No check on a real device.
        } else if (ENABLE_PROBE_IGNORED) {
            Assume.assumeFalse(shouldStillIgnoreInProbeIgnoreMode(description));
        } else {
+0 −17
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import static org.junit.Assert.fail;

import android.app.Instrumentation;
import android.content.Context;
import android.platform.test.annotations.DisabledOnNonRavenwood;
import android.platform.test.annotations.DisabledOnRavenwood;
import android.platform.test.annotations.EnabledOnRavenwood;
import android.platform.test.annotations.IgnoreUnderRavenwood;
@@ -273,21 +272,6 @@ public class RavenwoodRule implements TestRule {
                "Instrumentation is only available during @Test execution");
    }

    static boolean shouldEnableOnDevice(Description description) {
        if (description.isTest()) {
            if (description.getAnnotation(DisabledOnNonRavenwood.class) != null) {
                return false;
            }
        }
        final var clazz = description.getTestClass();
        if (clazz != null) {
            if (clazz.getAnnotation(DisabledOnNonRavenwood.class) != null) {
                return false;
            }
        }
        return true;
    }

    /**
     * Determine if the given {@link Description} should be enabled when running on the
     * Ravenwood test environment.
@@ -351,7 +335,6 @@ public class RavenwoodRule implements TestRule {
    public Statement apply(Statement base, Description description) {
        // No special treatment when running outside Ravenwood; run tests as-is
        if (!IS_ON_RAVENWOOD) {
            Assume.assumeTrue(shouldEnableOnDevice(description));
            return base;
        }