hardware/interfaces
Revision | 3d522614ec13d9d3911a81789c6776332b82cb43 (tree) |
---|---|
Time | 2017-10-27 23:50:01 |
Author | android-build-team Robot <android-build-team-robot@goog...> |
Commiter | android-build-team Robot |
Merge cherrypicks of [3134552, 3130583, 3131953, 3131954, 3131955, 3131956, 3131957, 3131958, 3131959, 3132062, 3132336, 3131074, 3133939, 3131024, 3131025, 3131026, 3130584, 3130879, 3130880] into oc-mr1-release
Change-Id: I06faeaf1e282dbf73aaa082e2944c5ea563f45fa
@@ -26,6 +26,7 @@ | ||
26 | 26 | #include <linux/netfilter/nfnetlink.h> |
27 | 27 | #include <linux/netlink.h> |
28 | 28 | #include <log/log.h> |
29 | +#include <net/if.h> | |
29 | 30 | #include <sys/socket.h> |
30 | 31 | #include <unistd.h> |
31 | 32 | #include <set> |
@@ -52,6 +53,8 @@ enum class ExpectBoolean { | ||
52 | 53 | True = 1, |
53 | 54 | }; |
54 | 55 | |
56 | +constexpr const char* TEST_IFACE = "rmnet_data0"; | |
57 | + | |
55 | 58 | // We use #defines here so as to get local lamba captures and error message line numbers |
56 | 59 | #define ASSERT_TRUE_CALLBACK \ |
57 | 60 | [&](bool success, std::string errMsg) { \ |
@@ -240,6 +243,18 @@ TEST_F(OffloadControlHidlTestBase, MultipleStopsWithoutInitReturnFalse) { | ||
240 | 243 | stopOffload(ExpectBoolean::False); |
241 | 244 | } |
242 | 245 | |
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 | + | |
243 | 258 | // Check that calling stopOffload() after a complete init/stop cycle returns false. |
244 | 259 | TEST_F(OffloadControlHidlTestBase, AdditionalStopsWithInitReturnFalse) { |
245 | 260 | initOffload(true); |
@@ -249,8 +264,11 @@ TEST_F(OffloadControlHidlTestBase, AdditionalStopsWithInitReturnFalse) { | ||
249 | 264 | const hidl_string v4Gw("192.0.0.1"); |
250 | 265 | const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:2")}; |
251 | 266 | 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); | |
253 | 268 | EXPECT_TRUE(upstream.isOk()); |
269 | + if (!interfaceIsUp(TEST_IFACE)) { | |
270 | + return; | |
271 | + } | |
254 | 272 | stopOffload(ExpectBoolean::True); // balance out initOffload(true) |
255 | 273 | stopOffload(ExpectBoolean::False); |
256 | 274 | stopOffload(ExpectBoolean::False); |
@@ -266,14 +284,14 @@ TEST_F(OffloadControlHidlTestBase, SetLocalPrefixesWithoutInitReturnsFalse) { | ||
266 | 284 | // Check that calling getForwardedStats() without first having called initOffload() |
267 | 285 | // returns zero bytes statistics. |
268 | 286 | TEST_F(OffloadControlHidlTestBase, GetForwardedStatsWithoutInitReturnsZeroValues) { |
269 | - const hidl_string upstream("rmnet_data0"); | |
287 | + const hidl_string upstream(TEST_IFACE); | |
270 | 288 | const Return<void> ret = control->getForwardedStats(upstream, ASSERT_ZERO_BYTES_CALLBACK); |
271 | 289 | EXPECT_TRUE(ret.isOk()); |
272 | 290 | } |
273 | 291 | |
274 | 292 | // Check that calling setDataLimit() without first having called initOffload() returns false. |
275 | 293 | TEST_F(OffloadControlHidlTestBase, SetDataLimitWithoutInitReturnsFalse) { |
276 | - const hidl_string upstream("rmnet_data0"); | |
294 | + const hidl_string upstream(TEST_IFACE); | |
277 | 295 | const uint64_t limit = 5000ULL; |
278 | 296 | const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_FALSE_CALLBACK); |
279 | 297 | EXPECT_TRUE(ret.isOk()); |
@@ -282,7 +300,7 @@ TEST_F(OffloadControlHidlTestBase, SetDataLimitWithoutInitReturnsFalse) { | ||
282 | 300 | // Check that calling setUpstreamParameters() without first having called initOffload() |
283 | 301 | // returns false. |
284 | 302 | TEST_F(OffloadControlHidlTestBase, SetUpstreamParametersWithoutInitReturnsFalse) { |
285 | - const hidl_string iface("rmnet_data0"); | |
303 | + const hidl_string iface(TEST_IFACE); | |
286 | 304 | const hidl_string v4Addr("192.0.2.0/24"); |
287 | 305 | const hidl_string v4Gw("192.0.2.1"); |
288 | 306 | const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")}; |
@@ -294,7 +312,7 @@ TEST_F(OffloadControlHidlTestBase, SetUpstreamParametersWithoutInitReturnsFalse) | ||
294 | 312 | // Check that calling addDownstream() with an IPv4 prefix without first having called |
295 | 313 | // initOffload() returns false. |
296 | 314 | TEST_F(OffloadControlHidlTestBase, AddIPv4DownstreamWithoutInitReturnsFalse) { |
297 | - const hidl_string iface("rmnet_data0"); | |
315 | + const hidl_string iface(TEST_IFACE); | |
298 | 316 | const hidl_string prefix("192.0.2.0/24"); |
299 | 317 | const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_FALSE_CALLBACK); |
300 | 318 | EXPECT_TRUE(ret.isOk()); |
@@ -303,7 +321,7 @@ TEST_F(OffloadControlHidlTestBase, AddIPv4DownstreamWithoutInitReturnsFalse) { | ||
303 | 321 | // Check that calling addDownstream() with an IPv6 prefix without first having called |
304 | 322 | // initOffload() returns false. |
305 | 323 | TEST_F(OffloadControlHidlTestBase, AddIPv6DownstreamWithoutInitReturnsFalse) { |
306 | - const hidl_string iface("rmnet_data0"); | |
324 | + const hidl_string iface(TEST_IFACE); | |
307 | 325 | const hidl_string prefix("2001:db8::/64"); |
308 | 326 | const Return<void> ret = control->addDownstream(iface, prefix, ASSERT_FALSE_CALLBACK); |
309 | 327 | EXPECT_TRUE(ret.isOk()); |
@@ -312,7 +330,7 @@ TEST_F(OffloadControlHidlTestBase, AddIPv6DownstreamWithoutInitReturnsFalse) { | ||
312 | 330 | // Check that calling removeDownstream() with an IPv4 prefix without first having called |
313 | 331 | // initOffload() returns false. |
314 | 332 | TEST_F(OffloadControlHidlTestBase, RemoveIPv4DownstreamWithoutInitReturnsFalse) { |
315 | - const hidl_string iface("rmnet_data0"); | |
333 | + const hidl_string iface(TEST_IFACE); | |
316 | 334 | const hidl_string prefix("192.0.2.0/24"); |
317 | 335 | const Return<void> ret = control->removeDownstream(iface, prefix, ASSERT_FALSE_CALLBACK); |
318 | 336 | EXPECT_TRUE(ret.isOk()); |
@@ -321,7 +339,7 @@ TEST_F(OffloadControlHidlTestBase, RemoveIPv4DownstreamWithoutInitReturnsFalse) | ||
321 | 339 | // Check that calling removeDownstream() with an IPv6 prefix without first having called |
322 | 340 | // initOffload() returns false. |
323 | 341 | TEST_F(OffloadControlHidlTestBase, RemoveIPv6DownstreamWithoutInitReturnsFalse) { |
324 | - const hidl_string iface("rmnet_data0"); | |
342 | + const hidl_string iface(TEST_IFACE); | |
325 | 343 | const hidl_string prefix("2001:db8::/64"); |
326 | 344 | const Return<void> ret = control->removeDownstream(iface, prefix, ASSERT_FALSE_CALLBACK); |
327 | 345 | EXPECT_TRUE(ret.isOk()); |
@@ -394,10 +412,10 @@ TEST_F(OffloadControlHidlTest, GetForwardedStatsInvalidUpstreamIface) { | ||
394 | 412 | EXPECT_TRUE(ret.isOk()); |
395 | 413 | } |
396 | 414 | |
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 | |
398 | 416 | // are ever actually caused to be forwarded. |
399 | 417 | TEST_F(OffloadControlHidlTest, GetForwardedStatsDummyIface) { |
400 | - const hidl_string upstream("rmnet_data0"); | |
418 | + const hidl_string upstream(TEST_IFACE); | |
401 | 419 | const Return<void> ret = control->getForwardedStats(upstream, ASSERT_ZERO_BYTES_CALLBACK); |
402 | 420 | EXPECT_TRUE(ret.isOk()); |
403 | 421 | } |
@@ -414,19 +432,19 @@ TEST_F(OffloadControlHidlTest, SetDataLimitEmptyUpstreamIfaceFails) { | ||
414 | 432 | EXPECT_TRUE(ret.isOk()); |
415 | 433 | } |
416 | 434 | |
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 | |
418 | 436 | // are ever actually caused to be forwarded. |
419 | 437 | TEST_F(OffloadControlHidlTest, SetDataLimitNonZeroOk) { |
420 | - const hidl_string upstream("rmnet_data0"); | |
438 | + const hidl_string upstream(TEST_IFACE); | |
421 | 439 | const uint64_t limit = 5000ULL; |
422 | 440 | const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_TRUE_CALLBACK); |
423 | 441 | EXPECT_TRUE(ret.isOk()); |
424 | 442 | } |
425 | 443 | |
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 | |
427 | 445 | // are ever actually caused to be forwarded. |
428 | 446 | TEST_F(OffloadControlHidlTest, SetDataLimitZeroOk) { |
429 | - const hidl_string upstream("rmnet_data0"); | |
447 | + const hidl_string upstream(TEST_IFACE); | |
430 | 448 | const uint64_t limit = 0ULL; |
431 | 449 | const Return<void> ret = control->setDataLimit(upstream, limit, ASSERT_TRUE_CALLBACK); |
432 | 450 | EXPECT_TRUE(ret.isOk()); |
@@ -436,10 +454,10 @@ TEST_F(OffloadControlHidlTest, SetDataLimitZeroOk) { | ||
436 | 454 | * Tests for IOffloadControl::setUpstreamParameters(). |
437 | 455 | */ |
438 | 456 | |
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 | |
440 | 458 | // are ever actually caused to be forwarded. |
441 | 459 | TEST_F(OffloadControlHidlTest, SetUpstreamParametersIPv6OnlyOk) { |
442 | - const hidl_string iface("rmnet_data0"); | |
460 | + const hidl_string iface(TEST_IFACE); | |
443 | 461 | const hidl_string v4Addr(""); |
444 | 462 | const hidl_string v4Gw(""); |
445 | 463 | const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:2")}; |
@@ -448,10 +466,10 @@ TEST_F(OffloadControlHidlTest, SetUpstreamParametersIPv6OnlyOk) { | ||
448 | 466 | EXPECT_TRUE(ret.isOk()); |
449 | 467 | } |
450 | 468 | |
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 | |
452 | 470 | // are ever actually caused to be forwarded. |
453 | 471 | TEST_F(OffloadControlHidlTest, SetUpstreamParametersAlternateIPv6OnlyOk) { |
454 | - const hidl_string iface("rmnet_data0"); | |
472 | + const hidl_string iface(TEST_IFACE); | |
455 | 473 | const hidl_string v4Addr; |
456 | 474 | const hidl_string v4Gw; |
457 | 475 | const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:3")}; |
@@ -460,10 +478,10 @@ TEST_F(OffloadControlHidlTest, SetUpstreamParametersAlternateIPv6OnlyOk) { | ||
460 | 478 | EXPECT_TRUE(ret.isOk()); |
461 | 479 | } |
462 | 480 | |
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 | |
464 | 482 | // are ever actually caused to be forwarded. |
465 | 483 | TEST_F(OffloadControlHidlTest, SetUpstreamParametersIPv4OnlyOk) { |
466 | - const hidl_string iface("rmnet_data0"); | |
484 | + const hidl_string iface(TEST_IFACE); | |
467 | 485 | const hidl_string v4Addr("192.0.2.2"); |
468 | 486 | const hidl_string v4Gw("192.0.2.1"); |
469 | 487 | const vector<hidl_string> v6Gws{}; |
@@ -472,10 +490,10 @@ TEST_F(OffloadControlHidlTest, SetUpstreamParametersIPv4OnlyOk) { | ||
472 | 490 | EXPECT_TRUE(ret.isOk()); |
473 | 491 | } |
474 | 492 | |
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 | |
476 | 494 | // are ever actually caused to be forwarded. |
477 | 495 | TEST_F(OffloadControlHidlTest, SetUpstreamParametersIPv4v6Ok) { |
478 | - const hidl_string iface("rmnet_data0"); | |
496 | + const hidl_string iface(TEST_IFACE); | |
479 | 497 | const hidl_string v4Addr("192.0.2.2"); |
480 | 498 | const hidl_string v4Gw("192.0.2.1"); |
481 | 499 | const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1"), hidl_string("fe80::db8:2")}; |
@@ -511,7 +529,7 @@ TEST_F(OffloadControlHidlTest, SetUpstreamParametersBogusIfaceFails) { | ||
511 | 529 | |
512 | 530 | // Test that setUpstreamParameters() fails when given unparseable IPv4 addresses. |
513 | 531 | TEST_F(OffloadControlHidlTest, SetUpstreamParametersInvalidIPv4AddrFails) { |
514 | - const hidl_string iface("rmnet_data0"); | |
532 | + const hidl_string iface(TEST_IFACE); | |
515 | 533 | const hidl_string v4Gw("192.0.2.1"); |
516 | 534 | const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")}; |
517 | 535 | for (const auto& bogus : {"invalid", "192.0.2"}) { |
@@ -525,7 +543,7 @@ TEST_F(OffloadControlHidlTest, SetUpstreamParametersInvalidIPv4AddrFails) { | ||
525 | 543 | |
526 | 544 | // Test that setUpstreamParameters() fails when given unparseable IPv4 gateways. |
527 | 545 | TEST_F(OffloadControlHidlTest, SetUpstreamParametersInvalidIPv4GatewayFails) { |
528 | - const hidl_string iface("rmnet_data0"); | |
546 | + const hidl_string iface(TEST_IFACE); | |
529 | 547 | const hidl_string v4Addr("192.0.2.2"); |
530 | 548 | const vector<hidl_string> v6Gws{hidl_string("fe80::db8:1")}; |
531 | 549 | for (const auto& bogus : {"invalid", "192.0.2"}) { |
@@ -539,7 +557,7 @@ TEST_F(OffloadControlHidlTest, SetUpstreamParametersInvalidIPv4GatewayFails) { | ||
539 | 557 | |
540 | 558 | // Test that setUpstreamParameters() fails when given unparseable IPv6 gateways. |
541 | 559 | TEST_F(OffloadControlHidlTest, SetUpstreamParametersBadIPv6GatewaysFail) { |
542 | - const hidl_string iface("rmnet_data0"); | |
560 | + const hidl_string iface(TEST_IFACE); | |
543 | 561 | const hidl_string v4Addr("192.0.2.2"); |
544 | 562 | const hidl_string v4Gw("192.0.2.1"); |
545 | 563 | for (const auto& bogus : {"", "invalid", "fe80::bogus", "192.0.2.66"}) { |