Skip to content

Commit

Permalink
Add tests for #675
Browse files Browse the repository at this point in the history
  • Loading branch information
Affonso-Gui committed Oct 28, 2022
1 parent 4d45a0d commit add0271
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
31 changes: 31 additions & 0 deletions roseus/test/test-memory-service.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env roseus
(require :unittest "lib/llib/unittest.l")
(init-unit-test)

(ros::roseus "test_memory_subscriber")
(ros::rate 200)

(defclass my-srv :slots (req))
(defmethod my-srv
(:update (_req)
(setq req _req)
(send _req :response))
(:get () req))

(sys:make-thread 1)
(defun test-once (topic)
(let ((srv (instance my-srv)))
(ros::advertise-service topic std_srvs::Empty #'send srv :update)
(ros::wait-for-service topic)
(sys:thread-no-wait #'ros::service-call topic (instance std_srvs::EmptyRequest :init))
(while (not (send srv :get))
(ros::spin-once))
(ros::unadvertise-service topic)))

(deftest test-service ()
(dotimes (i 5000)
(if (zerop (mod i 100)) (ros::ros-warn "service: ~A~%" i))
(test-once "/roseus_test/srv")))

(run-all-tests)
(exit)
27 changes: 27 additions & 0 deletions roseus/test/test-memory-subscriber.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env roseus
(require :unittest "lib/llib/unittest.l")
(init-unit-test)

(ros::roseus "test_memory_subscriber")
(ros::rate 200)

(defclass my-sub :slots (msg))
(defmethod my-sub
(:update (_msg) (setq msg _msg))
(:get () msg))

(defun test-once (topic msgtype)
(let ((sub (instance my-sub)))
(ros::subscribe topic msgtype #'send sub :update)
(while (not (send sub :get))
(ros::spin-once)
(ros::sleep))
(send sub :get)))

(deftest test-subscriber ()
(dotimes (i 5000)
(if (zerop (mod i 100)) (ros::ros-warn "subscriber: ~A" i))
(test-once "/roseus_test/msg" std_msgs::String)))

(run-all-tests)
(exit)
26 changes: 26 additions & 0 deletions roseus/test/test-memory-timer.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env roseus
(require :unittest "lib/llib/unittest.l")
(init-unit-test)

(ros::roseus "test_memory_timer")
(ros::rate 200)

(defclass my-cb :slots (done))
(defmethod my-cb
(:update (event) (setq done t))
(:get () done))

(defun test-once ()
(let ((tm (instance my-cb)))
(ros::create-timer 0.001 #'send tm :update :oneshot t)
(while (not (send tm :get))
(ros::spin-once)
(ros::sleep))))

(deftest test-timer ()
(dotimes (i 3000)
(if (zerop (mod i 100)) (ros::ros-warn "timer: ~A~%" i))
(test-once)))

(run-all-tests)
(exit)
11 changes: 11 additions & 0 deletions roseus/test/test-memory.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<launch>
<node name="publisher" pkg="rostopic" type="rostopic"
args='pub /roseus_test/msg std_msgs/String "Hello" -r 100' />
<test test-name="roseus_subscriber" pkg="roseus" type="roseus" args="$(find roseus)/test/test-memory-subscriber.l"
time-limit="600" />
<test test-name="roseus_service" pkg="roseus" type="roseus" args="$(find roseus)/test/test-memory-service.l"
time-limit="600" />
<test test-name="roseus_timer" pkg="roseus" type="roseus" args="$(find roseus)/test/test-memory-timer.l"
time-limit="600" />
</launch>

0 comments on commit add0271

Please sign in to comment.