remove fprintf, use logging macros#152
Merged
Karsten1987 merged 2 commits intomasterfrom Jul 27, 2017
Merged
Conversation
wjwwood
approved these changes
Jul 25, 2017
| fprintf(stderr, "No transition found for node %s with key %d\n", | ||
| state_machine->current_state->label, key); | ||
| RCUTILS_LOG_ERROR("No transition found for node %s with key %d", | ||
| state_machine->current_state->label, key) |
Member
There was a problem hiding this comment.
Nitpicks: some macros have ; after the closing parenthesis and some don't. I would expect (according to how the macros are implemented) to either fail to compile without the semi-colon or to produce a pedantic warning if they present and not needed
Member
There was a problem hiding this comment.
The macro invocation should not be followed by a semicolon. The rational is that the macros might evaluate to nothing in case the macro (or at least the specific log level) is being compiled out for efficiency reasons. At that point a trailing semicolon would be left.
rcl_lifecycle/src/rcl_lifecycle.c
Outdated
| #include "rcl_lifecycle/rcl_lifecycle.h" | ||
| #include "rcl_lifecycle/transition_map.h" | ||
|
|
||
| #include "rcutils/logging_macros.h" |
Member
There was a problem hiding this comment.
Nit: I think hat this should be imported with < like in the file above
00cc068 to
f5a75e2
Compare
emersonknapp
pushed a commit
to aws-ros-dev/rcl
that referenced
this pull request
Jun 3, 2019
Call rcutils_logging_shutdown() in TearDown
to avoid leaking logging internal objects.
As any change to this file makes test_logging_named
fail, this releaxes the EXACT_EQ call on
g_last_log_event.location->line_number[1]. Instead
of looking for a particular value, we test an invariant
of the field (line numbers are positive).
Finally, in test_logging_function, initialize g_counter
and g_function_called values to make sure the test will
not fail even if `--gtest_repeat=2` is passed.
Other tests are still failing when this flag is passed:
[ FAILED ] TestLoggingMacros.test_logging_once
[ FAILED ] TestLoggingMacros.test_logging_skipfirst
[ FAILED ] TestLoggingMacros.test_logging_skipfirst_throttle
However, fixing those tests would require actually changing
the logging implementation which is out of the scope of this
change.
Before:
$ ./test_logging_macros
Running main() from gmock_main.cc
[==========] Running 8 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 8 tests from TestLoggingMacros
[ RUN ] TestLoggingMacros.test_logging_named
[ OK ] TestLoggingMacros.test_logging_named (0 ms)
[ RUN ] TestLoggingMacros.test_logging_once
[ OK ] TestLoggingMacros.test_logging_once (0 ms)
[ RUN ] TestLoggingMacros.test_logging_expression
[ OK ] TestLoggingMacros.test_logging_expression (0 ms)
[ RUN ] TestLoggingMacros.test_logging_function
[ OK ] TestLoggingMacros.test_logging_function (0 ms)
[ RUN ] TestLoggingMacros.test_logging_skipfirst
[ OK ] TestLoggingMacros.test_logging_skipfirst (0 ms)
[ RUN ] TestLoggingMacros.test_logging_throttle
[ OK ] TestLoggingMacros.test_logging_throttle (302 ms)
[ RUN ] TestLoggingMacros.test_logging_skipfirst_throttle
[ OK ] TestLoggingMacros.test_logging_skipfirst_throttle (302 ms)
[ RUN ] TestLoggingMacros.test_logger_hierarchy
[ OK ] TestLoggingMacros.test_logger_hierarchy (0 ms)
[----------] 8 tests from TestLoggingMacros (605 ms total)
[----------] Global test environment tear-down
[==========] 8 tests from 1 test case ran. (605 ms total)
[ PASSED ] 8 tests.
=================================================================
==19903==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 504 byte(s) in 7 object(s) allocated from:
#0 0x7fd640c1fb50 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdeb50)
#1 0x7fd64091cbb5 in __default_allocate (/home/.../ros2_ws/install-asan/rcutils/lib/librcutils.so+0x8bb5)
#2 0x7fd64092f1b0 in rcutils_string_map_init (/home/.../ros2_ws/install-asan/rcutils/lib/librcutils.so+0x1b1b0)
#3 0x7fd640926641 in rcutils_logging_initialize_with_allocator (/home/.../ros2_ws/install-asan/rcutils/lib/librcutils.so+0x12641)
#4 0x7fd6409261ab in rcutils_logging_initialize (/home/.../ros2_ws/install-asan/rcutils/lib/librcutils.so+0x121ab)
#5 0x564405fc6627 in TestLoggingMacros::SetUp() (/home/.../ros2_ws/build-asan/rcutils/test_logging_macros+0x29627)
#6 0x564406045999 in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (/home/.../ros2_ws/build-asan/rcutils/test_logging_macros+0xa8999)
#7 0x564406037b7d in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (/home/.../ros2_ws/build-asan/rcutils/test_logging_macros+0x9ab7d)
#8 0x564405fe4503 in testing::Test::Run() (/home/.../ros2_ws/build-asan/rcutils/test_logging_macros+0x47503)
#9 0x564405fe59e4 in testing::TestInfo::Run() (/home/.../ros2_ws/build-asan/rcutils/test_logging_macros+0x489e4)
ros2#10 0x564405fe6588 in testing::TestCase::Run() (/home/.../ros2_ws/build-asan/rcutils/test_logging_macros+0x49588)
ros2#11 0x564406001699 in testing::internal::UnitTestImpl::RunAllTests() (/home/.../ros2_ws/build-asan/rcutils/test_logging_macros+0x64699)
ros2#12 0x56440604844c in bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) (/home/.../ros2_ws/build-asan/rcutils/test_logging_macros+0xab44c)
ros2#13 0x564406039e46 in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) (/home/.../ros2_ws/build-asan/rcutils/test_logging_macros+0x9ce46)
ros2#14 0x564405ffe42d in testing::UnitTest::Run() (/home/.../ros2_ws/build-asan/rcutils/test_logging_macros+0x6142d)
ros2#15 0x564405fd197d in RUN_ALL_TESTS() (/home/.../ros2_ws/build-asan/rcutils/test_logging_macros+0x3497d)
ros2#16 0x564405fd18c3 in main (/home/.../ros2_ws/build-asan/rcutils/test_logging_macros+0x348c3)
ros2#17 0x7fd63fd84b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
After:
$ ./test_logging_macros
Running main() from gmock_main.cc
[==========] Running 9 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 9 tests from TestLoggingMacros
[ RUN ] TestLoggingMacros.test_empty
[ OK ] TestLoggingMacros.test_empty (0 ms)
[ RUN ] TestLoggingMacros.test_logging_named
[ OK ] TestLoggingMacros.test_logging_named (0 ms)
[ RUN ] TestLoggingMacros.test_logging_once
[ OK ] TestLoggingMacros.test_logging_once (0 ms)
[ RUN ] TestLoggingMacros.test_logging_expression
[ OK ] TestLoggingMacros.test_logging_expression (0 ms)
[ RUN ] TestLoggingMacros.test_logging_function
[ OK ] TestLoggingMacros.test_logging_function (0 ms)
[ RUN ] TestLoggingMacros.test_logging_skipfirst
[ OK ] TestLoggingMacros.test_logging_skipfirst (0 ms)
[ RUN ] TestLoggingMacros.test_logging_throttle
[ OK ] TestLoggingMacros.test_logging_throttle (303 ms)
[ RUN ] TestLoggingMacros.test_logging_skipfirst_throttle
[ OK ] TestLoggingMacros.test_logging_skipfirst_throttle (302 ms)
[ RUN ] TestLoggingMacros.test_logger_hierarchy
[ OK ] TestLoggingMacros.test_logger_hierarchy (0 ms)
[----------] 9 tests from TestLoggingMacros (605 ms total)
[----------] Global test environment tear-down
[==========] 9 tests from 1 test case ran. (606 ms total)
[ PASSED ] 9 tests.
[1] https://testing.googleblog.com/2015/01/testing-on-toilet-change-detector-tests.html
Signed-off-by: Thomas Moulard <tmoulard@amazon.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
connects to ros2/rclcpp#344
title is self-explanatory