diff options
| author | 2025-01-24 18:18:49 -0800 | |
|---|---|---|
| committer | 2025-01-24 18:18:49 -0800 | |
| commit | 2b42f0cd28b724cb44f6485d1df47fa071e3b1bb (patch) | |
| tree | bb29d682d82e24a4ce50a1ddfd31799c4cfc3026 | |
| parent | 36dd6b15b6a2d65748c157d27b0b131a7d5947d9 (diff) | |
| parent | ddff2c6e7eb023b662bcf4885d43fdc9006142b7 (diff) | |
Merge "Add pagesizecompat warning test" into main
6 files changed, 122 insertions, 21 deletions
diff --git a/core/tests/FileSystemUtilsTest/Android.bp b/core/tests/FileSystemUtilsTest/Android.bp index bb0acc679dc1..f4d92522bb25 100644 --- a/core/tests/FileSystemUtilsTest/Android.bp +++ b/core/tests/FileSystemUtilsTest/Android.bp @@ -36,10 +36,10 @@ cc_library { ldflags: ["-z max-page-size=0x1000"], } -android_test_helper_app { - name: "app_with_4kb_elf", +java_defaults { + name: "app_with_4kb_elf_defaults", srcs: ["app_with_4kb_elf/src/**/*.java"], - manifest: "app_with_4kb_elf/app_with_4kb_elf.xml", + resource_dirs: ["app_with_4kb_elf/res"], compile_multilib: "64", jni_libs: [ "libpunchtest_4kb", @@ -47,37 +47,36 @@ android_test_helper_app { static_libs: [ "androidx.test.rules", "platform-test-annotations", + "androidx.test.uiautomator_uiautomator", + "sysui-helper", ], +} + +android_test_helper_app { + name: "app_with_4kb_elf", + defaults: ["app_with_4kb_elf_defaults"], + manifest: "app_with_4kb_elf/app_with_4kb_elf.xml", use_embedded_native_libs: true, } android_test_helper_app { name: "app_with_4kb_compressed_elf", - srcs: ["app_with_4kb_elf/src/**/*.java"], + defaults: ["app_with_4kb_elf_defaults"], manifest: "app_with_4kb_elf/app_with_4kb_elf.xml", - compile_multilib: "64", - jni_libs: [ - "libpunchtest_4kb", - ], - static_libs: [ - "androidx.test.rules", - "platform-test-annotations", - ], use_embedded_native_libs: false, } android_test_helper_app { name: "page_size_compat_disabled_app", - srcs: ["app_with_4kb_elf/src/**/*.java"], + defaults: ["app_with_4kb_elf_defaults"], manifest: "app_with_4kb_elf/page_size_compat_disabled.xml", - compile_multilib: "64", - jni_libs: [ - "libpunchtest_4kb", - ], - static_libs: [ - "androidx.test.rules", - "platform-test-annotations", - ], + use_embedded_native_libs: true, +} + +android_test_helper_app { + name: "app_with_4kb_elf_no_override", + defaults: ["app_with_4kb_elf_defaults"], + manifest: "app_with_4kb_elf/app_with_4kb_no_override.xml", use_embedded_native_libs: true, } @@ -131,6 +130,7 @@ java_test_host { ":app_with_4kb_elf", ":page_size_compat_disabled_app", ":app_with_4kb_compressed_elf", + ":app_with_4kb_elf_no_override", ], test_suites: ["general-tests"], test_config: "AndroidTest.xml", diff --git a/core/tests/FileSystemUtilsTest/app_with_4kb_elf/app_with_4kb_no_override.xml b/core/tests/FileSystemUtilsTest/app_with_4kb_elf/app_with_4kb_no_override.xml new file mode 100644 index 000000000000..b0b5204d6e80 --- /dev/null +++ b/core/tests/FileSystemUtilsTest/app_with_4kb_elf/app_with_4kb_no_override.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2025 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="android.test.pagesizecompat"> + <application + android:label="PageSizeCompatTestApp"> + <uses-library android:name="android.test.runner"/> + <activity android:name=".MainActivity" + android:exported="true" + android:label="Home page" + android:process=":NewProcess"> + <intent-filter> + <action android:name="android.intent.action.MAIN"/> + <category android:name="android.intent.category.LAUNCHER"/> + <category android:name="android.intent.category.DEFAULT"/> + </intent-filter> + </activity> + </application> + <instrumentation + android:name="androidx.test.runner.AndroidJUnitRunner" + android:targetPackage="android.test.pagesizecompat"/> +</manifest>
\ No newline at end of file diff --git a/core/tests/FileSystemUtilsTest/app_with_4kb_elf/res/layout/hello.xml b/core/tests/FileSystemUtilsTest/app_with_4kb_elf/res/layout/hello.xml new file mode 100644 index 000000000000..473f3f9f9402 --- /dev/null +++ b/core/tests/FileSystemUtilsTest/app_with_4kb_elf/res/layout/hello.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2025 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. +--> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:keepScreenOn="true"> + <TextView + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:text="this is a test activity" + /> +</LinearLayout> + diff --git a/core/tests/FileSystemUtilsTest/app_with_4kb_elf/src/android/test/pagesizecompat/MainActivity.java b/core/tests/FileSystemUtilsTest/app_with_4kb_elf/src/android/test/pagesizecompat/MainActivity.java index 893f9cd01497..5d8d8081b0e5 100644 --- a/core/tests/FileSystemUtilsTest/app_with_4kb_elf/src/android/test/pagesizecompat/MainActivity.java +++ b/core/tests/FileSystemUtilsTest/app_with_4kb_elf/src/android/test/pagesizecompat/MainActivity.java @@ -19,6 +19,7 @@ package android.test.pagesizecompat; import android.app.Activity; import android.content.Intent; import android.os.Bundle; +import android.view.View; import androidx.annotation.VisibleForTesting; @@ -43,6 +44,8 @@ public class MainActivity extends Activity { @Override public void onCreate(Bundle savedOnstanceState) { super.onCreate(savedOnstanceState); + View view = getLayoutInflater().inflate(R.layout.hello, null); + setContentView(view); Intent received = getIntent(); int op1 = received.getIntExtra(KEY_OPERAND_1, -1); diff --git a/core/tests/FileSystemUtilsTest/app_with_4kb_elf/src/android/test/pagesizecompat/PageSizeCompatTest.java b/core/tests/FileSystemUtilsTest/app_with_4kb_elf/src/android/test/pagesizecompat/PageSizeCompatTest.java index b4a801a09ed0..7d05c64f7624 100644 --- a/core/tests/FileSystemUtilsTest/app_with_4kb_elf/src/android/test/pagesizecompat/PageSizeCompatTest.java +++ b/core/tests/FileSystemUtilsTest/app_with_4kb_elf/src/android/test/pagesizecompat/PageSizeCompatTest.java @@ -16,6 +16,8 @@ package android.test.pagesizecompat; +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; + import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -23,6 +25,10 @@ import android.content.IntentFilter; import androidx.test.InstrumentationRegistry; import androidx.test.runner.AndroidJUnit4; +import androidx.test.uiautomator.By; +import androidx.test.uiautomator.UiDevice; +import androidx.test.uiautomator.UiObject2; +import androidx.test.uiautomator.Until; import org.junit.Assert; import org.junit.Test; @@ -33,6 +39,8 @@ import java.util.concurrent.TimeUnit; @RunWith(AndroidJUnit4.class) public class PageSizeCompatTest { + private static final String WARNING_TEXT = "PageSizeCompatTestApp"; + private static final long TIMEOUT = 5000; public void testPageSizeCompat_appLaunch(boolean shouldPass) throws Exception { Context context = InstrumentationRegistry.getContext(); @@ -61,6 +69,9 @@ public class PageSizeCompatTest { launchIntent.putExtra(MainActivity.KEY_OPERAND_2, op2); context.startActivity(launchIntent); + UiDevice device = UiDevice.getInstance(getInstrumentation()); + device.waitForWindowUpdate(null, TIMEOUT); + Assert.assertEquals(receivedSignal.await(10, TimeUnit.SECONDS), shouldPass); } @@ -73,4 +84,15 @@ public class PageSizeCompatTest { public void testPageSizeCompat_compatDisabled() throws Exception { testPageSizeCompat_appLaunch(false); } + + @Test + public void testPageSizeCompat_compatByAlignmentChecks() throws Exception { + testPageSizeCompat_appLaunch(true); + + //verify warning dialog + UiDevice device = UiDevice.getInstance(getInstrumentation()); + device.waitForWindowUpdate(null, TIMEOUT); + UiObject2 targetObject = device.wait(Until.findObject(By.text(WARNING_TEXT)), TIMEOUT); + Assert.assertTrue(targetObject != null); + } } diff --git a/core/tests/FileSystemUtilsTest/src/com/android/internal/content/FileSystemUtilsTest.java b/core/tests/FileSystemUtilsTest/src/com/android/internal/content/FileSystemUtilsTest.java index 6430813b9913..208d74e49afe 100644 --- a/core/tests/FileSystemUtilsTest/src/com/android/internal/content/FileSystemUtilsTest.java +++ b/core/tests/FileSystemUtilsTest/src/com/android/internal/content/FileSystemUtilsTest.java @@ -35,6 +35,8 @@ public class FileSystemUtilsTest extends BaseHostJUnit4Test { private static final String PAGE_SIZE_COMPAT_DISABLED = "page_size_compat_disabled_app.apk"; private static final String PAGE_SIZE_COMPAT_ENABLED_COMPRESSED_ELF = "app_with_4kb_compressed_elf.apk"; + private static final String PAGE_SIZE_COMPAT_ENABLED_BY_PLATFORM = + "app_with_4kb_elf_no_override.apk"; @Test @AppModeFull @@ -91,4 +93,13 @@ public class FileSystemUtilsTest extends BaseHostJUnit4Test { runPageSizeCompatTest(PAGE_SIZE_COMPAT_DISABLED, "testPageSizeCompat_compatDisabled"); } + + @Test + @AppModeFull + public void runAppWith4KbLib_compatByAlignmentChecks() + throws DeviceNotAvailableException, TargetSetupError { + // This test is expected to fail since compat is disabled in manifest + runPageSizeCompatTest(PAGE_SIZE_COMPAT_ENABLED_BY_PLATFORM, + "testPageSizeCompat_compatByAlignmentChecks"); + } } |