summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2017-10-23 18:46:56 +0900
committerandroid-build-team Robot <android-build-team-robot@google.com>2017-10-27 14:48:02 +0000
commit7d47ed708ea3f2d372347584925a3ab6a8b20852 (patch)
tree37c6f008c944c7b379545bf749796644af5b8377
parent6f11e984b1373c22a1601d95b4fe647271479929 (diff)
downloadandroid_hardware_interfaces-7d47ed708ea3f2d372347584925a3ab6a8b20852.tar.gz
android_hardware_interfaces-7d47ed708ea3f2d372347584925a3ab6a8b20852.tar.bz2
android_hardware_interfaces-7d47ed708ea3f2d372347584925a3ab6a8b20852.zip
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 (cherry picked from commit 3189d9de81c937d495482fa3dacc196878cfcda1)
-rw-r--r--tetheroffload/control/1.0/vts/functional/VtsHalTetheroffloadControlV1_0TargetTest.cpp68
1 files changed, 43 insertions, 25 deletions
diff --git a/tetheroffload/control/1.0/vts/functional/VtsHalTetheroffloadControlV1_0TargetTest.cpp b/tetheroffload/control/1.0/vts/functional/VtsHalTetheroffloadControlV1_0TargetTest.cpp
index d572728ea..d2fa92db3 100644
--- a/tetheroffload/control/1.0/vts/functional/VtsHalTetheroffloadControlV1_0TargetTest.cpp
+++ b/tetheroffload/control/1.0/vts/functional/VtsHalTetheroffloadControlV1_0TargetTest.cpp
@@ -26,6 +26,7 @@
#include <linux/netfilter/nfnetlink.h>
#include <linux/netlink.h>
#include <log/log.h>
+#include <net/if.h>
#include <sys/socket.h>
#include <unistd.h>
#include <set>
@@ -52,6 +53,8 @@ enum class ExpectBoolean {
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
#define ASSERT_TRUE_CALLBACK \
[&](bool success, std::string errMsg) { \
@@ -240,6 +243,18 @@ TEST_F(OffloadControlHidlTestBase, MultipleStopsWithoutInitReturnFalse) {
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.
TEST_F(OffloadControlHidlTestBase, AdditionalStopsWithInitReturnFalse) {
initOffload(true);
@@ -249,8 +264,11 @@ TEST_F(OffloadControlHidlTestBase, AdditionalStopsWithInitReturnFalse) {
const hidl_string v4Gw("192.0.0.1");
const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:2")};
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());
+ if (!interfaceIsUp(TEST_IFACE)) {
+ return;
+ }
stopOffload(ExpectBoolean::True); // balance out initOffload(true)
stopOffload(ExpectBoolean::False);
stopOffload(ExpectBoolean::False);
@@ -266,14 +284,14 @@ TEST_F(OffloadControlHidlTestBase, SetLocalPrefixesWithoutInitReturnsFalse) {
// Check that calling getForwardedStats() without first having called initOffload()
// returns zero bytes statistics.
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);
EXPECT_TRUE(ret.isOk());
}
// Check that calling setDataLimit() without first having called initOffload() returns false.
TEST_F(OffloadControlHidlTestBase, SetDataLimitWithoutInitReturnsFalse) {
- const hidl_string upstream("rmnet_data0");
+ const hidl_string upstream(TEST_IFACE);
const uint64_t limit = 5000ULL;
const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_FALSE_CALLBACK);
EXPECT_TRUE(ret.isOk());
@@ -282,7 +300,7 @@ TEST_F(OffloadControlHidlTestBase, SetDataLimitWithoutInitReturnsFalse) {
// Check that calling setUpstreamParameters() without first having called initOffload()
// returns false.
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 v4Gw("192.0.2.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
// initOffload() returns false.
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 Return<void> ret = control->addDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
EXPECT_TRUE(ret.isOk());
@@ -303,7 +321,7 @@ TEST_F(OffloadControlHidlTestBase, AddIPv4DownstreamWithoutInitReturnsFalse) {
// Check that calling addDownstream() with an IPv6 prefix without first having called
// initOffload() returns false.
TEST_F(OffloadControlHidlTestBase, AddIPv6DownstreamWithoutInitReturnsFalse) {
- const hidl_string iface("rmnet_data0");
+ const hidl_string iface(TEST_IFACE);
const hidl_string prefix("2001:db8::/64");
const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
EXPECT_TRUE(ret.isOk());
@@ -312,7 +330,7 @@ TEST_F(OffloadControlHidlTestBase, AddIPv6DownstreamWithoutInitReturnsFalse) {
// Check that calling removeDownstream() with an IPv4 prefix without first having called
// initOffload() returns false.
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 Return<void> ret = control->removeDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
EXPECT_TRUE(ret.isOk());
@@ -321,7 +339,7 @@ TEST_F(OffloadControlHidlTestBase, RemoveIPv4DownstreamWithoutInitReturnsFalse)
// Check that calling removeDownstream() with an IPv6 prefix without first having called
// initOffload() returns false.
TEST_F(OffloadControlHidlTestBase, RemoveIPv6DownstreamWithoutInitReturnsFalse) {
- const hidl_string iface("rmnet_data0");
+ const hidl_string iface(TEST_IFACE);
const hidl_string prefix("2001:db8::/64");
const Return<void> ret = control->removeDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
EXPECT_TRUE(ret.isOk());
@@ -394,10 +412,10 @@ TEST_F(OffloadControlHidlTest, GetForwardedStatsInvalidUpstreamIface) {
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.
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);
EXPECT_TRUE(ret.isOk());
}
@@ -414,19 +432,19 @@ TEST_F(OffloadControlHidlTest, SetDataLimitEmptyUpstreamIfaceFails) {
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.
TEST_F(OffloadControlHidlTest, SetDataLimitNonZeroOk) {
- const hidl_string upstream("rmnet_data0");
+ const hidl_string upstream(TEST_IFACE);
const uint64_t limit = 5000ULL;
const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_TRUE_CALLBACK);
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.
TEST_F(OffloadControlHidlTest, SetDataLimitZeroOk) {
- const hidl_string upstream("rmnet_data0");
+ const hidl_string upstream(TEST_IFACE);
const uint64_t limit = 0ULL;
const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_TRUE_CALLBACK);
EXPECT_TRUE(ret.isOk());
@@ -436,10 +454,10 @@ TEST_F(OffloadControlHidlTest, SetDataLimitZeroOk) {
* 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.
TEST_F(OffloadControlHidlTest, SetUpstreamParametersIPv6OnlyOk) {
- const hidl_string iface("rmnet_data0");
+ const hidl_string iface(TEST_IFACE);
const hidl_string v4Addr("");
const hidl_string v4Gw("");
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());
}
-// 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.
TEST_F(OffloadControlHidlTest, SetUpstreamParametersAlternateIPv6OnlyOk) {
- const hidl_string iface("rmnet_data0");
+ const hidl_string iface(TEST_IFACE);
const hidl_string v4Addr;
const hidl_string v4Gw;
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());
}
-// 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.
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 v4Gw("192.0.2.1");
const vector<hidl_string> v6Gws{};
@@ -472,10 +490,10 @@ TEST_F(OffloadControlHidlTest, SetUpstreamParametersIPv4OnlyOk) {
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.
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 v4Gw("192.0.2.1");
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_F(OffloadControlHidlTest, SetUpstreamParametersInvalidIPv4AddrFails) {
- const hidl_string iface("rmnet_data0");
+ const hidl_string iface(TEST_IFACE);
const hidl_string v4Gw("192.0.2.1");
const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")};
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_F(OffloadControlHidlTest, SetUpstreamParametersInvalidIPv4GatewayFails) {
- const hidl_string iface("rmnet_data0");
+ const hidl_string iface(TEST_IFACE);
const hidl_string v4Addr("192.0.2.2");
const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")};
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_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 v4Gw("192.0.2.1");
for (const auto& bogus : {"", "invalid", "fe80::bogus", "192.0.2.66"}) {