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

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

Merge "Add a test class validator to ravenizer" into main

parents abcf2659 f84ade4a
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
#!/bin/bash
# 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.

# Delete all the ravenizer output jar files from Soong's intermediate directory.

# `-a -prune` is needed because otherwise find would be confused if the directory disappears.

find "${ANDROID_BUILD_TOP:?}/out/soong/.intermediates/" \
    -type d \
    -name 'ravenizer' \
    -print \
    -exec rm -fr \{\} \; \
    -a -prune
+7 −0
Original line number Diff line number Diff line
@@ -17,7 +17,14 @@

package com.android.platform.test.ravenwood.ravenizer

import com.android.hoststubgen.UserErrorException

/**
 * Use it for internal exception that really shouldn't happen.
 */
class RavenizerInternalException(message: String) : Exception(message)

/**
 * Thrown when an invalid test is detected in the target jar. (e.g. JUni3 tests)
 */
class RavenizerInvalidTestException(message: String) : Exception(message), UserErrorException
+34 −2
Original line number Diff line number Diff line
@@ -44,6 +44,9 @@ data class RavenizerStats(
    /** Time took to build [ClasNodes] */
    var loadStructureTime: Double = .0,

    /** Time took to validate the classes */
    var validationTime: Double = .0,

    /** Total real time spent for converting the jar file */
    var totalProcessTime: Double = .0,

@@ -67,6 +70,7 @@ data class RavenizerStats(
            RavenizerStats{
              totalTime=$totalTime,
              loadStructureTime=$loadStructureTime,
              validationTime=$validationTime,
              totalProcessTime=$totalProcessTime,
              totalConversionTime=$totalConversionTime,
              totalCopyTime=$totalCopyTime,
@@ -84,16 +88,44 @@ data class RavenizerStats(
class Ravenizer(val options: RavenizerOptions) {
    fun run() {
        val stats = RavenizerStats()

        val fatalValidation = options.fatalValidation.get

        stats.totalTime = log.nTime {
            process(options.inJar.get, options.outJar.get, stats)
            process(
                options.inJar.get,
                options.outJar.get,
                options.enableValidation.get,
                fatalValidation,
                stats,
            )
        }
        log.i(stats.toString())
    }

    private fun process(inJar: String, outJar: String, stats: RavenizerStats) {
    private fun process(
        inJar: String,
        outJar: String,
        enableValidation: Boolean,
        fatalValidation: Boolean,
        stats: RavenizerStats,
    ) {
        var allClasses = ClassNodes.loadClassStructures(inJar) {
            time -> stats.loadStructureTime = time
        }
        if (enableValidation) {
            stats.validationTime = log.iTime("Validating classes") {
                if (!validateClasses(allClasses)) {
                    var message = "Invalid test class(es) detected." +
                            " See error log for details."
                    if (fatalValidation) {
                        throw RavenizerInvalidTestException(message)
                    } else {
                        log.w("Warning: $message")
                    }
                }
            }
        }

        stats.totalProcessTime = log.iTime("$executableName processing $inJar") {
            ZipFile(inJar).use { inZip ->
+14 −0
Original line number Diff line number Diff line
@@ -27,6 +27,12 @@ class RavenizerOptions(

    /** Output jar file */
    var outJar: SetOnce<String> = SetOnce(""),

    /** Whether to enable test validation. */
    var enableValidation: SetOnce<Boolean> = SetOnce(true),

    /** Whether the validation failure is fatal or not. */
    var fatalValidation: SetOnce<Boolean> = SetOnce(false),
) {
    companion object {
        fun parseArgs(args: Array<String>): RavenizerOptions {
@@ -52,6 +58,12 @@ class RavenizerOptions(
                        "--in-jar" -> ret.inJar.set(nextArg()).ensureFileExists()
                        "--out-jar" -> ret.outJar.set(nextArg())

                        "--enable-validation" -> ret.enableValidation.set(true)
                        "--disable-validation" -> ret.enableValidation.set(false)

                        "--fatal-validation" -> ret.fatalValidation.set(true)
                        "--no-fatal-validation" -> ret.fatalValidation.set(false)

                        else -> throw ArgumentsException("Unknown option: $arg")
                    }
                } catch (e: SetOnce.SetMoreThanOnceException) {
@@ -74,6 +86,8 @@ class RavenizerOptions(
            RavenizerOptions{
              inJar=$inJar,
              outJar=$outJar,
              enableValidation=$enableValidation,
              fatalValidation=$fatalValidation,
            }
            """.trimIndent()
    }
+3 −0
Original line number Diff line number Diff line
@@ -87,9 +87,12 @@ fun String.shouldByBypassed(): Boolean {
    return this.startsWithAny(
        "java/", // just in case...
        "javax/",
        "junit/",
        "org/junit/",
        "org/mockito/",
        "kotlin/",
        "androidx/",
        "android/support/",
        // TODO -- anything else?
    )
}
Loading