Skip to content

Commit

Permalink
Merge pull request #1006 from ApexAI/iox-#841-upgrade-gtest-gmock-to-…
Browse files Browse the repository at this point in the history
…v1.10

Iox #841 upgrade gtest gmock to v1.10
  • Loading branch information
elBoberido authored Jan 11, 2022
2 parents a41fd66 + d46593d commit 6c92309
Show file tree
Hide file tree
Showing 39 changed files with 301 additions and 473 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
- Make `cxx::string::capacity` a `static` method[\#979](https://github.com/eclipse-iceoryx/iceoryx/issues/979)
- Restructure iceoryx tools [\#471](https://github.com/eclipse-iceoryx/iceoryx/issues/471)
- Use cxx::expected for MemoryManager::getChunk [\#954](https://github.com/eclipse-iceoryx/iceoryx/pull/991)
- Upgrade GTest/GMock to v1.10 [\#841](https://github.com/eclipse-iceoryx/iceoryx/issues/841)

**API Breaking Changes:**

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ All new code should follow the folder structure.
## Testing

We use [Google test](https://github.com/google/googletest) for our unit and integration tests. We require compatibility
with the version 1.8.1.
with the version 1.10.0.

Have a look at our [best practice guidelines](./doc/website/advanced/best-practice-for-testing.md) for writing tests and
[installation guide for contributors](./doc/website/advanced/installation-guide-for-contributors.md#build-and-run-tests) for building them.
Expand Down
13 changes: 10 additions & 3 deletions cmake/googletest/0001-remove-werror-from-build-flags.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
--- /googletest/cmake/internal_utils.cmake
+++ /googletest/cmake/internal_utils.cmake.new
@@ -99,7 +99,7 @@
set(cxx_no_exception_flags "-EHs-c- -D_HAS_EXCEPTIONS=0")
set(cxx_no_rtti_flags "-GR-")
@@ -82,13 +82,13 @@ macro(config_compiler_and_linker)
# http://stackoverflow.com/questions/3232669 explains the issue.
set(cxx_base_flags "${cxx_base_flags} -wd4702")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
- set(cxx_base_flags "-Wall -Wshadow -Werror -Wconversion")
+ set(cxx_base_flags "-Wall -Wshadow -Wconversion")
set(cxx_exception_flags "-fexceptions")
set(cxx_no_exception_flags "-fno-exceptions")
set(cxx_strict_flags "-W -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wunused-parameter -Wcast-align -Wchar-subscripts -Winline -Wredundant-decls")
set(cxx_no_rtti_flags "-fno-rtti")
elseif (CMAKE_COMPILER_IS_GNUCXX)
- set(cxx_base_flags "-Wall -Wshadow -Werror")
+ set(cxx_base_flags "-Wall -Wshadow")
Expand Down
33 changes: 10 additions & 23 deletions cmake/googletest/googletest.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,13 @@ cmake_minimum_required(VERSION 3.5)
project(googletest-download NONE)

include(ExternalProject)
if(WIN32)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.10.0
SOURCE_DIR "${CMAKE_BINARY_DIR}/dependencies/googletest/src"
BINARY_DIR "${CMAKE_BINARY_DIR}/dependencies/googletest/build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
else()
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.8.1
SOURCE_DIR "${CMAKE_BINARY_DIR}/dependencies/googletest/src"
BINARY_DIR "${CMAKE_BINARY_DIR}/dependencies/googletest/build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
endif(WIN32)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.10.0
SOURCE_DIR "${CMAKE_BINARY_DIR}/dependencies/googletest/src"
BINARY_DIR "${CMAKE_BINARY_DIR}/dependencies/googletest/build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
4 changes: 2 additions & 2 deletions doc/website/advanced/best-practice-for-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ They also exert all the good practices mentioned previously, like clear and dist
There are situations when test cases only vary in the type applied to the `sut`. In this case typed tests can be used to reduce repetition.
The there is a section for [typed tests](https://github.com/google/googletest/blob/master/docs/advanced.md#typed-tests) in the advanced gtest documentation.
A more thorough [example](https://github.com/google/googletest/blob/release-1.8.1/googletest/samples/sample6_unittest.cc) is in the gtest github repository.
A more thorough [example](https://github.com/google/googletest/blob/release-1.10.0/googletest/samples/sample6_unittest.cc) is in the gtest github repository.
## Parameterized Tests
Expand All @@ -245,7 +245,7 @@ The block post mentions tuples to pass multiple parameters at once. Since tuples
Some classes are hard to test or to reach a full coverage. This might be due to external access or interaction with the operating system.
Mocks can help to have full control over the `sut` and reliably cause error conditions to test the negative code path.
There is an [extensive gmock documentation](https://github.com/google/googletest/tree/release-1.8.1/googlemock/docs) in the gtest github repository.
There is an [extensive gmock documentation](https://github.com/google/googletest/tree/release-1.10.0/googlemock/docs) in the gtest github repository.
## Pitfalls
Some tests require creating dummy classes and it might be that the same name is chosen multiple times, e.g. “class DummyData {...};”.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,8 @@ using LargeQueue = TestQueue<1000000>;
typedef ::testing::Types<SingleElementQueue, SmallQueue, MediumQueue, LargeQueue> TestQueues;
// typedef ::testing::Types<MediumQueue> TestQueues;

/// we require TYPED_TEST since we support gtest 1.8 for our safety targets
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
TYPED_TEST_CASE(LockFreeQueueStressTest, TestQueues);
#pragma GCC diagnostic pop
TYPED_TEST_SUITE(LockFreeQueueStressTest, TestQueues);


///@brief Tests concurrent operation of one prodcuer and one consumer
/// The producer pushes a fixed number of data elements which the consumer pops and checks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,7 @@ using HalfFull3 = HalfFull<Data, Large>;
/// @endcode
typedef ::testing::Types<HalfFull2> TestConfigs;

/// we require TYPED_TEST since we support gtest 1.8 for our safety targets
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
TYPED_TEST_CASE(ResizeableLockFreeQueueStressTest, TestConfigs);
#pragma GCC diagnostic pop
TYPED_TEST_SUITE(ResizeableLockFreeQueueStressTest, TestConfigs);


///@brief Tests concurrent operation of multiple producers and consumers
Expand Down
8 changes: 3 additions & 5 deletions iceoryx_hoofs/test/moduletests/test_concurrent_loffli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ using namespace ::testing;

constexpr uint32_t Size{4};
using LoFFLiTestSubjects = Types<iox::concurrent::LoFFLi>;
/// we require TYPED_TEST since we support gtest 1.8 for our safety targets
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
TYPED_TEST_CASE(LoFFLi_test, LoFFLiTestSubjects);
#pragma GCC diagnostic pop

TYPED_TEST_SUITE(LoFFLi_test, LoFFLiTestSubjects);


template <typename LoFFLiType>
class LoFFLi_test : public Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,8 @@ using TriggerQueueTestSubjects = Types<TriggerQueue<uint64_t, 1, FiFo>,
TriggerQueue<uint64_t, 10, ResizeableLockFreeQueue>,
TriggerQueue<uint64_t, 100, ResizeableLockFreeQueue>>;

/// we require TYPED_TEST since we support gtest 1.8 for our safety targets
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
TYPED_TEST_CASE(TriggerQueue_test, TriggerQueueTestSubjects);
#pragma GCC diagnostic pop
TYPED_TEST_SUITE(TriggerQueue_test, TriggerQueueTestSubjects);


TYPED_TEST(TriggerQueue_test, EmptyOnConstruction)
{
Expand Down
7 changes: 2 additions & 5 deletions iceoryx_hoofs/test/moduletests/test_cxx_helplets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,8 @@ class Helplets_test_isPowerOfTwo : public Helplets_test

using HelpletsIsPowerOfTwoTypes = Types<uint8_t, uint16_t, uint32_t, uint64_t, size_t>;

/// we require TYPED_TEST since we support gtest 1.8 for our safety targets
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
TYPED_TEST_CASE(Helplets_test_isPowerOfTwo, HelpletsIsPowerOfTwoTypes);
#pragma GCC diagnostic pop
TYPED_TEST_SUITE(Helplets_test_isPowerOfTwo, HelpletsIsPowerOfTwoTypes);


TYPED_TEST(Helplets_test_isPowerOfTwo, OneIsPowerOfTwo)
{
Expand Down
8 changes: 3 additions & 5 deletions iceoryx_hoofs/test/moduletests/test_cxx_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ class stringTyped_test : public Test
};

using Implementations = Types<string<1>, string<15>, string<100>, string<1000>>;
/// we require TYPED_TEST since we support gtest 1.8 for our safety targets
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
TYPED_TEST_CASE(stringTyped_test, Implementations);
#pragma GCC diagnostic pop

TYPED_TEST_SUITE(stringTyped_test, Implementations);


TEST(string_test, CapacityReturnsSpecifiedCapacity)
{
Expand Down
6 changes: 1 addition & 5 deletions iceoryx_hoofs/test/moduletests/test_index_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ TEST(LockFreeQueueTest, capacityIsConsistent)

typedef ::testing::Types<IndexQueue<1>, IndexQueue<10>, IndexQueue<1000>> TestQueues;

/// we require TYPED_TEST since we support gtest 1.8 for our safety targets
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
TYPED_TEST_CASE(IndexQueueTest, TestQueues);
#pragma GCC diagnostic pop
TYPED_TEST_SUITE(IndexQueueTest, TestQueues);


TYPED_TEST(IndexQueueTest, defaultConstructedQueueIsEmpty)
Expand Down
7 changes: 2 additions & 5 deletions iceoryx_hoofs/test/moduletests/test_ipc_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,8 @@ const size_t IpcChannel_test<T>::MaxMsgSize = IpcChannelType::MAX_MESSAGE_SIZE;
template <typename T>
constexpr uint64_t IpcChannel_test<T>::MaxMsgNumber;

/// we require TYPED_TEST since we support gtest 1.8 for our safety targets
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
TYPED_TEST_CASE(IpcChannel_test, IpcChannelTypes);
#pragma GCC diagnostic pop
TYPED_TEST_SUITE(IpcChannel_test, IpcChannelTypes);


TYPED_TEST(IpcChannel_test, CreateWithTooLargeMessageSizeLeadsToError)
{
Expand Down
7 changes: 2 additions & 5 deletions iceoryx_hoofs/test/moduletests/test_lockfree_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,8 @@ typedef ::testing::Types<LFFull1,
AlmostEmpty2>
TestConfigs;

/// we require TYPED_TEST since we support gtest 1.8 for our safety targets
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
TYPED_TEST_CASE(LockFreeQueueTest, TestConfigs);
#pragma GCC diagnostic pop
TYPED_TEST_SUITE(LockFreeQueueTest, TestConfigs);


TEST(LockFreeQueueTest, capacityIsConsistent)
{
Expand Down
7 changes: 2 additions & 5 deletions iceoryx_hoofs/test/moduletests/test_lockfree_queue_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,8 @@ TEST(LockFreeQueueBufferTest, capacityIsCorrect)

typedef ::testing::Types<Buffer<int, 10>, Buffer<Integer, 10>> TestBuffers;

/// we require TYPED_TEST since we support gtest 1.8 for our safety targets
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
TYPED_TEST_CASE(LockFreeQueueBufferTest, TestBuffers);
#pragma GCC diagnostic pop
TYPED_TEST_SUITE(LockFreeQueueBufferTest, TestBuffers);


TYPED_TEST(LockFreeQueueBufferTest, accessElements)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,8 @@ class LockFreeQueueCyclicIndexTest : public ::testing::Test

typedef ::testing::Types<CyclicIndex<1>, CyclicIndex<2>, CyclicIndex<10>, CyclicIndex<1000>> TestIndices;

/// we require TYPED_TEST since we support gtest 1.8 for our safety targets
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
TYPED_TEST_CASE(LockFreeQueueCyclicIndexTest, TestIndices);
#pragma GCC diagnostic pop
TYPED_TEST_SUITE(LockFreeQueueCyclicIndexTest, TestIndices);


// note that in all tests we will check whether the getCycle and getIndex methods
// behave as expected after certain operations (mainly addition),
Expand Down
22 changes: 9 additions & 13 deletions iceoryx_hoofs/test/moduletests/test_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,15 @@ class IoxLoggerLogLevel_test : public TestWithParam<iox::log::LogLevel>, public
}
};

/// we require INSTANTIATE_TEST_CASE_P since we support gtest 1.8 for our safety targets
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
INSTANTIATE_TEST_CASE_P(AllLogLevel,
IoxLoggerLogLevel_test,
Values(iox::log::LogLevel::kOff,
iox::log::LogLevel::kFatal,
iox::log::LogLevel::kError,
iox::log::LogLevel::kWarn,
iox::log::LogLevel::kInfo,
iox::log::LogLevel::kDebug,
iox::log::LogLevel::kVerbose));
#pragma GCC diagnostic pop
INSTANTIATE_TEST_SUITE_P(AllLogLevel,
IoxLoggerLogLevel_test,
Values(iox::log::LogLevel::kOff,
iox::log::LogLevel::kFatal,
iox::log::LogLevel::kError,
iox::log::LogLevel::kWarn,
iox::log::LogLevel::kInfo,
iox::log::LogLevel::kDebug,
iox::log::LogLevel::kVerbose));

TEST_P(IoxLoggerLogLevel_test, LogLevel)
{
Expand Down
14 changes: 4 additions & 10 deletions iceoryx_hoofs/test/moduletests/test_logstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,8 @@ class IoxLogStreamHexBin_test : public IoxLogStream_test

using LogHexBinTypes = Types<uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t>;

/// we require TYPED_TEST since we support gtest 1.8 for our safety targets
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
TYPED_TEST_CASE(IoxLogStreamHexBin_test, LogHexBinTypes);
#pragma GCC diagnostic pop
TYPED_TEST_SUITE(IoxLogStreamHexBin_test, LogHexBinTypes);


template <typename LogType>
void testStreamOperatorLogHex(Logger_Mock& loggerMock, LogType logValue)
Expand Down Expand Up @@ -263,11 +260,8 @@ TYPED_TEST(IoxLogStreamHexBin_test, StreamOperatorLogBin_ValueMax)
using ArithmeticTypes =
Types<bool, int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, size_t, float, double>;

/// we require TYPED_TEST since we support gtest 1.8 for our safety targets
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
TYPED_TEST_CASE(IoxLogStreamArithmetic_test, ArithmeticTypes);
#pragma GCC diagnostic pop
TYPED_TEST_SUITE(IoxLogStreamArithmetic_test, ArithmeticTypes);


template <typename Arithmetic>
class IoxLogStreamArithmetic_test : public IoxLogStream_test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class SignalHandler_test : public Test
using Implementations =
Types<SignalType<Signal::INT>, SignalType<Signal::BUS>, SignalType<Signal::TERM>, SignalType<Signal::HUP>>;

TYPED_TEST_CASE(SignalHandler_test, Implementations);
TYPED_TEST_SUITE(SignalHandler_test, Implementations);

TYPED_TEST(SignalHandler_test, RegisteringSignalGuardCallbackWorks)
{
Expand Down
7 changes: 2 additions & 5 deletions iceoryx_hoofs/test/moduletests/test_relative_pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,8 @@ class base_relative_ptr_test : public Test

typedef testing::Types<uint8_t, int8_t, double> Types;

/// we require TYPED_TEST since we support gtest 1.8 for our safety targets
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
TYPED_TEST_CASE(base_relative_ptr_test, Types);
#pragma GCC diagnostic pop
TYPED_TEST_SUITE(base_relative_ptr_test, Types);


TYPED_TEST(base_relative_ptr_test, ConstrTests)
{
Expand Down
7 changes: 2 additions & 5 deletions iceoryx_hoofs/test/moduletests/test_relocatable_ptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,8 @@ class Relocatable_ptr_test : public Test

typedef ::testing::Types<int, Data, void, char*, const Data, const void> TestTypes;

/// we require TYPED_TEST since we support gtest 1.8 for our safety targets
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
TYPED_TEST_CASE(Relocatable_ptr_typed_test, TestTypes);
#pragma GCC diagnostic pop
TYPED_TEST_SUITE(Relocatable_ptr_typed_test, TestTypes);


TYPED_TEST(Relocatable_ptr_typed_test, wrappedPointerTypeIsCorrect)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,8 @@ using IntQueue = iox::concurrent::ResizeableLockFreeQueue<uint64_t, Capacity>;

typedef ::testing::Types<IntegerQueue<1>, IntegerQueue<11>, IntQueue<10>> TestQueues;

TYPED_TEST_SUITE(ResizeableLockFreeQueueTest, TestQueues);

/// we require TYPED_TEST since we support gtest 1.8 for our safety targets
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
TYPED_TEST_CASE(ResizeableLockFreeQueueTest, TestQueues);
#pragma GCC diagnostic pop

TEST(ResizeableLockFreeQueueTest, maxCapacityIsConsistent)
{
Expand Down
6 changes: 1 addition & 5 deletions iceoryx_hoofs/test/moduletests/test_semaphore_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,7 @@ class SemaphoreCreate_test : public Test
}
};

/// we require INSTANTIATE_TEST_CASE since we support gtest 1.8 for our safety targets
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
INSTANTIATE_TEST_CASE_P(Semaphore_test, Semaphore_test, Values(&createNamedSemaphore, &createUnnamedSemaphore));
#pragma GCC diagnostic pop
INSTANTIATE_TEST_SUITE_P(Semaphore_test, Semaphore_test, Values(&createNamedSemaphore, &createUnnamedSemaphore));

TEST_F(SemaphoreCreate_test, CreateNamedSemaphore)
{
Expand Down
Loading

0 comments on commit 6c92309

Please sign in to comment.