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

Commit 97014999 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Ignore static initializers, throw assumptions.

For classes that haven't built out Ravenwood support, they still may
be referenced in a way that causes their <clinit> to be invoked.  This
can cause a cascade of trouble as we try constructing other classes
that aren't yet supported.

Instead, we take the path of "ignoring" these initializers for the
time being, treating them as no-op.  This does leave `static final`
values as their defaults values (such as null), which feels
reasonable, as the remainder of the class would throw when used.

Additionally, pivot to throwing `AssumptionViolatedException` when
we encounter unsupported behavior.  This has a nice side-effect of
allowing large numbers of existing tests to be executed under
Ravenwood as-is, where we can get an "unknown" signal today that
automatically turns "green" once all underlying infrastructure is
supported in the future.

Bug: 292141694
Test: atest-dev CtsUtilTestCasesRavenwood
Change-Id: Ia0a93f5e0af0b4c8c680daca1732c10c5fe404af
parent c69a84e4
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -7,3 +7,5 @@ class android.util.MapCollections stubclass

class android.util.Log stubclass
class android.util.Log !com.android.hoststubgen.nativesubstitution.Log_host

class com.android.internal.util.LineBreakBufferedWriter stubclass
+1 −0
Original line number Diff line number Diff line
@@ -89,6 +89,7 @@ java_binary_host {
    srcs: ["src/**/*.kt"],
    static_libs: [
        "hoststubgen-helper-runtime",
        "junit",
        "ow2-asm",
        "ow2-asm-analysis",
        "ow2-asm-commons",
+36 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.
 */
package android.hosttest.annotation;

import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * THIS ANNOTATION IS EXPERIMENTAL. REACH OUT TO g/ravenwood BEFORE USING IT, OR YOU HAVE ANY
 * QUESTIONS ABOUT IT.
 *
 * @hide
 */
@Target({TYPE, FIELD, METHOD, CONSTRUCTOR})
@Retention(RetentionPolicy.CLASS)
public @interface HostSideTestStaticInitializerStub {
}
+3 −1
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import java.util.HashMap;

import javax.annotation.concurrent.GuardedBy;

import org.junit.AssumptionViolatedException;

/**
 * Utilities used in the host side test environment.
 */
@@ -63,7 +65,7 @@ public class HostTestUtils {
     */
    public static void onThrowMethodCalled() {
        // TODO: Maybe add call tracking?
        throw new RuntimeException("This method is not supported on the host side");
        throw new AssumptionViolatedException("This method is not supported on the host side");
    }

    /**
+3 −0
Original line number Diff line number Diff line
@@ -39,3 +39,6 @@

--class-load-hook-annotation
    android.hosttest.annotation.HostSideTestClassLoadHook

--stub-static-initializer-annotation
    android.hosttest.annotation.HostSideTestStaticInitializerStub
Loading