@@ -63,6 +63,9 @@ TEST_F(TestTime, clock_type_access) {
6363
6464 rclcpp::Clock steady_clock (RCL_STEADY_TIME);
6565 EXPECT_EQ (RCL_STEADY_TIME, steady_clock.get_clock_type ());
66+
67+ rclcpp::Clock raw_steady_clock (RCL_RAW_STEADY_TIME);
68+ EXPECT_EQ (RCL_RAW_STEADY_TIME, raw_steady_clock.get_clock_type ());
6669}
6770
6871// Check that the clock may go out of the scope before the jump callback without leading in UB.
@@ -93,6 +96,11 @@ TEST_F(TestTime, time_sources) {
9396 Time steady_now = steady_clock.now ();
9497 EXPECT_NE (0 , steady_now.sec );
9598 EXPECT_NE (0u , steady_now.nanosec );
99+
100+ rclcpp::Clock raw_steady_clock (RCL_RAW_STEADY_TIME);
101+ Time raw_steady_now = raw_steady_clock.now ();
102+ EXPECT_NE (0 , raw_steady_now.sec );
103+ EXPECT_NE (0u , raw_steady_now.nanosec );
96104}
97105
98106static const int64_t HALF_SEC_IN_NS = RCUTILS_MS_TO_NS(500 );
@@ -193,30 +201,47 @@ TEST_F(TestTime, operators) {
193201
194202 rclcpp::Time system_time (0 , 0 , RCL_SYSTEM_TIME);
195203 rclcpp::Time steady_time (0 , 0 , RCL_STEADY_TIME);
204+ rclcpp::Time raw_steady_time (0 , 0 , RCL_RAW_STEADY_TIME);
196205
197206 EXPECT_ANY_THROW ((void )(system_time == steady_time));
207+ EXPECT_ANY_THROW ((void )(system_time == raw_steady_time));
198208 EXPECT_ANY_THROW ((void )(system_time != steady_time));
209+ EXPECT_ANY_THROW ((void )(system_time != raw_steady_time));
199210 EXPECT_ANY_THROW ((void )(system_time <= steady_time));
211+ EXPECT_ANY_THROW ((void )(system_time <= raw_steady_time));
200212 EXPECT_ANY_THROW ((void )(system_time >= steady_time));
213+ EXPECT_ANY_THROW ((void )(system_time >= raw_steady_time));
201214 EXPECT_ANY_THROW ((void )(system_time < steady_time));
215+ EXPECT_ANY_THROW ((void )(system_time < raw_steady_time));
202216 EXPECT_ANY_THROW ((void )(system_time > steady_time));
217+ EXPECT_ANY_THROW ((void )(system_time > raw_steady_time));
203218 EXPECT_ANY_THROW ((void )(system_time - steady_time));
219+ EXPECT_ANY_THROW ((void )(system_time - raw_steady_time));
204220
205221 rclcpp::Clock system_clock (RCL_SYSTEM_TIME);
206222 rclcpp::Clock steady_clock (RCL_STEADY_TIME);
223+ rclcpp::Clock raw_steady_clock (RCL_RAW_STEADY_TIME);
207224
208225 rclcpp::Time now = system_clock.now ();
209226 rclcpp::Time later = steady_clock.now ();
227+ rclcpp::Time raw_later = raw_steady_clock.now ();
210228
211229 EXPECT_ANY_THROW ((void )(now == later));
230+ EXPECT_ANY_THROW ((void )(now == raw_later));
212231 EXPECT_ANY_THROW ((void )(now != later));
232+ EXPECT_ANY_THROW ((void )(now != raw_later));
213233 EXPECT_ANY_THROW ((void )(now <= later));
234+ EXPECT_ANY_THROW ((void )(now <= raw_later));
214235 EXPECT_ANY_THROW ((void )(now >= later));
236+ EXPECT_ANY_THROW ((void )(now >= raw_later));
215237 EXPECT_ANY_THROW ((void )(now < later));
238+ EXPECT_ANY_THROW ((void )(now < raw_later));
216239 EXPECT_ANY_THROW ((void )(now > later));
240+ EXPECT_ANY_THROW ((void )(now > raw_later));
217241 EXPECT_ANY_THROW ((void )(now - later));
242+ EXPECT_ANY_THROW ((void )(now - raw_later));
218243
219- for (auto time_source : {RCL_ROS_TIME, RCL_SYSTEM_TIME, RCL_STEADY_TIME}) {
244+ for (auto time_source : {RCL_ROS_TIME, RCL_SYSTEM_TIME, RCL_STEADY_TIME, RCL_RAW_STEADY_TIME }) {
220245 rclcpp::Time time = rclcpp::Time (0 , 0 , time_source);
221246 rclcpp::Time copy_constructor_time (time);
222247 rclcpp::Time assignment_op_time = rclcpp::Time (1 , 0 , time_source);
@@ -312,7 +337,7 @@ TEST_F(TestTime, seconds) {
312337TEST_F (TestTime, test_max) {
313338 // Same clock types
314339 for (rcl_clock_type_t type = RCL_ROS_TIME;
315- type != RCL_STEADY_TIME ; type = static_cast <rcl_clock_type_t >(type + 1 ))
340+ type != RCL_RAW_STEADY_TIME ; type = static_cast <rcl_clock_type_t >(type + 1 ))
316341 {
317342 const rclcpp::Time time_max = rclcpp::Time::max (type);
318343 const rclcpp::Time max_time (std::numeric_limits<int32_t >::max (), 999999999 , type);
@@ -323,13 +348,22 @@ TEST_F(TestTime, test_max) {
323348 {
324349 const rclcpp::Time time_max = rclcpp::Time::max (RCL_ROS_TIME);
325350 const rclcpp::Time max_time (std::numeric_limits<int32_t >::max (), 999999999 , RCL_STEADY_TIME);
351+ const rclcpp::Time raw_max_time (
352+ std::numeric_limits<int32_t >::max (), 999999999 , RCL_RAW_STEADY_TIME);
326353 EXPECT_ANY_THROW ((void )(time_max == max_time));
354+ EXPECT_ANY_THROW ((void )(time_max == raw_max_time));
327355 EXPECT_ANY_THROW ((void )(time_max != max_time));
356+ EXPECT_ANY_THROW ((void )(time_max != raw_max_time));
328357 EXPECT_ANY_THROW ((void )(time_max <= max_time));
358+ EXPECT_ANY_THROW ((void )(time_max <= raw_max_time));
329359 EXPECT_ANY_THROW ((void )(time_max >= max_time));
360+ EXPECT_ANY_THROW ((void )(time_max >= raw_max_time));
330361 EXPECT_ANY_THROW ((void )(time_max < max_time));
362+ EXPECT_ANY_THROW ((void )(time_max < raw_max_time));
331363 EXPECT_ANY_THROW ((void )(time_max > max_time));
364+ EXPECT_ANY_THROW ((void )(time_max > raw_max_time));
332365 EXPECT_ANY_THROW ((void )(time_max - max_time));
366+ EXPECT_ANY_THROW ((void )(time_max - raw_max_time));
333367 }
334368}
335369
@@ -433,6 +467,11 @@ TEST_F(TestClockSleep, bad_clock_type) {
433467 RCLCPP_EXPECT_THROW_EQ (
434468 clock.sleep_until (ros_until),
435469 std::runtime_error (" until's clock type does not match this clock's type" ));
470+
471+ rclcpp::Time raw_steady_until (54321 , 0 , RCL_RAW_STEADY_TIME);
472+ RCLCPP_EXPECT_THROW_EQ (
473+ clock.sleep_until (raw_steady_until),
474+ std::runtime_error (" until's clock type does not match this clock's type" ));
436475}
437476
438477TEST_F (TestClockSleep, sleep_until_invalid_context) {
@@ -493,13 +532,34 @@ TEST_F(TestClockSleep, sleep_until_basic_steady) {
493532 EXPECT_GE (steady_end - steady_start, std::chrono::milliseconds (milliseconds));
494533}
495534
535+ TEST_F (TestClockSleep, sleep_until_basic_raw_steady) {
536+ const auto milliseconds = 300 ;
537+ rclcpp::Clock clock (RCL_RAW_STEADY_TIME);
538+ auto delay = rclcpp::Duration (0 , RCUTILS_MS_TO_NS (milliseconds));
539+ auto sleep_until = clock.now () + delay;
540+
541+ auto steady_start = std::chrono::steady_clock::now ();
542+ ASSERT_TRUE (clock.sleep_until (sleep_until));
543+ auto steady_end = std::chrono::steady_clock::now ();
544+
545+ EXPECT_GE (clock.now (), sleep_until);
546+ EXPECT_GE (steady_end - steady_start, std::chrono::milliseconds (milliseconds));
547+ }
548+
496549TEST_F (TestClockSleep, sleep_until_steady_past_returns_immediately) {
497550 rclcpp::Clock clock (RCL_STEADY_TIME);
498551 auto until = clock.now () - rclcpp::Duration (1000 , 0 );
499552 // This should return immediately, other possible behavior might be sleep forever and timeout
500553 ASSERT_TRUE (clock.sleep_until (until));
501554}
502555
556+ TEST_F (TestClockSleep, sleep_until_raw_steady_past_returns_immediately) {
557+ rclcpp::Clock clock (RCL_RAW_STEADY_TIME);
558+ auto until = clock.now () - rclcpp::Duration (1000 , 0 );
559+ // This should return immediately, other possible behavior might be sleep forever and timeout
560+ ASSERT_TRUE (clock.sleep_until (until));
561+ }
562+
503563TEST_F (TestClockSleep, sleep_until_system_past_returns_immediately) {
504564 rclcpp::Clock clock (RCL_SYSTEM_TIME);
505565 auto until = clock.now () - rclcpp::Duration (1000 , 0 );
@@ -660,6 +720,25 @@ TEST_F(TestClockSleep, sleep_for_basic_system) {
660720 EXPECT_GE (end - start, std::chrono::milliseconds (milliseconds));
661721}
662722
723+ TEST_F (TestClockSleep, sleep_for_basic_raw_steady) {
724+ const auto milliseconds = 300 ;
725+ rclcpp::Clock clock (RCL_RAW_STEADY_TIME);
726+ auto rel_time = rclcpp::Duration (0 , RCUTILS_MS_TO_NS (milliseconds));
727+
728+ auto steady_start = std::chrono::steady_clock::now ();
729+ ASSERT_TRUE (clock.sleep_for (rel_time));
730+ auto steady_end = std::chrono::steady_clock::now ();
731+
732+ EXPECT_GE (steady_end - steady_start, std::chrono::milliseconds (milliseconds));
733+ }
734+
735+ TEST_F (TestClockSleep, sleep_for_raw_steady_past_returns_immediately) {
736+ rclcpp::Clock clock (RCL_RAW_STEADY_TIME);
737+ auto rel_time = rclcpp::Duration (-1000 , 0 );
738+ // This should return immediately
739+ ASSERT_TRUE (clock.sleep_for (rel_time));
740+ }
741+
663742TEST_F (TestClockSleep, sleep_for_basic_steady) {
664743 const auto milliseconds = 300 ;
665744 rclcpp::Clock clock (RCL_STEADY_TIME);
0 commit comments