Add test coverage for IptablesAlert{,Fwd}Cmd.
Additionally, remove some unused code.
(cherry picked from commit 615df791ab6081921114369052ffcdba7b67eebe)
Bug: 37641280
Test: marlin builds and boots
Test: new unit test passes
Test: netd_{unit,integration}_test pass
Change-Id: I8224b4cc0382f5efe57723baa1513c693d42535b
Merged-In: I32072a2701fe1f52d5b3cfb0d57b3f296d7c37df
diff --git a/server/BandwidthControllerTest.cpp b/server/BandwidthControllerTest.cpp
index c6b21d8..85c6b96 100644
--- a/server/BandwidthControllerTest.cpp
+++ b/server/BandwidthControllerTest.cpp
@@ -102,6 +102,16 @@
expectIptablesRestoreCommands(expected);
}
+
+ using IptOp = BandwidthController::IptOp;
+
+ int runIptablesAlertCmd(IptOp a, const char *b, int64_t c) {
+ return mBw.runIptablesAlertCmd(a, b, c);
+ }
+
+ int runIptablesAlertFwdCmd(IptOp a, const char *b, int64_t c) {
+ return mBw.runIptablesAlertFwdCmd(a, b, c);
+ }
};
TEST_F(BandwidthControllerTest, TestSetupIptablesHooks) {
@@ -388,3 +398,33 @@
EXPECT_EQ(0, mBw.removeInterfaceQuota(iface));
expectIptablesCommands(expected);
}
+
+TEST_F(BandwidthControllerTest, IptablesAlertCmd) {
+ std::vector<std::string> expected = {
+ "-I bw_INPUT -m quota2 ! --quota 123456 --name MyWonderfulAlert",
+ "-I bw_OUTPUT -m quota2 ! --quota 123456 --name MyWonderfulAlert",
+ };
+ EXPECT_EQ(0, runIptablesAlertCmd(IptOp::IptOpInsert, "MyWonderfulAlert", 123456));
+ expectIptablesCommands(expected);
+
+ expected = {
+ "-D bw_INPUT -m quota2 ! --quota 123456 --name MyWonderfulAlert",
+ "-D bw_OUTPUT -m quota2 ! --quota 123456 --name MyWonderfulAlert",
+ };
+ EXPECT_EQ(0, runIptablesAlertCmd(IptOp::IptOpDelete, "MyWonderfulAlert", 123456));
+ expectIptablesCommands(expected);
+}
+
+TEST_F(BandwidthControllerTest, IptablesAlertFwdCmd) {
+ std::vector<std::string> expected = {
+ "-I bw_FORWARD -m quota2 ! --quota 123456 --name MyWonderfulAlert",
+ };
+ EXPECT_EQ(0, runIptablesAlertFwdCmd(IptOp::IptOpInsert, "MyWonderfulAlert", 123456));
+ expectIptablesCommands(expected);
+
+ expected = {
+ "-D bw_FORWARD -m quota2 ! --quota 123456 --name MyWonderfulAlert",
+ };
+ EXPECT_EQ(0, runIptablesAlertFwdCmd(IptOp::IptOpDelete, "MyWonderfulAlert", 123456));
+ expectIptablesCommands(expected);
+}