Android-x86
Fork
Faire un don

  • R/O
  • HTTP
  • SSH
  • HTTPS

hardware-interfaces: Commit

hardware/interfaces


Commit MetaInfo

Révision7d47ed708ea3f2d372347584925a3ab6a8b20852 (tree)
l'heure2017-10-27 23:48:02
AuteurLorenzo Colitti <lorenzo@goog...>
Commiterandroid-build-team Robot

Message de Log

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)

Change Summary

Modification

--- a/tetheroffload/control/1.0/vts/functional/VtsHalTetheroffloadControlV1_0TargetTest.cpp
+++ b/tetheroffload/control/1.0/vts/functional/VtsHalTetheroffloadControlV1_0TargetTest.cpp
@@ -26,6 +26,7 @@
2626 #include <linux/netfilter/nfnetlink.h>
2727 #include <linux/netlink.h>
2828 #include <log/log.h>
29+#include <net/if.h>
2930 #include <sys/socket.h>
3031 #include <unistd.h>
3132 #include <set>
@@ -52,6 +53,8 @@ enum class ExpectBoolean {
5253 True = 1,
5354 };
5455
56+constexpr const char* TEST_IFACE = "rmnet_data0";
57+
5558 // We use #defines here so as to get local lamba captures and error message line numbers
5659 #define ASSERT_TRUE_CALLBACK \
5760 [&](bool success, std::string errMsg) { \
@@ -240,6 +243,18 @@ TEST_F(OffloadControlHidlTestBase, MultipleStopsWithoutInitReturnFalse) {
240243 stopOffload(ExpectBoolean::False);
241244 }
242245
246+// Check whether the specified interface is up.
247+bool interfaceIsUp(const char* name) {
248+ if (name == nullptr) return false;
249+ struct ifreq ifr = {};
250+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
251+ int sock = socket(AF_INET6, SOCK_DGRAM, 0);
252+ if (sock == -1) return false;
253+ int ret = ioctl(sock, SIOCGIFFLAGS, &ifr, sizeof(ifr));
254+ close(sock);
255+ return (ret == 0) && (ifr.ifr_flags & IFF_UP);
256+}
257+
243258 // Check that calling stopOffload() after a complete init/stop cycle returns false.
244259 TEST_F(OffloadControlHidlTestBase, AdditionalStopsWithInitReturnFalse) {
245260 initOffload(true);
@@ -249,8 +264,11 @@ TEST_F(OffloadControlHidlTestBase, AdditionalStopsWithInitReturnFalse) {
249264 const hidl_string v4Gw("192.0.0.1");
250265 const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:2")};
251266 const Return<void> upstream =
252- control->setUpstreamParameters("rmnet_data0", v4Addr, v4Gw, v6Gws, ASSERT_TRUE_CALLBACK);
267+ control->setUpstreamParameters(TEST_IFACE, v4Addr, v4Gw, v6Gws, ASSERT_TRUE_CALLBACK);
253268 EXPECT_TRUE(upstream.isOk());
269+ if (!interfaceIsUp(TEST_IFACE)) {
270+ return;
271+ }
254272 stopOffload(ExpectBoolean::True); // balance out initOffload(true)
255273 stopOffload(ExpectBoolean::False);
256274 stopOffload(ExpectBoolean::False);
@@ -266,14 +284,14 @@ TEST_F(OffloadControlHidlTestBase, SetLocalPrefixesWithoutInitReturnsFalse) {
266284 // Check that calling getForwardedStats() without first having called initOffload()
267285 // returns zero bytes statistics.
268286 TEST_F(OffloadControlHidlTestBase, GetForwardedStatsWithoutInitReturnsZeroValues) {
269- const hidl_string upstream("rmnet_data0");
287+ const hidl_string upstream(TEST_IFACE);
270288 const Return<void> ret = control->getForwardedStats(upstream, ASSERT_ZERO_BYTES_CALLBACK);
271289 EXPECT_TRUE(ret.isOk());
272290 }
273291
274292 // Check that calling setDataLimit() without first having called initOffload() returns false.
275293 TEST_F(OffloadControlHidlTestBase, SetDataLimitWithoutInitReturnsFalse) {
276- const hidl_string upstream("rmnet_data0");
294+ const hidl_string upstream(TEST_IFACE);
277295 const uint64_t limit = 5000ULL;
278296 const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_FALSE_CALLBACK);
279297 EXPECT_TRUE(ret.isOk());
@@ -282,7 +300,7 @@ TEST_F(OffloadControlHidlTestBase, SetDataLimitWithoutInitReturnsFalse) {
282300 // Check that calling setUpstreamParameters() without first having called initOffload()
283301 // returns false.
284302 TEST_F(OffloadControlHidlTestBase, SetUpstreamParametersWithoutInitReturnsFalse) {
285- const hidl_string iface("rmnet_data0");
303+ const hidl_string iface(TEST_IFACE);
286304 const hidl_string v4Addr("192.0.2.0/24");
287305 const hidl_string v4Gw("192.0.2.1");
288306 const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")};
@@ -294,7 +312,7 @@ TEST_F(OffloadControlHidlTestBase, SetUpstreamParametersWithoutInitReturnsFalse)
294312 // Check that calling addDownstream() with an IPv4 prefix without first having called
295313 // initOffload() returns false.
296314 TEST_F(OffloadControlHidlTestBase, AddIPv4DownstreamWithoutInitReturnsFalse) {
297- const hidl_string iface("rmnet_data0");
315+ const hidl_string iface(TEST_IFACE);
298316 const hidl_string prefix("192.0.2.0/24");
299317 const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
300318 EXPECT_TRUE(ret.isOk());
@@ -303,7 +321,7 @@ TEST_F(OffloadControlHidlTestBase, AddIPv4DownstreamWithoutInitReturnsFalse) {
303321 // Check that calling addDownstream() with an IPv6 prefix without first having called
304322 // initOffload() returns false.
305323 TEST_F(OffloadControlHidlTestBase, AddIPv6DownstreamWithoutInitReturnsFalse) {
306- const hidl_string iface("rmnet_data0");
324+ const hidl_string iface(TEST_IFACE);
307325 const hidl_string prefix("2001:db8::/64");
308326 const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
309327 EXPECT_TRUE(ret.isOk());
@@ -312,7 +330,7 @@ TEST_F(OffloadControlHidlTestBase, AddIPv6DownstreamWithoutInitReturnsFalse) {
312330 // Check that calling removeDownstream() with an IPv4 prefix without first having called
313331 // initOffload() returns false.
314332 TEST_F(OffloadControlHidlTestBase, RemoveIPv4DownstreamWithoutInitReturnsFalse) {
315- const hidl_string iface("rmnet_data0");
333+ const hidl_string iface(TEST_IFACE);
316334 const hidl_string prefix("192.0.2.0/24");
317335 const Return<void> ret = control->removeDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
318336 EXPECT_TRUE(ret.isOk());
@@ -321,7 +339,7 @@ TEST_F(OffloadControlHidlTestBase, RemoveIPv4DownstreamWithoutInitReturnsFalse)
321339 // Check that calling removeDownstream() with an IPv6 prefix without first having called
322340 // initOffload() returns false.
323341 TEST_F(OffloadControlHidlTestBase, RemoveIPv6DownstreamWithoutInitReturnsFalse) {
324- const hidl_string iface("rmnet_data0");
342+ const hidl_string iface(TEST_IFACE);
325343 const hidl_string prefix("2001:db8::/64");
326344 const Return<void> ret = control->removeDownstream(iface, prefix, ASSERT_FALSE_CALLBACK);
327345 EXPECT_TRUE(ret.isOk());
@@ -394,10 +412,10 @@ TEST_F(OffloadControlHidlTest, GetForwardedStatsInvalidUpstreamIface) {
394412 EXPECT_TRUE(ret.isOk());
395413 }
396414
397-// The "rmnet_data0" is presumed to exist on the device and be up. No packets
415+// TEST_IFACE is presumed to exist on the device and be up. No packets
398416 // are ever actually caused to be forwarded.
399417 TEST_F(OffloadControlHidlTest, GetForwardedStatsDummyIface) {
400- const hidl_string upstream("rmnet_data0");
418+ const hidl_string upstream(TEST_IFACE);
401419 const Return<void> ret = control->getForwardedStats(upstream, ASSERT_ZERO_BYTES_CALLBACK);
402420 EXPECT_TRUE(ret.isOk());
403421 }
@@ -414,19 +432,19 @@ TEST_F(OffloadControlHidlTest, SetDataLimitEmptyUpstreamIfaceFails) {
414432 EXPECT_TRUE(ret.isOk());
415433 }
416434
417-// The "rmnet_data0" is presumed to exist on the device and be up. No packets
435+// TEST_IFACE is presumed to exist on the device and be up. No packets
418436 // are ever actually caused to be forwarded.
419437 TEST_F(OffloadControlHidlTest, SetDataLimitNonZeroOk) {
420- const hidl_string upstream("rmnet_data0");
438+ const hidl_string upstream(TEST_IFACE);
421439 const uint64_t limit = 5000ULL;
422440 const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_TRUE_CALLBACK);
423441 EXPECT_TRUE(ret.isOk());
424442 }
425443
426-// The "rmnet_data0" is presumed to exist on the device and be up. No packets
444+// TEST_IFACE is presumed to exist on the device and be up. No packets
427445 // are ever actually caused to be forwarded.
428446 TEST_F(OffloadControlHidlTest, SetDataLimitZeroOk) {
429- const hidl_string upstream("rmnet_data0");
447+ const hidl_string upstream(TEST_IFACE);
430448 const uint64_t limit = 0ULL;
431449 const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_TRUE_CALLBACK);
432450 EXPECT_TRUE(ret.isOk());
@@ -436,10 +454,10 @@ TEST_F(OffloadControlHidlTest, SetDataLimitZeroOk) {
436454 * Tests for IOffloadControl::setUpstreamParameters().
437455 */
438456
439-// The "rmnet_data0" is presumed to exist on the device and be up. No packets
457+// TEST_IFACE is presumed to exist on the device and be up. No packets
440458 // are ever actually caused to be forwarded.
441459 TEST_F(OffloadControlHidlTest, SetUpstreamParametersIPv6OnlyOk) {
442- const hidl_string iface("rmnet_data0");
460+ const hidl_string iface(TEST_IFACE);
443461 const hidl_string v4Addr("");
444462 const hidl_string v4Gw("");
445463 const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:2")};
@@ -448,10 +466,10 @@ TEST_F(OffloadControlHidlTest, SetUpstreamParametersIPv6OnlyOk) {
448466 EXPECT_TRUE(ret.isOk());
449467 }
450468
451-// The "rmnet_data0" is presumed to exist on the device and be up. No packets
469+// TEST_IFACE is presumed to exist on the device and be up. No packets
452470 // are ever actually caused to be forwarded.
453471 TEST_F(OffloadControlHidlTest, SetUpstreamParametersAlternateIPv6OnlyOk) {
454- const hidl_string iface("rmnet_data0");
472+ const hidl_string iface(TEST_IFACE);
455473 const hidl_string v4Addr;
456474 const hidl_string v4Gw;
457475 const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:3")};
@@ -460,10 +478,10 @@ TEST_F(OffloadControlHidlTest, SetUpstreamParametersAlternateIPv6OnlyOk) {
460478 EXPECT_TRUE(ret.isOk());
461479 }
462480
463-// The "rmnet_data0" is presumed to exist on the device and be up. No packets
481+// TEST_IFACE is presumed to exist on the device and be up. No packets
464482 // are ever actually caused to be forwarded.
465483 TEST_F(OffloadControlHidlTest, SetUpstreamParametersIPv4OnlyOk) {
466- const hidl_string iface("rmnet_data0");
484+ const hidl_string iface(TEST_IFACE);
467485 const hidl_string v4Addr("192.0.2.2");
468486 const hidl_string v4Gw("192.0.2.1");
469487 const vector<hidl_string> v6Gws{};
@@ -472,10 +490,10 @@ TEST_F(OffloadControlHidlTest, SetUpstreamParametersIPv4OnlyOk) {
472490 EXPECT_TRUE(ret.isOk());
473491 }
474492
475-// The "rmnet_data0" is presumed to exist on the device and be up. No packets
493+// TEST_IFACE is presumed to exist on the device and be up. No packets
476494 // are ever actually caused to be forwarded.
477495 TEST_F(OffloadControlHidlTest, SetUpstreamParametersIPv4v6Ok) {
478- const hidl_string iface("rmnet_data0");
496+ const hidl_string iface(TEST_IFACE);
479497 const hidl_string v4Addr("192.0.2.2");
480498 const hidl_string v4Gw("192.0.2.1");
481499 const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:2")};
@@ -511,7 +529,7 @@ TEST_F(OffloadControlHidlTest, SetUpstreamParametersBogusIfaceFails) {
511529
512530 // Test that setUpstreamParameters() fails when given unparseable IPv4 addresses.
513531 TEST_F(OffloadControlHidlTest, SetUpstreamParametersInvalidIPv4AddrFails) {
514- const hidl_string iface("rmnet_data0");
532+ const hidl_string iface(TEST_IFACE);
515533 const hidl_string v4Gw("192.0.2.1");
516534 const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")};
517535 for (const auto& bogus : {"invalid", "192.0.2"}) {
@@ -525,7 +543,7 @@ TEST_F(OffloadControlHidlTest, SetUpstreamParametersInvalidIPv4AddrFails) {
525543
526544 // Test that setUpstreamParameters() fails when given unparseable IPv4 gateways.
527545 TEST_F(OffloadControlHidlTest, SetUpstreamParametersInvalidIPv4GatewayFails) {
528- const hidl_string iface("rmnet_data0");
546+ const hidl_string iface(TEST_IFACE);
529547 const hidl_string v4Addr("192.0.2.2");
530548 const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")};
531549 for (const auto& bogus : {"invalid", "192.0.2"}) {
@@ -539,7 +557,7 @@ TEST_F(OffloadControlHidlTest, SetUpstreamParametersInvalidIPv4GatewayFails) {
539557
540558 // Test that setUpstreamParameters() fails when given unparseable IPv6 gateways.
541559 TEST_F(OffloadControlHidlTest, SetUpstreamParametersBadIPv6GatewaysFail) {
542- const hidl_string iface("rmnet_data0");
560+ const hidl_string iface(TEST_IFACE);
543561 const hidl_string v4Addr("192.0.2.2");
544562 const hidl_string v4Gw("192.0.2.1");
545563 for (const auto& bogus : {"", "invalid", "fe80::bogus", "192.0.2.66"}) {
Afficher sur ancien navigateur de dépôt.