Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Slightly better test
Browse files Browse the repository at this point in the history
TrentHouliston committed Nov 30, 2023
1 parent 7879c3f commit b0ce045
Showing 3 changed files with 31 additions and 32 deletions.
18 changes: 1 addition & 17 deletions src/dsl/word/Idle.hpp
Original file line number Diff line number Diff line change
@@ -70,23 +70,7 @@ namespace dsl {
struct Idle {
template <typename DSL>
static inline void bind(const std::shared_ptr<threading::Reaction>& reaction) {
bind_idle(reaction, Pool<PoolType>::template pool<DSL>(*reaction));
}
};

template <>
struct Idle<Pool<>> {
template <typename DSL>
static inline void bind(const std::shared_ptr<threading::Reaction>& reaction) {
bind_idle(reaction, Pool<>::template pool<DSL>(*reaction));
}
};

template <>
struct Idle<MainThread> {
template <typename DSL>
static inline void bind(const std::shared_ptr<threading::Reaction>& reaction) {
bind_idle(reaction, MainThread::pool<DSL>(*reaction));
bind_idle(reaction, PoolType::template pool<DSL>(*reaction));
}
};

1 change: 1 addition & 0 deletions src/dsl/word/Pool.hpp
Original file line number Diff line number Diff line change
@@ -84,6 +84,7 @@ namespace dsl {
}
};

// When given void as the pool type we use the default thread pool
template <>
struct Pool<void> {
template <typename DSL>
44 changes: 29 additions & 15 deletions tests/dsl/Idle.cpp
Original file line number Diff line number Diff line change
@@ -35,9 +35,9 @@ struct SimpleMessage {
int data;
};

constexpr int time_step = 50;
constexpr int time_step = 100;

class TestReactor : public test_util::TestBase<TestReactor> {
class TestReactor : public test_util::TestBase<TestReactor, 10000> {
public:
struct CustomPool {
static constexpr int thread_count = 2;
@@ -52,42 +52,56 @@ class TestReactor : public test_util::TestBase<TestReactor> {

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

start_time = NUClear::clock::now();

// Idle testing for default thread
on<Startup>().then([this] { do_step<1>("Default Startup"); });
on<Trigger<Step<1>>>().then([this] { do_step<1>("Default Startup"); });
on<Trigger<Step<2>>>().then([this] { do_step<2>("Default Step"); });
on<Trigger<Step<3>>>().then([this] { do_step<3>("Default Step"); });
on<Idle<Pool<>>>().then([this] { do_step<4>("Default Idle"); });
drh = on<Idle<Pool<>>>().then([this] { do_step<4>("Default Idle"); });
on<Trigger<Step<5>>>().then([this] { do_step<5>("Default Step"); });
on<Trigger<Step<6>>>().then([this] { do_step<6>("Default Step"); });
on<Trigger<Step<7>>>().then([this] { do_step<7>("Default Step"); });
on<Trigger<Step<8>>>().then([this] { drh.unbind(); });

// Idle testing for main thread
on<Startup, MainThread>().then([this] { do_step<8>("Main Startup"); });
on<Trigger<Step<9>>, MainThread>().then([this] { do_step<9>("Main Step"); });
on<Trigger<Step<9>>, MainThread>().then([this] { do_step<9>("Main Startup"); });
on<Trigger<Step<10>>, MainThread>().then([this] { do_step<10>("Main Step"); });
on<Idle<MainThread>>().then([this] { do_step<11>("Main Idle"); });
on<Trigger<Step<12>>, MainThread>().then([this] { do_step<12>("Main Step"); });
on<Trigger<Step<11>>, MainThread>().then([this] { do_step<11>("Main Step"); });
mrh = on<Idle<MainThread>>().then([this] { do_step<12>("Main Idle"); });
on<Trigger<Step<13>>, MainThread>().then([this] { do_step<13>("Main Step"); });
on<Trigger<Step<14>>, MainThread>().then([this] { do_step<14>("Main Step"); });
on<Trigger<Step<15>>, MainThread>().then([this] { do_step<15>("Main Step"); });
on<Trigger<Step<15>>, MainThread>().then([this] { mrh.unbind(); });

// Idle testing for custom pool
on<Startup, Pool<CustomPool>>().then([this] { do_step<15>("Custom Startup"); });
on<Trigger<Step<16>>, Pool<CustomPool>>().then([this] { do_step<16>("Custom Step"); });
on<Trigger<Step<16>>, Pool<CustomPool>>().then([this] { do_step<16>("Custom Startup"); });
on<Trigger<Step<17>>, Pool<CustomPool>>().then([this] { do_step<17>("Custom Step"); });
on<Idle<Pool<CustomPool>>>().then([this] { do_step<18>("Custom Idle"); });
on<Trigger<Step<18>>, Pool<CustomPool>>().then([this] { do_step<19>("Custom Step"); });
on<Trigger<Step<19>>, Pool<CustomPool>>().then([this] { do_step<20>("Custom Step"); });
on<Trigger<Step<20>>, Pool<CustomPool>>().then([this] { do_step<21>("Custom Step"); });
on<Trigger<Step<18>>, Pool<CustomPool>>().then([this] { do_step<18>("Custom Step"); });
crh = on<Idle<Pool<CustomPool>>>().then([this] { do_step<19>("Custom Idle"); });
on<Trigger<Step<20>>, Pool<CustomPool>>().then([this] { do_step<20>("Custom Step"); });
on<Trigger<Step<21>>, Pool<CustomPool>>().then([this] { do_step<21>("Custom Step"); });
on<Trigger<Step<22>>, Pool<CustomPool>>().then([this] { do_step<22>("Custom Step"); });
on<Trigger<Step<23>>, Pool<CustomPool>>().then([this] { crh.unbind(); });

// Global idle everything finished
on<Idle<>>().then([this] {
events.push_back("Global Idle");
powerplant.shutdown();
});

on<Startup>().then([this] {
emit(std::make_unique<Step<1>>());
emit(std::make_unique<Step<9>>());
emit(std::make_unique<Step<16>>());
});
}

private:
NUClear::clock::time_point start_time = NUClear::clock::now();
NUClear::clock::time_point start_time;
NUClear::threading::ReactionHandle drh;
NUClear::threading::ReactionHandle mrh;
NUClear::threading::ReactionHandle crh;
};

} // namespace

0 comments on commit b0ce045

Please sign in to comment.