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

Commit b9461f64 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Enhance "enablement" mechanism

- Now we have a dedicated policy file for each test module.
RavenwoodEnablementChecker can load multiple policy files and
it'll only use the one matching the current test. Policy files now
start with the test module name.

- Policy files now support wildcards: "**" for "any string" and "*" for
"any string without periods".

- Policy lines now match from the top of the file. A default policy
needs to be put at the end as "** false" (to disable all tests).
But method-level policies can still override it because of the following
rule, so you can put method-level polices after this.

- There are now 3 states: "enable" ("true"), "disable" ("false")
and "never".

- $RAVENWOOD_RUN_DISABLED_TESTS now runs enabled tests too, in addition
to disabled tests. But it will still not run "never" tests.

This makes the test stats files to be always "correct", even after
a RAVENWOOD_RUN_DISABLED_TESTS=1 run.

- Now, if a policy file has a method as "enabled", the enclosing class
will also be executed, even if the class's policy is "disable".
And the rest of the methods in the same class will still default to the
classes policy. So if you have the following lines:

TestClass       false
TestClass#test1 true

Then TestClass#test1 will be executed, but the other methods in
TestClass still won't be executed.

- A new script update-enablement-policies.sh updates all the policy
files using the "latest" stats files. This will add method level
"true" / "false" according to the latest result. So if you run it after
a RAVENWOOD_RUN_DISABLED_TESTS=1, you'll potentially get more tests to
be enabled.

Bug: 292141694
Fix: 435711089
Flag: TEST_ONLY
Test: $ANDROID_BUILD_TOP/frameworks/base/ravenwood/scripts/run-ravenwood-tests.sh -s
Test: Manual test running update-enablement-policies.sh
Change-Id: I22d5650877bec633ecf4a05dc60c2747b092481c
parent ee24e3f5
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.function.Supplier;
import java.util.regex.Pattern;

public class RavenwoodInternalUtils {
    public static final String TAG = "Ravenwood";
@@ -270,4 +271,32 @@ public class RavenwoodInternalUtils {
    public static <T> T withDefault(@Nullable T value, @Nullable T def) {
        return value != null ? value : def;
    }


    private static final Pattern sWildcardValidater =
            Pattern.compile("[^\\w.*$]");

    /**
     * Convert a wildcard string using "*" and "**" to match Java classnames.
     *
     * The input string can only contain alnum, "$", "." and "*".
     */
    public static Pattern parseClassNameWildcard(String pattern) {
        // Convert "**" -> match anything (== .*)
        // Convert "*" -> match anything except for periods (== [^.]*)
        // Convert "." -> \.

        if (sWildcardValidater.matcher(pattern).find()) {
            throw new IllegalArgumentException(
                    "Invalid character found in wildcard '" + pattern + "'");
        }

        // Save "**" to something else and convert it back to ".*" at the end.
        String temp = pattern.replace("**", "@@");
        temp = temp.replace(".", "\\.");
        temp = temp.replace("$", "\\$");
        temp = temp.replace("*", "[^.]*");
        temp = temp.replace("@@", ".*");
        return Pattern.compile(temp);
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -118,7 +118,7 @@ public final class RavenwoodAwareTestRunner extends RavenwoodAwareTestRunnerBase
         *
         * We need to do it before instantiating TestClass for b/367694651.
         */
        if (!RavenwoodEnablementChecker.shouldRunClassOnRavenwood(testClass, true)) {
        if (!RavenwoodEnablementChecker.getInstance().shouldRunClassOnRavenwood(testClass)) {
            mRealRunner = new ClassSkippingTestRunner(testClass);
            return;
        }
@@ -244,7 +244,7 @@ public final class RavenwoodAwareTestRunner extends RavenwoodAwareTestRunnerBase
        private boolean mFilteredOut;

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

@@ -288,7 +288,7 @@ public final class RavenwoodAwareTestRunner extends RavenwoodAwareTestRunnerBase
        // Class-level annotations are checked by the runner already, so we only check
        // method-level annotations here.
        if (scope == Scope.Instance && order == Order.Outer) {
            if (!RavenwoodEnablementChecker.shouldEnableOnRavenwood(description, true)) {
            if (!RavenwoodEnablementChecker.getInstance().shouldEnableOnRavenwood(description)) {
                return false;
            }
        }
+8 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import android.util.Log_ravenwood;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.os.RuntimeInit;
import com.android.ravenwood.OpenJdkWorkaround;
import com.android.ravenwood.RavenwoodRuntimeNative;
import com.android.ravenwood.common.RavenwoodInternalUtils;
import com.android.ravenwood.common.SneakyThrow;
@@ -263,6 +264,13 @@ public class RavenwoodDriver {
        // TODO(b/428775903) Make sure nothing would try to access compat-IDs before this call.
        // We may want to do it within initAppDriver().
        initializeCompatIds();

        // `pkill -USR2 -f tradefed-isolation.jar` will interrupt the test thread.
        final Thread testThread = Thread.currentThread();
        OpenJdkWorkaround.registerSignalHandler("USR2", () -> {
            sRawStdErr.println("-----SIGUSR2 HANDLER-----");
            testThread.interrupt();
        });
    }

    /**
+491 −189

File changed.

Preview size limit exceeded, changes collapsed.

+12 −0
Original line number Diff line number Diff line
@@ -367,4 +367,16 @@ public final class RavenwoodEnvironment {
    public boolean getBoolEnvVar(String keyName) {
        return "1".equals(getEnvVar(keyName, ""));
    }

    /**
     * Reads a per-module environmental string variable, and split it with whitespace.
     * Default is an empty array;
     */
    public String[] getArrayEnvVar(String keyName) {
        var val = getEnvVar(keyName, "");
        if (val.isEmpty()) {
            return new String[0];
        }
        return val.split("\\s+");
    }
}
Loading