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

Commit 62e3e4bd authored by Erik Kline's avatar Erik Kline
Browse files

Tweaks to tetheroffload VTS: fixes and fd leaks

Specifically:
    - always use hidl_handle::setTo(..., true) to force fd ownership
      (and thereby cleanup in hidl_handle destructor)
    - initialize config HAL multiple times to try to trigger fd leaking bugs

Test: as follows
    - make vts -j30 BUILD_GOOGLE_VTS=true && \
      vts-tradefed run commandAndExit vts \
          --skip-all-system-status-check  \
          --primary-abi-only              \
          --skip-preconditions            \
          --module VtsHalTetherOffloadConfigV1_0Target -l INFO

      I/ResultReporter: Invocation finished in 48s. PASSED: 4, FAILED: 0, MODULES: 1 of 1

    - make vts -j30 BUILD_GOOGLE_VTS=true && \
      vts-tradefed run commandAndExit vts \
          --skip-all-system-status-check  \
          --primary-abi-only              \
          --skip-preconditions            \
          --module VtsHalTetherOffloadControlV1_0Target -l INFO
Bug: 29337859
Bug: 32163131
Bug: 64976634
Bug: 65270149
Bug: 65529504
Change-Id: Ib47b35a01092bb2052d241f7bba951bbf7691b66
parent 39ac22e9
Loading
Loading
Loading
Loading
+36 −25
Original line number Original line Diff line number Diff line
@@ -91,6 +91,8 @@ class OffloadConfigHidlTest : public testing::VtsHalHidlTargetTestBase {


// Ensure handles can be set with correct socket options.
// Ensure handles can be set with correct socket options.
TEST_F(OffloadConfigHidlTest, TestSetHandles) {
TEST_F(OffloadConfigHidlTest, TestSetHandles) {
    // Try multiple times in a row to see if it provokes file descriptor leaks.
    for (int i = 0; i < 1024; i++) {
        unique_fd fd1(netlinkSocket(kFd1Groups));
        unique_fd fd1(netlinkSocket(kFd1Groups));
        if (fd1.get() < 0) {
        if (fd1.get() < 0) {
            ALOGE("Unable to create conntrack handles: %d/%s", errno, strerror(errno));
            ALOGE("Unable to create conntrack handles: %d/%s", errno, strerror(errno));
@@ -98,7 +100,8 @@ TEST_F(OffloadConfigHidlTest, TestSetHandles) {
        }
        }
        native_handle_t* const nativeHandle1 = native_handle_create(1, 0);
        native_handle_t* const nativeHandle1 = native_handle_create(1, 0);
        nativeHandle1->data[0] = fd1.release();
        nativeHandle1->data[0] = fd1.release();
    const hidl_handle h1 = hidl_handle(nativeHandle1);
        hidl_handle h1;
        h1.setTo(nativeHandle1, true);


        unique_fd fd2(netlinkSocket(kFd2Groups));
        unique_fd fd2(netlinkSocket(kFd2Groups));
        if (fd2.get() < 0) {
        if (fd2.get() < 0) {
@@ -107,19 +110,23 @@ TEST_F(OffloadConfigHidlTest, TestSetHandles) {
        }
        }
        native_handle_t* const nativeHandle2 = native_handle_create(1, 0);
        native_handle_t* const nativeHandle2 = native_handle_create(1, 0);
        nativeHandle2->data[0] = fd2.release();
        nativeHandle2->data[0] = fd2.release();
    const hidl_handle h2 = hidl_handle(nativeHandle2);
        hidl_handle h2;
        h2.setTo(nativeHandle2, true);


        const Return<void> ret = config->setHandles(h1, h2, ASSERT_TRUE_CALLBACK);
        const Return<void> ret = config->setHandles(h1, h2, ASSERT_TRUE_CALLBACK);
        ASSERT_TRUE(ret.isOk());
        ASSERT_TRUE(ret.isOk());
    }
    }
}


// Passing a handle without an associated file descriptor should return an error
// Passing a handle without an associated file descriptor should return an error
// (e.g. "Failed Input Checks"). Check that this occurs when both FDs are empty.
// (e.g. "Failed Input Checks"). Check that this occurs when both FDs are empty.
TEST_F(OffloadConfigHidlTest, TestSetHandleNone) {
TEST_F(OffloadConfigHidlTest, TestSetHandleNone) {
    native_handle_t* const nativeHandle1 = native_handle_create(0, 0);
    native_handle_t* const nativeHandle1 = native_handle_create(0, 0);
    const hidl_handle h1 = hidl_handle(nativeHandle1);
    hidl_handle h1;
    h1.setTo(nativeHandle1, true);
    native_handle_t* const nativeHandle2 = native_handle_create(0, 0);
    native_handle_t* const nativeHandle2 = native_handle_create(0, 0);
    const hidl_handle h2 = hidl_handle(nativeHandle2);
    hidl_handle h2;
    h2.setTo(nativeHandle2, true);


    const Return<void> ret = config->setHandles(h1, h2, ASSERT_FALSE_CALLBACK);
    const Return<void> ret = config->setHandles(h1, h2, ASSERT_FALSE_CALLBACK);
    ASSERT_TRUE(ret.isOk());
    ASSERT_TRUE(ret.isOk());
@@ -135,10 +142,12 @@ TEST_F(OffloadConfigHidlTest, TestSetHandle1Only) {
    }
    }
    native_handle_t* const nativeHandle1 = native_handle_create(1, 0);
    native_handle_t* const nativeHandle1 = native_handle_create(1, 0);
    nativeHandle1->data[0] = fd1.release();
    nativeHandle1->data[0] = fd1.release();
    const hidl_handle h1 = hidl_handle(nativeHandle1);
    hidl_handle h1;
    h1.setTo(nativeHandle1, true);


    native_handle_t* const nativeHandle2 = native_handle_create(0, 0);
    native_handle_t* const nativeHandle2 = native_handle_create(0, 0);
    const hidl_handle h2 = hidl_handle(nativeHandle2);
    hidl_handle h2;
    h2.setTo(nativeHandle2, true);


    const Return<void> ret = config->setHandles(h1, h2, ASSERT_FALSE_CALLBACK);
    const Return<void> ret = config->setHandles(h1, h2, ASSERT_FALSE_CALLBACK);
    ASSERT_TRUE(ret.isOk());
    ASSERT_TRUE(ret.isOk());
@@ -148,7 +157,8 @@ TEST_F(OffloadConfigHidlTest, TestSetHandle1Only) {
// (e.g. "Failed Input Checks"). Check that this occurs when FD1 is empty.
// (e.g. "Failed Input Checks"). Check that this occurs when FD1 is empty.
TEST_F(OffloadConfigHidlTest, TestSetHandle2OnlyNotOk) {
TEST_F(OffloadConfigHidlTest, TestSetHandle2OnlyNotOk) {
    native_handle_t* const nativeHandle1 = native_handle_create(0, 0);
    native_handle_t* const nativeHandle1 = native_handle_create(0, 0);
    const hidl_handle h1 = hidl_handle(nativeHandle1);
    hidl_handle h1;
    h1.setTo(nativeHandle1, true);


    unique_fd fd2(netlinkSocket(kFd2Groups));
    unique_fd fd2(netlinkSocket(kFd2Groups));
    if (fd2.get() < 0) {
    if (fd2.get() < 0) {
@@ -157,7 +167,8 @@ TEST_F(OffloadConfigHidlTest, TestSetHandle2OnlyNotOk) {
    }
    }
    native_handle_t* const nativeHandle2 = native_handle_create(1, 0);
    native_handle_t* const nativeHandle2 = native_handle_create(1, 0);
    nativeHandle2->data[0] = fd2.release();
    nativeHandle2->data[0] = fd2.release();
    const hidl_handle h2 = hidl_handle(nativeHandle2);
    hidl_handle h2;
    h2.setTo(nativeHandle2, true);


    const Return<void> ret = config->setHandles(h1, h2, ASSERT_FALSE_CALLBACK);
    const Return<void> ret = config->setHandles(h1, h2, ASSERT_FALSE_CALLBACK);
    ASSERT_TRUE(ret.isOk());
    ASSERT_TRUE(ret.isOk());
+4 −2
Original line number Original line Diff line number Diff line
@@ -127,7 +127,8 @@ class OffloadControlHidlTestBase : public testing::VtsHalHidlTargetTestBase {
        }
        }
        native_handle_t* const nativeHandle1 = native_handle_create(1, 0);
        native_handle_t* const nativeHandle1 = native_handle_create(1, 0);
        nativeHandle1->data[0] = fd1.release();
        nativeHandle1->data[0] = fd1.release();
        hidl_handle h1 = hidl_handle(nativeHandle1);
        hidl_handle h1;
        h1.setTo(nativeHandle1, true);


        unique_fd fd2(conntrackSocket(NFNLGRP_CONNTRACK_UPDATE | NFNLGRP_CONNTRACK_DESTROY));
        unique_fd fd2(conntrackSocket(NFNLGRP_CONNTRACK_UPDATE | NFNLGRP_CONNTRACK_DESTROY));
        if (fd2.get() < 0) {
        if (fd2.get() < 0) {
@@ -136,7 +137,8 @@ class OffloadControlHidlTestBase : public testing::VtsHalHidlTargetTestBase {
        }
        }
        native_handle_t* const nativeHandle2 = native_handle_create(1, 0);
        native_handle_t* const nativeHandle2 = native_handle_create(1, 0);
        nativeHandle2->data[0] = fd2.release();
        nativeHandle2->data[0] = fd2.release();
        hidl_handle h2 = hidl_handle(nativeHandle2);
        hidl_handle h2;
        h2.setTo(nativeHandle2, true);


        const Return<void> ret = config->setHandles(h1, h2, ASSERT_TRUE_CALLBACK);
        const Return<void> ret = config->setHandles(h1, h2, ASSERT_TRUE_CALLBACK);
        ASSERT_TRUE(ret.isOk());
        ASSERT_TRUE(ret.isOk());