Skip to content

Commit

Permalink
iox-#337 next try to fix macOS
Browse files Browse the repository at this point in the history
Signed-off-by: Mathias Kraus <[email protected]>
  • Loading branch information
elBoberido committed Dec 22, 2020
1 parent 1b4a927 commit 4694bc4
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions iceoryx_utils/test/moduletests/test_concurrent_periodic_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,29 @@ TEST_F(PeriodicTask_test, TestTimedWaitOnSemaphore)
using namespace units::duration_literals;
units::Duration m_interval = 10_ms;
auto foo = posix::Semaphore::create(posix::CreateUnnamedSingleProcessSemaphore, 0U);
if (foo.has_error()) {
if (foo.has_error())
{
std::cout << "#### Error creating Semaphore ####" << std::endl;
}
posix::Semaphore m_stop{std::move(foo.value())};

posix::SemaphoreWaitState waitState = posix::SemaphoreWaitState::NO_TIMEOUT;

int counter = 0;

auto stopper = std::thread([&] {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
m_stop.post();
});
do
{
std::cout << "#### loop: " << counter << std::endl;
m_callable();
if (counter >= 10)
{
m_stop.post();
}
++counter;
/// @todo use a refactored posix::Timer::wait method returning TIMER_TICK and TIMER_STOPPED once available
auto now = posix::Timer::now().value();
auto ts1 = now.timespec();
std::cout << "clock_gettime: " << ts1.tv_sec << "s " << ts1.tv_nsec << "ns" << std::endl;
std::cout << "Timer::now : " << ts1.tv_sec << "s " << ts1.tv_nsec << "ns" << std::endl;


struct timespec ts2;
Expand All @@ -102,12 +104,17 @@ TEST_F(PeriodicTask_test, TestTimedWaitOnSemaphore)


auto targetTime = (now + m_interval).timespec();
std::cout << "targetTime: " << targetTime.tv_sec << "s " << targetTime.tv_nsec << "ns" << std::endl;
std::cout << "targetTime : " << targetTime.tv_sec << "s " << targetTime.tv_nsec << "ns" << std::endl;
auto waitResult = m_stop.timedWait(&targetTime, true);
cxx::Expects(!waitResult.has_error());

waitState = waitResult.value();
} while (waitState == posix::SemaphoreWaitState::TIMEOUT);

if (stopper.joinable())
{
stopper.join();
}
}

TEST_F(PeriodicTask_test, CopyConstructorIsDeleted)
Expand Down

0 comments on commit 4694bc4

Please sign in to comment.