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

Commit 3189d9de authored by Lorenzo Colitti's avatar Lorenzo Colitti
Browse files

Don't expect stopOffload to succeed if interface doesn't exist.

The AdditionalStopsWithInitReturnFalse test inits offload and
then checks that stopOffload returns true. However, the HAL is
allowed to return false to stopOffload if no upstream was ever
successfully programmed.

To ensure this test doesn't fail in the common case that the
interface is not up, don't expect stopOffload to return true in
this case.

Bug: 67439856
Test: VtsHalTetheroffloadControlV1_0TargetTest passes with and without mobile data connection
Change-Id: I245f9e3e4376a7799572a3b3967e2bf6c52b5e4d
parent d97f8714
Loading
Loading
Loading
Loading
+43 −25
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@
#include <linux/netfilter/nfnetlink.h>
#include <linux/netfilter/nfnetlink.h>
#include <linux/netlink.h>
#include <linux/netlink.h>
#include <log/log.h>
#include <log/log.h>
#include <net/if.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <unistd.h>
#include <unistd.h>
#include <set>
#include <set>
@@ -52,6 +53,8 @@ enum class ExpectBoolean {
    True = 1,
    True = 1,
};
};


constexpr const char* TEST_IFACE = "rmnet_data0";

// We use #defines here so as to get local lamba captures and error message line numbers
// We use #defines here so as to get local lamba captures and error message line numbers
#define ASSERT_TRUE_CALLBACK                            \
#define ASSERT_TRUE_CALLBACK                            \
    [&](bool success, std::string errMsg) {             \
    [&](bool success, std::string errMsg) {             \
@@ -240,6 +243,18 @@ TEST_F(OffloadControlHidlTestBase, MultipleStopsWithoutInitReturnFalse) {
    stopOffload(ExpectBoolean::False);
    stopOffload(ExpectBoolean::False);
}
}


// Check whether the specified interface is up.
bool interfaceIsUp(const char* name) {
    if (name == nullptr) return false;
    struct ifreq ifr = {};
    strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
    int sock = socket(AF_INET6, SOCK_DGRAM, 0);
    if (sock == -1) return false;
    int ret = ioctl(sock, SIOCGIFFLAGS, &ifr, sizeof(ifr));
    close(sock);
    return (ret == 0) && (ifr.ifr_flags & IFF_UP);
}

// Check that calling stopOffload() after a complete init/stop cycle returns false.
// Check that calling stopOffload() after a complete init/stop cycle returns false.
TEST_F(OffloadControlHidlTestBase, AdditionalStopsWithInitReturnFalse) {
TEST_F(OffloadControlHidlTestBase, AdditionalStopsWithInitReturnFalse) {
    initOffload(true);
    initOffload(true);
@@ -249,8 +264,11 @@ TEST_F(OffloadControlHidlTestBase, AdditionalStopsWithInitReturnFalse) {
    const hidl_string v4Gw("192.0.0.1");
    const hidl_string v4Gw("192.0.0.1");
    const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:2")};
    const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:2")};
    const Return<void> upstream =
    const Return<void> upstream =
        control->setUpstreamParameters("rmnet_data0", v4Addr, v4Gw, v6Gws, ASSERT_TRUE_CALLBACK);
        control->setUpstreamParameters(TEST_IFACE, v4Addr, v4Gw, v6Gws, ASSERT_TRUE_CALLBACK);
    EXPECT_TRUE(upstream.isOk());
    EXPECT_TRUE(upstream.isOk());
    if (!interfaceIsUp(TEST_IFACE)) {
        return;
    }
    stopOffload(ExpectBoolean::True);  // balance out initOffload(true)
    stopOffload(ExpectBoolean::True);  // balance out initOffload(true)
    stopOffload(ExpectBoolean::False);
    stopOffload(ExpectBoolean::False);
    stopOffload(ExpectBoolean::False);
    stopOffload(ExpectBoolean::False);
@@ -266,14 +284,14 @@ TEST_F(OffloadControlHidlTestBase, SetLocalPrefixesWithoutInitReturnsFalse) {
// Check that calling getForwardedStats() without first having called initOffload()
// Check that calling getForwardedStats() without first having called initOffload()
// returns zero bytes statistics.
// returns zero bytes statistics.
TEST_F(OffloadControlHidlTestBase, GetForwardedStatsWithoutInitReturnsZeroValues) {
TEST_F(OffloadControlHidlTestBase, GetForwardedStatsWithoutInitReturnsZeroValues) {
    const hidl_string upstream("rmnet_data0");
    const hidl_string upstream(TEST_IFACE);
    const Return<void> ret = control->getForwardedStats(upstream, ASSERT_ZERO_BYTES_CALLBACK);
    const Return<void> ret = control->getForwardedStats(upstream, ASSERT_ZERO_BYTES_CALLBACK);
    EXPECT_TRUE(ret.isOk());
    EXPECT_TRUE(ret.isOk());
}
}


// Check that calling setDataLimit() without first having called initOffload() returns false.
// Check that calling setDataLimit() without first having called initOffload() returns false.
TEST_F(OffloadControlHidlTestBase, SetDataLimitWithoutInitReturnsFalse) {
TEST_F(OffloadControlHidlTestBase, SetDataLimitWithoutInitReturnsFalse) {
    const hidl_string upstream("rmnet_data0");
    const hidl_string upstream(TEST_IFACE);
    const uint64_t limit = 5000ULL;
    const uint64_t limit = 5000ULL;
    const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_FALSE_CALLBACK);
    const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_FALSE_CALLBACK);
    EXPECT_TRUE(ret.isOk());
    EXPECT_TRUE(ret.isOk());
@@ -282,7 +300,7 @@ TEST_F(OffloadControlHidlTestBase, SetDataLimitWithoutInitReturnsFalse) {
// Check that calling setUpstreamParameters() without first having called initOffload()
// Check that calling setUpstreamParameters() without first having called initOffload()
// returns false.
// returns false.
TEST_F(OffloadControlHidlTestBase, SetUpstreamParametersWithoutInitReturnsFalse) {
TEST_F(OffloadControlHidlTestBase, SetUpstreamParametersWithoutInitReturnsFalse) {
    const hidl_string iface("rmnet_data0");
    const hidl_string iface(TEST_IFACE);
    const hidl_string v4Addr("192.0.2.0/24");
    const hidl_string v4Addr("192.0.2.0/24");
    const hidl_string v4Gw("192.0.2.1");
    const hidl_string v4Gw("192.0.2.1");
    const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")};
    const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")};
@@ -294,7 +312,7 @@ TEST_F(OffloadControlHidlTestBase, SetUpstreamParametersWithoutInitReturnsFalse)
// Check that calling addDownstream() with an IPv4 prefix without first having called
// Check that calling addDownstream() with an IPv4 prefix without first having called
// initOffload() returns false.
// initOffload() returns false.
TEST_F(OffloadControlHidlTestBase, AddIPv4DownstreamWithoutInitReturnsFalse) {
TEST_F(OffloadControlHidlTestBase, AddIPv4DownstreamWithoutInitReturnsFalse) {
    const hidl_string iface("rmnet_data0");
    const hidl_string iface(TEST_IFACE);
    const hidl_string prefix("192.0.2.0/24");
    const hidl_string prefix("192.0.2.0/24");
    const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
    const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
    EXPECT_TRUE(ret.isOk());
    EXPECT_TRUE(ret.isOk());
@@ -303,7 +321,7 @@ TEST_F(OffloadControlHidlTestBase, AddIPv4DownstreamWithoutInitReturnsFalse) {
// Check that calling addDownstream() with an IPv6 prefix without first having called
// Check that calling addDownstream() with an IPv6 prefix without first having called
// initOffload() returns false.
// initOffload() returns false.
TEST_F(OffloadControlHidlTestBase, AddIPv6DownstreamWithoutInitReturnsFalse) {
TEST_F(OffloadControlHidlTestBase, AddIPv6DownstreamWithoutInitReturnsFalse) {
    const hidl_string iface("rmnet_data0");
    const hidl_string iface(TEST_IFACE);
    const hidl_string prefix("2001:db8::/64");
    const hidl_string prefix("2001:db8::/64");
    const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
    const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
    EXPECT_TRUE(ret.isOk());
    EXPECT_TRUE(ret.isOk());
@@ -312,7 +330,7 @@ TEST_F(OffloadControlHidlTestBase, AddIPv6DownstreamWithoutInitReturnsFalse) {
// Check that calling removeDownstream() with an IPv4 prefix without first having called
// Check that calling removeDownstream() with an IPv4 prefix without first having called
// initOffload() returns false.
// initOffload() returns false.
TEST_F(OffloadControlHidlTestBase, RemoveIPv4DownstreamWithoutInitReturnsFalse) {
TEST_F(OffloadControlHidlTestBase, RemoveIPv4DownstreamWithoutInitReturnsFalse) {
    const hidl_string iface("rmnet_data0");
    const hidl_string iface(TEST_IFACE);
    const hidl_string prefix("192.0.2.0/24");
    const hidl_string prefix("192.0.2.0/24");
    const Return<void> ret = control->removeDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
    const Return<void> ret = control->removeDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
    EXPECT_TRUE(ret.isOk());
    EXPECT_TRUE(ret.isOk());
@@ -321,7 +339,7 @@ TEST_F(OffloadControlHidlTestBase, RemoveIPv4DownstreamWithoutInitReturnsFalse)
// Check that calling removeDownstream() with an IPv6 prefix without first having called
// Check that calling removeDownstream() with an IPv6 prefix without first having called
// initOffload() returns false.
// initOffload() returns false.
TEST_F(OffloadControlHidlTestBase, RemoveIPv6DownstreamWithoutInitReturnsFalse) {
TEST_F(OffloadControlHidlTestBase, RemoveIPv6DownstreamWithoutInitReturnsFalse) {
    const hidl_string iface("rmnet_data0");
    const hidl_string iface(TEST_IFACE);
    const hidl_string prefix("2001:db8::/64");
    const hidl_string prefix("2001:db8::/64");
    const Return<void> ret = control->removeDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
    const Return<void> ret = control->removeDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
    EXPECT_TRUE(ret.isOk());
    EXPECT_TRUE(ret.isOk());
@@ -394,10 +412,10 @@ TEST_F(OffloadControlHidlTest, GetForwardedStatsInvalidUpstreamIface) {
    EXPECT_TRUE(ret.isOk());
    EXPECT_TRUE(ret.isOk());
}
}


// The "rmnet_data0" is presumed to exist on the device and be up. No packets
// TEST_IFACE is presumed to exist on the device and be up. No packets
// are ever actually caused to be forwarded.
// are ever actually caused to be forwarded.
TEST_F(OffloadControlHidlTest, GetForwardedStatsDummyIface) {
TEST_F(OffloadControlHidlTest, GetForwardedStatsDummyIface) {
    const hidl_string upstream("rmnet_data0");
    const hidl_string upstream(TEST_IFACE);
    const Return<void> ret = control->getForwardedStats(upstream, ASSERT_ZERO_BYTES_CALLBACK);
    const Return<void> ret = control->getForwardedStats(upstream, ASSERT_ZERO_BYTES_CALLBACK);
    EXPECT_TRUE(ret.isOk());
    EXPECT_TRUE(ret.isOk());
}
}
@@ -414,19 +432,19 @@ TEST_F(OffloadControlHidlTest, SetDataLimitEmptyUpstreamIfaceFails) {
    EXPECT_TRUE(ret.isOk());
    EXPECT_TRUE(ret.isOk());
}
}


// The "rmnet_data0" is presumed to exist on the device and be up. No packets
// TEST_IFACE is presumed to exist on the device and be up. No packets
// are ever actually caused to be forwarded.
// are ever actually caused to be forwarded.
TEST_F(OffloadControlHidlTest, SetDataLimitNonZeroOk) {
TEST_F(OffloadControlHidlTest, SetDataLimitNonZeroOk) {
    const hidl_string upstream("rmnet_data0");
    const hidl_string upstream(TEST_IFACE);
    const uint64_t limit = 5000ULL;
    const uint64_t limit = 5000ULL;
    const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_TRUE_CALLBACK);
    const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_TRUE_CALLBACK);
    EXPECT_TRUE(ret.isOk());
    EXPECT_TRUE(ret.isOk());
}
}


// The "rmnet_data0" is presumed to exist on the device and be up. No packets
// TEST_IFACE is presumed to exist on the device and be up. No packets
// are ever actually caused to be forwarded.
// are ever actually caused to be forwarded.
TEST_F(OffloadControlHidlTest, SetDataLimitZeroOk) {
TEST_F(OffloadControlHidlTest, SetDataLimitZeroOk) {
    const hidl_string upstream("rmnet_data0");
    const hidl_string upstream(TEST_IFACE);
    const uint64_t limit = 0ULL;
    const uint64_t limit = 0ULL;
    const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_TRUE_CALLBACK);
    const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_TRUE_CALLBACK);
    EXPECT_TRUE(ret.isOk());
    EXPECT_TRUE(ret.isOk());
@@ -436,10 +454,10 @@ TEST_F(OffloadControlHidlTest, SetDataLimitZeroOk) {
 * Tests for IOffloadControl::setUpstreamParameters().
 * Tests for IOffloadControl::setUpstreamParameters().
 */
 */


// The "rmnet_data0" is presumed to exist on the device and be up. No packets
// TEST_IFACE is presumed to exist on the device and be up. No packets
// are ever actually caused to be forwarded.
// are ever actually caused to be forwarded.
TEST_F(OffloadControlHidlTest, SetUpstreamParametersIPv6OnlyOk) {
TEST_F(OffloadControlHidlTest, SetUpstreamParametersIPv6OnlyOk) {
    const hidl_string iface("rmnet_data0");
    const hidl_string iface(TEST_IFACE);
    const hidl_string v4Addr("");
    const hidl_string v4Addr("");
    const hidl_string v4Gw("");
    const hidl_string v4Gw("");
    const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:2")};
    const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:2")};
@@ -448,10 +466,10 @@ TEST_F(OffloadControlHidlTest, SetUpstreamParametersIPv6OnlyOk) {
    EXPECT_TRUE(ret.isOk());
    EXPECT_TRUE(ret.isOk());
}
}


// The "rmnet_data0" is presumed to exist on the device and be up. No packets
// TEST_IFACE is presumed to exist on the device and be up. No packets
// are ever actually caused to be forwarded.
// are ever actually caused to be forwarded.
TEST_F(OffloadControlHidlTest, SetUpstreamParametersAlternateIPv6OnlyOk) {
TEST_F(OffloadControlHidlTest, SetUpstreamParametersAlternateIPv6OnlyOk) {
    const hidl_string iface("rmnet_data0");
    const hidl_string iface(TEST_IFACE);
    const hidl_string v4Addr;
    const hidl_string v4Addr;
    const hidl_string v4Gw;
    const hidl_string v4Gw;
    const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:3")};
    const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:3")};
@@ -460,10 +478,10 @@ TEST_F(OffloadControlHidlTest, SetUpstreamParametersAlternateIPv6OnlyOk) {
    EXPECT_TRUE(ret.isOk());
    EXPECT_TRUE(ret.isOk());
}
}


// The "rmnet_data0" is presumed to exist on the device and be up. No packets
// TEST_IFACE is presumed to exist on the device and be up. No packets
// are ever actually caused to be forwarded.
// are ever actually caused to be forwarded.
TEST_F(OffloadControlHidlTest, SetUpstreamParametersIPv4OnlyOk) {
TEST_F(OffloadControlHidlTest, SetUpstreamParametersIPv4OnlyOk) {
    const hidl_string iface("rmnet_data0");
    const hidl_string iface(TEST_IFACE);
    const hidl_string v4Addr("192.0.2.2");
    const hidl_string v4Addr("192.0.2.2");
    const hidl_string v4Gw("192.0.2.1");
    const hidl_string v4Gw("192.0.2.1");
    const vector<hidl_string> v6Gws{};
    const vector<hidl_string> v6Gws{};
@@ -472,10 +490,10 @@ TEST_F(OffloadControlHidlTest, SetUpstreamParametersIPv4OnlyOk) {
    EXPECT_TRUE(ret.isOk());
    EXPECT_TRUE(ret.isOk());
}
}


// The "rmnet_data0" is presumed to exist on the device and be up. No packets
// TEST_IFACE is presumed to exist on the device and be up. No packets
// are ever actually caused to be forwarded.
// are ever actually caused to be forwarded.
TEST_F(OffloadControlHidlTest, SetUpstreamParametersIPv4v6Ok) {
TEST_F(OffloadControlHidlTest, SetUpstreamParametersIPv4v6Ok) {
    const hidl_string iface("rmnet_data0");
    const hidl_string iface(TEST_IFACE);
    const hidl_string v4Addr("192.0.2.2");
    const hidl_string v4Addr("192.0.2.2");
    const hidl_string v4Gw("192.0.2.1");
    const hidl_string v4Gw("192.0.2.1");
    const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:2")};
    const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:2")};
@@ -511,7 +529,7 @@ TEST_F(OffloadControlHidlTest, SetUpstreamParametersBogusIfaceFails) {


// Test that setUpstreamParameters() fails when given unparseable IPv4 addresses.
// Test that setUpstreamParameters() fails when given unparseable IPv4 addresses.
TEST_F(OffloadControlHidlTest, SetUpstreamParametersInvalidIPv4AddrFails) {
TEST_F(OffloadControlHidlTest, SetUpstreamParametersInvalidIPv4AddrFails) {
    const hidl_string iface("rmnet_data0");
    const hidl_string iface(TEST_IFACE);
    const hidl_string v4Gw("192.0.2.1");
    const hidl_string v4Gw("192.0.2.1");
    const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")};
    const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")};
    for (const auto& bogus : {"invalid", "192.0.2"}) {
    for (const auto& bogus : {"invalid", "192.0.2"}) {
@@ -525,7 +543,7 @@ TEST_F(OffloadControlHidlTest, SetUpstreamParametersInvalidIPv4AddrFails) {


// Test that setUpstreamParameters() fails when given unparseable IPv4 gateways.
// Test that setUpstreamParameters() fails when given unparseable IPv4 gateways.
TEST_F(OffloadControlHidlTest, SetUpstreamParametersInvalidIPv4GatewayFails) {
TEST_F(OffloadControlHidlTest, SetUpstreamParametersInvalidIPv4GatewayFails) {
    const hidl_string iface("rmnet_data0");
    const hidl_string iface(TEST_IFACE);
    const hidl_string v4Addr("192.0.2.2");
    const hidl_string v4Addr("192.0.2.2");
    const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")};
    const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")};
    for (const auto& bogus : {"invalid", "192.0.2"}) {
    for (const auto& bogus : {"invalid", "192.0.2"}) {
@@ -539,7 +557,7 @@ TEST_F(OffloadControlHidlTest, SetUpstreamParametersInvalidIPv4GatewayFails) {


// Test that setUpstreamParameters() fails when given unparseable IPv6 gateways.
// Test that setUpstreamParameters() fails when given unparseable IPv6 gateways.
TEST_F(OffloadControlHidlTest, SetUpstreamParametersBadIPv6GatewaysFail) {
TEST_F(OffloadControlHidlTest, SetUpstreamParametersBadIPv6GatewaysFail) {
    const hidl_string iface("rmnet_data0");
    const hidl_string iface(TEST_IFACE);
    const hidl_string v4Addr("192.0.2.2");
    const hidl_string v4Addr("192.0.2.2");
    const hidl_string v4Gw("192.0.2.1");
    const hidl_string v4Gw("192.0.2.1");
    for (const auto& bogus : {"", "invalid", "fe80::bogus", "192.0.2.66"}) {
    for (const auto& bogus : {"", "invalid", "fe80::bogus", "192.0.2.66"}) {