-
Notifications
You must be signed in to change notification settings - Fork 18
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
Capture and inspect all logs in Catch2 tests, fix race #234
Conversation
Check-perf-impact results: (4c65f1399a47e0eb1340f63004745b17) ❓ No new benchmark data submitted. ❓ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. It's a bit silly that this took so much infrastructure to do, but it's great to be rid of that race condition.
360a5a5
to
a4276d9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work! I've added one small note. Also you could maybe consider squashing some of the commits before merging.
The one concern I have with this design (which is already infinitely better than what we had before!) is that by setting e.g. allow_max_log_level(detail::log_level::warn)
, a test might inadvertently swallow some additional, unexpected warnings. There's already a mechanism that could kind of deal with that (allow_higher_level_log_messages
), but then we'd have to repeat the message twice (once to allow it, and once to check that it actually was emitted). I'm just spitballing here, and this doesn't have to be in v1, but maybe something like this could work?
TEST_CASE("my test") {
test_utils::log_inspector logs;
logs.allow_max_level(detail::log_level::info); // no-op as info would be the default
// do stuff
CHECK(logs.contains(detail::log_level::warn, "some warning"));
CHECK(logs.contains(detail::log_level::error, "some error"));
// if there's any unconsumed messages > info once log_inspector goes out of scope, fail test in destructor.
}
71fe151
to
7bda070
Compare
I agree, finer control over which warnings to allow would be great in a follow-up PR! I have created an issue about this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
7bda070
to
0108a80
Compare
This fixes a long-standing race condition that existed with test_utils::log_capture, which is has now been removed. Tests now unconditionally capturing logs in the global thread-safe test_utils::log_test_capture. This allows the test code to query captured messages, and will echo the captured logs through a global Catch2 hook if the test fails. By default, this mechanism will fail any test that logs a warning or error, but it provides functions to relax that behavior either explicitly through test_utils::allow_max_log_level or implicitly through runtime_fixture / device_queue_fixture which permit system-dependent warnings to appear. The "log.h" interface has also been simplified somewhat.
0108a80
to
da8e3b4
Compare
This PR completely redefines how logging is handled inside unit tests.
It works by unconditionally capturing logs in the global thread-safe
test_utils::log_test_capture
. This allows the test code to query captured messages, and will echo the captured logs through a global Catch2 hook if the test fails. By default, this mechanism will fail any test that logs a warning or error, but it provides functions to relax that behavior either explicitly throughtest_utils::allow_max_log_level
or implicitly throughruntime_fixture
/device_queue_fixture
which permit system-dependent warnings to appear.The new mechanism is fully independent of the
CELERITY_LOG_LEVEL
environment, both in which messages it captures and also which ones it dumps in case of a test failure.Some refactorings and fixes happened alogn the way:
log_context
and its printing was unnecessarily complexutils::panic
independent of LOG_LEVEL when called from tests