Skip to content

Commit

Permalink
[TimeoutManager]: minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
matemat13 committed May 9, 2024
1 parent d1767c3 commit 8566e70
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ add_definitions(-Wall)
add_definitions(-Wextra)
add_definitions(-Wpedantic)

# if(CATKIN_ENABLE_TESTING AND MRS_ENABLE_TESTING)
# add_definitions(-fsanitize=address -g3 -fno-omit-frame-pointer)
# add_link_options(-fsanitize=address)
# endif()

if(COVERAGE)
message(WARNING "building with --coverage, the performance might be limited")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
Expand Down
12 changes: 6 additions & 6 deletions src/timeout_manager/timeout_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ namespace mrs_lib
const auto new_id = m_timeouts.size();
m_timeouts.emplace_back(
timeout_info_t{
.oneshot = oneshot,
.started = autostart,
.callback = callback,
.timeout = timeout,
.last_reset = last_reset,
.last_callback = last_reset
oneshot,
autostart,
callback,
timeout,
last_reset,
last_reset
});
return new_id;
}
Expand Down
7 changes: 6 additions & 1 deletion test/timeout_manager/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct obj_t
// error flags
std::mutex mtx;
int n_cbks = 0;
int sooner_cbks = 0;
bool null_cbk = false;
bool cbk_not_running = false;
std::atomic_bool cbk_running = false;
Expand Down Expand Up @@ -63,7 +64,10 @@ struct obj_t
const ros::Duration dt = now - last_update;
const auto dt_err = dt - desired_dt;
if (dt_err < ros::Duration(0))
ROS_ERROR_STREAM("Callback has a larger/smaller delay than expected: " << dt << "s (should be " << desired_dt << "s). Error: " << dt_err << "s (max. expected: " << max_expected_dt_err << "s)!");
{
ROS_ERROR_STREAM("Callback called sooner than expected: " << dt << "s (should be " << desired_dt << "s). Error: " << dt_err << "s < 0!");
sooner_cbks++;
}
if (dt_err > max_expected_dt_err)
ROS_ERROR_STREAM("Callback has a larger/smaller delay than expected: " << dt << "s (should be " << desired_dt << "s). Error: " << dt_err << "s (max. expected: " << max_expected_dt_err << "s)!");
if (dt_err > max_dt_err || n_cbks == 1)
Expand Down Expand Up @@ -183,6 +187,7 @@ TEST(TESTSuite, timeout_test)

EXPECT_LE(obj.max_dt_err, obj.max_expected_dt_err);
EXPECT_LE(obj.avg_dt_err, update_period);
EXPECT_EQ(obj.sooner_cbks, 0);
EXPECT_FALSE(callback_while_tm_null);
EXPECT_FALSE(callback_while_not_running);

Expand Down

0 comments on commit 8566e70

Please sign in to comment.