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

Commit 3be795c0 authored by Makoto Onuki's avatar Makoto Onuki Committed by Android (Google) Code Review
Browse files

Merge "Enhance "enablement" mechanism" into main

parents 07111953 b9461f64
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