Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[20945] Fix SecurityTest unittests memory error #4750

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions test/unittest/rtps/security/SecurityHandshakeProcessTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,13 @@ TEST_F(SecurityTest, discovered_participant_process_message_ok_begin_handshake_r
info.guid = participant_data.m_guid;
EXPECT_CALL(*participant_.getListener(), onParticipantAuthentication(_, info)).Times(1);

CacheChange_t* kx_change = new CacheChange_t(500);
expect_kx_exchange(kx_change);
CacheChange_t kx_change_to_add;
CacheChange_t* kx_change_to_remove = new CacheChange_t(500);
expect_kx_exchange(kx_change_to_add, kx_change_to_remove);

stateless_reader_->listener_->onNewCacheChangeAdded(stateless_reader_, change);

volatile_writer_->listener_->onWriterChangeReceivedByAll(volatile_writer_, kx_change);
volatile_writer_->listener_->onWriterChangeReceivedByAll(volatile_writer_, kx_change_to_remove);

return_handle(remote_identity_handle);
return_handle(handshake_handle);
Expand Down Expand Up @@ -527,14 +528,15 @@ TEST_F(SecurityTest, discovered_participant_process_message_pending_handshake_re
WillOnce(DoAll(SetArgPointee<0>(&remote_identity_handle),
Return(ValidationResult_t::VALIDATION_PENDING_HANDSHAKE_MESSAGE)));

CacheChange_t* kx_change = new CacheChange_t(500);
expect_kx_exchange(kx_change);
CacheChange_t kx_change_to_add;
CacheChange_t* kx_change_to_remove = new CacheChange_t(500);
expect_kx_exchange(kx_change_to_add, kx_change_to_remove);

ParticipantProxyData participant_data;
fill_participant_key(participant_data.m_guid);
ASSERT_TRUE(manager_.discovered_participant(participant_data));

volatile_writer_->listener_->onWriterChangeReceivedByAll(volatile_writer_, kx_change);
volatile_writer_->listener_->onWriterChangeReceivedByAll(volatile_writer_, kx_change_to_remove);

ParticipantGenericMessage message;
message.message_identity().source_guid(participant_data.m_guid);
Expand Down Expand Up @@ -732,12 +734,13 @@ TEST_F(SecurityTest, discovered_participant_process_message_ok_process_handshake
info.guid = remote_participant_key;
EXPECT_CALL(*participant_.getListener(), onParticipantAuthentication(_, info)).Times(1);

CacheChange_t* kx_change = new CacheChange_t(500);
expect_kx_exchange(kx_change);
CacheChange_t kx_change_to_add;
CacheChange_t* kx_change_to_remove = new CacheChange_t(500);
expect_kx_exchange(kx_change_to_add, kx_change_to_remove);

stateless_reader_->listener_->onNewCacheChangeAdded(stateless_reader_, change);

volatile_writer_->listener_->onWriterChangeReceivedByAll(volatile_writer_, kx_change);
volatile_writer_->listener_->onWriterChangeReceivedByAll(volatile_writer_, kx_change_to_remove);
}

TEST_F(SecurityTest, discovered_participant_process_message_process_handshake_reply_new_change_fail)
Expand Down Expand Up @@ -1131,12 +1134,13 @@ TEST_F(SecurityTest, discovered_participant_process_message_ok_process_handshake
info.guid = remote_participant_key;
EXPECT_CALL(*participant_.getListener(), onParticipantAuthentication(_, info)).Times(1);

CacheChange_t* kx_change = new CacheChange_t(500);
expect_kx_exchange(kx_change);
CacheChange_t kx_change_to_add;
CacheChange_t* kx_change_to_remove = new CacheChange_t(500);
expect_kx_exchange(kx_change_to_add, kx_change_to_remove);

stateless_reader_->listener_->onNewCacheChangeAdded(stateless_reader_, change);

volatile_writer_->listener_->onWriterChangeReceivedByAll(volatile_writer_, kx_change);
volatile_writer_->listener_->onWriterChangeReceivedByAll(volatile_writer_, kx_change_to_remove);
}

int main(
Expand Down
20 changes: 11 additions & 9 deletions test/unittest/rtps/security/SecurityTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,13 @@ void SecurityTest::final_message_process_ok(
info.guid = remote_participant_key;
EXPECT_CALL(*participant_.getListener(), onParticipantAuthentication(_, info)).Times(1);

CacheChange_t* kx_change = new CacheChange_t(200);
expect_kx_exchange(kx_change);
CacheChange_t kx_change_to_add;
CacheChange_t* kx_change_to_remove = new CacheChange_t(200);
expect_kx_exchange(kx_change_to_add, kx_change_to_remove);

stateless_reader_->listener_->onNewCacheChangeAdded(stateless_reader_, change);

volatile_writer_->listener_->onWriterChangeReceivedByAll(volatile_writer_, kx_change);
volatile_writer_->listener_->onWriterChangeReceivedByAll(volatile_writer_, kx_change_to_remove);

if (final_message_change == nullptr)
{
Expand All @@ -263,17 +264,18 @@ void SecurityTest::final_message_process_ok(
}

void SecurityTest::expect_kx_exchange(
CacheChange_t* kx_change)
CacheChange_t& kx_change_to_add,
CacheChange_t* kx_change_to_remove)
{
EXPECT_CALL(*volatile_writer_, new_change(_, _, _)).Times(1).WillOnce(
DoAll(Invoke([kx_change](const std::function<uint32_t()>& f, ChangeKind_t, InstanceHandle_t)
DoAll(Invoke([&kx_change_to_add](const std::function<uint32_t()>& f, ChangeKind_t, InstanceHandle_t)
{
kx_change->serializedPayload.reserve(f());
kx_change_to_add.serializedPayload.reserve(f());
}),
Return(kx_change)));
EXPECT_CALL(*volatile_writer_->history_, add_change_mock(kx_change)).Times(1).
Return(&kx_change_to_add)));
EXPECT_CALL(*volatile_writer_->history_, add_change_mock(&kx_change_to_add)).Times(1).
WillOnce(Return(true));
EXPECT_CALL(*volatile_writer_->history_, remove_change_mock(kx_change)).Times(1).
EXPECT_CALL(*volatile_writer_->history_, remove_change_mock(kx_change_to_remove)).Times(1).
WillOnce(Return(true));
}

Expand Down
3 changes: 2 additions & 1 deletion test/unittest/rtps/security/SecurityTests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ class SecurityTest : public ::testing::Test
CacheChange_t** final_message_change = nullptr);

void expect_kx_exchange(
CacheChange_t* kx_change);
CacheChange_t& kx_change_to_add,
CacheChange_t* kx_change_to_remove);

void destroy_manager_and_change(
CacheChange_t*& change,
Expand Down
14 changes: 8 additions & 6 deletions test/unittest/rtps/security/SecurityValidationRemoteTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,13 @@ TEST_F(SecurityTest, discovered_participant_validation_remote_identity_pending_h
info.guid = participant_data.m_guid;
EXPECT_CALL(*participant_.getListener(), onParticipantAuthentication(_, info)).Times(1);

CacheChange_t* kx_change = new CacheChange_t(500);
expect_kx_exchange(kx_change);
CacheChange_t kx_change_to_add;
CacheChange_t* kx_change_to_remove = new CacheChange_t(500);
expect_kx_exchange(kx_change_to_add, kx_change_to_remove);

ASSERT_TRUE(manager_.discovered_participant(participant_data));

volatile_writer_->listener_->onWriterChangeReceivedByAll(volatile_writer_, kx_change);
volatile_writer_->listener_->onWriterChangeReceivedByAll(volatile_writer_, kx_change_to_remove);

return_handle(remote_identity_handle);
return_handle(handshake_handle);
Expand Down Expand Up @@ -330,12 +331,13 @@ TEST_F(SecurityTest, discovered_participant_validation_remote_identity_pending_h
info.guid = participant_data.m_guid;
EXPECT_CALL(*participant_.getListener(), onParticipantAuthentication(_, info)).Times(1);

CacheChange_t* kx_change = new CacheChange_t(500);
expect_kx_exchange(kx_change);
CacheChange_t kx_change_to_add;
CacheChange_t* kx_change_to_remove = new CacheChange_t(500);
expect_kx_exchange(kx_change_to_add, kx_change_to_remove);

ASSERT_TRUE(manager_.discovered_participant(participant_data));

volatile_writer_->listener_->onWriterChangeReceivedByAll(volatile_writer_, kx_change);
volatile_writer_->listener_->onWriterChangeReceivedByAll(volatile_writer_, kx_change_to_remove);

destroy_manager_and_change(change);

Expand Down
Loading