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

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

Merge "Make run-ravenwood-tests.sh to set "enablement" policy too" into main

parents e8402bc4 342eb08e
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -60,6 +60,8 @@ import com.android.server.compat.PlatformCompat;
import org.junit.internal.management.ManagementFactory;
import org.junit.runner.Description;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Comparator;
import java.util.HashMap;
@@ -90,6 +92,18 @@ public class RavenwoodDriver {
    static final PrintStream sRawStdOut = System.out;
    static final PrintStream sRawStdErr = System.err;

    /**
     * The current directory when the test started.
     */
    private static final File sInitialDirectory;
    static {
        try {
            sInitialDirectory = new File(".").getCanonicalFile();
        } catch (IOException e) {
            throw new RuntimeException("Unable to get the current directory", e);
        }
    }

    private static final String MAIN_THREAD_NAME = "Ravenwood:Main";
    private static final String TEST_THREAD_NAME = "Ravenwood:Test";

@@ -575,4 +589,15 @@ public class RavenwoodDriver {
        var itz = android.icu.util.TimeZone.getDefault();
        Log.i(TAG, "  android.icu.util.TimeZone="  + itz.getDisplayName() + " / " + itz);
    }

    /**
     * @return the name of the current test module.
     *
     * The current version "guesses" the name from the current directory name.
     *
     * TODO: Write the real module name in ravenwood.go to ravenwood.properties and use that.
     */
    public static String getTestModuleName() {
        return sInitialDirectory.getName();
    }
}
+28 −10
Original line number Diff line number Diff line
@@ -108,18 +108,23 @@ public class RavenwoodEnablementChecker {
    }

    private static class EnablementPolicy {
        boolean mEnabled = true;
        final Map<String, Boolean> mModules = new HashMap<>();
        final Map<String, ClassEnablementPolicy> mClasses = new HashMap<>();

        boolean shouldEnableClass(String className) {
        private boolean shouldEnableModule(String testModule) {
            return mModules.getOrDefault(testModule, true);
        }

        boolean shouldEnableClass(String testModule, String className) {
            final boolean moduleEnabled = shouldEnableModule(testModule);
            if (mClasses.isEmpty()) {
                return mEnabled;
                return moduleEnabled;
            }
            var clazz = mClasses.get(className);
            if (clazz == null) {
                return mEnabled;
                return moduleEnabled;
            }
            return clazz.mEnabled != null ? clazz.mEnabled : mEnabled;
            return clazz.mEnabled != null ? clazz.mEnabled : moduleEnabled;
        }

        Boolean shouldEnableMethod(String className, String methodName) {
@@ -141,9 +146,9 @@ public class RavenwoodEnablementChecker {
            if (columns.length != 2) return;
            var signature = columns[0];
            boolean enable = Boolean.parseBoolean(columns[1]);
            if (signature.equals("*")) {
                // Setting the global default policy
                mEnabled = enable;
            if (signature.contains("*")) {
                // Setting the test module default policy
                parseWildcard(signature, enable);
            } else {
                var s = signature.split("\\#");
                var clazz = s[0];
@@ -158,8 +163,20 @@ public class RavenwoodEnablementChecker {
            }
        }

        private void parseWildcard(String signature, boolean enabled) {
            // Only "[TEST-MODULE]:*" is supported, for now.
            if (signature.endsWith(":*")) {
                var module = signature.substring(0, signature.length() - 2);
                mModules.put(module, enabled);
                return;
            }
            throw new RuntimeException(
                    "Invalid use of '*' in enablement policy '" + signature + "': "
                    + " Only '[TEST-MODULE]:*' is supported");
        }

        void clear() {
            mEnabled = true;
            mModules.clear();
            mClasses.clear();
        }
    }
@@ -242,7 +259,8 @@ public class RavenwoodEnablementChecker {
        } else if (testClass.getAnnotation(DisabledOnRavenwood.class) != null) {
            result = false;
        } else {
            result = sEnablementPolicy.shouldEnableClass(testClass.getName());
            result = sEnablementPolicy.shouldEnableClass(
                    RavenwoodDriver.getTestModuleName(), testClass.getName());
        }
        if (checkRunDisabledTestsFlag && RUN_DISABLED_TESTS) {
            // Invert the result + check the really disable pattern
+1 −12
Original line number Diff line number Diff line
@@ -139,7 +139,7 @@ public class RavenwoodTestStats {

    /** Ctor */
    public RavenwoodTestStats() {
        String testModuleName = guessTestModuleName();
        String testModuleName = RavenwoodDriver.getTestModuleName();

        var basename = "Ravenwood-stats_" + testModuleName + "_";

@@ -174,17 +174,6 @@ public class RavenwoodTestStats {
        mOutputWriter.flush();
    }

    private String guessTestModuleName() {
        // Assume the current directory name is the test module name.
        File cwd;
        try {
            cwd = new File(".").getCanonicalFile();
        } catch (IOException e) {
            throw new RuntimeException("Failed to get the current directory", e);
        }
        return cwd.getName();
    }

    private void addResult(String className, String methodName, Outcome outcome) {
        mStats.computeIfAbsent(className, k -> new TreeMap<>()).putIfAbsent(methodName, outcome);
    }
+37 −7
Original line number Diff line number Diff line
@@ -25,10 +25,19 @@
#   -f PCRE: Specify inclusion filter in PCRE

set -e
shopt -s nullglob # if a glob matches no file, expands to an empty string.

# Move to the script's directory
cd "${0%/*}"

# Find the enablement files. This may be an empty list if there's no match.
default_enablement_policy=(../texts/*-enablement-policy.txt)

# ROLLING_TF_SUBPROCESS_OUTPUT is often quite behind for large tests.
# let's disable it by default.
: ${ROLLING_TF_SUBPROCESS_OUTPUT:=0}
export ROLLING_TF_SUBPROCESS_OUTPUT

smoke=0
include_re=""
exclude_re=""
@@ -93,6 +102,10 @@ esac
done
shift $(($OPTIND - 1))

# If the rest of the arguments are available, just run these tests.
targets=("$@")


if (( $with_tools_tests )) ; then
    all_tests=(hoststubgentest tiny-framework-dump-test hoststubgen-invoke-test ravenwood-stats-checker ravenhelpertest)
fi
@@ -142,12 +155,15 @@ filter_out() {
    filter "$1" -v
}

# Remove the slow tests.
# If targets are not specified in the command line, run all tests w/ the filters.
if (( "${#targets[@]}" == 0 )) ; then
    # Filter the tests.
    targets=( $(
        for t in "${all_tests[@]}"; do
        echo $t | filter_in "$include_re" | filter_out "$smoke_exclude_re" | filter_out "$exclude_re" | filter_out "SystemUiRavenTests"
            echo $t | filter_in "$include_re" | filter_out "$smoke_exclude_re" | filter_out "$exclude_re"
        done
    ) )
fi

# Show the target tests

@@ -158,13 +174,27 @@ done

# Calculate the removed tests.

diff="$(diff  <(echo "${all_tests[@]}" | tr ' ' '\n') <(echo "${targets[@]}" | tr ' ' '\n') | grep -v [0-9] || true)"
diff="$(diff  <(echo "${all_tests[@]}" | tr ' ' '\n') <(echo "${targets[@]}" | tr ' ' '\n') | grep -v '[0-9]' || true)"

if [[ "$diff" != "" ]]; then
    echo "Excluded tests:"
    echo "$diff"
fi

# Build the "enablement" policy by merging all the policy files.
# But if RAVENWOOD_TEST_ENABLEMENT_POLICY is already set, just use it.
if [[ "$RAVENWOOD_TEST_ENABLEMENT_POLICY" == "" ]] && (( "${#default_enablement_policy[@]}" > 0 )) ; then
    # This path must be a full path.
    combined_enablement_policy=/tmp/ravenwood-enablement-$$.txt

    cat "${default_enablement_policy[@]}" >$combined_enablement_policy

    export RAVENWOOD_TEST_ENABLEMENT_POLICY=$combined_enablement_policy
fi

echo "RAVENWOOD_TEST_ENABLEMENT_POLICY=$RAVENWOOD_TEST_ENABLEMENT_POLICY"

# =========================================================

run() {
    echo "Running: ${@}"
+1 −3
Original line number Diff line number Diff line
@@ -18,6 +18,4 @@ set -e
# Move to the script's directory
cd "${0%/*}"

export ROLLING_TF_SUBPROCESS_OUTPUT=0
export RAVENWOOD_TEST_ENABLEMENT_POLICY=$(readlink -f ../texts/sysui-enablement-policy.txt)
${ATEST:-atest} --class-level-report SystemUiRavenTests "$@"
./run-ravenwood-tests.sh SystemUiRavenTests
Loading