Loading ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodAwareTestRunner.java +5 −1 Original line number Diff line number Diff line Loading @@ -30,6 +30,8 @@ import android.util.Log; import androidx.test.platform.app.InstrumentationRegistry; import com.android.ravenwood.common.RavenwoodCommonUtils; import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runner.Runner; Loading Loading @@ -229,7 +231,9 @@ public final class RavenwoodAwareTestRunner extends RavenwoodAwareTestRunnerBase s.evaluate(); onAfter(description, scope, order, null); } catch (Throwable t) { if (onAfter(description, scope, order, t)) { var shouldReportFailure = RavenwoodCommonUtils.runIgnoringException( () -> onAfter(description, scope, order, t)); if (shouldReportFailure == null || shouldReportFailure) { throw t; } } Loading ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java +14 −4 Original line number Diff line number Diff line Loading @@ -256,7 +256,9 @@ public class RavenwoodRuntimeEnvironmentController { initInner(runner.mState.getConfig()); } catch (Exception th) { Log.e(TAG, "init() failed", th); reset(); RavenwoodCommonUtils.runIgnoringException(()-> reset()); SneakyThrow.sneakyThrow(th); } } Loading Loading @@ -349,9 +351,12 @@ public class RavenwoodRuntimeEnvironmentController { * Partially re-initialize after each test method invocation */ public static void reinit() { // sRunner could be null, if there was a failure in the initialization. if (sRunner != null) { var config = sRunner.mState.getConfig(); Binder.restoreCallingIdentity(packBinderIdentityToken(false, config.mUid, config.mPid)); } } private static void initializeCompatIds(RavenwoodConfig config) { // Set up compat-IDs for the app side. Loading Loading @@ -380,6 +385,9 @@ public class RavenwoodRuntimeEnvironmentController { /** * De-initialize. * * Note, we call this method when init() fails too, so this method should deal with * any partially-initialized states. */ public static void reset() { if (RAVENWOOD_VERBOSE_LOGGING) { Loading Loading @@ -411,7 +419,9 @@ public class RavenwoodRuntimeEnvironmentController { config.mState.mSystemServerContext.cleanUp(); } if (Looper.getMainLooper() != null) { Looper.getMainLooper().quit(); } Looper.clearMainLooperForTest(); ActivityManager.reset$ravenwood(); Loading ravenwood/runtime-common-src/com/android/ravenwood/common/RavenwoodCommonUtils.java +29 −1 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import java.lang.reflect.Member; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.function.Supplier; public class RavenwoodCommonUtils { private static final String TAG = "RavenwoodCommonUtils"; Loading Loading @@ -277,8 +278,35 @@ public class RavenwoodCommonUtils { (isStatic ? "static" : ""))); } /** * Run a supplier and swallow the exception, if any. * * It's a dangerous function. Only use it in an exception handler where we don't want to crash. */ @Nullable public static <T> T runIgnoringException(@NonNull Supplier<T> s) { try { return s.get(); } catch (Throwable th) { log(TAG, "Warning: Exception detected! " + getStackTraceString(th)); } return null; } /** * Run a runnable and swallow the exception, if any. * * It's a dangerous function. Only use it in an exception handler where we don't want to crash. */ public static void runIgnoringException(@NonNull Runnable r) { runIgnoringException(() -> { r.run(); return null; }); } @NonNull public static String getStackTraceString(@Nullable Throwable th) { public static String getStackTraceString(@NonNull Throwable th) { StringWriter stringWriter = new StringWriter(); PrintWriter writer = new PrintWriter(stringWriter); th.printStackTrace(writer); Loading Loading
ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodAwareTestRunner.java +5 −1 Original line number Diff line number Diff line Loading @@ -30,6 +30,8 @@ import android.util.Log; import androidx.test.platform.app.InstrumentationRegistry; import com.android.ravenwood.common.RavenwoodCommonUtils; import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runner.Runner; Loading Loading @@ -229,7 +231,9 @@ public final class RavenwoodAwareTestRunner extends RavenwoodAwareTestRunnerBase s.evaluate(); onAfter(description, scope, order, null); } catch (Throwable t) { if (onAfter(description, scope, order, t)) { var shouldReportFailure = RavenwoodCommonUtils.runIgnoringException( () -> onAfter(description, scope, order, t)); if (shouldReportFailure == null || shouldReportFailure) { throw t; } } Loading
ravenwood/junit-impl-src/android/platform/test/ravenwood/RavenwoodRuntimeEnvironmentController.java +14 −4 Original line number Diff line number Diff line Loading @@ -256,7 +256,9 @@ public class RavenwoodRuntimeEnvironmentController { initInner(runner.mState.getConfig()); } catch (Exception th) { Log.e(TAG, "init() failed", th); reset(); RavenwoodCommonUtils.runIgnoringException(()-> reset()); SneakyThrow.sneakyThrow(th); } } Loading Loading @@ -349,9 +351,12 @@ public class RavenwoodRuntimeEnvironmentController { * Partially re-initialize after each test method invocation */ public static void reinit() { // sRunner could be null, if there was a failure in the initialization. if (sRunner != null) { var config = sRunner.mState.getConfig(); Binder.restoreCallingIdentity(packBinderIdentityToken(false, config.mUid, config.mPid)); } } private static void initializeCompatIds(RavenwoodConfig config) { // Set up compat-IDs for the app side. Loading Loading @@ -380,6 +385,9 @@ public class RavenwoodRuntimeEnvironmentController { /** * De-initialize. * * Note, we call this method when init() fails too, so this method should deal with * any partially-initialized states. */ public static void reset() { if (RAVENWOOD_VERBOSE_LOGGING) { Loading Loading @@ -411,7 +419,9 @@ public class RavenwoodRuntimeEnvironmentController { config.mState.mSystemServerContext.cleanUp(); } if (Looper.getMainLooper() != null) { Looper.getMainLooper().quit(); } Looper.clearMainLooperForTest(); ActivityManager.reset$ravenwood(); Loading
ravenwood/runtime-common-src/com/android/ravenwood/common/RavenwoodCommonUtils.java +29 −1 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import java.lang.reflect.Member; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.function.Supplier; public class RavenwoodCommonUtils { private static final String TAG = "RavenwoodCommonUtils"; Loading Loading @@ -277,8 +278,35 @@ public class RavenwoodCommonUtils { (isStatic ? "static" : ""))); } /** * Run a supplier and swallow the exception, if any. * * It's a dangerous function. Only use it in an exception handler where we don't want to crash. */ @Nullable public static <T> T runIgnoringException(@NonNull Supplier<T> s) { try { return s.get(); } catch (Throwable th) { log(TAG, "Warning: Exception detected! " + getStackTraceString(th)); } return null; } /** * Run a runnable and swallow the exception, if any. * * It's a dangerous function. Only use it in an exception handler where we don't want to crash. */ public static void runIgnoringException(@NonNull Runnable r) { runIgnoringException(() -> { r.run(); return null; }); } @NonNull public static String getStackTraceString(@Nullable Throwable th) { public static String getStackTraceString(@NonNull Throwable th) { StringWriter stringWriter = new StringWriter(); PrintWriter writer = new PrintWriter(stringWriter); th.printStackTrace(writer); Loading