Skip to content
Snippets Groups Projects
Commit 8e4eb7ed authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Add @OnlyOnRavenwood

Also add a bivalent test.

Test: atest RavenwoodBivalentTest && atest RavenwoodBivalentTest_device
Bug: 292141694
Change-Id: I10f258e62e8a7f6a85fad5b39eda27c397e08f55
parent a60c144b
No related branches found
No related tags found
No related merge requests found
Showing
with 237 additions and 5 deletions
......@@ -2,6 +2,9 @@
"presubmit": [
{
"name": "RavenwoodMockitoTest_device"
},
{
"name": "RavenwoodBivalentTest_device"
}
],
"ravenwood-presubmit": [
......@@ -16,6 +19,14 @@
{
"name": "CtsUtilTestCasesRavenwood",
"host": true
},
{
"name": "RavenwoodCoreTest",
"host": true
},
{
"name": "RavenwoodBivalentTest",
"host": true
}
]
}
package {
// See: http://go/android-license-faq
// A large-scale-change added 'default_applicable_licenses' to import
// all of the 'license_kinds' from "frameworks_base_license"
// to get the below license kinds:
// SPDX-license-identifier-Apache-2.0
default_applicable_licenses: ["frameworks_base_license"],
}
android_ravenwood_test {
name: "RavenwoodBivalentTest",
static_libs: [
"androidx.annotation_annotation",
"androidx.test.ext.junit",
"androidx.test.rules",
],
srcs: [
"test/**/*.java",
],
sdk_version: "test_current",
auto_gen_config: true,
}
android_test {
name: "RavenwoodBivalentTest_device",
srcs: [
"test/**/*.java",
],
static_libs: [
"junit",
"truth",
"androidx.annotation_annotation",
"androidx.test.ext.junit",
"androidx.test.rules",
"ravenwood-junit",
],
test_suites: [
"device-tests",
],
optimize: {
enabled: false,
},
}
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.ravenwood.bivalenttest">
<application android:debuggable="true" >
<uses-library android:name="android.test.runner" />
</application>
<instrumentation
android:name="androidx.test.runner.AndroidJUnitRunner"
android:targetPackage="com.android.ravenwood.bivalenttest"
/>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<configuration description="Runs Frameworks Services Tests.">
<option name="test-suite-tag" value="apct" />
<option name="test-suite-tag" value="apct-instrumentation" />
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
<option name="cleanup-apks" value="true" />
<option name="test-file-name" value="RavenwoodBivalentTest_device.apk" />
</target_preparer>
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
<option name="package" value="com.android.ravenwood.bivalenttest" />
<option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
</test>
</configuration>
# Ravenwood bivalent test
This test contains bivalent tests for Ravenwood itself.
\ No newline at end of file
/*
* 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 com.android.platform.test.ravenwood.bivalenttest;
import android.platform.test.annotations.DisabledOnNonRavenwood;
import android.platform.test.annotations.DisabledOnRavenwood;
import android.platform.test.ravenwood.RavenwoodRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class RavenwoodRuleTest {
@Rule
public final RavenwoodRule mRavenwood = new RavenwoodRule();
@Test
@DisabledOnRavenwood
public void testDeviceOnly() {
Assert.assertFalse(RavenwoodRule.isOnRavenwood());
}
@Test
@DisabledOnNonRavenwood
public void testRavenwoodOnly() {
Assert.assertTrue(RavenwoodRule.isOnRavenwood());
}
// TODO: Add more tests
}
......@@ -12,9 +12,9 @@ android_ravenwood_test {
static_libs: [
"androidx.annotation_annotation",
"androidx.test.ext.junit",
"androidx.test.rules",
],
srcs: [
"test/**/*.java",
],
......
# Ravenwood core test
This test contains (non-bivalent) tests for Ravenwood itself -- e.g. tests for the ravenwood rules.
\ No newline at end of file
......@@ -17,7 +17,7 @@ package com.android.platform.test.ravenwood.coretest;
import android.platform.test.ravenwood.RavenwoodRule;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.runner.AndroidJUnit4; // Intentionally use the deprecated one.
import org.junit.Assume;
import org.junit.Rule;
......
/*
* 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.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Tests marked with this annotation are only executed when running on Ravenwood, but not
* on a device.
*
* This is basically equivalent to the opposite of {@link DisabledOnRavenwood}, but in order to
* avoid complex structure, and there's no equivalent to the opposite {@link EnabledOnRavenwood},
* which means if a test class has this annotation, you can't negate it in subclasses or
* on a per-method basis.
*
* The {@code RAVENWOOD_RUN_DISABLED_TESTS} environmental variable won't work because it won't be
* propagated to the device. (We may support it in the future, possibly using a debug. sysprop.)
*
* @hide
*/
@Inherited
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface DisabledOnNonRavenwood {
/**
* General free-form description of why this test is being ignored.
*/
String reason() default "";
}
......@@ -18,6 +18,7 @@ package android.platform.test.ravenwood;
import static android.platform.test.ravenwood.RavenwoodRule.ENABLE_PROBE_IGNORED;
import static android.platform.test.ravenwood.RavenwoodRule.IS_ON_RAVENWOOD;
import static android.platform.test.ravenwood.RavenwoodRule.shouldEnableOnDevice;
import static android.platform.test.ravenwood.RavenwoodRule.shouldEnableOnRavenwood;
import static android.platform.test.ravenwood.RavenwoodRule.shouldStillIgnoreInProbeIgnoreMode;
......@@ -42,6 +43,7 @@ public class RavenwoodClassRule implements TestRule {
public Statement apply(Statement base, Description description) {
// No special treatment when running outside Ravenwood; run tests as-is
if (!IS_ON_RAVENWOOD) {
Assume.assumeTrue(shouldEnableOnDevice(description));
return base;
}
......
......@@ -22,6 +22,7 @@ import static android.os.UserHandle.USER_SYSTEM;
import static org.junit.Assert.fail;
import android.platform.test.annotations.DisabledOnNonRavenwood;
import android.platform.test.annotations.DisabledOnRavenwood;
import android.platform.test.annotations.EnabledOnRavenwood;
import android.platform.test.annotations.IgnoreUnderRavenwood;
......@@ -211,6 +212,15 @@ public class RavenwoodRule implements TestRule {
return IS_ON_RAVENWOOD;
}
static boolean shouldEnableOnDevice(Description description) {
if (description.isTest()) {
if (description.getAnnotation(DisabledOnNonRavenwood.class) != null) {
return false;
}
}
return true;
}
/**
* Determine if the given {@link Description} should be enabled when running on the
* Ravenwood test environment.
......@@ -271,6 +281,7 @@ public class RavenwoodRule implements TestRule {
public Statement apply(Statement base, Description description) {
// No special treatment when running outside Ravenwood; run tests as-is
if (!IS_ON_RAVENWOOD) {
Assume.assumeTrue(shouldEnableOnDevice(description));
return base;
}
......
# Ravenwood minimum test
This directory contains a minimum possible ravenwood test -- no extra dependencies, etc.
\ No newline at end of file
......@@ -28,7 +28,7 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class RavenwoodMinimumTest {
@Rule
public RavenwoodRule mRavenwood = new RavenwoodRule.Builder()
public final RavenwoodRule mRavenwood = new RavenwoodRule.Builder()
.setProcessApp()
.build();
......
......@@ -22,8 +22,6 @@
<option name="test-file-name" value="RavenwoodMockitoTest_device.apk" />
</target_preparer>
<option name="test-tag" value="FrameworksMockingServicesTests" />
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
<option name="package" value="com.android.ravenwood.mockitotest" />
<option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
......
# Ravenwood mockito test
This directory contains a sample bivalent test using Mockito.
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment