$search
00001 /* 00002 * Copyright (c) 2011, Willow Garage, Inc. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of Willow Garage, Inc. nor the names of its 00014 * contributors may be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 00030 /* Author: Troy Straszheim */ 00031 00032 /* 00033 * Spinny spinner basic tests. 00034 00035 these do NOT ACTUALLY TEST ANYTHING as it is diffcult to restart all 00036 of ros in a unit test, and there is no way to test (that I can see 00037 right now) that certain error messages are emitted, nor any way to 00038 specify that a test should fail or return an error. So this is just 00039 a placeholder to be run manually, one test at a time (via 00040 --gtest_filter) when the next problem occurs. Those that end with 00041 'fail' actually success, but they send a fatal error message that 00042 you're trying to spin from multiple threads. 00043 */ 00044 00045 #include <gtest/gtest.h> 00046 #include "ros/spinner.h" 00047 #include "ros/init.h" 00048 #include "ros/node_handle.h" 00049 #include <boost/thread.hpp> 00050 00051 using namespace ros; 00052 00053 int argc_; 00054 char** argv_; 00055 00056 void fire_shutdown(const ros::WallTimerEvent& event) { 00057 ROS_INFO("Asking for shutdown"); 00058 ros::shutdown(); 00059 } 00060 00061 #define DOIT() \ 00062 ros::init(argc_, argv_, "test_spinners"); \ 00063 NodeHandle nh; \ 00064 ros::WallTimer t = nh.createWallTimer(ros::WallDuration(2.0), \ 00065 &fire_shutdown); \ 00066 00067 TEST(Spinners, spin) 00068 { 00069 DOIT(); 00070 ros::spin(); 00071 } 00072 00073 TEST(Spinners, spinfail) 00074 { 00075 DOIT(); 00076 boost::thread th(boost::bind(&ros::spin)); 00077 ros::spin(); 00078 } 00079 00080 TEST(Spinners, single) 00081 { 00082 DOIT(); 00083 SingleThreadedSpinner s; 00084 ros::spin(s); 00085 } 00086 00087 TEST(Spinners, singlefail) 00088 { 00089 DOIT(); 00090 boost::thread th(boost::bind(&ros::spin)); 00091 SingleThreadedSpinner s; 00092 ros::spin(s); 00093 } 00094 00095 TEST(Spinners, singlefail2) 00096 { 00097 DOIT(); 00098 SingleThreadedSpinner s; 00099 boost::thread th(boost::bind(&ros::spin, s)); 00100 ros::spin(s); 00101 } 00102 00103 TEST(Spinners, multi) 00104 { 00105 DOIT(); 00106 MultiThreadedSpinner s; 00107 ros::spin(s); 00108 } 00109 00110 TEST(Spinners, multifail) 00111 { 00112 DOIT(); 00113 boost::thread th(boost::bind(&ros::spin)); 00114 MultiThreadedSpinner s; 00115 ros::spin(s); 00116 } 00117 00118 TEST(Spinners, multifail2) 00119 { 00120 DOIT(); 00121 MultiThreadedSpinner s; 00122 boost::thread th(boost::bind(&ros::spin, s)); 00123 ros::spin(s); 00124 } 00125 00126 TEST(Spinners, async) 00127 { 00128 DOIT(); 00129 AsyncSpinner s(2); 00130 s.start(); 00131 ros::waitForShutdown(); 00132 } 00133 00134 TEST(Spinners, asyncfail) 00135 { 00136 DOIT(); 00137 boost::thread th(boost::bind(&ros::spin)); 00138 AsyncSpinner s(2); 00139 s.start(); 00140 ros::waitForShutdown(); 00141 } 00142 00143 00144 int 00145 main(int argc, char** argv) 00146 { 00147 testing::InitGoogleTest(&argc, argv); 00148 argc_ = argc; 00149 argv_ = argv; 00150 return RUN_ALL_TESTS(); 00151 } 00152 00153