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

Commit 799a3489 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Add ravenhelper command to bulk-disable tests

- Add "ravenhelper mm", which stands for "mark-method", which reads
from STDIN a list of methods in a form of:
com.android.ravenwoodtest.tests.Test1#testA
com.android.ravenwoodtest.tests.Test1#testB
com.android.ravenwoodtest.tests.Test1#testC

(which is basically a failed test list from atest)

and inject arbitrary lines on each of these methods.

- This is similar to "ravenizer pta" -- it creates a shell script that
updates the source files, rather than directly updating them.

- The primary purpose is for bulk-adding arbitrary annotations, such as
"@Ignore" or "@DisabledOnRavenwood" to broken test methods.

- Add a wrapper script "add-annotations.sh".

Flag: EXEMPT host test change only
Bug: 292141694
Test:  Manual test:
./scripts/add-annotations.sh -t '@@Ignore' /android/main-without-vendor/frameworks/base/ravenwood/tests/ <method-list.txt
Run the generated script and make sure '@Ignore' is added to the target methods.

Change-Id: If61cc968cae26a1a8dbff7b68a9f42a7459ad0dc
parent 9b828add
Loading
Loading
Loading
Loading
+84 −0
Original line number Diff line number Diff line
#!/bin/bash
# Copyright (C) 2025 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.

#
# Use "ravehleper mm" to create a shell script which:
# - Reads read a list of methods from STDIN
#   Which basically looks like a list of 'com.android.ravenwoodtest.tests.Test1#testA'
# - Add @DisabledOnRavenwood to them
#
# Example usage:
#
# ./add-annotations.sh $ANDROID_BUILD_TOP/frameworks/base/ravenwood/tests <METHOD-LIST.txt
#
# Use a different annotation instead. (Note, in order to use an at, you need to use a double-at.)
# ./add-annotations.sh -t '@@Ignore' $ANDROID_BUILD_TOP/frameworks/base/ravenwood/tests <METHOD-LIST.txt
#

set -e

# Uncomment it to always build ravenhelper (slow)
# ${BUILD_CMD:-m} ravenhelper

# We add this line to each methods found.
# Note, if we used a single @, that'd be handled as an at file. Use
# the double-at instead.
annotation="@@android.platform.test.annotations.DisabledOnRavenwood"
while getopts "t:" opt; do
case "$opt" in
    t)
        annotation="$OPTARG"
        ;;
    '?')
        exit 1
        ;;
esac
done
shift $(($OPTIND - 1))

source_dirs="$@"

OUT_SCRIPT="${OUT_SCRIPT:-/tmp/add-annotations.sh}"

rm -f "$OUT_SCRIPT"


with_flag() {
    local flag="$1"
    shift

    for arg in "$@"; do
        echo "$flag $arg"
    done
}

run() {
    echo "Running: $*"
    "$@"
}

run ${RAVENHELPER_CMD:-ravenhelper mm} \
    --output-script $OUT_SCRIPT \
    --text "$annotation" \
    $(with_flag --src $source_dirs)


if ! [[ -f $OUT_SCRIPT ]] ; then
    # no operations generated.
    exit 0
fi

echo
echo "Created script at $OUT_SCRIPT. Run it with: sh $OUT_SCRIPT"
+1 −1
Original line number Diff line number Diff line
#!/bin/bash
# Copyright (C) 2024 The Android Open Source Project
# Copyright (C) 2025 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.
+6 −1
Original line number Diff line number Diff line
@@ -354,6 +354,8 @@ class ArgIterator(
 * Scan the arguments, and if any of them starts with an `@`, then load from the file
 * and use its content as arguments.
 *
 * In order to pass an argument that starts with an '@', use '@@' instead.
 *
 * In this file, each line is treated as a single argument.
 *
 * The file can contain '#' as comments.
@@ -362,7 +364,10 @@ private fun expandAtFiles(args: Array<String>): List<String> {
    val ret = mutableListOf<String>()

    args.forEach { arg ->
        if (!arg.startsWith('@')) {
        if (arg.startsWith("@@")) {
            ret += arg.substring(1)
            return@forEach
        } else if (!arg.startsWith('@')) {
            ret += arg
            return@forEach
        }
+6 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import com.android.hoststubgen.executableName
import com.android.hoststubgen.log
import com.android.hoststubgen.runMainWithBoilerplate
import com.android.platform.test.ravenwood.ravenhelper.policytoannot.PtaProcessor
import com.android.platform.test.ravenwood.ravenhelper.sourcemap.MarkMethodHandler

interface SubcommandHandler {
    fun handle(args: List<String>)
@@ -39,7 +40,10 @@ fun usage() {

        Subcommands:
          pta:        "policy-to-annotations" Convert policy file to annotations.
                      (See the pta-framework.sh script for usage.) 1
                      (See the pta-framework.sh script for usage.)

          mm:         "mark methods" Used to add annotations (such as @DisabledOnRavenwood)
                      to methods.

        """.trimIndent())
}
@@ -60,6 +64,7 @@ fun main(args: Array<String>) {
        val subcommand = args[0]
        val handler: SubcommandHandler = when (subcommand) {
            "pta" -> PtaProcessor()
            "mm" -> MarkMethodHandler()
            else -> {
                usage()
                throw GeneralUserErrorException("Unknown subcommand '$subcommand'")
+24 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ package com.android.platform.test.ravenwood.ravenhelper.policytoannot
import com.android.hoststubgen.log
import java.io.BufferedWriter
import java.io.File
import java.io.FileOutputStream
import java.io.OutputStreamWriter

enum class SourceOperationType {
    /** Insert a line */
@@ -199,3 +201,25 @@ private fun toSedScript(ops: List<SourceOperation>, writer: BufferedWriter) {
        }
    }
}

fun createShellScript(ops: SourceOperations, scriptFile: String?): Boolean {
    if (ops.size == 0) {
        log.i("No files need to be updated.")
        return false
    }

    val scriptWriter = BufferedWriter(
        OutputStreamWriter(
            scriptFile?.let { file ->
            FileOutputStream(file)
        } ?: System.out
    ))

    scriptWriter.use { writer ->
        scriptFile?.let {
            log.i("Creating script file at $it ...")
        }
        createShellScript(ops, writer)
    }
    return true
}
 No newline at end of file
Loading