Skip to content

Commit

Permalink
Test refactor for windows compilation
Browse files Browse the repository at this point in the history
Signed-off-by: Eugenio Collado <eugeniocollado@eprosima.com>
  • Loading branch information
EugenioCollado committed Dec 13, 2024
1 parent 71a0fb8 commit 07a4d8c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 129 deletions.
9 changes: 6 additions & 3 deletions test/unittest/rtps/history/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,14 @@ target_compile_definitions(WriterHistoryTests PRIVATE
$<$<BOOL:${INTERNAL_DEBUG}>:__INTERNALDEBUG> # Internal debug activated.
)
target_include_directories(WriterHistoryTests PRIVATE
${Asio_INCLUDE_DIR})
${Asio_INCLUDE_DIR}
${THIRDPARTY_BOOST_INCLUDE_DIR}
${PROJECT_SOURCE_DIR}/src/cpp
${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/include)
target_link_libraries(WriterHistoryTests
fastcdr
fastdds
fastdds
foonathan_memory
GTest::gmock
GTest::gtest
${CMAKE_DL_LIBS})
gtest_discover_tests(WriterHistoryTests)
58 changes: 39 additions & 19 deletions test/unittest/rtps/history/WriterHistoryTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include <fastdds/rtps/RTPSDomain.hpp>
Expand All @@ -21,8 +20,6 @@
#include <fastdds/rtps/history/IPayloadPool.hpp>
#include <fastdds/rtps/history/WriterHistory.hpp>

#include <rtps/writer/BaseWriter.hpp>


namespace eprosima {
namespace fastdds {
Expand All @@ -33,11 +30,12 @@ using namespace testing;
#define MAX_MESSAGE_SIZE 300

void cache_change_fragment(
uint32_t inline_qos_length)
uint32_t max_message_size,
uint32_t inline_qos_length,
bool expected_fragmentation)
{
uint32_t domain_id = 0;
uint32_t initial_reserved_caches = 10;
uint32_t max_message_size = MAX_MESSAGE_SIZE;
std::string max_message_size_str = std::to_string(max_message_size);

RTPSParticipantAttributes p_attr;
Expand All @@ -58,31 +56,53 @@ void cache_change_fragment(

ASSERT_NE(writer, nullptr);

BaseWriter* bwriter = BaseWriter::downcast(writer);
auto max_allowed_payload_size = bwriter->get_max_allowed_payload_size();

CacheChange_t change;
change.writerGUID = bwriter->getGuid();
change.serializedPayload.length = 3 * max_allowed_payload_size; // Force to setFragmentSize
change.inline_qos.length = inline_qos_length;

history->add_change(&change);
CacheChange_t* change = history->create_change(ALIVE);
if (expected_fragmentation)
{
change->serializedPayload.length = 3 * max_message_size;
}
else
{
change->serializedPayload.length = max_message_size / 3;
}
change->inline_qos.length = inline_qos_length;
history->add_change(change);

auto result = change.getFragmentSize();
auto result = change->getFragmentSize();
std::cout << "Fragment size: " << result << std::endl;
ASSERT_NE(result, 0); // Fragment size should always be greater than 0
if (expected_fragmentation)
{
ASSERT_NE(result, 0);
}
else
{
ASSERT_EQ(result, 0);
}
}

/**
* This test checks the get_max_allowed_payload_size() method of the BaseWriter class.
* When setting the RTPS Participant Attribute property fastdds.max_message_size to a value lower than the
* message overhead, if the method does not overflow the fragment size will be set.
* If the max_message_size is big enough for the overhead, inline_qos and serializedPayload,
* then no fragmentation will occur.
*/
TEST(WriterHistoryTests, get_max_allowed_payload_size_overflow)
{
cache_change_fragment(100, 0, true);
cache_change_fragment(MAX_MESSAGE_SIZE, 0, false);
}

/**
* This test checks the fragment size calculation for a cache change depending on the inline qos length.
* The change.serializedPayload.length is set to 3 times the max_allowed_payload_size, so the fragment size should always be set.
* In case of an overflow in the attribute high_mark_for_frag_ the fragment size will not be set, which is an error.
*/
TEST(WriterHistoryTests, calculate_max_payload_size_overflow)
TEST(WriterHistoryTests, final_high_mark_for_frag_overflow)
{
for (uint32_t inline_qos_length = 0; inline_qos_length < MAX_MESSAGE_SIZE; inline_qos_length += 40)
{
cache_change_fragment(inline_qos_length);
cache_change_fragment(MAX_MESSAGE_SIZE, inline_qos_length, true);
}
}

Expand All @@ -94,6 +114,6 @@ int main(
int argc,
char** argv)
{
testing::InitGoogleMock(&argc, argv);
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
91 changes: 0 additions & 91 deletions test/unittest/rtps/writer/BaseWriterTests.cpp

This file was deleted.

16 changes: 0 additions & 16 deletions test/unittest/rtps/writer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,6 @@ target_link_libraries(LivelinessManagerTests PRIVATE
)
gtest_discover_tests(LivelinessManagerTests)

set(BASEWRITERTESTS_SOURCE BaseWriterTests.cpp)

add_executable(BaseWriterTests ${BASEWRITERTESTS_SOURCE})
target_compile_definitions(BaseWriterTests PRIVATE
BOOST_ASIO_STANDALONE
ASIO_STANDALONE
$<$<AND:$<NOT:$<BOOL:${WIN32}>>,$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">>:__DEBUG>
$<$<BOOL:${INTERNAL_DEBUG}>:__INTERNALDEBUG> # Internal debug activated.
)
target_include_directories(BaseWriterTests PRIVATE
${Asio_INCLUDE_DIR})
target_link_libraries(BaseWriterTests fastcdr fastdds foonathan_memory
GTest::gmock
${CMAKE_DL_LIBS})
gtest_discover_tests(BaseWriterTests)

if(NOT QNX)
set(RTPSWRITERTESTS_SOURCE RTPSWriterTests.cpp)

Expand Down

0 comments on commit 07a4d8c

Please sign in to comment.