Merge "TrafficController - remove dead code" into main

This commit is contained in:
Treehugger Robot 2023-08-21 17:14:34 +00:00 • committed by Gerrit Code Review
commit 02c6061cf8
2 changed files with 0 additions and 112 deletions

View file

@ -586,15 +586,6 @@ std::string getMapStatus(const base::unique_fd& map_fd, const char* path) {
return StringPrintf("OK");
}
// NOLINTNEXTLINE(google-runtime-references): grandfathered pass by non-const reference
void dumpBpfMap(const std::string& mapName, DumpWriter& dw, const std::string& header) {
dw.blankline();
dw.println("%s:", mapName.c_str());
if (!header.empty()) {
dw.println(header);
}
}
void TrafficController::dump(int fd, bool verbose __unused) {
std::lock_guard guard(mMutex);
DumpWriter dw(fd);

View file

@ -269,109 +269,6 @@ class TrafficControllerTest : public ::testing::Test {
}
return ret;
}
Status dump(bool verbose, std::vector<std::string>& outputLines) {
if (!outputLines.empty()) return statusFromErrno(EUCLEAN, "Output buffer is not empty");
android::base::unique_fd localFd, remoteFd;
if (!Pipe(&localFd, &remoteFd)) return statusFromErrno(errno, "Failed on pipe");
// dump() blocks until another thread has consumed all its output.
std::thread dumpThread =
std::thread([this, remoteFd{std::move(remoteFd)}, verbose]() {
mTc.dump(remoteFd, verbose);
});
std::string dumpContent;
if (!android::base::ReadFdToString(localFd.get(), &dumpContent)) {
return statusFromErrno(errno, "Failed to read dump results from fd");
}
dumpThread.join();
std::stringstream dumpStream(std::move(dumpContent));
std::string line;
while (std::getline(dumpStream, line)) {
outputLines.push_back(line);
}
return netdutils::status::ok;
}
// Strings in the |expect| must exist in dump results in order. But no need to be consecutive.
bool expectDumpsysContains(std::vector<std::string>& expect) {
if (expect.empty()) return false;
std::vector<std::string> output;
Status result = dump(true, output);
if (!isOk(result)) {
GTEST_LOG_(ERROR) << "TrafficController dump failed: " << netdutils::toString(result);
return false;
}
int matched = 0;
auto it = expect.begin();
for (const auto& line : output) {
if (it == expect.end()) break;
if (std::string::npos != line.find(*it)) {
matched++;
++it;
}
}
if (matched != expect.size()) {
// dump results for debugging
for (const auto& o : output) LOG(INFO) << "output: " << o;
for (const auto& e : expect) LOG(INFO) << "expect: " << e;
return false;
}
return true;
}
// Once called, the maps of TrafficController can't recover to valid maps which initialized
// in SetUp().
void makeTrafficControllerMapsInvalid() {
constexpr char INVALID_PATH[] = "invalid";
mFakeCookieTagMap.init(INVALID_PATH);
mTc.mCookieTagMap = mFakeCookieTagMap;
ASSERT_INVALID(mTc.mCookieTagMap);
mFakeAppUidStatsMap.init(INVALID_PATH);
mTc.mAppUidStatsMap = mFakeAppUidStatsMap;
ASSERT_INVALID(mTc.mAppUidStatsMap);
mFakeStatsMapA.init(INVALID_PATH);
mTc.mStatsMapA = mFakeStatsMapA;
ASSERT_INVALID(mTc.mStatsMapA);
mFakeStatsMapB.init(INVALID_PATH);
mTc.mStatsMapB = mFakeStatsMapB;
ASSERT_INVALID(mTc.mStatsMapB);
mFakeIfaceStatsMap.init(INVALID_PATH);
mTc.mIfaceStatsMap = mFakeIfaceStatsMap;
ASSERT_INVALID(mTc.mIfaceStatsMap);
mFakeConfigurationMap.init(INVALID_PATH);
mTc.mConfigurationMap = mFakeConfigurationMap;
ASSERT_INVALID(mTc.mConfigurationMap);
mFakeUidOwnerMap.init(INVALID_PATH);
mTc.mUidOwnerMap = mFakeUidOwnerMap;
ASSERT_INVALID(mTc.mUidOwnerMap);
mFakeUidPermissionMap.init(INVALID_PATH);
mTc.mUidPermissionMap = mFakeUidPermissionMap;
ASSERT_INVALID(mTc.mUidPermissionMap);
mFakeUidCounterSetMap.init(INVALID_PATH);
mTc.mUidCounterSetMap = mFakeUidCounterSetMap;
ASSERT_INVALID(mTc.mUidCounterSetMap);
mFakeIfaceIndexNameMap.init(INVALID_PATH);
mTc.mIfaceIndexNameMap = mFakeIfaceIndexNameMap;
ASSERT_INVALID(mTc.mIfaceIndexNameMap);
}
};
TEST_F(TrafficControllerTest, TestUpdateOwnerMapEntry) {