Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TrentHouliston committed Sep 5, 2024
1 parent 41bdcc7 commit 589435e
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 143 deletions.
1 change: 1 addition & 0 deletions src/util/SleeperPosix.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "Sleeper.hpp"

extern "C" {
// NOLINTNEXTLINE(misc-use-anonymous-namespace)
static void signal_handler(int /*unused*/) {
// Do nothing, we just want to interrupt the sleep
}
Expand Down
82 changes: 0 additions & 82 deletions src/util/precise_sleep.cpp

This file was deleted.

36 changes: 0 additions & 36 deletions src/util/precise_sleep.hpp

This file was deleted.

4 changes: 2 additions & 2 deletions tests/tests/api/ReactionStatisticsTiming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "test_util/TestBase.hpp"
#include "test_util/TimeUnit.hpp"
#include "test_util/common.hpp"
#include "util/precise_sleep.hpp"
#include "util/Sleeper.hpp"

using TimeUnit = test_util::TimeUnit;

Expand Down Expand Up @@ -82,7 +82,7 @@ class TestReactor : public test_util::TestBase<TestReactor> {
});
on<Trigger<LightTask>>().then(light_name, [] {
code_events.emplace_back("Started " + light_name, NUClear::clock::now());
NUClear::util::precise_sleep(TimeUnit(scale));
NUClear::util::Sleeper().sleep_for(TimeUnit(scale));
code_events.emplace_back("Finished " + light_name, NUClear::clock::now());
});

Expand Down
4 changes: 2 additions & 2 deletions tests/tests/api/TimeTravelFrozen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "test_util/TestBase.hpp"
#include "test_util/common.hpp"
#include "util/precise_sleep.hpp"
#include "util/Sleeper.hpp"

constexpr std::chrono::milliseconds EVENT_1_TIME = std::chrono::milliseconds(4);
constexpr std::chrono::milliseconds EVENT_2_TIME = std::chrono::milliseconds(8);
Expand Down Expand Up @@ -49,7 +49,7 @@ class TestReactor : public test_util::TestBase<TestReactor> {
});

on<Trigger<WaitForShutdown>>().then([this] {
NUClear::util::precise_sleep(SHUTDOWN_TIME);
NUClear::util::Sleeper().sleep_for(SHUTDOWN_TIME);
add_event("Finished");
powerplant.shutdown();
});
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/dsl/IdleCrossPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "test_util/TestBase.hpp"
#include "test_util/TimeUnit.hpp"
#include "test_util/common.hpp"
#include "util/precise_sleep.hpp"
#include "util/Sleeper.hpp"

class TestReactor : public test_util::TestBase<TestReactor> {
public:
Expand All @@ -45,7 +45,7 @@ class TestReactor : public test_util::TestBase<TestReactor> {
default_thread_id = std::this_thread::get_id();
events.push_back("Step<2>");
// Sleep for a bit to coax out any more idle triggers
NUClear::util::precise_sleep(test_util::TimeUnit(2));
NUClear::util::Sleeper().sleep_for(test_util::TimeUnit(2));
powerplant.shutdown();
});

Expand Down
4 changes: 2 additions & 2 deletions tests/tests/dsl/IdleGlobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "test_util/TestBase.hpp"
#include "test_util/TimeUnit.hpp"
#include "test_util/common.hpp"
#include "util/precise_sleep.hpp"
#include "util/Sleeper.hpp"

class TestReactor : public test_util::TestBase<TestReactor> {
public:
Expand Down Expand Up @@ -101,7 +101,7 @@ class TestReactor : public test_util::TestBase<TestReactor> {

static void wait_for_set(const std::atomic<bool>& flag) {
while (!flag.load(std::memory_order_acquire)) {
NUClear::util::precise_sleep(test_util::TimeUnit(1));
NUClear::util::Sleeper().sleep_for(test_util::TimeUnit(1));
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/tests/dsl/IdleSingle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "test_util/TestBase.hpp"
#include "test_util/TimeUnit.hpp"
#include "test_util/common.hpp"
#include "util/precise_sleep.hpp"
#include "util/Sleeper.hpp"

namespace Catch {

Expand Down Expand Up @@ -70,7 +70,7 @@ class TestReactor : public test_util::TestBase<TestReactor> {
on<Trigger<TaskA>, Pool<>, Sync<TestReactor>>().then([this](const TaskA& t) {
entry_calls[t.i].fetch_add(1, std::memory_order_relaxed);
emit(std::make_unique<TaskB>(t.i));
NUClear::util::precise_sleep(std::chrono::milliseconds(1));
NUClear::util::Sleeper().sleep_for(std::chrono::milliseconds(1));
});

// Run this at low priority but have it first
Expand Down
6 changes: 3 additions & 3 deletions tests/tests/dsl/IdleSync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@
#include "test_util/TestBase.hpp"
#include "test_util/TimeUnit.hpp"
#include "test_util/common.hpp"
#include "util/precise_sleep.hpp"
#include "util/Sleeper.hpp"

class TestReactor : public test_util::TestBase<TestReactor> {
public:
explicit TestReactor(std::unique_ptr<NUClear::Environment> environment) : TestBase(std::move(environment), false) {

on<Trigger<Step<1>>, MainThread>().then([this] {
emit(std::make_unique<Step<2>>());
NUClear::util::precise_sleep(test_util::TimeUnit(1));
NUClear::util::Sleeper().sleep_for(test_util::TimeUnit(1));
emit(std::make_unique<Step<3>>());
});

// Idle testing for default thread
on<Trigger<Step<2>>, Sync<TestReactor>>().then([this] {
add_event("Default Start");
NUClear::util::precise_sleep(test_util::TimeUnit(3));
NUClear::util::Sleeper().sleep_for(test_util::TimeUnit(3));
add_event("Default End");
});

Expand Down
8 changes: 5 additions & 3 deletions tests/tests/dsl/Inline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "test_util/TestBase.hpp"
#include "test_util/TimeUnit.hpp"
#include "test_util/common.hpp"
#include "util/precise_sleep.hpp"
#include "util/Sleeper.hpp"

class TestReactor : public test_util::TestBase<TestReactor> {
public:
Expand Down Expand Up @@ -61,12 +61,14 @@ class TestReactor : public test_util::TestBase<TestReactor> {
on<Trigger<Step<1>>, MainThread>().then([this] {
emit(std::make_unique<SimpleMessage>("Main Local"));
emit<Scope::INLINE>(std::make_unique<SimpleMessage>("Main Inline"));
NUClear::util::precise_sleep(test_util::TimeUnit(2)); // Sleep for a bit to give other threads a chance
NUClear::util::Sleeper().sleep_for(
test_util::TimeUnit(2)); // Sleep for a bit to give other threads a chance
});
on<Trigger<Step<2>>, Pool<>>().then([this] {
emit(std::make_unique<SimpleMessage>("Default Local"));
emit<Scope::INLINE>(std::make_unique<SimpleMessage>("Default Inline"));
NUClear::util::precise_sleep(test_util::TimeUnit(2)); // Sleep for a bit to give other threads a chance
NUClear::util::Sleeper().sleep_for(
test_util::TimeUnit(2)); // Sleep for a bit to give other threads a chance
});

on<Startup>().then([this] {
Expand Down
14 changes: 7 additions & 7 deletions tests/tests/dsl/Sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "test_util/TestBase.hpp"
#include "test_util/TimeUnit.hpp"
#include "test_util/common.hpp"
#include "util/precise_sleep.hpp"
#include "util/Sleeper.hpp"

class TestReactor : public test_util::TestBase<TestReactor> {
public:
Expand All @@ -42,14 +42,14 @@ class TestReactor : public test_util::TestBase<TestReactor> {
events.push_back("Sync A " + m.data);

// Sleep for some time to be safe
NUClear::util::precise_sleep(test_util::TimeUnit(1));
NUClear::util::Sleeper().sleep_for(test_util::TimeUnit(1));

// Emit a message 1 here, it should not run yet
events.push_back("Sync A emitting");
emit(std::make_unique<Message<1>>("From Sync A"));

// Sleep for some time again
NUClear::util::precise_sleep(test_util::TimeUnit(1));
NUClear::util::Sleeper().sleep_for(test_util::TimeUnit(1));

events.push_back("Sync A " + m.data + " finished");
});
Expand All @@ -58,14 +58,14 @@ class TestReactor : public test_util::TestBase<TestReactor> {
events.push_back("Sync B " + m.data);

// Sleep for some time to be safe
NUClear::util::precise_sleep(test_util::TimeUnit(1));
NUClear::util::Sleeper().sleep_for(test_util::TimeUnit(1));

// Emit a message 1 here, it should not run yet
events.push_back("Sync B emitting");
emit(std::make_unique<Message<1>>("From Sync B"));

// Sleep for some time again
NUClear::util::precise_sleep(test_util::TimeUnit(1));
NUClear::util::Sleeper().sleep_for(test_util::TimeUnit(1));

events.push_back("Sync B " + m.data + " finished");
});
Expand All @@ -74,13 +74,13 @@ class TestReactor : public test_util::TestBase<TestReactor> {
events.push_back("Sync C " + m.data);

// Sleep for some time to be safe
NUClear::util::precise_sleep(test_util::TimeUnit(1));
NUClear::util::Sleeper().sleep_for(test_util::TimeUnit(1));

// Emit a message 1 here, it should not run yet
events.push_back("Sync C waiting");

// Sleep for some time again
NUClear::util::precise_sleep(test_util::TimeUnit(1));
NUClear::util::Sleeper().sleep_for(test_util::TimeUnit(1));

events.push_back("Sync C " + m.data + " finished");

Expand Down
4 changes: 2 additions & 2 deletions tests/tests/dsl/SyncMulti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "test_util/TestBase.hpp"
#include "test_util/TimeUnit.hpp"
#include "test_util/common.hpp"
#include "util/precise_sleep.hpp"
#include "util/Sleeper.hpp"

class TestReactor : public test_util::TestBase<TestReactor> {
public:
Expand All @@ -37,7 +37,7 @@ class TestReactor : public test_util::TestBase<TestReactor> {
auto start = test_util::round_to_test_units(std::chrono::steady_clock::now() - start_time);
events.push_back(event + " started @ " + std::to_string(start.count()));
// Sleep for a bit to give a chance for the other threads to cause problems
NUClear::util::precise_sleep(test_util::TimeUnit(2));
NUClear::util::Sleeper().sleep_for(test_util::TimeUnit(2));
auto end = test_util::round_to_test_units(std::chrono::steady_clock::now() - start_time);
events.push_back(event + " finished @ " + std::to_string(end.count()));
}
Expand Down

0 comments on commit 589435e

Please sign in to comment.