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

Commit 1ad068f5 authored by Pawan Wagh's avatar Pawan Wagh
Browse files

Adding FileSystemUtils test

Adding tests to check whether apps can be launched after
loading the punched libs. One app has uncompressed shared lib which
will be directly loaded from apk and other will extract it.

Test: acloud delete --all && m && acloud create --local-instance --local-image && adb logcat -c && m FileSystemUtilsTests && atest -c FileSystemUtilsTests
Bug: 301631861
Change-Id: I4f7b38902f2e02e83a350cd1cc907f8edaa20c81
parent 5f47f060
Loading
Loading
Loading
Loading
+78 −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 {
    default_applicable_licenses: ["frameworks_base_license"],
    default_team: "trendy_team_android_kernel",
}

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

android_test_helper_app {
    name: "embedded_native_libs_test_app",
    srcs: ["apk_embedded_native_libs/src/**/*.java"],
    manifest: "apk_embedded_native_libs/embedded_native_libs_test_app.xml",
    compile_multilib: "64",
    jni_libs: [
        "libpunchtest",
    ],
    static_libs: [
        "androidx.test.rules",
        "platform-test-annotations",
    ],
    use_embedded_native_libs: true,
}

android_test_helper_app {
    name: "extract_native_libs_test_app",
    srcs: ["apk_extract_native_libs/src/**/*.java"],
    manifest: "apk_extract_native_libs/extract_native_libs_test_app.xml",
    compile_multilib: "64",
    jni_libs: [
        "libpunchtest",
    ],
    static_libs: [
        "androidx.test.rules",
        "platform-test-annotations",
    ],
    use_embedded_native_libs: false,
}

java_test_host {
    name: "FileSystemUtilsTests",
    // Include all test java files
    srcs: ["src/**/*.java"],
    static_libs: [
        "junit",
        "platform-test-annotations",
        "truth",
    ],
    libs: [
        "tradefed",
        "compatibility-host-util",
        "compatibility-tradefed",
    ],
    data: [
        ":embedded_native_libs_test_app",
        ":extract_native_libs_test_app",
    ],
    test_suites: ["general-tests"],
    test_config: "AndroidTest.xml",
}
+27 −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"
          android:installLocation="internalOnly"
          package="com.android.internal.content.fstests">

    <instrumentation
            android:name="androidx.test.runner.AndroidJUnitRunner"
            android:targetPackage="com.android.internal.content.fstests"
            android:label="Frameworks FileSystemUtils Tests" />

</manifest>
+30 −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.
  -->

<configuration description="Runs FileSystemUtilsTest.">
    <option name="test-suite-tag" value="apct"/>

    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
        <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" />
    </target_preparer>

    <test class="com.android.compatibility.common.tradefed.testtype.JarHostTest" >
        <option name="jar" value="FileSystemUtilsTests.jar" />
    </test>
</configuration>
+35 −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.embedded">
    <application android:extractNativeLibs="false">
        <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.embedded"/>
</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.embedded;

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");
    }

    @VisibleForTesting
    static final String INTENT_TYPE = "android.test.embedded.EMBEDDED_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);
}
Loading