From 768fc687a818cde61fde6f34c0c750fd13d2db77 Mon Sep 17 00:00:00 2001 From: John Wu Date: Fri, 25 Oct 2024 21:16:27 +0000 Subject: [Ravenwood] Cleanup RATR implementation and project structure - Create a dedicated RATR implementation specifically for device-side tests in junit-stub-src so we won't need to worry about device-side compatibility when updating RATR. - Enable Ravenizer on RavenwoodBivalentTest to ensure the "stub" RATR is working as intended - Because the real RATR is now in junit-impl-src, a lot of classes no longer need to be in junit-stub-src, as junit-src is now a lot cleaner - Remove all Ravenwood checks in RATR since the real one will always only run on Ravenwood tests - Remove RATRHook and move the hook callback methods directly in RATR Flag: EXEMPT host test change only Bug: 356918135 Test: atest RavenwoodBivalentTest_device_ravenizer Test: $ANDROID_BUILD_TOP/frameworks/base/ravenwood/scripts/run-ravenwood-tests.sh Change-Id: I18577373833d8f6390bc685c23b857be65b904dc --- .../test/ravenwood/RavenwoodAwareTestRunner.java | 70 ++++++++++++++ .../ravenwood/RavenwoodAwareTestRunnerHook.java | 101 --------------------- .../test/ravenwood/RavenwoodConfigState.java | 2 +- .../test/ravenwood/RavenwoodRunnerState.java | 22 ----- 4 files changed, 71 insertions(+), 124 deletions(-) create mode 100644 ravenwood/junit-stub-src/android/platform/test/ravenwood/RavenwoodAwareTestRunner.java delete mode 100644 ravenwood/junit-stub-src/android/platform/test/ravenwood/RavenwoodAwareTestRunnerHook.java delete mode 100644 ravenwood/junit-stub-src/android/platform/test/ravenwood/RavenwoodRunnerState.java (limited to 'ravenwood/junit-stub-src') diff --git a/ravenwood/junit-stub-src/android/platform/test/ravenwood/RavenwoodAwareTestRunner.java b/ravenwood/junit-stub-src/android/platform/test/ravenwood/RavenwoodAwareTestRunner.java new file mode 100644 index 000000000000..b4b751788c6e --- /dev/null +++ b/ravenwood/junit-stub-src/android/platform/test/ravenwood/RavenwoodAwareTestRunner.java @@ -0,0 +1,70 @@ +/* + * 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. + */ +package android.platform.test.ravenwood; + +import android.util.Log; + +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runner.Runner; +import org.junit.runner.notification.RunNotifier; +import org.junit.runners.model.Statement; +import org.junit.runners.model.TestClass; + +/** + * A simple pass-through runner that just delegates to the inner runner without doing + * anything special (no hooks, etc.). + * + * This is only used when a real device-side test has Ravenizer enabled. + */ +public class RavenwoodAwareTestRunner extends RavenwoodAwareTestRunnerBase { + private static final String TAG = "Ravenwood"; + + private static class NopRule implements TestRule { + @Override + public Statement apply(Statement base, Description description) { + return base; + } + } + + public static final TestRule sImplicitClassOuterRule = new NopRule(); + public static final TestRule sImplicitClassInnerRule = sImplicitClassOuterRule; + public static final TestRule sImplicitInstOuterRule = sImplicitClassOuterRule; + public static final TestRule sImplicitInstInnerRule = sImplicitClassOuterRule; + + private final Runner mRealRunner; + + public RavenwoodAwareTestRunner(Class clazz) { + Log.v(TAG, "RavenwoodAwareTestRunner starting for " + clazz.getCanonicalName()); + mRealRunner = instantiateRealRunner(new TestClass(clazz)); + } + + @Override + Runner getRealRunner() { + return mRealRunner; + } + + @Override + public void run(RunNotifier notifier) { + mRealRunner.run(notifier); + } + + static void onRavenwoodRuleEnter(Description description, RavenwoodRule rule) { + } + + static void onRavenwoodRuleExit(Description description, RavenwoodRule rule) { + } +} diff --git a/ravenwood/junit-stub-src/android/platform/test/ravenwood/RavenwoodAwareTestRunnerHook.java b/ravenwood/junit-stub-src/android/platform/test/ravenwood/RavenwoodAwareTestRunnerHook.java deleted file mode 100644 index aa8c29936082..000000000000 --- a/ravenwood/junit-stub-src/android/platform/test/ravenwood/RavenwoodAwareTestRunnerHook.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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. - */ -package android.platform.test.ravenwood; - -import android.platform.test.ravenwood.RavenwoodAwareTestRunner.Order; -import android.platform.test.ravenwood.RavenwoodAwareTestRunner.Scope; - -import org.junit.runner.Description; -import org.junit.runners.model.TestClass; - -/** - * Provide hook points created by {@link RavenwoodAwareTestRunner}. This is a version - * that's used on a device side test. - * - * All methods are no-op in real device tests. - * - * TODO: Use some kind of factory to provide different implementation for the device test - * and the ravenwood test. - */ -public class RavenwoodAwareTestRunnerHook { - private RavenwoodAwareTestRunnerHook() { - } - - /** - * Called before any code starts. Internally it will only initialize the environment once. - */ - public static void performGlobalInitialization() { - } - - /** - * Called when a runner starts, before the inner runner gets a chance to run. - */ - public static void onRunnerInitializing(RavenwoodAwareTestRunner runner, TestClass testClass) { - } - - /** - * Called when a whole test class is skipped. - */ - public static void onClassSkipped(Description description) { - } - - /** - * Called before the inner runner starts. - */ - public static void onBeforeInnerRunnerStart( - RavenwoodAwareTestRunner runner, Description description) throws Throwable { - } - - /** - * Called after the inner runner finished. - */ - public static void onAfterInnerRunnerFinished( - RavenwoodAwareTestRunner runner, Description description) throws Throwable { - } - - /** - * Called before a test / class. - * - * Return false if it should be skipped. - */ - public static boolean onBefore(RavenwoodAwareTestRunner runner, Description description, - Scope scope, Order order) throws Throwable { - return true; - } - - public static void onRavenwoodRuleEnter(RavenwoodAwareTestRunner runner, - Description description, RavenwoodRule rule) throws Throwable { - } - - public static void onRavenwoodRuleExit(RavenwoodAwareTestRunner runner, - Description description, RavenwoodRule rule) throws Throwable { - } - - - /** - * Called after a test / class. - * - * Return false if the exception should be ignored. - */ - public static boolean onAfter(RavenwoodAwareTestRunner runner, Description description, - Scope scope, Order order, Throwable th) { - return true; - } - - public static boolean shouldRunClassOnRavenwood(Class clazz) { - return true; - } -} diff --git a/ravenwood/junit-stub-src/android/platform/test/ravenwood/RavenwoodConfigState.java b/ravenwood/junit-stub-src/android/platform/test/ravenwood/RavenwoodConfigState.java index 43a28ba72ec9..7d3d8b9f7974 100644 --- a/ravenwood/junit-stub-src/android/platform/test/ravenwood/RavenwoodConfigState.java +++ b/ravenwood/junit-stub-src/android/platform/test/ravenwood/RavenwoodConfigState.java @@ -15,7 +15,7 @@ */ package android.platform.test.ravenwood; -/** Stub class. The actual implementaetion is in junit-impl-src. */ +/** Stub class. The actual implementation is in junit-impl-src. */ public class RavenwoodConfigState { public RavenwoodConfigState(RavenwoodConfig config) { } diff --git a/ravenwood/junit-stub-src/android/platform/test/ravenwood/RavenwoodRunnerState.java b/ravenwood/junit-stub-src/android/platform/test/ravenwood/RavenwoodRunnerState.java deleted file mode 100644 index 83cbc5265d8f..000000000000 --- a/ravenwood/junit-stub-src/android/platform/test/ravenwood/RavenwoodRunnerState.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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. - */ -package android.platform.test.ravenwood; - -/** Stub class. The actual implementaetion is in junit-impl-src. */ -public class RavenwoodRunnerState { - public RavenwoodRunnerState(RavenwoodAwareTestRunner runner) { - } -} -- cgit v1.2.3-59-g8ed1b