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

Commit 3d14bf44 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Improve Ravenwood logging/messages.

Emit "TestRunner" log messages around each test method, so that our
local debugging logs match what developers experience with tests run
on a physical device.

Refine `onThrowMethodCalled()` message to be more descriptive about
Ravenwood and link to docs.

Bug: 322817109, 322526754
Test: atest FrameworksCoreTestsRavenwood
Change-Id: Id9f6a936145dd2024295c2eb14666fc43a5c7e34
parent 9614500d
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -20,9 +20,12 @@ import android.app.Instrumentation;
import android.os.Bundle;
import android.os.HandlerThread;
import android.os.Looper;
import android.util.Log;

import androidx.test.platform.app.InstrumentationRegistry;

import org.junit.runner.Description;

import java.io.PrintStream;
import java.util.Map;
import java.util.concurrent.Executors;
@@ -92,6 +95,13 @@ public class RavenwoodRuleImpl {
        android.os.Process.reset$ravenwood();
    }

    public static void logTestRunner(String label, Description description) {
        // This message string carefully matches the exact format emitted by on-device tests, to
        // aid developers in debugging raw text logs
        Log.e("TestRunner", label + ": " + description.getMethodName()
                + "(" + description.getTestClass().getName() + ")");
    }

    private static void dumpStacks() {
        final PrintStream out = System.err;
        out.println("-----BEGIN ALL THREAD STACKS-----");
+8 −0
Original line number Diff line number Diff line
@@ -280,9 +280,14 @@ public class RavenwoodRule implements TestRule {
            public void evaluate() throws Throwable {
                Assume.assumeTrue(shouldEnableOnRavenwood(description));

                RavenwoodRuleImpl.logTestRunner("started", description);
                RavenwoodRuleImpl.init(RavenwoodRule.this);
                try {
                    base.evaluate();
                    RavenwoodRuleImpl.logTestRunner("finished", description);
                } catch (Throwable t) {
                    RavenwoodRuleImpl.logTestRunner("failed", description);
                    throw t;
                } finally {
                    RavenwoodRuleImpl.reset(RavenwoodRule.this);
                }
@@ -300,6 +305,8 @@ public class RavenwoodRule implements TestRule {
            @Override
            public void evaluate() throws Throwable {
                Assume.assumeFalse(shouldStillIgnoreInProbeIgnoreMode(description));

                RavenwoodRuleImpl.logTestRunner("started", description);
                RavenwoodRuleImpl.init(RavenwoodRule.this);
                try {
                    base.evaluate();
@@ -309,6 +316,7 @@ public class RavenwoodRule implements TestRule {
                    Assume.assumeTrue(shouldEnableOnRavenwood(description));
                    throw t;
                } finally {
                    RavenwoodRuleImpl.logTestRunner("finished", description);
                    RavenwoodRuleImpl.reset(RavenwoodRule.this);
                }

+6 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.platform.test.ravenwood;

import org.junit.runner.Description;

public class RavenwoodRuleImpl {
    public static boolean isOnRavenwood() {
        return false;
@@ -28,4 +30,8 @@ public class RavenwoodRuleImpl {
    public static void reset(RavenwoodRule rule) {
        // No-op when running on a real device
    }

    public static void logTestRunner(String label, Description description) {
        // No-op when running on a real device
    }
}
+4 −1
Original line number Diff line number Diff line
@@ -63,7 +63,10 @@ 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 RuntimeException(
                "This method is not yet supported under the Ravenwood deviceless testing "
                        + "environment; consider requesting support from the API owner or "
                        + "consider using Mockito; more details at go/ravenwood-docs");
    }

    /**
+2 −2
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ public class TinyFrameworkClassTest {
        TinyFrameworkForTextPolicy tfc = new TinyFrameworkForTextPolicy();

        thrown.expect(RuntimeException.class);
        thrown.expectMessage("This method is not supported on the host side");
        thrown.expectMessage("not yet supported");
        tfc.visibleButUsesUnsupportedMethod();
    }

@@ -182,7 +182,7 @@ public class TinyFrameworkClassTest {

        } catch (java.lang.reflect.InvocationTargetException e) {
            var inner = e.getCause();
            assertThat(inner.getMessage()).contains("not supported on the host side");
            assertThat(inner.getMessage()).contains("not yet supported");
        }
    }

Loading