Add e2e tests for updatable shared libs
Just adding the tests now, not making them run yet. Test: atest UpdatableSharedLibsTest Bug: 191978330 Ignore-AOSP-First: logic under test is only available in internal master Change-Id: I48e8b9422c8703cd4cec6552e0dcfd3b82021816
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
// Copyright (C) 2021 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 {
|
||||
default_applicable_licenses: ["Android-Apache-2.0"],
|
||||
}
|
||||
|
||||
android_test_helper_app {
|
||||
name: "com.android.modules.updatablesharedlibs.apps.targetS",
|
||||
srcs: ["UpdatableSharedLibraryTargetSTest.java"],
|
||||
static_libs: [
|
||||
"androidx.test.rules",
|
||||
"androidx.test.core",
|
||||
"truth-prebuilt",
|
||||
],
|
||||
sdk_version: "current",
|
||||
target_sdk_version: "31",
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2021 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.modules.updatablesharedlibs.apps.targetS">
|
||||
<application>
|
||||
</application>
|
||||
|
||||
<instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
|
||||
android:targetPackage="com.android.modules.updatablesharedlibs.apps.targetS"
|
||||
></instrumentation>
|
||||
</manifest>
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.modules.updatablesharedlibs.apps.targetS;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import junit.framework.Assert;
|
||||
|
||||
import com.google.common.truth.Correspondence;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
/**
|
||||
* Tests an app targeting S.
|
||||
*
|
||||
* <p>One of the shared libraries included in this test claims to be in the
|
||||
* BOOTCLASSPATH before T so it should be added transparently to this app.
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class UpdatableSharedLibraryTargetSTest {
|
||||
private static String SHARED_LIB_PATH = "/apex/test_com.android.modules.updatablesharedlibs"
|
||||
+ "/javalib/com.android.modules.updatablesharedlibs.libs.before.t.jar";
|
||||
|
||||
private static final Context sContext = InstrumentationRegistry.getInstrumentation()
|
||||
.getContext();
|
||||
|
||||
@Test
|
||||
public void checkSharedLibrary() throws Exception {
|
||||
String packageName = sContext.getPackageName();
|
||||
ApplicationInfo appInfo = sContext.getPackageManager().getApplicationInfo(packageName,
|
||||
PackageManager.GET_SHARED_LIBRARY_FILES);
|
||||
|
||||
assertThat(appInfo.sharedLibraryFiles)
|
||||
.asList()
|
||||
.contains(SHARED_LIB_PATH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void callApi() throws Exception {
|
||||
Object api = Class.forName("com.android.modules.updatablesharedlibs.libs.before.t.Api")
|
||||
.getDeclaredConstructor()
|
||||
.newInstance();
|
||||
|
||||
String actual = (String) api.getClass().getDeclaredMethod("methodBeforeT").invoke(api);
|
||||
assertThat(actual).isEqualTo("Success");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// Copyright (C) 2021 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 {
|
||||
default_applicable_licenses: ["Android-Apache-2.0"],
|
||||
}
|
||||
|
||||
android_test_helper_app {
|
||||
name: "com.android.modules.updatablesharedlibs.apps.targetT",
|
||||
srcs: ["UpdatableSharedLibraryTargetTTest.java"],
|
||||
static_libs: [
|
||||
"androidx.test.rules",
|
||||
"androidx.test.core",
|
||||
"truth-prebuilt",
|
||||
],
|
||||
sdk_version: "current",
|
||||
target_sdk_version: "Tiramisu",
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2021 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.modules.updatablesharedlibs.apps.targetT">
|
||||
<application>
|
||||
</application>
|
||||
|
||||
<instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
|
||||
android:targetPackage="com.android.modules.updatablesharedlibs.apps.targetT"
|
||||
></instrumentation>
|
||||
</manifest>
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.modules.updatablesharedlibs.apps.targetT;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import junit.framework.Assert;
|
||||
|
||||
import com.google.common.truth.Correspondence;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
/**
|
||||
* Tests an app targeting T.
|
||||
*
|
||||
* <p>With the shared libraries included in this test, none of the shared libraries present in this
|
||||
* test should be included for this app.
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class UpdatableSharedLibraryTargetTTest {
|
||||
private static final Correspondence<String, String> CONTAINS_SUBSTRING =
|
||||
Correspondence.from(String::contains, "contains");
|
||||
private static final Context sContext = InstrumentationRegistry.getInstrumentation()
|
||||
.getContext();
|
||||
|
||||
@Test
|
||||
public void checkHasNoSharedLibrary() throws Exception {
|
||||
String packageName = sContext.getPackageName();
|
||||
ApplicationInfo appInfo = sContext.getPackageManager().getApplicationInfo(packageName,
|
||||
PackageManager.GET_SHARED_LIBRARY_FILES);
|
||||
|
||||
assertThat(appInfo.sharedLibraryFiles)
|
||||
.asList()
|
||||
.comparingElementsUsing(CONTAINS_SUBSTRING)
|
||||
.doesNotContain("com.android.modules.updatablesharedlibs");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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 {
|
||||
default_applicable_licenses: ["Android-Apache-2.0"],
|
||||
}
|
||||
|
||||
android_test_helper_app {
|
||||
name: "com.android.modules.updatablesharedlibs.apps.targetTWithLib",
|
||||
srcs: ["UpdatableSharedLibraryTargetTWithLibraryTest.java"],
|
||||
libs: [
|
||||
"com.android.modules.updatablesharedlibs.libs.since.t",
|
||||
],
|
||||
static_libs: [
|
||||
"androidx.test.rules",
|
||||
"androidx.test.core",
|
||||
],
|
||||
sdk_version: "current",
|
||||
target_sdk_version: "Tiramisu",
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2021 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.modules.updatablesharedlibs.apps.targetTWithLib">
|
||||
<application>
|
||||
</application>
|
||||
|
||||
<instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
|
||||
android:targetPackage="com.android.modules.updatablesharedlibs.apps.targetTWithLib"
|
||||
></instrumentation>
|
||||
</manifest>
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.modules.updatablesharedlibs.apps.targetTWithLib;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
/**
|
||||
* Tests an app targeting T which also includes a shared library that is part of the BOOTCLASSPATH
|
||||
* from T.
|
||||
*
|
||||
* <p>This means the shared library should not be explicitly in the shared libraries in order
|
||||
* to avoid duplication of the BCP.
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class UpdatableSharedLibraryTargetTWithLibraryTest {
|
||||
// private static final Context sContext = InstrumentationRegistry.getInstrumentation()
|
||||
// .getContext();
|
||||
|
||||
@Test
|
||||
public void checkHasNoSharedLibrary() throws Exception {
|
||||
// TODO(b/205261027): not possible to test yet
|
||||
|
||||
// This is the code we'd like to run. But because before API finalisation PM
|
||||
// will see the shared library as
|
||||
// having "on-bcp-since 9001" this means that it never considers that shared
|
||||
// library to be in the BCP.
|
||||
|
||||
// String packageName = getContext().getPackageName();
|
||||
// ApplicationInfo appInfo = getPackageManager().getApplicationInfo(packageName,
|
||||
// PackageManager.GET_SHARED_LIBRARY_FILES);
|
||||
// Log.d(TAG, "checkHasNoSharedLibrary in " + appInfo.sharedLibraryFiles.length
|
||||
// + " libraries");
|
||||
// for (String path : appInfo.sharedLibraryFiles) {
|
||||
// if (path.contains("com.android.modules.updatablesharedlibs")) {
|
||||
// Assert.fail("Unexpectedly found a shared library: " + path);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user