diff options
| author | Lorenzo Colitti <lorenzo@google.com> | 2017-08-24 14:20:32 +0900 |
|---|---|---|
| committer | Lorenzo Colitti <lorenzo@google.com> | 2017-08-31 16:24:33 +0900 |
| commit | 0935339bb85483697070fc618ad1e820eb8e45aa (patch) | |
| tree | 35b95f0ca8b3f6548af59293c554724c6cfd8fa5 /server/TetherControllerTest.cpp | |
| parent | a93126d6a1fb762537916adf2f103f893689e50f (diff) | |
Remove support for filtering tether stats.
The framework does not use this filtering, so it's just
dead code. It also requires that NatController publicly
expose its list of interface pairs.
Also make the parsing code a bit stricter - for example, return
an error if any of the lines (except the headers) fail to parse.
Bug: 32163131
Bug: 64995262
Test: bullhead builds and boots
Test: netd_{unit,integration}_test pass
Test: output of "adb shell ndc bandwidth gettetherstats" looks correct
Change-Id: Ib7440f935809c59d8b48396764cc63eb95f509b4
Diffstat (limited to 'server/TetherControllerTest.cpp')
| -rw-r--r-- | server/TetherControllerTest.cpp | 70 |
1 files changed, 14 insertions, 56 deletions
diff --git a/server/TetherControllerTest.cpp b/server/TetherControllerTest.cpp index 887c6488..1e44db45 100644 --- a/server/TetherControllerTest.cpp +++ b/server/TetherControllerTest.cpp @@ -198,6 +198,11 @@ TEST_F(TetherControllerTest, TestAddAndRemoveNat) { expectIptablesRestoreCommands(expected); } +std::string kTetherCounterHeaders = Join(std::vector<std::string> { + "Chain natctrl_tether_counters (4 references)", + " pkts bytes target prot opt in out source destination", +}, '\n'); + std::string kIPv4TetherCounters = Join(std::vector<std::string> { "Chain natctrl_tether_counters (4 references)", " pkts bytes target prot opt in out source destination", @@ -228,7 +233,7 @@ std::string readSocketClientResponse(int fd) { void expectNoSocketClientResponse(int fd) { char buf[64]; - EXPECT_EQ(-1, read(fd, buf, sizeof(buf))); + EXPECT_EQ(-1, read(fd, buf, sizeof(buf))) << "Unexpected response: " << buf << "\n"; } TEST_F(TetherControllerTest, TestGetTetherStats) { @@ -239,74 +244,36 @@ TEST_F(TetherControllerTest, TestGetTetherStats) { SocketClient cli(socketPair[0], false); std::string err; - TetherController::TetherStats filter; // If no filter is specified, both IPv4 and IPv6 counters must have at least one interface pair. addIptablesRestoreOutput(kIPv4TetherCounters); - ASSERT_EQ(-1, mTetherCtrl.getTetherStats(&cli, filter, err)); + ASSERT_EQ(-1, mTetherCtrl.getTetherStats(&cli, err)); expectNoSocketClientResponse(socketPair[1]); clearIptablesRestoreOutput(); addIptablesRestoreOutput(kIPv6TetherCounters); - ASSERT_EQ(-1, mTetherCtrl.getTetherStats(&cli, filter, err)); + ASSERT_EQ(-1, mTetherCtrl.getTetherStats(&cli, err)); clearIptablesRestoreOutput(); // IPv4 and IPv6 counters are properly added together. addIptablesRestoreOutput(kIPv4TetherCounters, kIPv6TetherCounters); - filter = TetherController::TetherStats(); std::string expected = "114 wlan0 rmnet0 10002373 10026 20002002 20027\n" "114 bt-pan rmnet0 107471 1040 1708806 1450\n" "200 Tethering stats list completed\n"; - ASSERT_EQ(0, mTetherCtrl.getTetherStats(&cli, filter, err)); - ASSERT_EQ(expected, readSocketClientResponse(socketPair[1])); - expectNoSocketClientResponse(socketPair[1]); - clearIptablesRestoreOutput(); - - // Test filtering. - addIptablesRestoreOutput(kIPv4TetherCounters, kIPv6TetherCounters); - filter = TetherController::TetherStats("bt-pan", "rmnet0", -1, -1, -1, -1); - expected = "221 bt-pan rmnet0 107471 1040 1708806 1450\n"; - ASSERT_EQ(0, mTetherCtrl.getTetherStats(&cli, filter, err)); + ASSERT_EQ(0, mTetherCtrl.getTetherStats(&cli, err)); ASSERT_EQ(expected, readSocketClientResponse(socketPair[1])); expectNoSocketClientResponse(socketPair[1]); clearIptablesRestoreOutput(); - addIptablesRestoreOutput(kIPv4TetherCounters, kIPv6TetherCounters); - filter = TetherController::TetherStats("wlan0", "rmnet0", -1, -1, -1, -1); - expected = "221 wlan0 rmnet0 10002373 10026 20002002 20027\n"; - ASSERT_EQ(0, mTetherCtrl.getTetherStats(&cli, filter, err)); - ASSERT_EQ(expected, readSocketClientResponse(socketPair[1])); - clearIptablesRestoreOutput(); - - // Select nonexistent interfaces. - addIptablesRestoreOutput(kIPv4TetherCounters, kIPv6TetherCounters); - filter = TetherController::TetherStats("rmnet0", "foo0", -1, -1, -1, -1); - expected = "200 Tethering stats list completed\n"; - ASSERT_EQ(0, mTetherCtrl.getTetherStats(&cli, filter, err)); - ASSERT_EQ(expected, readSocketClientResponse(socketPair[1])); - clearIptablesRestoreOutput(); - - // No stats with a filter: no error. - addIptablesRestoreOutput("", ""); - ASSERT_EQ(0, mTetherCtrl.getTetherStats(&cli, filter, err)); - ASSERT_EQ("200 Tethering stats list completed\n", readSocketClientResponse(socketPair[1])); - clearIptablesRestoreOutput(); - - addIptablesRestoreOutput("foo", "foo"); - ASSERT_EQ(0, mTetherCtrl.getTetherStats(&cli, filter, err)); - ASSERT_EQ("200 Tethering stats list completed\n", readSocketClientResponse(socketPair[1])); - clearIptablesRestoreOutput(); - - // No stats and empty filter: error. - filter = TetherController::TetherStats(); + // No stats: error. addIptablesRestoreOutput("", kIPv6TetherCounters); - ASSERT_EQ(-1, mTetherCtrl.getTetherStats(&cli, filter, err)); + ASSERT_EQ(-1, mTetherCtrl.getTetherStats(&cli, err)); expectNoSocketClientResponse(socketPair[1]); clearIptablesRestoreOutput(); addIptablesRestoreOutput(kIPv4TetherCounters, ""); - ASSERT_EQ(-1, mTetherCtrl.getTetherStats(&cli, filter, err)); + ASSERT_EQ(-1, mTetherCtrl.getTetherStats(&cli, err)); expectNoSocketClientResponse(socketPair[1]); clearIptablesRestoreOutput(); @@ -319,7 +286,7 @@ TEST_F(TetherControllerTest, TestGetTetherStats) { expected = "114 wlan0 rmnet0 4746 52 4004 54\n" "200 Tethering stats list completed\n"; - ASSERT_EQ(0, mTetherCtrl.getTetherStats(&cli, filter, err)); + ASSERT_EQ(0, mTetherCtrl.getTetherStats(&cli, err)); ASSERT_EQ(expected, readSocketClientResponse(socketPair[1])); clearIptablesRestoreOutput(); @@ -328,7 +295,7 @@ TEST_F(TetherControllerTest, TestGetTetherStats) { counterLines.resize(3); counters = Join(counterLines, "\n") + "\n"; addIptablesRestoreOutput(counters, counters); - ASSERT_EQ(-1, mTetherCtrl.getTetherStats(&cli, filter, err)); + ASSERT_EQ(-1, mTetherCtrl.getTetherStats(&cli, err)); expectNoSocketClientResponse(socketPair[1]); clearIptablesRestoreOutput(); @@ -336,15 +303,6 @@ TEST_F(TetherControllerTest, TestGetTetherStats) { // ignores. std::string expectedError = counters; EXPECT_EQ(expectedError, err); - - addIptablesRestoreOutput(kIPv4TetherCounters); - ASSERT_EQ(-1, mTetherCtrl.getTetherStats(&cli, filter, err)); - expectNoSocketClientResponse(socketPair[1]); - clearIptablesRestoreOutput(); - addIptablesRestoreOutput(kIPv6TetherCounters); - ASSERT_EQ(-1, mTetherCtrl.getTetherStats(&cli, filter, err)); - expectNoSocketClientResponse(socketPair[1]); - clearIptablesRestoreOutput(); } } // namespace net |
