Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor tests to use an event style and fix some found bugs #70

Merged
merged 188 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
188 commits
Select commit Hold shift + click to select a range
ce05976
Refactor tests to use an event style
TrentHouliston Jul 21, 2023
c72cafe
Refactor some more tests
TrentHouliston Jul 21, 2023
b602864
Refactor trigger
TrentHouliston Jul 21, 2023
cdbb213
Refactor last
TrentHouliston Jul 21, 2023
0d091fd
More refactored tests
TrentHouliston Jul 21, 2023
05c8192
Missing header for strlen
TrentHouliston Jul 21, 2023
584d88b
clang-tidy
TrentHouliston Jul 21, 2023
bdfc9b0
IO test
TrentHouliston Jul 26, 2023
3c07855
Reaction handle
TrentHouliston Jul 26, 2023
cd1fa6f
Optional test
TrentHouliston Jul 26, 2023
ce46a53
Replace single test with more robust buffer test
TrentHouliston Jul 27, 2023
441103b
clang-tidy
TrentHouliston Jul 27, 2023
7f310fd
Fix IO test as read/write could be out of order
TrentHouliston Jul 27, 2023
2967a18
Sync order test is pretty good already
TrentHouliston Jul 27, 2023
a24577f
Priority test
TrentHouliston Aug 3, 2023
3acb343
Shutdown test
TrentHouliston Aug 3, 2023
fdcbd0b
Raw function test
TrentHouliston Aug 3, 2023
11463a6
Combine and improve the every test
TrentHouliston Aug 3, 2023
d9580da
Swap argument fission test to do an implicit conversion
TrentHouliston Aug 3, 2023
a59b120
Fix the bug with dynamic every
TrentHouliston Aug 3, 2023
65cafe4
Fix shadow
TrentHouliston Aug 3, 2023
2ebb063
Sync test
TrentHouliston Aug 3, 2023
deff1ef
Watchdog test
TrentHouliston Aug 3, 2023
919e41d
remove weird comment
TrentHouliston Aug 3, 2023
46cd107
Floor is safer than round
TrentHouliston Aug 3, 2023
0cd84de
Update custom clock test
TrentHouliston Aug 3, 2023
62cb8f0
Finished time is closer to the correct time
TrentHouliston Aug 3, 2023
fc3664f
Split off the DSL ordering test and add a proper With test
TrentHouliston Aug 3, 2023
e2be993
Fix some tests
TrentHouliston Aug 3, 2023
f05015b
Make watchdog behave like every with a stable tick rate
TrentHouliston Aug 3, 2023
43ac810
Improve transients test
TrentHouliston Aug 3, 2023
715b5c7
Reaction statistics test
TrentHouliston Aug 3, 2023
4670b60
revamp the TCP test
TrentHouliston Aug 4, 2023
5bd1006
error
TrentHouliston Aug 4, 2023
10b4f22
Make ReactionStatistics test more repeatable
TrentHouliston Aug 4, 2023
286a258
Include fnctl
TrentHouliston Aug 4, 2023
f35f6d6
ok
TrentHouliston Aug 4, 2023
d9cd03a
Windows error
TrentHouliston Aug 4, 2023
abcdcfb
clang-tidy
TrentHouliston Aug 4, 2023
0943208
/shrug
TrentHouliston Aug 4, 2023
a435df9
Make test end at the end
TrentHouliston Aug 4, 2023
07af03f
Fix
TrentHouliston Aug 4, 2023
1b58247
clang-tidy
TrentHouliston Aug 4, 2023
f513224
clang-tidy
TrentHouliston Aug 4, 2023
929d4a1
clang-tidy
TrentHouliston Aug 4, 2023
a5ea925
.
TrentHouliston Aug 4, 2023
f49212d
.
TrentHouliston Aug 4, 2023
2b5c7e6
windows
TrentHouliston Aug 4, 2023
ffbf130
Windows!!! "shakes fist"
TrentHouliston Aug 5, 2023
7473fd0
windows wants to be difficult
TrentHouliston Aug 5, 2023
41c91b5
more windows nonsense
TrentHouliston Aug 7, 2023
dcb3044
clang tidy rules
TrentHouliston Aug 7, 2023
59fb065
clang-tidy
TrentHouliston Aug 7, 2023
44b35ca
Refactor and update the IO/TCP to make it's behaviour more consistent…
TrentHouliston Aug 9, 2023
9173fd0
OSX closes differently
TrentHouliston Aug 9, 2023
f0a12f4
fix warnings clang-tidy etc
TrentHouliston Aug 9, 2023
1e5c5e9
Test margin of 1ms
TrentHouliston Aug 9, 2023
2a5fbf3
clang-tidy
TrentHouliston Aug 9, 2023
5f8daa9
windows platform changes
TrentHouliston Aug 9, 2023
414034f
clang-tidy
TrentHouliston Aug 9, 2023
c0e9081
Fix the reactor name for windows
TrentHouliston Aug 9, 2023
96e2000
Fix log level
TrentHouliston Aug 9, 2023
54a4e7b
/shrug
TrentHouliston Aug 9, 2023
c6c57bc
Didn't mean to swap both
TrentHouliston Aug 9, 2023
7c217c8
How could this possibly have made windows fail to run reaction statis…
TrentHouliston Aug 9, 2023
df816d7
How does this make reaction stats not run on windows?
TrentHouliston Aug 9, 2023
7b26974
Move the demangling normalisation into demangle
TrentHouliston Aug 10, 2023
dca757d
.
TrentHouliston Aug 10, 2023
fff3a4b
.
TrentHouliston Aug 10, 2023
cd9a11f
Demangle
TrentHouliston Aug 10, 2023
ac1b471
Review comments
TrentHouliston Aug 10, 2023
41ce4f4
more review comments
TrentHouliston Aug 10, 2023
6831bf1
Build already!
TrentHouliston Aug 10, 2023
edeefa3
Test a potential refactor for chrono controller to improve windows ac…
TrentHouliston Aug 10, 2023
2df9f82
.
TrentHouliston Aug 10, 2023
4daf418
.
TrentHouliston Aug 10, 2023
92781e4
.
TrentHouliston Aug 10, 2023
5da9e10
I don't even need those!
TrentHouliston Aug 10, 2023
e741d47
.
TrentHouliston Aug 10, 2023
4fed00d
.
TrentHouliston Aug 10, 2023
37a7a4b
.
TrentHouliston Aug 10, 2023
59ce1f1
See if this makes windows pass the tests
TrentHouliston Aug 10, 2023
5440261
Try a few loops to get better wait accuracy
TrentHouliston Aug 10, 2023
9752334
Remove connection accepted from TCP as it's implied by having a conne…
TrentHouliston Aug 10, 2023
c0f7484
clang-tidy
TrentHouliston Aug 10, 2023
e2a5349
Continuously update the error
TrentHouliston Aug 11, 2023
251ddd6
Merge branch 'main' into houliston/testrefactor
TrentHouliston Aug 11, 2023
19a61dd
.
TrentHouliston Aug 11, 2023
6abd417
Attempt to update the windows iocontroller to be similar to posix
TrentHouliston Aug 11, 2023
9d3149e
.
TrentHouliston Aug 11, 2023
401c13f
.
TrentHouliston Aug 11, 2023
31bda94
.
TrentHouliston Aug 11, 2023
f7f0d1f
.
TrentHouliston Aug 11, 2023
3613ffd
.
TrentHouliston Aug 11, 2023
7d38150
.
TrentHouliston Aug 11, 2023
6793e0c
.
TrentHouliston Aug 11, 2023
6ff441f
Try the same bytes trick on windows
TrentHouliston Aug 11, 2023
fb9c844
Windows loves being different
TrentHouliston Aug 11, 2023
907d5d7
Doubt this makes a difference
TrentHouliston Aug 11, 2023
9cd6016
Make it clearer that it's a bitwise or
TrentHouliston Aug 11, 2023
38144fc
Try disabling the eof detector again?
TrentHouliston Aug 11, 2023
d6efc49
.
TrentHouliston Aug 11, 2023
f4351c7
Add timeouts to UDP
TrentHouliston Aug 11, 2023
6cd5a3e
Update min cmake version
TrentHouliston Aug 11, 2023
0261a49
This works fine locally
TrentHouliston Aug 11, 2023
3c46aa9
clang-tidy
TrentHouliston Aug 11, 2023
db1075d
Add timeouts to emit tests (need to refactor these)
TrentHouliston Aug 11, 2023
8dad0a4
Update the delay test
TrentHouliston Aug 14, 2023
636b86a
Update emit fusion test
TrentHouliston Aug 14, 2023
a0c9517
Refactor the task scheduler to take generic tasks and use it to updat…
TrentHouliston Aug 15, 2023
d772d5d
Try fix older gcc/clang
TrentHouliston Aug 15, 2023
24baaed
clang-tidy
TrentHouliston Aug 15, 2023
e89e351
Fix shadowing
TrentHouliston Aug 15, 2023
3027a7a
Merge branch 'main' into houliston/testrefactor
TrentHouliston Aug 15, 2023
800dd85
Merge branch 'main' into houliston/testrefactor
TrentHouliston Aug 16, 2023
990d4d4
Merge branch 'main' into houliston/testrefactor
TrentHouliston Aug 16, 2023
49bc5b8
Clang-tidy
TrentHouliston Aug 17, 2023
0f0b033
Move socket size onto sock_t as a member
TrentHouliston Aug 18, 2023
cf408cc
Add a resolve utility
TrentHouliston Aug 18, 2023
d620443
Lots of refactoring and combining tests
TrentHouliston Aug 22, 2023
f237931
add unit tests for resolve
TrentHouliston Aug 22, 2023
a725768
Remove couts
TrentHouliston Aug 22, 2023
3cccf8f
Add expected output
TrentHouliston Aug 22, 2023
6058466
.
TrentHouliston Aug 22, 2023
77009b2
Fix filtering and make UDP tests pass
TrentHouliston Aug 24, 2023
c1ba0c0
Update NUClearNet based on changes to UDP
TrentHouliston Aug 24, 2023
b0170d5
fixes from osx
TrentHouliston Aug 24, 2023
238409e
clang-tidy
TrentHouliston Aug 24, 2023
ce31581
clang-tidy
TrentHouliston Aug 24, 2023
967c202
Bind IPv6 tests to any rather than localhost
TrentHouliston Aug 24, 2023
aa9260f
Fix IPv6 problems on osx
TrentHouliston Aug 31, 2023
6389d8b
Remove unused code
TrentHouliston Aug 31, 2023
2f11c3f
No need for memset when doing {} initialisation
TrentHouliston Aug 31, 2023
27afc80
clang-tidy
TrentHouliston Aug 31, 2023
7b7c99f
Try to fix windows build
TrentHouliston Aug 31, 2023
41cc1a8
clang-tidy
TrentHouliston Sep 1, 2023
236522d
clang-tidy
TrentHouliston Sep 4, 2023
36e9567
Test for ipv6 to see if the runners have it
TrentHouliston Sep 4, 2023
c48e91a
add a test utility to check if any interface has ipv6
TrentHouliston Sep 4, 2023
77c184e
use locally built nuclear in tests
TrentHouliston Sep 4, 2023
547a664
Make the TCP test only do IPv6 tests if there is IPv6
TrentHouliston Sep 4, 2023
d2c425a
Allow the UDP test to dynamically test for IPv6 if available
TrentHouliston Sep 4, 2023
5b5185b
Print out on success
TrentHouliston Sep 4, 2023
fc6262f
clang-tidy
TrentHouliston Sep 4, 2023
4a02617
Merge branch 'main' into houliston/testrefactor
TrentHouliston Sep 4, 2023
7964c4e
Merge branch 'main' into houliston/testrefactor
TrentHouliston Sep 5, 2023
c38ea4b
Merge remote-tracking branch 'origin/main' into houliston/testrefactor
TrentHouliston Sep 5, 2023
c717de9
Fix return before close
TrentHouliston Sep 5, 2023
5674920
Some cmake fixes
TrentHouliston Sep 5, 2023
6adbd4d
Make the sync order test check the sequence
TrentHouliston Sep 5, 2023
deb553b
Add numeric header
TrentHouliston Sep 5, 2023
aa6060b
Just add a check on timeout so the rest of the checks print still
TrentHouliston Sep 5, 2023
e2cd44e
Move WSA to a static holder so I don't have to think about it
TrentHouliston Sep 5, 2023
64de873
Make TCP timeout on error
TrentHouliston Sep 5, 2023
b550ac5
.
TrentHouliston Sep 5, 2023
580c8f3
Shutdown before catch does stuff
TrentHouliston Sep 5, 2023
5b3d043
...
TrentHouliston Sep 5, 2023
69d55ed
.
TrentHouliston Sep 5, 2023
22a3640
Fix instance
TrentHouliston Sep 5, 2023
19f41f8
Windows can't do leading 0s and it's not that important
TrentHouliston Sep 6, 2023
0811e5f
Refactor the iocontroller to make it handle event timing better
TrentHouliston Sep 6, 2023
4a78e2b
Fix closes on linux
TrentHouliston Sep 8, 2023
7e9d1c9
clang-tidy
TrentHouliston Sep 8, 2023
4511323
Make the IO read read as much as it can
TrentHouliston Sep 8, 2023
49a21cc
More time for tests
TrentHouliston Sep 8, 2023
6e43eee
Merge branch 'main' into houliston/testrefactor
TrentHouliston Sep 10, 2023
a1e3276
Merge branch 'main' into houliston/testrefactor
TrentHouliston Sep 10, 2023
9124ec8
Merge branch 'main' into houliston/testrefactor
TrentHouliston Sep 15, 2023
7a62355
Make the IO nonblocking to avoid hanging
TrentHouliston Sep 15, 2023
b9a5131
clang-tidy
TrentHouliston Sep 15, 2023
d0155be
lint rule no longer violated
TrentHouliston Sep 15, 2023
13b4602
Add a test for demangle
TrentHouliston Sep 15, 2023
acaf2f9
Add license string
TrentHouliston Sep 15, 2023
824a7d0
Remove unused code
TrentHouliston Sep 15, 2023
33ab54c
Add exceptions when sending fails
TrentHouliston Sep 15, 2023
245287d
Windows returns "??" sometimes for demangle
TrentHouliston Sep 15, 2023
9fa1ada
Always return the if number even if it's not multicast
TrentHouliston Sep 15, 2023
733b02d
Formatting
TrentHouliston Sep 15, 2023
526e660
Change UDP test so it works on linux
TrentHouliston Sep 15, 2023
e66f493
Just short circuit for empty strings
TrentHouliston Sep 15, 2023
08d522a
Remove -s it's too hard to read
TrentHouliston Sep 15, 2023
8a5200f
Windows hates resolving ipv6 sometimes
TrentHouliston Sep 15, 2023
8fa71c4
Who let this obvious bug through!
TrentHouliston Sep 15, 2023
fdf098c
Increase timeouts (CI is slow) and add log line for when echos time out
TrentHouliston Sep 15, 2023
93f2a1c
.
TrentHouliston Sep 15, 2023
73cfd62
.
TrentHouliston Sep 15, 2023
aeb5ad9
Merge branch 'main' into houliston/testrefactor
TrentHouliston Sep 16, 2023
c3702ea
Merge branch 'main' into houliston/testrefactor
TrentHouliston Sep 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/PowerPlant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ void PowerPlant::start() {
// We are now running
is_running.store(true);

// Direct emit startup event
// Direct emit startup event and command line arguments
emit<dsl::word::emit::Direct>(std::make_unique<dsl::word::Startup>());
emit_shared<dsl::word::emit::Direct>(dsl::store::DataStore<message::CommandLineArguments>::get());

// Start all of the threads
scheduler.start();
Expand Down
3 changes: 1 addition & 2 deletions src/PowerPlant.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ inline PowerPlant::PowerPlant(Configuration config, int argc, const char* argv[]
args.emplace_back(argv[i]);
}

// We emit this twice, so the data is available for extensions
// We emit this twice, so the data is available for extensions, it will also be emitted in start
emit(std::make_unique<message::CommandLineArguments>(args));
emit<dsl::word::emit::Initialise>(std::make_unique<message::CommandLineArguments>(args));
}

template <typename T, enum LogLevel level>
Expand Down
7 changes: 6 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ if(CATCH_FOUND)
add_compile_options(-Wall -Wextra -pedantic -Werror)
endif(MSVC)

file(GLOB test_src test.cpp "api/*.cpp" "dsl/*.cpp" "dsl/emit/*.cpp" "log/*.cpp")
add_compile_definitions(CATCH_CONFIG_CONSOLE_WIDTH=120)

file(GLOB test_src test.cpp "api/*.cpp" "dsl/*.cpp" "dsl/emit/*.cpp" "log/*.cpp" "test_util/*.cpp")

# Some tests must be executed as individual binaries
file(GLOB individual_tests "${CMAKE_CURRENT_SOURCE_DIR}/individual/*.cpp")
Expand All @@ -40,6 +42,7 @@ if(CATCH_FOUND)
add_executable(${test_name} ${test_src})
target_link_libraries(${test_name} NUClear::nuclear)
set_target_properties(${test_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/individual")
target_include_directories(${test_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(
${test_name} SYSTEM
PRIVATE ${CATCH_INCLUDE_DIRS} ${PROJECT_BINARY_DIR}/include "${PROJECT_SOURCE_DIR}/src"
Expand All @@ -51,6 +54,7 @@ if(CATCH_FOUND)
endforeach(test_src)

add_executable(test_nuclear ${test_src})
target_include_directories(test_nuclear PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(test_nuclear NUClear::nuclear)
target_include_directories(
test_nuclear SYSTEM
Expand All @@ -60,6 +64,7 @@ if(CATCH_FOUND)

add_executable(test_network networktest.cpp)
target_link_libraries(test_network NUClear::nuclear)
target_include_directories(test_network PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(
test_network SYSTEM
PRIVATE ${CATCH_INCLUDE_DIRS} ${PROJECT_BINARY_DIR}/include "${PROJECT_SOURCE_DIR}/src"
Expand Down
54 changes: 42 additions & 12 deletions tests/api/ReactionHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,67 @@
#include <catch.hpp>
#include <nuclear>

#include "test_util/TestBase.hpp"

// Anonymous namespace to keep everything file local
namespace {

template <int id>
struct Message {};
/// @brief Events that occur during the test
std::vector<std::string> events; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)

struct Message {
Message(int i) : i(i) {}
int i;
};

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

// Make an always disabled reaction
ReactionHandle a =
on<Trigger<Message<0>>, Priority::HIGH>().then([] { FAIL("This reaction is disabled always"); });
a = on<Trigger<Message>, Priority::HIGH>().then([](const Message& msg) { //
events.push_back("Executed disabled reaction " + std::to_string(msg.i));
});
a.disable();

const ReactionHandle b = on<Trigger<Message<0>>>().then([this] { powerplant.shutdown(); });
// Make a reaction that we toggle on and off
b = on<Trigger<Message>, Priority::HIGH>().then([this](const Message& msg) { //
events.push_back("Executed toggled reaction " + std::to_string(msg.i));
b.disable();
emit(std::make_unique<Message>(1));
});

on<Trigger<Message>>().then([](const Message& msg) { //
events.push_back("Executed enabled reaction " + std::to_string(msg.i));
});

// Start our test
on<Startup>().then([this] { emit(std::make_unique<Message<0>>()); });
on<Startup>().then([this] { //
emit(std::make_unique<Message>(0));
});
}

ReactionHandle a{};
ReactionHandle b{};
};
} // namespace

TEST_CASE("Testing reaction handle functionality", "[api][reactionhandle]") {

NUClear::PowerPlant::Configuration config;
config.thread_count = 1;
NUClear::PowerPlant plant(config);

// We are installing with an initial log level of debug
plant.install<TestReactor>();

plant.start();

std::vector<std::string> expected = {
"Executed toggled reaction 0",
"Executed enabled reaction 0",
"Executed enabled reaction 1",
};

// Make an info print the diff in an easy to read way if we fail
INFO(test_util::diff_string(expected, events));

// Check the events fired in order and only those events
REQUIRE(events == expected);
}
67 changes: 41 additions & 26 deletions tests/dsl/Always.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,67 @@
#include <catch.hpp>
#include <nuclear>

#include "test_util/TestBase.hpp"

namespace {
struct BlankMessage {};

int i = 0; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
bool emitted_message = false; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
/// @brief Events that occur during the test
std::vector<std::string> events; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)

struct SimpleMessage {};

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

on<Always>().then([this] {
// Run until it's 11 then emit the blank message
if (i > 10) {
if (!emitted_message) {
emitted_message = true;
emit(std::make_unique<BlankMessage>());
}
}
else {
if (i < 10) {
events.push_back("Always " + std::to_string(i));
++i;
}
else if (i == 10) {
emit(std::make_unique<SimpleMessage>());
}
});

on<Always, With<BlankMessage>>().then([this] {
if (i == 11) {
++i;
powerplant.shutdown();
}
on<Always, With<SimpleMessage>>().then([this] {
events.push_back("Always with SimpleMessage " + std::to_string(i));

// We need to shutdown manually as the default pool will always be idle
powerplant.shutdown();
});
}

/// Counter for the number of times we have run
int i = 0;
};
} // namespace

TEST_CASE("Testing on<Always> functionality (permanent run)", "[api][always]") {
TEST_CASE("The Always DSL keyword runs continuously when it can", "[api][always]") {

NUClear::PowerPlant::Configuration config;
config.thread_count = 1;
NUClear::PowerPlant plant(config);
plant.install<TestReactor>();
plant.start();

// We are installing with an initial log level of debug
plant.install<TestReactor, NUClear::DEBUG>();

plant.emit(std::make_unique<int>(5));
std::vector<std::string> expected = {
"Always 0",
"Always 1",
"Always 2",
"Always 3",
"Always 4",
"Always 5",
"Always 6",
"Always 7",
"Always 8",
"Always 9",
"Always with SimpleMessage 10",
};

plant.start();
// Make an info print the diff in an easy to read way if we fail
INFO(test_util::diff_string(expected, events));

REQUIRE(emitted_message);
REQUIRE(i == 12);
// Check the events fired in order and only those events
REQUIRE(events == expected);
}
Loading
Loading