Skip to content

Commit

Permalink
fix: eBPFServer UT memory leak (alibaba#1937)
Browse files Browse the repository at this point in the history
  • Loading branch information
KayzzzZ authored Dec 2, 2024
1 parent bf1d12d commit 5707547
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
6 changes: 3 additions & 3 deletions core/unittest/ebpf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
cmake_minimum_required(VERSION 3.22)
project(ebpf_unittest)

# add_executable(ebpf_server_unittest eBPFServerUnittest.cpp)
# target_link_libraries(ebpf_server_unittest ${UT_BASE_TARGET})
add_executable(ebpf_server_unittest eBPFServerUnittest.cpp)
target_link_libraries(ebpf_server_unittest ${UT_BASE_TARGET})

include(GoogleTest)

# gtest_discover_tests(ebpf_server_unittest)
gtest_discover_tests(ebpf_server_unittest)

13 changes: 5 additions & 8 deletions core/unittest/ebpf/eBPFServerUnittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class eBPFServerUnittest : public testing::Test {
config_->mProfileProbeConfig.mProfileUploadDuration = 10;
config_->mProcessProbeConfig.mEnableOOMDetect = false;
}
void TearDown() override { delete config_; }
private:
template <typename T>
void setJSON(Json::Value& v, const std::string& key, const T& value) {
Expand Down Expand Up @@ -500,7 +501,6 @@ void eBPFServerUnittest::HandleStats(nami::NamiStatisticsHandler cb, int plus) {
stats.emplace_back(std::move(networkSecurityStat));
stats.emplace_back(std::move(processSecurityStat));
stats.emplace_back(std::move(fileSecurityStat));
std::cout << "3" << std::endl;
if (cb) cb(stats);
}

Expand Down Expand Up @@ -601,18 +601,16 @@ void eBPFServerUnittest::TestEnableNetworkPlugin() {
bool res = ebpf::InitObserverNetworkOption(configJson, network_option, &ctx, "test");
EXPECT_TRUE(res);
// observer_options.Init(ObserverType::NETWORK, configJson, &ctx, "test");
auto input = new InputNetworkObserver();
std::shared_ptr<InputNetworkObserver> input(new InputNetworkObserver());
input->SetContext(ctx);
input->SetMetricsRecordRef("test", "1");
auto initStatus = input->Init(configJson, optionalGoPipeline);
EXPECT_TRUE(initStatus);
std::cout << "1" << std::endl;
res = ebpf::eBPFServer::GetInstance()->EnablePlugin(
"test", 1,
nami::PluginType::NETWORK_OBSERVE,
&ctx,
&network_option, input->mPluginMgr);
std::cout << "2" << std::endl;

EXPECT_EQ(ebpf::eBPFServer::GetInstance()->mMonitorMgr->mInited[int(nami::PluginType::NETWORK_OBSERVE)], true);
auto& mgr = ebpf::eBPFServer::GetInstance()->mMonitorMgr->mSelfMonitors[int(nami::PluginType::NETWORK_OBSERVE)];
Expand All @@ -627,7 +625,6 @@ void eBPFServerUnittest::TestEnableNetworkPlugin() {
EXPECT_TRUE(res);
auto conf = ebpf::eBPFServer::GetInstance()->mSourceManager->mConfig.get();
HandleStats(conf->stats_handler_, 1);
std::cout << "3" << std::endl;
auto network_conf = std::get<nami::NetworkObserveConfig>(conf->config_);
EXPECT_EQ(conf->plugin_type_, nami::PluginType::NETWORK_OBSERVE);
EXPECT_EQ(conf->type, UpdataType::SECURE_UPDATE_TYPE_ENABLE_PROBE);
Expand Down Expand Up @@ -695,7 +692,7 @@ void eBPFServerUnittest::TestEnableProcessPlugin() {
APSARA_TEST_TRUE(ParseJsonTable(configStr, configJson, errorMsg));
SecurityOptions security_options;
security_options.Init(SecurityProbeType::PROCESS, configJson, &ctx, "input_process_security");
auto input = new InputProcessSecurity();
std::shared_ptr<InputProcessSecurity> input(new InputProcessSecurity());
input->SetContext(ctx);
input->SetMetricsRecordRef("test", "1");
input->Init(configJson, optionalGoPipeline);
Expand Down Expand Up @@ -753,7 +750,7 @@ void eBPFServerUnittest::TestEnableNetworkSecurePlugin() {
}
}
)";
auto input = new InputNetworkSecurity();
std::shared_ptr<InputNetworkSecurity> input(new InputNetworkSecurity());
input->SetContext(ctx);
input->SetMetricsRecordRef("test", "1");

Expand Down Expand Up @@ -824,7 +821,7 @@ void eBPFServerUnittest::TestEnableFileSecurePlugin() {
}
)";

auto input = new InputFileSecurity();
std::shared_ptr<InputFileSecurity> input(new InputFileSecurity());
input->SetContext(ctx);
input->SetMetricsRecordRef("test", "1");

Expand Down

0 comments on commit 5707547

Please sign in to comment.