Merge "Add demo code for testing" into main

This commit is contained in:
Zhi Dou
2023-08-18 20:35:46 +00:00
committed by Gerrit Code Review
5 changed files with 247 additions and 18 deletions

View File

@@ -2,8 +2,8 @@ package {
default_applicable_licenses: ["Android-Apache-2.0"],
}
android_app {
name: "AconfigDemoActivity",
java_defaults {
name: "AconfigDemoActivityDefault",
manifest: "AndroidManifest.xml",
srcs: [
"src/**/*.java"
@@ -11,7 +11,6 @@ android_app {
platform_apis: true,
certificate: "platform",
static_libs: [
"ContentLibs",
"dagger2",
"jsr330",
],
@@ -30,6 +29,14 @@ android_app {
plugins: ["dagger2-compiler"]
}
android_app {
name: "AconfigDemoActivity",
defaults: ["AconfigDemoActivityDefault"],
static_libs: [
"ContentLibs",
]
}
aconfig_declarations {
name: "aconfig_demo_flags",
package: "com.example.android.aconfig.demo.flags",
@@ -49,18 +56,24 @@ filegroup {
],
}
java_library {
name: "ContentLibs",
java_defaults {
name: "ContentLibsDefault",
sdk_version: "current",
srcs: [
":ContentLibsFile",
],
sdk_version: "current",
libs: ["jsr330"],
}
java_library {
name: "ContentLibs",
defaults: ["ContentLibsDefault"],
static_libs: [
"aconfig_demo_flags_java_lib",
],
libs: ["jsr330"],
}
cc_aconfig_library {
name: "aconfig_demo_flags_c_lib",
aconfig_declarations: "aconfig_demo_flags",
@@ -103,3 +116,96 @@ rust_ffi_shared {
"libaconfig_demo_flags_rust",
]
}
// Test setup
// Create test verion of the jave flag library
// It needs to use the same aconfig_declarations as
// the production one
java_aconfig_library {
name: "aconfig_demo_flags_java_lib_test",
aconfig_declarations: "aconfig_demo_flags",
// host_supported is set to true here for test running
// one host, in tests/unittests/Android.bp
host_supported: true,
test: true
}
// Option 1
// Create a test version of the library under testing
// The test version of this library shares the common
// settings in a java_defaults target with the production
// version library. The test version library statically
// links to the test flag library, and the production
// version library links to the production version flag
// library.
java_library {
name: "ContentLibsTest1",
defaults: ["ContentLibsDefault"],
static_libs: [
"aconfig_demo_flags_java_lib_test",
],
}
// Create the test version of the android_app. This app is used
// for self-instrumentation test. This app uses the test version
// of the library which uses flags.
// Please check tests/unittests/Android.bp:AconfigDemoUnitTests1
android_app {
name: "AconfigDemoActivityTest1",
defaults: ["AconfigDemoActivityDefault"],
optimize: {
enabled: false,
},
static_libs: [
"ContentLibsTest1",
]
}
// Option 2
// Instead of creating two verions of the library containing flags,
// it could work that create one version of the library and dynamically
// link to the flag library. The flag library here just works as a stub
// library for the purpose of building. The real flag library should be
// statically linked in the final binary.
// This library is created to demonstrate dynamically linking to flag
// library
java_library {
name: "ContentLibs2",
defaults: ["ContentLibsDefault"],
sdk_version: "current",
libs: [
// link the flag library for building purpose
"aconfig_demo_flags_java_lib",
],
}
// This app is created to demonstrate the production version of the app
// statically links to the production version of the flag library.
android_app {
name: "AconfigDemoActivity2",
defaults: ["AconfigDemoActivityDefault"],
static_libs: [
"ContentLibs2",
"aconfig_demo_flags_java_lib",
]
}
// This app is created to demonstrate the test version of app uses the same
// ContentLibs2 library, but links to test version of the flag library.
// Please check tests/unittests/Android.bp:AconfigDemoUnitTests2
android_app {
name: "AconfigDemoActivityTest2",
defaults: ["AconfigDemoActivityDefault"],
optimize: {
enabled: false,
},
static_libs: [
"ContentLibs2",
"aconfig_demo_flags_java_lib",
]
}

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<!-- This test config file is auto-generated. -->
<configuration description="Runs AconfigDemoUnitTests1.">
<target_preparer class="com.android.tradefed.targetprep.DeviceSetup">
<option name="run-command" value="pm uninstall com.example.android.aconfig.demo" />
<option name="run-command" value="pm uninstall com.example.android.aconfig.demo.tests" />
</target_preparer>
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
<option name="cleanup-apks" value="true" />
<option name="test-file-name" value="AconfigDemoUnitTests1.apk" />
<option name="test-file-name" value="AconfigDemoActivityTest1.apk" />
</target_preparer>
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
<option name="package" value="com.example.android.aconfig.demo.tests" />
<option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
</test>
</configuration>

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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.
-->
<!-- This test config file is auto-generated. -->
<configuration description="Runs AconfigDemoUnitTests2.">
<target_preparer class="com.android.tradefed.targetprep.DeviceSetup">
<option name="run-command" value="pm uninstall com.example.android.aconfig.demo" />
<option name="run-command" value="pm uninstall com.example.android.aconfig.demo.tests" />
</target_preparer>
<target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
<option name="cleanup-apks" value="true" />
<option name="test-file-name" value="AconfigDemoUnitTests2.apk" />
<option name="test-file-name" value="AconfigDemoActivityTest2.apk" />
</target_preparer>
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
<option name="package" value="com.example.android.aconfig.demo.tests" />
<option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
</test>
</configuration>

View File

@@ -1,26 +1,19 @@
java_aconfig_library {
name: "aconfig_demo_flags_lib_test",
aconfig_declarations: "aconfig_demo_flags",
host_supported: true,
test: true
}
java_library_host {
name: "ContentLibs_test",
name: "ContentLibsHost",
srcs: [
":ContentLibsFile",
],
static_libs: [
"aconfig_demo_flags_lib_test",
"aconfig_demo_flags_java_lib_test",
],
libs: ["jsr330"],
}
java_test_host {
name: "ContentLibs_test_host",
name: "ContentLibsTestHost",
srcs: ["*.java"],
static_libs: [
"ContentLibs_test",
"ContentLibsHost",
"junit",
"flag-junit-base",
],
@@ -29,3 +22,35 @@ java_test_host {
},
test_suites: ["general-tests"],
}
android_test {
name: "AconfigDemoUnitTests1",
srcs: ["*.java"],
certificate: "platform",
static_libs: [
"junit",
"androidx.test.runner",
"flag-junit-base",
"platform-test-annotations",
],
manifest: "AndroidManifest.xml",
test_config: "AconfigDemoUnitTests1.xml",
data: [":AconfigDemoActivityTest1"],
instrumentation_for: "AconfigDemoActivityTest1",
}
android_test {
name: "AconfigDemoUnitTests2",
srcs: ["*.java"],
certificate: "platform",
static_libs: [
"junit",
"androidx.test.runner",
"flag-junit-base",
"platform-test-annotations",
],
manifest: "AndroidManifest.xml",
test_config: "AconfigDemoUnitTests2.xml",
data: [":AconfigDemoActivityTest2"],
instrumentation_for: "AconfigDemoActivityTest2",
}

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 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.example.android.aconfig.demo.tests">
<uses-permission android:name="android.permission.READ_DEVICE_CONFIG" />
<!-- We add an application tag here just so that we can indicate that
this package needs to link against the android.test library,
which is needed when building test cases. -->
<application>
<uses-library android:name="android.test.runner" />
</application>
<instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
android:targetPackage="com.example.android.aconfig.demo"
android:label="AconfigDemoActivity sample tests">
</instrumentation>
</manifest>