summaryrefslogtreecommitdiff
path: root/server/TetherControllerTest.cpp
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2017-09-15 11:40:01 +0900
committerLorenzo Colitti <lorenzo@google.com>2017-09-15 11:47:03 +0900
commit38fd1360ae940079ab81c018565d95295bcd12bd (patch)
tree715eaacba71c439c35c65a095a76b07b42c1003b /server/TetherControllerTest.cpp
parent5e03a893d999d04b7329ab8825782d75872d680f (diff)
Don't complain when finding no tether stats.
TetherController::addForwardChainStats returns an error if it doesn't find any tethering stats. This was fine when we were still using CommandListener, which would not attempt to fetch the stats if tethering was not enabled. Instead of returning an error when no stats are found, return an error only if the output was empty (implying that no headers were found and thus the required rules do not exist). If the output contains headers but no stats, don't return an error. Returning an error was a necessity in the previous code because it had no unit or integration tests, but such measures are not necessary now that we have test coverage. Fix: 65550883 Bug: 65369386 Test: bullhead builds, boots Test: netd_{unit,integration}_test pass Change-Id: Ie32f4d941dd52c8dc9ff09fde26cc97cedf96bc3
Diffstat (limited to 'server/TetherControllerTest.cpp')
-rw-r--r--server/TetherControllerTest.cpp25
1 files changed, 21 insertions, 4 deletions
diff --git a/server/TetherControllerTest.cpp b/server/TetherControllerTest.cpp
index 362af2f2..b92dc242 100644
--- a/server/TetherControllerTest.cpp
+++ b/server/TetherControllerTest.cpp
@@ -234,11 +234,28 @@ void expectTetherStatsEqual(const TetherController::TetherStats& expected,
}
TEST_F(TetherControllerTest, TestGetTetherStats) {
- // If no filter is specified, both IPv4 and IPv6 counters must have at least one interface pair.
- addIptablesRestoreOutput(kIPv4TetherCounters);
+ // Finding no headers is an error.
ASSERT_FALSE(isOk(mTetherCtrl.getTetherStats()));
clearIptablesRestoreOutput();
+ // Finding only v4 or only v6 headers is an error.
+ addIptablesRestoreOutput(kTetherCounterHeaders, "");
+ ASSERT_FALSE(isOk(mTetherCtrl.getTetherStats()));
+ clearIptablesRestoreOutput();
+
+ addIptablesRestoreOutput("", kTetherCounterHeaders);
+ ASSERT_FALSE(isOk(mTetherCtrl.getTetherStats()));
+ clearIptablesRestoreOutput();
+
+ // Finding headers but no stats is not an error.
+ addIptablesRestoreOutput(kTetherCounterHeaders, kTetherCounterHeaders);
+ StatusOr<TetherStatsList> result = mTetherCtrl.getTetherStats();
+ ASSERT_TRUE(isOk(result));
+ TetherStatsList actual = result.value();
+ ASSERT_EQ(0U, actual.size());
+ clearIptablesRestoreOutput();
+
+
addIptablesRestoreOutput(kIPv6TetherCounters);
ASSERT_FALSE(isOk(mTetherCtrl.getTetherStats()));
clearIptablesRestoreOutput();
@@ -247,9 +264,9 @@ TEST_F(TetherControllerTest, TestGetTetherStats) {
addIptablesRestoreOutput(kIPv4TetherCounters, kIPv6TetherCounters);
TetherStats expected0("wlan0", "rmnet0", 20002002, 20027, 10002373, 10026);
TetherStats expected1("bt-pan", "rmnet0", 1708806, 1450, 107471, 1040);
- StatusOr<TetherStatsList> result = mTetherCtrl.getTetherStats();
+ result = mTetherCtrl.getTetherStats();
ASSERT_TRUE(isOk(result));
- TetherStatsList actual = result.value();
+ actual = result.value();
ASSERT_EQ(2U, actual.size());
expectTetherStatsEqual(expected0, result.value()[0]);
expectTetherStatsEqual(expected1, result.value()[1]);