aconfig: add Java integration tests

Add integration tests for Java. This test setup verifies that

  - the build system calls aconfig to generate a Java library
  - the Java test compiles against the auto-generated library
  - the auto-generated code returns expected values

Similar integration tests for C++ and Rust will be added in follow-up
CLs.

Note: the build does not currently support specifying that
tests/*.values should be applied, so the test flags will all be assigned
the defaults. A later CL will fix this.

Bug: b/283911467
Test: atest aconfig.test aconfig.test.java
Change-Id: Ia365e209261f4935a23e2dac9ef0ab5b60f76e52
This commit is contained in:
Mårten Kongstad
2023-05-30 11:15:02 +02:00
parent a85c8a863a
commit 9c59c31499
8 changed files with 114 additions and 7 deletions

View File

@@ -2,6 +2,8 @@ package {
default_applicable_licenses: ["Android-Apache-2.0"], default_applicable_licenses: ["Android-Apache-2.0"],
} }
// host binary: aconfig
rust_protobuf_host { rust_protobuf_host {
name: "libaconfig_protos", name: "libaconfig_protos",
protos: ["protos/aconfig.proto"], protos: ["protos/aconfig.proto"],
@@ -39,3 +41,42 @@ rust_test_host {
"libitertools", "libitertools",
], ],
} }
// integration tests: java
device_config_definitions {
name: "aconfig.test.flags",
namespace: "com.android.aconfig.test",
srcs: ["tests/test.aconfig"],
}
device_config_values {
name: "aconfig.test.flag.values",
namespace: "com.android.aconfig.test",
srcs: [
"tests/first.values",
"tests/second.values",
],
}
device_config_value_set {
name: "aconfig.test.flag.value_set",
values: [
"aconfig.test.flag.values",
],
}
android_test {
name: "aconfig.test.java",
srcs: [
"tests/**/*.java",
":aconfig.test.flags{.srcjar}",
],
manifest: "tests/AndroidManifest.xml",
certificate: "platform",
static_libs: [
"androidx.test.rules",
"testng",
],
test_suites: ["device-tests"],
}

View File

@@ -59,7 +59,7 @@ fn create_class_element(package: &str, item: &Item) -> ClassElement {
let device_config_flag = codegen::create_device_config_ident(package, &item.name) let device_config_flag = codegen::create_device_config_ident(package, &item.name)
.expect("values checked at cache creation time"); .expect("values checked at cache creation time");
ClassElement { ClassElement {
method_name: item.name.clone(), method_name: item.name.replace('-', "_"),
readwrite: item.permission == Permission::ReadWrite, readwrite: item.permission == Permission::ReadWrite,
default_value: if item.state == FlagState::Enabled { default_value: if item.state == FlagState::Enabled {
"true".to_string() "true".to_string()

View File

@@ -24,17 +24,17 @@ pub mod test_utils {
crate::commands::create_cache( crate::commands::create_cache(
"com.android.aconfig.test", "com.android.aconfig.test",
vec![Input { vec![Input {
source: Source::File("testdata/test.aconfig".to_string()), source: Source::File("tests/test.aconfig".to_string()),
reader: Box::new(include_bytes!("../testdata/test.aconfig").as_slice()), reader: Box::new(include_bytes!("../tests/test.aconfig").as_slice()),
}], }],
vec![ vec![
Input { Input {
source: Source::File("testdata/first.values".to_string()), source: Source::File("tests/first.values".to_string()),
reader: Box::new(include_bytes!("../testdata/first.values").as_slice()), reader: Box::new(include_bytes!("../tests/first.values").as_slice()),
}, },
Input { Input {
source: Source::File("testdata/test.aconfig".to_string()), source: Source::File("tests/test.aconfig".to_string()),
reader: Box::new(include_bytes!("../testdata/second.values").as_slice()), reader: Box::new(include_bytes!("../tests/second.values").as_slice()),
}, },
], ],
) )

View File

@@ -0,0 +1,37 @@
import static com.android.aconfig.test.Flags.disabled_ro;
import static com.android.aconfig.test.Flags.disabled_rw;
import static com.android.aconfig.test.Flags.enabled_ro;
import static com.android.aconfig.test.Flags.enabled_rw;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public final class AconfigTest {
@Test
public void testDisabledReadOnlyFlag() {
assertFalse(disabled_ro());
}
@Test
public void testEnabledReadOnlyFlag() {
// TODO: change to assertTrue(enabled_ro()) when the build supports reading tests/*.values
// (currently all flags are assigned the default READ_ONLY + DISABLED)
assertFalse(enabled_ro());
}
@Test
public void testDisabledReadWriteFlag() {
assertFalse(disabled_rw());
}
@Test
public void testEnabledReadWriteFlag() {
// TODO: change to assertTrue(enabled_rw()) when the build supports reading tests/*.values
// (currently all flags are assigned the default READ_ONLY + DISABLED)
assertFalse(enabled_rw());
}
}

View File

@@ -0,0 +1,29 @@
<?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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="aconfig.test.java">
<uses-permission android:name="android.permission.READ_DEVICE_CONFIG" />
<application>
<uses-library android:name="android.test.runner"/>
</application>
<instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
android:targetPackage="aconfig.test.java"
android:label="aconfig integration tests (java)" />
</manifest>