Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1196 Fix warning in further hoofs tests
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Eltzschig <[email protected]>
  • Loading branch information
elfenpiff committed Jul 6, 2022
1 parent 3a7d7be commit 6cccd84
Show file tree
Hide file tree
Showing 17 changed files with 145 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ template <typename VertexType, int32_t VERTEX_LIMIT, int32_t DEGREE_LIMIT>
class DirectedGraph
{
public:
using Index_t = int32_t;
using Index_t = uint64_t;
using AdjacencyList = iox::cxx::vector<VertexType*, DEGREE_LIMIT>;

static constexpr Index_t INVALID_INDEX = -1;
static constexpr Index_t INVALID_INDEX = std::numeric_limits<uint64_t>::max();

virtual ~DirectedGraph() = default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ namespace
{
struct Data
{
Data(int id = 0, size_t count = 0)
Data(uint64_t id = 0U, uint64_t count = 0)
: id(id)
, count(count)
{
}

int id{0};
size_t count{0};
uint64_t id{0};
uint64_t count{0};

void print()
{
Expand All @@ -53,12 +53,12 @@ struct Data
Barrier g_barrier;

template <typename Queue>
void produce(Queue& queue, int id, int iterations)
void produce(Queue& queue, uint64_t id, uint64_t iterations)
{
g_barrier.notify();

Data d(id, 0);
for (int i = 0; i < iterations; ++i)
for (uint64_t i = 0; i < iterations; ++i)
{
d.count++;
while (!queue.tryPush(d))
Expand All @@ -68,13 +68,13 @@ void produce(Queue& queue, int id, int iterations)
}

template <typename Queue>
void consume(Queue& queue, std::atomic<bool>& run, size_t expectedFinalCount, int maxId, bool& testResult)
void consume(Queue& queue, std::atomic<bool>& run, uint64_t expectedFinalCount, uint64_t maxId, bool& testResult)
{
g_barrier.notify();

bool error = false;

std::vector<size_t> lastCount(maxId + 1, 0);
std::vector<uint64_t> lastCount(maxId + 1, 0);

while (run || !queue.empty())
{
Expand All @@ -91,7 +91,7 @@ void consume(Queue& queue, std::atomic<bool>& run, size_t expectedFinalCount, in
}
}

for (int i = 1; i <= maxId; ++i)
for (uint64_t i = 1; i <= maxId; ++i)
{
if (lastCount[i] != expectedFinalCount)
{
Expand Down Expand Up @@ -121,7 +121,7 @@ void consumeAndStore(Queue& queue, std::atomic<bool>& run, std::list<Data>& cons
}
}

std::list<Data> filter(std::list<Data>& list, int id)
std::list<Data> filter(std::list<Data>& list, uint64_t id)
{
std::list<Data> filtered;

Expand Down Expand Up @@ -186,12 +186,12 @@ bool isComplete(std::list<Data>& list1, std::list<Data>& list2, size_t finalCoun

bool checkTwoConsumerResult(std::list<Data>& consumed1,
std::list<Data>& consumed2,
size_t expectedFinalCount,
int maxId)
uint64_t expectedFinalCount,
uint64_t maxId)
{
std::vector<std::list<Data>> consumed(maxId + 1);
std::vector<std::list<Data>> consumed(maxId + 1U);

for (int id = 1; id <= maxId; ++id)
for (uint64_t id = 1; id <= maxId; ++id)
{
auto filtered1 = filter(consumed1, id);
auto filtered2 = filter(consumed2, id);
Expand All @@ -215,7 +215,7 @@ bool checkTwoConsumerResult(std::list<Data>& consumed1,

// alternates between push and pop
template <typename Queue>
void work(Queue& queue, int id, std::atomic<bool>& run)
void work(Queue& queue, uint64_t id, std::atomic<bool>& run)
{
g_barrier.notify();

Expand Down Expand Up @@ -262,9 +262,9 @@ void work(Queue& queue, int id, std::atomic<bool>& run)
// popProbability essentially controls whether the queue tends to be full or empty on average
template <typename Queue>
void randomWork(Queue& queue,
int id,
uint64_t id,
std::atomic<bool>& run,
int& overflowCount,
uint64_t& overflowCount,
std::list<Data>& items,
double popProbability = 0.5)
{
Expand Down Expand Up @@ -364,8 +364,14 @@ using LargeQueue = TestQueue<1000000>;
typedef ::testing::Types<SingleElementQueue, SmallQueue, MediumQueue, LargeQueue> TestQueues;
// typedef ::testing::Types<MediumQueue> TestQueues;

#ifdef __clang__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#endif
TYPED_TEST_SUITE(LockFreeQueueStressTest, TestQueues);

#ifdef __clang__
#pragma GCC diagnostic pop
#endif

///@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 All @@ -380,8 +386,8 @@ TYPED_TEST(LockFreeQueueStressTest, DISABLED_singleProducerSingleConsumer)
bool testResult;
int iterations = 10000000;

std::thread consumer(consume<Queue>, std::ref(queue), std::ref(run), iterations, 1, std::ref(testResult));
std::thread producer(produce<Queue>, std::ref(queue), 1, iterations);
std::thread consumer(consume<Queue>, std::ref(queue), std::ref(run), iterations, 1U, std::ref(testResult));
std::thread producer(produce<Queue>, std::ref(queue), 1U, iterations);

producer.join();

Expand All @@ -402,15 +408,15 @@ TYPED_TEST(LockFreeQueueStressTest, DISABLED_multiProducerSingleConsumer)
auto& queue = this->sut;
std::atomic<bool> run{true};
bool testResult;
int iterations = 1000000;
int numProducers = 8;
uint64_t iterations = 1000000U;
uint64_t numProducers = 8U;

std::vector<std::thread> producers;

std::thread consumer(
consume<Queue>, std::ref(queue), std::ref(run), iterations, numProducers, std::ref(testResult));

for (int id = 1; id <= numProducers; ++id)
for (uint64_t id = 1U; id <= numProducers; ++id)
{
producers.emplace_back(produce<Queue>, std::ref(queue), id, iterations);
}
Expand Down Expand Up @@ -441,8 +447,8 @@ TYPED_TEST(LockFreeQueueStressTest, DISABLED_multiProducerTwoConsumer)

auto& queue = this->sut;
std::atomic<bool> run{true};
int iterations = 1000000;
int numProducers = 4;
uint64_t iterations = 1000000U;
uint64_t numProducers = 4;

std::vector<std::thread> producers;

Expand All @@ -453,7 +459,7 @@ TYPED_TEST(LockFreeQueueStressTest, DISABLED_multiProducerTwoConsumer)
std::thread consumer1(consumeAndStore<Queue>, std::ref(queue), std::ref(run), std::ref(consumed1));
std::thread consumer2(consumeAndStore<Queue>, std::ref(queue), std::ref(run), std::ref(consumed2));

for (int id = 1; id <= numProducers; ++id)
for (uint64_t id = 1U; id <= numProducers; ++id)
{
producers.emplace_back(produce<Queue>, std::ref(queue), id, iterations);
}
Expand Down Expand Up @@ -484,7 +490,7 @@ TYPED_TEST(LockFreeQueueStressTest, DISABLED_timedMultiProducerMultiConsumer)

auto& q = this->sut;
std::chrono::seconds runtime(10);
int numThreads = 32;
uint32_t numThreads = 32U;

auto capacity = q.capacity();

Expand All @@ -503,7 +509,7 @@ TYPED_TEST(LockFreeQueueStressTest, DISABLED_timedMultiProducerMultiConsumer)

std::vector<std::thread> threads;

for (int id = 1; id <= numThreads; ++id)
for (uint64_t id = 1; id <= numThreads; ++id)
{
threads.emplace_back(work<Queue>, std::ref(q), id, std::ref(run));
}
Expand Down Expand Up @@ -558,30 +564,30 @@ TYPED_TEST(LockFreeQueueStressTest, DISABLED_timedMultiProducerMultiConsumer0ver

auto& q = this->sut;
std::chrono::seconds runtime(10);
int numThreads = 32;
uint32_t numThreads = 32U;
double popProbability = 0.45; // tends to overflow

auto capacity = q.capacity();

std::atomic<bool> run{true};

std::vector<std::thread> threads;
std::vector<int> overflowCount(numThreads);
std::vector<uint64_t> overflowCount(numThreads);
std::vector<std::list<Data>> itemVec(numThreads);

g_barrier.reset(numThreads);

// fill the queue
Data d;
for (size_t i = 0; i < capacity; ++i)
for (uint64_t i = 0U; i < capacity; ++i)
{
d.count = i;
while (!q.tryPush(d))
{
}
}

for (int id = 1; id <= numThreads; ++id)
for (uint64_t id = 1U; id <= numThreads; ++id)
{
threads.emplace_back(randomWork<Queue>,
std::ref(q),
Expand All @@ -605,7 +611,7 @@ TYPED_TEST(LockFreeQueueStressTest, DISABLED_timedMultiProducerMultiConsumer0ver
// check whether all elements are there, but there is no specific ordering we can expect
// items are either in the local lists or the queue, in total we expect each count numThreads times

std::vector<int> count(capacity, 0);
std::vector<uint64_t> count(capacity, 0U);
auto popped = q.pop();
while (popped.has_value())
{
Expand Down
10 changes: 5 additions & 5 deletions iceoryx_hoofs/test/moduletests/test_directed_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ class DirectedGraph_test : public Test

DirectedGraph<TestNode, MAX_VERTICES, MAX_DEGREE> m_graph;

TestNode node1{0, 0};
TestNode node2{2, 1};
TestNode node3{100, 0};
TestNode node4{13, 42};
TestNode node5{10000, 88};
TestNode node1{0U, 0U};
TestNode node2{2U, 1U};
TestNode node3{100U, 0U};
TestNode node4{13U, 42U};
TestNode node5{10000U, 88U};
};

TEST_F(DirectedGraph_test, addVertices)
Expand Down
7 changes: 7 additions & 0 deletions iceoryx_hoofs/test/moduletests/test_index_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ TEST(LockFreeQueueTest, capacityIsConsistent)

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

#ifdef __clang__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#endif
TYPED_TEST_SUITE(IndexQueueTest, TestQueues);
#ifdef __clang__
#pragma GCC diagnostic pop
#endif


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

#ifdef __clang__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#endif
TYPED_TEST_SUITE(IpcChannel_test, IpcChannelTypes);
#ifdef __clang__
#pragma GCC diagnostic pop
#endif


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

#ifdef __clang__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#endif
TYPED_TEST_SUITE(LockFreeQueueTest, TestConfigs);
#ifdef __clang__
#pragma GCC diagnostic pop
#endif


TEST(LockFreeQueueTest, capacityIsConsistent)
Expand Down
7 changes: 7 additions & 0 deletions iceoryx_hoofs/test/moduletests/test_lockfree_queue_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ TEST(LockFreeQueueBufferTest, capacityIsCorrect)

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

#ifdef __clang__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#endif
TYPED_TEST_SUITE(LockFreeQueueBufferTest, TestBuffers);
#ifdef __clang__
#pragma GCC diagnostic pop
#endif


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

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

#ifdef __clang__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#endif
TYPED_TEST_SUITE(LockFreeQueueCyclicIndexTest, TestIndices);
#ifdef __clang__
#pragma GCC diagnostic pop
#endif


// note that in all tests we will check whether the getCycle and getIndex methods
Expand Down
14 changes: 14 additions & 0 deletions iceoryx_hoofs/test/moduletests/test_logstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,14 @@ 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>;

#ifdef __clang__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#endif
TYPED_TEST_SUITE(IoxLogStreamHexBin_test, LogHexBinTypes);
#ifdef __clang__
#pragma GCC diagnostic pop
#endif


template <typename LogType>
Expand Down Expand Up @@ -276,7 +283,14 @@ 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>;

#ifdef __clang__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
#endif
TYPED_TEST_SUITE(IoxLogStreamArithmetic_test, ArithmeticTypes);
#ifdef __clang__
#pragma GCC diagnostic pop
#endif


template <typename Arithmetic>
Expand Down
Loading

0 comments on commit 6cccd84

Please sign in to comment.