summaryrefslogtreecommitdiff
path: root/server/TetherControllerTest.cpp
diff options
context:
space:
mode:
authorNucca Chen <nuccachen@google.com>2020-06-01 23:33:24 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2020-06-01 23:33:24 +0000
commit88c3ea4cb43a9d3d374383d82d4a6885c5b34e21 (patch)
treef5fcf0804fc0919e464e4e99118cd832d54b51ef /server/TetherControllerTest.cpp
parent3e9cc187a373ed6275c3cc6d489fa59ab5b1ea88 (diff)
parent47b21a691603d28bb022573e27c03e5f9677e415 (diff)
Merge changes from topic "tether_offload_data_limit"
* changes: Add com.android.tethering to be netd_aidl_interface's apex user Add binder call tetherOffloadGetStats
Diffstat (limited to 'server/TetherControllerTest.cpp')
-rw-r--r--server/TetherControllerTest.cpp60
1 files changed, 22 insertions, 38 deletions
diff --git a/server/TetherControllerTest.cpp b/server/TetherControllerTest.cpp
index fd6e43a8..d2ff4a75 100644
--- a/server/TetherControllerTest.cpp
+++ b/server/TetherControllerTest.cpp
@@ -43,17 +43,20 @@ using android::netdutils::StatusOr;
using ::testing::Contains;
using TetherStats = android::net::TetherController::TetherStats;
using TetherStatsList = android::net::TetherController::TetherStatsList;
+using TetherOffloadStats = android::net::TetherController::TetherOffloadStats;
+using TetherOffloadStatsList = android::net::TetherController::TetherOffloadStatsList;
namespace android {
namespace net {
constexpr int TEST_MAP_SIZE = 10;
-// Comparison for TetherStats. Need to override operator== because class TetherStats doesn't have.
-// TODO: once C++20 is used, use default operator== in TetherStats and remove the overriding here.
-bool operator==(const TetherStats& lhs, const TetherStats& rhs) {
- return lhs.intIface == rhs.intIface && lhs.extIface == rhs.extIface &&
- lhs.rxBytes == rhs.rxBytes && lhs.txBytes == rhs.txBytes &&
+// Comparison for TetherOffloadStats. Need to override operator== because class TetherOffloadStats
+// doesn't have one.
+// TODO: once C++20 is used, use default operator== in TetherOffloadStats and remove the overriding
+// here.
+bool operator==(const TetherOffloadStats& lhs, const TetherOffloadStats& rhs) {
+ return lhs.ifIndex == rhs.ifIndex && lhs.rxBytes == rhs.rxBytes && lhs.txBytes == rhs.txBytes &&
lhs.rxPackets == rhs.rxPackets && lhs.txPackets == rhs.txPackets;
}
@@ -65,41 +68,33 @@ public:
protected:
TetherController mTetherCtrl;
- BpfMap<uint32_t, IfaceValue> mFakeIfaceIndexNameMap{BPF_MAP_TYPE_HASH, TEST_MAP_SIZE};
BpfMap<uint32_t, TetherStatsValue> mFakeTetherStatsMap{BPF_MAP_TYPE_HASH, TEST_MAP_SIZE};
BpfMap<uint32_t, uint64_t> mFakeTetherLimitMap{BPF_MAP_TYPE_HASH, TEST_MAP_SIZE};
void SetUp() {
SKIP_IF_BPF_NOT_SUPPORTED;
- ASSERT_TRUE(mFakeIfaceIndexNameMap.isValid());
ASSERT_TRUE(mFakeTetherStatsMap.isValid());
ASSERT_TRUE(mFakeTetherLimitMap.isValid());
- mTetherCtrl.mIfaceIndexNameMap = mFakeIfaceIndexNameMap;
- ASSERT_TRUE(mTetherCtrl.mIfaceIndexNameMap.isValid());
mTetherCtrl.mBpfStatsMap = mFakeTetherStatsMap;
ASSERT_TRUE(mTetherCtrl.mBpfStatsMap.isValid());
mTetherCtrl.mBpfLimitMap = mFakeTetherLimitMap;
ASSERT_TRUE(mTetherCtrl.mBpfLimitMap.isValid());
}
- std::string toString(const TetherStatsList& statsList) {
+ std::string toString(const TetherOffloadStatsList& statsList) {
std::string result;
for (const auto& stats : statsList) {
- result += StringPrintf("%s, %s, %" PRId64 ", %" PRId64 ", %" PRId64 ", %" PRId64 "\n",
- stats.intIface.c_str(), stats.extIface.c_str(), stats.rxBytes,
- stats.rxPackets, stats.txBytes, stats.txPackets);
+ result += StringPrintf("%d, %" PRId64 ", %" PRId64 ", %" PRId64 ", %" PRId64 "\n",
+ stats.ifIndex, stats.rxBytes, stats.rxPackets, stats.txBytes,
+ stats.txPackets);
}
return result;
}
- void updateMaps(uint32_t ifaceIndex, const char* ifaceName, uint64_t rxBytes,
- uint64_t rxPackets, uint64_t txBytes, uint64_t txPackets) {
- IfaceValue iface{};
- strlcpy(iface.name, ifaceName, sizeof(iface.name));
- ASSERT_RESULT_OK(mFakeIfaceIndexNameMap.writeValue(ifaceIndex, iface, BPF_ANY));
-
+ void updateMaps(uint32_t ifaceIndex, uint64_t rxBytes, uint64_t rxPackets, uint64_t txBytes,
+ uint64_t txPackets) {
// {rx, tx}Errors in |tetherStats| are set zero because getTetherStats doesn't use them.
const TetherStatsValue tetherStats = {rxPackets, rxBytes, 0 /*unused*/,
txPackets, txBytes, 0 /*unused*/};
@@ -490,31 +485,20 @@ TEST_F(TetherControllerTest, TestGetTetherStats) {
EXPECT_TRUE(std::equal(expectedError.rbegin(), expectedError.rend(), err.rbegin()));
}
-TEST_F(TetherControllerTest, TestGetTetherStatsWithBpfTetherStatsMap) {
+TEST_F(TetherControllerTest, TestTetherOffloadGetStats) {
SKIP_IF_BPF_NOT_SUPPORTED;
- // Setup BPF tether stats maps. The tether stats of interface rmnet0 comes from two tether
- // stats map items with different interface index. Therefore, need to sum up both of them
- // for the tether stats of interface rmnet0.
- updateMaps(101, "wlan0", 100, 10, 200, 20);
- updateMaps(102, "rmnet0", 300, 30, 400, 40);
- updateMaps(103, "rmnet0", 500, 50, 600, 60);
- const TetherStats expected0("BPFOffloadInterface", "wlan0", 100, 10, 200, 20);
- const TetherStats expected1("BPFOffloadInterface", "rmnet0", 800, 80, 1000, 100);
-
- // Setup iptables tether counters. IPv4 and IPv6 counters are added together.
- addIptablesRestoreOutput(kIPv4TetherCounters, kIPv6TetherCounters);
- const TetherStats expected2("wlan0", "rmnet0", 20002002, 20027, 10002373, 10026);
- const TetherStats expected3("bt-pan", "rmnet0", 1708806, 1450, 107471, 1040);
+ updateMaps(101, 100, 10, 200, 20);
+ updateMaps(102, 300, 30, 400, 40);
+ const TetherOffloadStats expected0{101, 100, 10, 200, 20};
+ const TetherOffloadStats expected1{102, 300, 30, 400, 40};
- const StatusOr<TetherStatsList> result = mTetherCtrl.getTetherStats();
+ const StatusOr<TetherOffloadStatsList> result = mTetherCtrl.getTetherOffloadStats();
ASSERT_OK(result);
- const TetherStatsList& actual = result.value();
- ASSERT_EQ(4U, actual.size());
+ const TetherOffloadStatsList& actual = result.value();
+ ASSERT_EQ(2U, actual.size());
EXPECT_THAT(actual, Contains(expected0)) << toString(actual);
EXPECT_THAT(actual, Contains(expected1)) << toString(actual);
- EXPECT_THAT(actual, Contains(expected2)) << toString(actual);
- EXPECT_THAT(actual, Contains(expected3)) << toString(actual);
clearIptablesRestoreOutput();
}