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

Commit 738b6c36 authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN Committed by Gerrit Code Review
Browse files

Merge "Add a NetworkStackCoverageTests target."

parents 33f2e3bc b891b5ea
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -133,6 +133,15 @@ android_library {
    manifest: "AndroidManifestBase.xml",
}

filegroup {
    name: "NetworkStackJarJarRules",
    srcs: ["jarjar-rules-shared.txt"],
    visibility: [
        "//packages/modules/NetworkStack/tests/unit",
        "//packages/modules/NetworkStack/tests/integration",
    ]
}

// Common defaults for compiling the actual APK, based on the NetworkStackApiXBase android libraries
java_defaults {
    name: "NetworkStackAppDefaults",
@@ -143,7 +152,7 @@ java_defaults {
    ],
    // Resources already included in NetworkStackBase
    resource_dirs: [],
    jarjar_rules: "jarjar-rules-shared.txt",
    jarjar_rules: ":NetworkStackJarJarRules",
    use_embedded_native_libs: true,
    optimize: {
        proguard_flags_files: ["proguard.flags"],
@@ -201,6 +210,7 @@ android_library {
    defaults: ["NetworkStackAppDefaults", "NetworkStackReleaseApiLevel"],
    static_libs: ["NetworkStackApiStableLib"],
    manifest: "AndroidManifestBase.xml",
    visibility: ["//frameworks/base/tests/net/integration"],
}

cc_library_shared {
+43 −13
Original line number Diff line number Diff line
@@ -14,31 +14,61 @@
// limitations under the License.
//

android_test {
    name: "NetworkStackIntegrationTests",
    certificate: "networkstack",
java_defaults {
    name: "NetworkStackIntegrationTestsJniDefaults",
    defaults: ["libnetworkstackutilsjni_deps"],
    jni_libs: [
        // For mockito extended
        "libdexmakerjvmtiagent",
        "libstaticjvmtiagent",
        // For NetworkStackUtils included in NetworkStackBase
        "libnetworkstackutilsjni",
    ],
    visibility: ["//visibility:private"],
}

android_library {
    name: "NetworkStackIntegrationTestsLib",
    min_sdk_version: "29",
    srcs: ["src/**/*.java"],
    test_suites: ["device-tests"],
    static_libs: [
        "androidx.annotation_annotation",
        "androidx.test.rules",
        "mockito-target-extended-minus-junit4",
        "net-tests-utils",
        "testables",
        "TestNetworkStackLib",
        "NetworkStackApiStableLib",
    ],
    libs: [
        "android.test.runner",
        "android.test.base",
        "android.test.mock",
    ],
    defaults: ["libnetworkstackutilsjni_deps"],
    jni_libs: [
        // For mockito extended
        "libdexmakerjvmtiagent",
        "libstaticjvmtiagent",
        // For NetworkStackUtils included in NetworkStackBase
        "libnetworkstackutilsjni",
    ],
    jarjar_rules: ":NetworkStackJarJarRules",
    visibility: ["//visibility:private"],
}

// Network stack integration tests.
android_test {
    name: "NetworkStackIntegrationTests",
    defaults: ["NetworkStackIntegrationTestsJniDefaults"],
    static_libs: ["NetworkStackIntegrationTestsLib"],
    certificate: "networkstack",
    platform_apis: true,
    test_suites: ["device-tests"],
    min_sdk_version: "29",
}

// Special version of the network stack tests that includes all tests necessary for code coverage
// purposes. This is currently the union of NetworkStackTests and NetworkStackIntegrationTests.
android_test {
    name: "NetworkStackCoverageTests",
    certificate: "networkstack",
    platform_apis: true,
    min_sdk_version: "29",
    test_suites: ["device-tests", "mts"],
    defaults: ["NetworkStackIntegrationTestsJniDefaults"],
    static_libs: ["NetworkStackTestsLib", "NetworkStackIntegrationTestsLib"],
    compile_multilib: "both",
    manifest: "AndroidManifest_coverage.xml",
}
+36 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2019 The Android Open Source Project
<!-- Copyright (C) 2020 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.
@@ -13,17 +13,24 @@
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<configuration description="Runs Integration Tests for NetworkStack">
    <target_preparer class="com.android.tradefed.targetprep.TestAppInstallSetup">
        <option name="test-file-name" value="NetworkStackIntegrationTests.apk" />
    </target_preparer>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.android.server.networkstack.coverage"
          android:sharedUserId="android.uid.networkstack">
    <uses-sdk android:minSdkVersion="29" android:targetSdkVersion="29" />

    <option name="test-suite-tag" value="apct" />
    <option name="test-suite-tag" value="framework-base-presubmit" />
    <option name="test-tag" value="NetworkStackIntegrationTests" />
    <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
        <option name="package" value="com.android.server.networkstack.integrationtests" />
        <option name="runner" value="androidx.test.runner.AndroidJUnitRunner" />
        <option name="hidden-api-checks" value="false"/>
    </test>
</configuration>
    <!-- Note: do not add any privileged or signature permissions that are granted
         to the network stack app. Otherwise, the test APK will install, but when the device is
         rebooted, it will bootloop with something like:

         05-14 00:41:02.723 18330 18330 E AndroidRuntime: java.lang.IllegalStateException: Signature|privileged permissions not in privapp-permissions whitelist: {com.android.server.networkstack.integrationtests: android.permission.CONNECTIVITY_INTERNAL}
    -->
    <uses-permission android:name="android.permission.MAINLINE_NETWORK_STACK" />

    <application android:debuggable="true">
        <uses-library android:name="android.test.runner" />
    </application>
    <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
        android:targetPackage="com.android.server.networkstack.coverage"
        android:label="Networking stack coverage tests">
    </instrumentation>
</manifest>
+7 −4
Original line number Diff line number Diff line
@@ -25,13 +25,12 @@ import static android.net.dhcp.DhcpPacket.ENCAP_L2;
import static android.net.dhcp.DhcpPacket.INADDR_BROADCAST;
import static android.net.dhcp.DhcpPacket.INFINITE_LEASE;
import static android.net.ipmemorystore.Status.SUCCESS;
import static android.net.networkstack.shared.Inet4AddressUtils.getBroadcastAddress;
import static android.net.networkstack.shared.Inet4AddressUtils.getPrefixMaskAsInet4Address;
import static android.net.shared.Inet4AddressUtils.getBroadcastAddress;
import static android.net.shared.Inet4AddressUtils.getPrefixMaskAsInet4Address;
import static android.system.OsConstants.ETH_P_IPV6;
import static android.system.OsConstants.IPPROTO_ICMPV6;
import static android.system.OsConstants.IPPROTO_TCP;

import static com.android.internal.util.BitUtils.uint16;
import static com.android.server.util.NetworkStackConstants.ARP_REPLY;
import static com.android.server.util.NetworkStackConstants.ARP_REQUEST;
import static com.android.server.util.NetworkStackConstants.ETHER_ADDR_LEN;
@@ -96,7 +95,6 @@ import android.net.dhcp.DhcpRequestPacket;
import android.net.ipmemorystore.NetworkAttributes;
import android.net.ipmemorystore.OnNetworkAttributesRetrievedListener;
import android.net.ipmemorystore.Status;
import android.net.networkstack.util.StateMachine;
import android.net.shared.ProvisioningConfiguration;
import android.net.util.InterfaceParams;
import android.net.util.IpUtils;
@@ -116,6 +114,7 @@ import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.internal.util.StateMachine;
import com.android.networkstack.arp.ArpPacket;
import com.android.server.NetworkObserverRegistry;
import com.android.server.NetworkStackService.NetworkStackServiceManager;
@@ -1137,6 +1136,10 @@ public class IpClientIntegrationTest {
        return (short) ~tempSum;
    }

    public static int uint16(short s) {
        return s & 0xffff;
    }

    private static short icmpv6Checksum(ByteBuffer buf, int ipOffset, int transportOffset,
            int transportLen) {
        // The ICMPv6 checksum is the same as the TCP checksum, except the pseudo-header uses
+13 −0
Original line number Diff line number Diff line
@@ -38,8 +38,10 @@ java_defaults {
        "libstaticjvmtiagent",
        "libnetworkstackutilsjni",
    ],
    jarjar_rules: ":NetworkStackJarJarRules",
}

// Tests for NetworkStackNext.
android_test {
    name: "NetworkStackNextTests",
    srcs: [], // TODO: tests that only apply to the current, non-stable API can be added here
@@ -48,6 +50,17 @@ android_test {
    static_libs: ["NetworkStackApiCurrentLib"],
}

// Library containing the unit tests. This is used by the coverage test target to pull in the
// unit test code. It is not currently used by the tests themselves because all the build
// configuration needed by the tests is in the NetworkStackTestsDefaults rule.
android_library {
    name: "NetworkStackTestsLib",
    min_sdk_version: "29",
    defaults: ["NetworkStackTestsDefaults"],
    static_libs: ["NetworkStackApiStableLib"],
    visibility: ["//packages/modules/NetworkStack/tests/integration"]
}

android_test {
    name: "NetworkStackTests",
    min_sdk_version: "29",
Loading