Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 21b37bb7 authored by Pawan Wagh's avatar Pawan Wagh
Browse files

Add test for 16kb app compat

- set manifest option for override
- Load 4KB ELF inside app

Flag: android.content.pm.app_compat_option_16kb
Test: atest -c FileSystemUtilsTests
Test: Install 4KB aligned app and see the dialog on 16 KB device
Bug: 371049373
Change-Id: Iccf63811c747da99dad8842676b130913df2e7dd
parent 2f74017a
Loading
Loading
Loading
Loading
+29 −2
Original line number Diff line number Diff line
@@ -17,14 +17,40 @@ package {
    default_team: "trendy_team_android_kernel",
}

cc_library {
    name: "libpunchtest",
cc_defaults {
    name: "libpunch_defaults",
    stl: "none",
    host_supported: true,
    srcs: ["jni/android_test_jni_source.cpp"],
    header_libs: ["jni_headers"],
}

cc_library {
    name: "libpunchtest",
    defaults: ["libpunch_defaults"],
}

cc_library {
    name: "libpunchtest_4kb",
    defaults: ["libpunch_defaults"],
    ldflags: ["-z max-page-size=0x1000"],
}

android_test_helper_app {
    name: "app_with_4kb_elf",
    srcs: ["app_with_4kb_elf/src/**/*.java"],
    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: true,
}

android_test_helper_app {
    name: "embedded_native_libs_test_app",
    srcs: ["apk_embedded_native_libs/src/**/*.java"],
@@ -72,6 +98,7 @@ java_test_host {
    device_common_data: [
        ":embedded_native_libs_test_app",
        ":extract_native_libs_test_app",
        ":app_with_4kb_elf",
    ],
    test_suites: ["general-tests"],
    test_config: "AndroidTest.xml",
+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
        <option name="cleanup-apks" value="true" />
        <option name="test-file-name" value="embedded_native_libs_test_app.apk" />
        <option name="test-file-name" value="extract_native_libs_test_app.apk" />
        <option name="test-file-name" value="app_with_4kb_elf.apk" />
    </target_preparer>

    <test class="com.android.compatibility.common.tradefed.testtype.JarHostTest" >
+37 −0
Original line number Diff line number Diff line
<?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="android.test.pagesizecompat">
    <application
        android:extractNativeLibs="false"
        android:pageSizeCompat="enabled">
        <uses-library android:name="android.test.runner"/>
        <activity android:name=".MainActivity"
                  android:exported="true"
                  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
+60 −0
Original line number Diff line number Diff line
/*
 * 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.test.pagesizecompat;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.VisibleForTesting;

public class MainActivity extends Activity {

    static {
        System.loadLibrary("punchtest_4kb");
    }

    @VisibleForTesting
    static final String INTENT_TYPE = "android.test.pagesizecompat.EMBEDDED_4KB_LIB_LOADED";

    @VisibleForTesting
    static final String KEY_OPERAND_1 = "OP1";

    @VisibleForTesting
    static final String KEY_OPERAND_2 = "OP2";

    @VisibleForTesting
    static final String KEY_RESULT = "RESULT";

    @Override
    public void onCreate(Bundle savedOnstanceState) {
        super.onCreate(savedOnstanceState);

        Intent received =  getIntent();
        int op1 = received.getIntExtra(KEY_OPERAND_1, -1);
        int op2 = received.getIntExtra(KEY_OPERAND_2, -1);
        int result = add(op1, op2);

        // Send broadcast so that test can know app has launched and lib is loaded
        // attach result which has been fetched from JNI lib
        Intent intent = new Intent(INTENT_TYPE);
        intent.putExtra(KEY_RESULT, result);
        sendBroadcast(intent);
    }

    private native int add(int op1, int op2);
}
+67 −0
Original line number Diff line number Diff line
/*
 * 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.test.pagesizecompat;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

@RunWith(AndroidJUnit4.class)
public class PageSizeCompatTest {

    @Test
    public void testPageSizeCompat_embedded4KbLib() throws Exception {
        Context context = InstrumentationRegistry.getContext();
        CountDownLatch receivedSignal = new CountDownLatch(1);

        // Test app is expected to receive this and perform addition of operands using ELF
        // loaded in compat mode on 16 KB device
        int op1 = 48;
        int op2 = 75;
        IntentFilter intentFilter = new IntentFilter(MainActivity.INTENT_TYPE);
        BroadcastReceiver broadcastReceiver =
                new BroadcastReceiver() {
                    @Override
                    public void onReceive(Context context, Intent intent) {
                        receivedSignal.countDown();
                        int result = intent.getIntExtra(MainActivity.KEY_RESULT, 1000);
                        Assert.assertEquals(result, op1 + op2);

                    }
                };
        context.registerReceiver(broadcastReceiver, intentFilter, Context.RECEIVER_EXPORTED);

        Intent launchIntent =
                context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
        launchIntent.putExtra(MainActivity.KEY_OPERAND_1, op1);
        launchIntent.putExtra(MainActivity.KEY_OPERAND_2, op2);
        context.startActivity(launchIntent);

        Assert.assertTrue("Failed to launch app", receivedSignal.await(10, TimeUnit.SECONDS));
    }
}
Loading