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

Commit 93533836 authored by Xiao Ma's avatar Xiao Ma
Browse files

Run NetworkStackIntegrationTest with Parameterized.class.

The flag of parsing netlink event brings two different codepath, when
it's disabled NetworkObserver is still used in the integration test,
otherwise, new codepath which processes netlink message in upper layer
will be used instead.

To cover both above cases in the integration test, make test run with
Parameterized.class, that iterates each test method with the pre-defined
parameterized boolean flag value.

Bug: 163492391
Test: atest NetworkStackIntegrationTests
Change-Id: Id0f6db887794c8e172e43bc4b093c3951ae27d00
parent f3dd8d71
Loading
Loading
Loading
Loading
+27 −4
Original line number Diff line number Diff line
@@ -146,7 +146,6 @@ import android.system.Os;
import androidx.annotation.NonNull;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.internal.util.HexDump;
import com.android.internal.util.StateMachine;
@@ -181,6 +180,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.Mock;
@@ -224,7 +224,7 @@ import kotlin.LazyKt;
 *
 * Tests in this class can either be run with signature permissions, or with root access.
 */
@RunWith(AndroidJUnit4.class)
@RunWith(Parameterized.class)
@SmallTest
public abstract class IpClientIntegrationTestCommon {
    private static final int DATA_BUFFER_LEN = 4096;
@@ -247,6 +247,17 @@ public abstract class IpClientIntegrationTestCommon {
    @Rule
    public final TestName mTestNameRule = new TestName();

    // Indicate whether the flag of parsing netlink event is enabled or not. If it's disabled,
    // integration test still covers the old codepath(i.e. using NetworkObserver), otherwise,
    // test goes through the new codepath(i.e. processRtNetlinkxxx).
    @Parameterized.Parameter(0)
    public boolean mIsNetlinkEventParseEnabled;

    @Parameterized.Parameters
    public static Iterable<? extends Object> data() {
        return Arrays.asList(Boolean.valueOf("false"), Boolean.valueOf("true"));
    }

    /**
     * Indicates that a test requires signature permissions to run.
     *
@@ -553,8 +564,14 @@ public abstract class IpClientIntegrationTestCommon {

    @Before
    public void setUp() throws Exception {
        final Method testMethod = IpClientIntegrationTestCommon.class.getMethod(
                mTestNameRule.getMethodName());
        // Suffix "[0]" or "[1]" is added to the end of test method name after running with
        // Parameterized.class, that's intended behavior, to iterate each test method with the
        // parameterize value. However, Class#getMethod() throws NoSuchMethodException when
        // searching the target test method name due to this change. Just keep the original test
        // method name to fix NoSuchMethodException, and find the correct annotation associated
        // to test method.
        final String testMethodName = mTestNameRule.getMethodName().split("\\[")[0];
        final Method testMethod = IpClientIntegrationTestCommon.class.getMethod(testMethodName);
        mIsSignatureRequiredTest = testMethod.getAnnotation(SignatureRequiredTest.class) != null;
        assumeFalse(testSkipped());

@@ -567,6 +584,12 @@ public abstract class IpClientIntegrationTestCommon {
        }

        mIIpClient = makeIIpClient(mIfaceName, mCb);

        // Depend on the parameterized value to enable/disable netlink message refactor flag.
        // Make sure both of the old codepath(rely on the INetdUnsolicitedEventListener aidl)
        // and new codepath(parse netlink event from kernel) will be executed.
        setFeatureEnabled(NetworkStackUtils.IPCLIENT_PARSE_NETLINK_EVENTS_VERSION,
                mIsNetlinkEventParseEnabled /* default value */);
    }

    protected void setUpMocks() throws Exception {