From add0271a1fac573c33dff9bd3ec0085d4e075ab7 Mon Sep 17 00:00:00 2001 From: Guilherme Affonso Date: Fri, 28 Oct 2022 17:15:38 +0900 Subject: [PATCH] Add tests for #675 --- roseus/test/test-memory-service.l | 31 ++++++++++++++++++++++++++++ roseus/test/test-memory-subscriber.l | 27 ++++++++++++++++++++++++ roseus/test/test-memory-timer.l | 26 +++++++++++++++++++++++ roseus/test/test-memory.test | 11 ++++++++++ 4 files changed, 95 insertions(+) create mode 100755 roseus/test/test-memory-service.l create mode 100755 roseus/test/test-memory-subscriber.l create mode 100755 roseus/test/test-memory-timer.l create mode 100644 roseus/test/test-memory.test diff --git a/roseus/test/test-memory-service.l b/roseus/test/test-memory-service.l new file mode 100755 index 000000000..ad3a969d3 --- /dev/null +++ b/roseus/test/test-memory-service.l @@ -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) diff --git a/roseus/test/test-memory-subscriber.l b/roseus/test/test-memory-subscriber.l new file mode 100755 index 000000000..6d9e5b3b9 --- /dev/null +++ b/roseus/test/test-memory-subscriber.l @@ -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) diff --git a/roseus/test/test-memory-timer.l b/roseus/test/test-memory-timer.l new file mode 100755 index 000000000..5e3984500 --- /dev/null +++ b/roseus/test/test-memory-timer.l @@ -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) diff --git a/roseus/test/test-memory.test b/roseus/test/test-memory.test new file mode 100644 index 000000000..70d446c8c --- /dev/null +++ b/roseus/test/test-memory.test @@ -0,0 +1,11 @@ + + + + + + +