test.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 /* Author: Wim Meeussen */
36 
37 #include <string>
38 #include <gtest/gtest.h>
39 #include <ros/ros.h>
40 #include <boost/thread.hpp>
41 #include <cstdlib>
42 
43 #include <pr2_mechanism_msgs/LoadController.h>
44 #include <pr2_mechanism_msgs/UnloadController.h>
45 #include <pr2_mechanism_msgs/ListControllers.h>
46 #include <pr2_mechanism_msgs/SwitchController.h>
47 #include <sensor_msgs/JointState.h>
48 #include <pr2_mechanism_msgs/MechanismStatistics.h>
49 #include <diagnostic_msgs/DiagnosticArray.h>
50 
51 static const unsigned int _failure = 0;
52 static const unsigned int _unloaded = 1;
53 static const unsigned int _stopped = 2;
54 static const unsigned int _running = 3;
55 
56 
57 int g_argc;
58 char** g_argv;
59 
60 static bool bombardment_started_ = false;
61 
62 
63 class TestController : public testing::Test
64 {
65 public:
70  std::vector<ros::Time> callback1_timing_;
73 
74  void callbackDiagnostic(const diagnostic_msgs::DiagnosticArrayConstPtr& msg)
75  {
76  if (!msg->status.empty()){
77  bool found_joint = false;
78  bool found_controller = false;
79  for (unsigned int i=0; i<msg->status.size(); i++){
80  if (!found_joint && msg->status[i].name.substr(0,5) == "Joint")
81  joint_diagnostic_counter_++;
82  if (!found_controller && msg->status[i].name.substr(0,10) == "Controller")
83  controller_diagnostic_counter_++;
84  }
85  }
86  }
87 
88  void callbackJs(const sensor_msgs::JointStateConstPtr& msg)
89  {
90  if (!msg->name.empty())
91  callback_js_counter_++;
92  }
93 
94  void callbackMs(const pr2_mechanism_msgs::MechanismStatisticsConstPtr& msg)
95  {
96  callback_ms_counter_++;
97  }
98 
99  void callback1(const sensor_msgs::JointStateConstPtr& msg)
100  {
101  if (callback1_counter_ < 1000){
102  callback1_timing_[callback1_counter_] = ros::Time::now();
103  }
104  callback1_name_ = msg->name[0];
105  callback1_effort_ = msg->effort[0];
106  callback1_counter_++;
107  }
108 
109  void callback4(const sensor_msgs::JointStateConstPtr& msg)
110  {
111  callback4_name_ = msg->name[0];
112  }
113 
114  bool loadController(const std::string& name)
115  {
116 
117  pr2_mechanism_msgs::LoadController srv_msg;
118  srv_msg.request.name = name;
119  if (!load_srv_.call(srv_msg)) return false;
120  return srv_msg.response.ok;
121  }
122 
123  bool unloadController(const std::string& name)
124  {
125 
126  pr2_mechanism_msgs::UnloadController srv_msg;
127  srv_msg.request.name = name;
128  if (!unload_srv_.call(srv_msg)) return false;
129  return srv_msg.response.ok;
130  }
131 
132  bool switchController(const std::vector<std::string>& start, const std::vector<std::string>& stop, int strictness)
133  {
134 
135  pr2_mechanism_msgs::SwitchController srv_msg;
136  srv_msg.request.start_controllers = start;
137  srv_msg.request.stop_controllers = stop;
138  srv_msg.request.strictness = strictness;
139  if (!switch_srv_.call(srv_msg)) return false;
140  return srv_msg.response.ok;
141  }
142 
143  unsigned int nrControllers()
144  {
145 
146  pr2_mechanism_msgs::ListControllers srv_msg;
147  if (!list_srv_.call(srv_msg)) return 0;;
148  return srv_msg.response.controllers.size();
149  }
150 
151  unsigned int controllerState(const std::string& name)
152  {
153 
154  pr2_mechanism_msgs::ListControllers srv_msg;
155  if (!list_srv_.call(srv_msg)) return _failure;
156  for (unsigned int i=0; i<srv_msg.response.controllers.size(); i++){
157  if (name == srv_msg.response.controllers[i]){
158  if (srv_msg.response.state[i] == "running") return _running;
159  else if (srv_msg.response.state[i] == "stopped") return _stopped;
160  else return _failure;
161  }
162  }
163  return _unloaded;
164  }
165 
166  std::string randomController()
167  {
168  unsigned int random = rand();
169  random = random % 10;
170  std::stringstream s;
171  s << random;
172  return "controller" + s.str();
173  }
174 
175  void randomBombardment(unsigned int times)
176  {
177  while (!bombardment_started_)
178  ros::Duration(0.1).sleep();
179 
180  for (unsigned int i=0; i<times; i++){
181  unsigned int random = rand();
182  random = random % 4;
183  switch (random){
184  case 0:{
186  break;
187  }
188  case 1:{
190  break;
191  }
192  case 2:{
193  std::vector<std::string> start, stop;
194  unsigned int start_size = rand() %10;
195  unsigned int stop_size = rand() %10;
196  for (unsigned int i=0; i<start_size; i++)
197  start.push_back(randomController());
198  for (unsigned int i=0; i<stop_size; i++)
199  stop.push_back(randomController());
200  if (rand() %1 == 0)
201  switchController(start, stop, pr2_mechanism_msgs::SwitchController::Request::STRICT);
202  else
203  switchController(start, stop, pr2_mechanism_msgs::SwitchController::Request::BEST_EFFORT);
204  break;
205  }
206  case 3:{
208  break;
209  }
210  }
211  }
212  }
213 
214 
215 protected:
218  : callback1_timing_(1000)
219  {
220  }
221 
224  {
225  }
226 
227  void SetUp()
228  {
229  ros::service::waitForService("pr2_controller_manager/load_controller");
230  ros::service::waitForService("pr2_controller_manager/unload_controller");
231  ros::service::waitForService("pr2_controller_manager/switch_controller");
232  ros::service::waitForService("pr2_controller_manager/list_controllers");
233  ros::service::waitForService("pr2_controller_manager/list_controllers");
234 
235  load_srv_ = node_.serviceClient<pr2_mechanism_msgs::LoadController>("pr2_controller_manager/load_controller");
236  unload_srv_ = node_.serviceClient<pr2_mechanism_msgs::UnloadController>("pr2_controller_manager/unload_controller");
237  switch_srv_ = node_.serviceClient<pr2_mechanism_msgs::SwitchController>("pr2_controller_manager/switch_controller");
238  list_srv_ = node_.serviceClient<pr2_mechanism_msgs::ListControllers>("pr2_controller_manager/list_controllers");
239  }
240 
241  void TearDown()
242  {
243  load_srv_.shutdown();
244  }
245 };
246 
247 
248 
249 
250 // test spawner
252 {
253  // wait until all controllers are loaded
255  ros::Duration timeout(60.0);
256  while (nrControllers() != 6 && ros::Time::now() - start < timeout)
257  ros::Duration(1.0).sleep();
258  EXPECT_TRUE(ros::Time::now() - start < timeout);
259 
260  // this should be the controller state if spawner worked
261  EXPECT_EQ(controllerState("controller1"), _running);
262  EXPECT_EQ(controllerState("controller2"), _stopped);
263  EXPECT_EQ(controllerState("controller3"), _running);
264  EXPECT_EQ(controllerState("controller4"), _running);
265  EXPECT_EQ(controllerState("controller5"), _stopped);
266  EXPECT_EQ(controllerState("controller6"), _stopped);
267  EXPECT_EQ(controllerState("controller7"), _unloaded);
268  EXPECT_EQ(controllerState("controller8"), _unloaded);
269  EXPECT_EQ(controllerState("controller9"), _unloaded);
270  SUCCEED();
271 }
272 
273 
275 {
276  // check initial state
277  EXPECT_EQ(controllerState("controller1"), _running);
278  EXPECT_EQ(controllerState("controller2"), _stopped);
279  EXPECT_EQ(controllerState("controller3"), _running);
280  EXPECT_EQ(controllerState("controller4"), _running);
281  EXPECT_EQ(controllerState("controller5"), _stopped);
282  EXPECT_EQ(controllerState("controller6"), _stopped);
283  EXPECT_EQ(controllerState("controller7"), _unloaded);
284  EXPECT_EQ(controllerState("controller8"), _unloaded);
285  EXPECT_EQ(controllerState("controller9"), _unloaded);
286 
287  // these are already loaded
288  EXPECT_FALSE(loadController("controller1"));
289  EXPECT_FALSE(loadController("controller2"));
290  EXPECT_FALSE(loadController("controller3"));
291  EXPECT_FALSE(loadController("controller4"));
292  EXPECT_FALSE(loadController("controller5"));
293  EXPECT_FALSE(loadController("controller6"));
294 
295  // this one is not loaded yet
296  EXPECT_TRUE(loadController("controller7"));
297 
298  // this one is wrongly configured
299  EXPECT_FALSE(loadController("controller9"));
300  EXPECT_FALSE(loadController("controller11"));
301  EXPECT_FALSE(loadController("controller12"));
302  EXPECT_FALSE(loadController("controller13"));
303  EXPECT_FALSE(loadController("controller14"));
304  EXPECT_FALSE(loadController("controller15"));
305  EXPECT_FALSE(loadController("controller16"));
306  EXPECT_FALSE(loadController("controller17"));
307  EXPECT_FALSE(loadController("controller18"));
308  EXPECT_FALSE(loadController("controller19"));
309 
310  // this one is not configured
311  EXPECT_FALSE(loadController("controller10"));
312 
313  // check end state
314  EXPECT_EQ(controllerState("controller1"), _running);
315  EXPECT_EQ(controllerState("controller2"), _stopped);
316  EXPECT_EQ(controllerState("controller3"), _running);
317  EXPECT_EQ(controllerState("controller4"), _running);
318  EXPECT_EQ(controllerState("controller5"), _stopped);
319  EXPECT_EQ(controllerState("controller6"), _stopped);
320  EXPECT_EQ(controllerState("controller7"), _stopped);
321  EXPECT_EQ(controllerState("controller8"), _unloaded);
322  EXPECT_EQ(controllerState("controller9"), _unloaded);
323 
324  SUCCEED();
325 }
326 
328 {
329  // check initial state
330  EXPECT_EQ(controllerState("controller1"), _running);
331  EXPECT_EQ(controllerState("controller2"), _stopped);
332  EXPECT_EQ(controllerState("controller3"), _running);
333  EXPECT_EQ(controllerState("controller4"), _running);
334  EXPECT_EQ(controllerState("controller5"), _stopped);
335  EXPECT_EQ(controllerState("controller6"), _stopped);
336  EXPECT_EQ(controllerState("controller7"), _stopped);
337  EXPECT_EQ(controllerState("controller8"), _unloaded);
338  EXPECT_EQ(controllerState("controller9"), _unloaded);
339 
340  // these are running, so unloading should fail
341  EXPECT_FALSE(unloadController("controller1"));
342  EXPECT_FALSE(unloadController("controller3"));
343  EXPECT_FALSE(unloadController("controller4"));
344 
345  // these are stopped, so unloading should succeed
346  EXPECT_TRUE(unloadController("controller2"));
347  EXPECT_TRUE(unloadController("controller5"));
348  EXPECT_TRUE(unloadController("controller6"));
349  EXPECT_TRUE(unloadController("controller7"));
350 
351  // this one is not loaded, so unloading should fail
352  EXPECT_FALSE(unloadController("controller8"));
353 
354  // check end state
355  EXPECT_EQ(controllerState("controller1"), _running);
356  EXPECT_EQ(controllerState("controller2"), _unloaded);
357  EXPECT_EQ(controllerState("controller3"), _running);
358  EXPECT_EQ(controllerState("controller4"), _running);
359  EXPECT_EQ(controllerState("controller5"), _unloaded);
360  EXPECT_EQ(controllerState("controller6"), _unloaded);
361  EXPECT_EQ(controllerState("controller7"), _unloaded);
362  EXPECT_EQ(controllerState("controller8"), _unloaded);
363  EXPECT_EQ(controllerState("controller9"), _unloaded);
364 
365  SUCCEED();
366 }
367 
368 TEST_F(TestController, start_stop_strict)
369 {
370  // check initial state
371  EXPECT_EQ(controllerState("controller1"), _running);
372  EXPECT_EQ(controllerState("controller2"), _unloaded);
373  EXPECT_EQ(controllerState("controller3"), _running);
374  EXPECT_EQ(controllerState("controller4"), _running);
375  EXPECT_EQ(controllerState("controller5"), _unloaded);
376  EXPECT_EQ(controllerState("controller6"), _unloaded);
377  EXPECT_EQ(controllerState("controller7"), _unloaded);
378  EXPECT_EQ(controllerState("controller8"), _unloaded);
379  EXPECT_EQ(controllerState("controller9"), _unloaded);
380 
381  // starting already started controller
382  std::vector<std::string> start, stop;
383  start.push_back("controller1");
384  EXPECT_TRUE(switchController(start, stop, pr2_mechanism_msgs::SwitchController::Request::STRICT));
385  EXPECT_EQ(controllerState("controller1"), _running);
386 
387  // starting unloaded controller
388  start.push_back("controller2");
389  EXPECT_FALSE(switchController(start, stop, pr2_mechanism_msgs::SwitchController::Request::STRICT));
390  EXPECT_EQ(controllerState("controller1"), _running);
391  EXPECT_EQ(controllerState("controller2"), _unloaded);
392 
393  // starting one already stated, 1 stopped
394  EXPECT_TRUE(loadController("controller2"));
395  EXPECT_TRUE(switchController(start, stop, pr2_mechanism_msgs::SwitchController::Request::STRICT));
396  EXPECT_EQ(controllerState("controller1"), _running);
397  EXPECT_EQ(controllerState("controller2"), _running);
398 
399  // start and stop same controller
400  stop.push_back("controller2");
401  EXPECT_TRUE(switchController(start, stop, pr2_mechanism_msgs::SwitchController::Request::STRICT));
402  EXPECT_EQ(controllerState("controller1"), _running);
403  EXPECT_EQ(controllerState("controller2"), _running);
404 
405  // stop unloaded controller
406  stop.push_back("controller5");
407  EXPECT_FALSE(switchController(start, stop, pr2_mechanism_msgs::SwitchController::Request::STRICT));
408  EXPECT_EQ(controllerState("controller1"), _running);
409  EXPECT_EQ(controllerState("controller2"), _running);
410  EXPECT_EQ(controllerState("controller5"), _unloaded);
411 
412  // stop unloaded and running controller
413  stop.push_back("controller4");
414  EXPECT_FALSE(switchController(start, stop, pr2_mechanism_msgs::SwitchController::Request::STRICT));
415  EXPECT_EQ(controllerState("controller1"), _running);
416  EXPECT_EQ(controllerState("controller2"), _running);
417  EXPECT_EQ(controllerState("controller4"), _running);
418  EXPECT_EQ(controllerState("controller5"), _unloaded);
419 
420  // stop running and stopped controller
421  EXPECT_TRUE(loadController("controller5"));
422  EXPECT_TRUE(switchController(start, stop, pr2_mechanism_msgs::SwitchController::Request::STRICT));
423  EXPECT_EQ(controllerState("controller1"), _running);
424  EXPECT_EQ(controllerState("controller2"), _running);
425  EXPECT_EQ(controllerState("controller4"), _stopped);
426  EXPECT_EQ(controllerState("controller5"), _stopped);
427 
428  // stop 2 stopped controllers, and 1 running controller
429  stop.push_back("controller3");
430  EXPECT_TRUE(switchController(start, stop, pr2_mechanism_msgs::SwitchController::Request::STRICT));
431  EXPECT_EQ(controllerState("controller1"), _running);
432  EXPECT_EQ(controllerState("controller2"), _running);
433  EXPECT_EQ(controllerState("controller3"), _stopped);
434  EXPECT_EQ(controllerState("controller4"), _stopped);
435  EXPECT_EQ(controllerState("controller5"), _stopped);
436 
437  SUCCEED();
438 }
439 
440 
441 TEST_F(TestController, start_stop_best_effort)
442 {
443  // check initial state
444  EXPECT_EQ(controllerState("controller1"), _running);
445  EXPECT_EQ(controllerState("controller2"), _running);
446  EXPECT_EQ(controllerState("controller3"), _stopped);
447  EXPECT_EQ(controllerState("controller4"), _stopped);
448  EXPECT_EQ(controllerState("controller5"), _stopped);
449  EXPECT_EQ(controllerState("controller6"), _unloaded);
450  EXPECT_EQ(controllerState("controller7"), _unloaded);
451  EXPECT_EQ(controllerState("controller8"), _unloaded);
452  EXPECT_EQ(controllerState("controller9"), _unloaded);
453 
454  // starting already started controller
455  std::vector<std::string> start, stop;
456  start.push_back("controller1");
457  EXPECT_TRUE(switchController(start, stop, pr2_mechanism_msgs::SwitchController::Request::BEST_EFFORT));
458  EXPECT_EQ(controllerState("controller1"), _running);
459 
460  // starting unloaded, started and stopped controller
461  start.push_back("controller3");
462  start.push_back("controller6");
463  EXPECT_TRUE(switchController(start, stop, pr2_mechanism_msgs::SwitchController::Request::BEST_EFFORT));
464  EXPECT_EQ(controllerState("controller1"), _running);
465  EXPECT_EQ(controllerState("controller3"), _running);
466  EXPECT_EQ(controllerState("controller6"), _unloaded);
467 
468  SUCCEED();
469 }
470 
471 
472 
473 TEST_F(TestController, service_and_realtime_publisher)
474 {
475  EXPECT_EQ(controllerState("controller1"), _running);
476  EXPECT_EQ(controllerState("controller4"), _stopped);
477 
478  callback1_timing_.resize(1000);
479  callback1_counter_ = 0;
480 
481  // connect to topic
482  ros::Subscriber sub1 = node_.subscribe<sensor_msgs::JointState>("controller1/my_topic", 100,
483  boost::bind(&TestController_service_and_realtime_publisher_Test::callback1, this, _1));
484  ros::Subscriber sub4 = node_.subscribe<sensor_msgs::JointState>("controller4/my_topic", 100,
485  boost::bind(&TestController_service_and_realtime_publisher_Test::callback4, this, _1));
486 
487  std::string not_started = "not_started";
488  callback1_name_ = not_started;
489  callback4_name_ = not_started;
490 
492  ros::Duration timeout(5.0);
493  while (callback1_name_ == "not_started" && ros::Time::now() - start < timeout)
494  ros::Duration(0.1).sleep();
495  ros::Duration(1.0).sleep(); // avoid problem with simultanious access to callback1_name_
496  EXPECT_EQ(callback1_name_, "");
497  EXPECT_EQ(callback4_name_, not_started);
498 
499  // check for effort limits
500  for (unsigned int i=0; i<1000; i++){
501  EXPECT_LE(callback1_effort_, 0.0);
502  ros::Duration(0.01).sleep();
503  }
504 
505  std::string test_message = "Hoe gaat het met Wim?";
506  ros::ServiceClient srv_client1 = node_.serviceClient<pr2_mechanism_msgs::LoadController>("controller1/my_service");
507  ros::ServiceClient srv_client4 = node_.serviceClient<pr2_mechanism_msgs::LoadController>("controller1/my_service");
508  pr2_mechanism_msgs::LoadController srv_msg;
509  srv_msg.request.name = test_message;
510  EXPECT_TRUE(srv_client1.call(srv_msg));
511  EXPECT_TRUE(srv_client4.call(srv_msg));
512 
513  ros::Duration(1.0).sleep();
514  EXPECT_EQ(callback1_name_, test_message);
515  EXPECT_EQ(callback4_name_, not_started);
516 
517  sub1.shutdown();
518  sub4.shutdown();
519 
520  SUCCEED();
521 }
522 
523 
524 TEST_F(TestController, publisher_hz)
525 {
526  EXPECT_EQ(controllerState("controller1"), _running);
527 
528  // connect to topic
529  ros::Subscriber sub1 = node_.subscribe<sensor_msgs::JointState>("controller1/my_topic", 100,
530  boost::bind(&TestController_publisher_hz_Test::callback1, this, _1));
531 
532  callback1_counter_ = 0;
534  ros::Duration timeout(5.0);
535  while (callback1_counter_ == 0 && ros::Time::now() - start < timeout)
536  ros::Duration(0.01).sleep();
537  callback1_counter_ = 0;
538  ros::Duration(5.0).sleep();
539  // gathering debugging info
540  if (callback1_counter_ < 450){
541  unsigned int nr = callback1_counter_;
542  ROS_ERROR("Only received %u callbacks between start time %f and end time %f", nr, start.toSec(), ros::Time::now().toSec());
543  for (unsigned int i=0; i<nr-1; i++){
544  ROS_ERROR(" - %u: time %f, delta time %f", i, callback1_timing_[i].toSec(), (callback1_timing_[i+1]-callback1_timing_[i]).toSec());
545  }
546  }
547  EXPECT_NEAR(callback1_counter_, 500, 50);
548 
549  sub1.shutdown();
550  SUCCEED();
551 }
552 
553 
554 TEST_F(TestController, manager_hz)
555 {
556  // connect to topic
557  ros::Subscriber sub_js = node_.subscribe<sensor_msgs::JointState>("joint_states", 100,
558  boost::bind(&TestController_manager_hz_Test::callbackJs, this, _1));
561  ros::Duration timeout(5.0);
562  while (callback_js_counter_ == 0 && ros::Time::now() - start < timeout)
563  ros::Duration(0.1).sleep();
564  callback_js_counter_ = 0;
565  ros::Duration(5.0).sleep();
566  EXPECT_NEAR(callback_js_counter_, 1000, 40);
567  sub_js.shutdown();
568 
569 
570  ros::Subscriber sub_ms = node_.subscribe<pr2_mechanism_msgs::MechanismStatistics>("mechanism_statistics", 100,
571  boost::bind(&TestController_manager_hz_Test::callbackMs, this, _1));
573  start = ros::Time::now();
574  while (callback_ms_counter_ == 0 && ros::Time::now() - start < timeout)
575  ros::Duration(0.1).sleep();
576  callback_ms_counter_ = 0;
577  ros::Duration(5.0).sleep();
578  EXPECT_NEAR(callback_ms_counter_, 10, 2);
579  sub_ms.shutdown();
580 
581  SUCCEED();
582 }
583 
584 
585 TEST_F(TestController, diagnostic_hz)
586 {
587  // connect to topic
588  ros::Subscriber sub_diagnostics = node_.subscribe<diagnostic_msgs::DiagnosticArray>("/diagnostics", 100,
589  boost::bind(&TestController_manager_hz_Test::callbackDiagnostic, this, _1));
592  ros::Duration(5.0).sleep();
593  EXPECT_GT(joint_diagnostic_counter_, (unsigned int)1);
594  EXPECT_GT(controller_diagnostic_counter_, (unsigned int)1);
595  sub_diagnostics.shutdown();
596 
597  SUCCEED();
598 }
599 
600 
601 
602 TEST_F(TestController, singlethread_bombardment)
603 {
604  bombardment_started_ = true;
605  randomBombardment(1000);
606  bombardment_started_ = false;
607  SUCCEED();
608 }
609 
610 TEST_F(TestController, multithread_bombardment)
611 {
612  boost::thread bomb1(boost::bind(&TestController_multithread_bombardment_Test::randomBombardment, this, 500));
613  boost::thread bomb2(boost::bind(&TestController_multithread_bombardment_Test::randomBombardment, this, 500));
614  boost::thread bomb3(boost::bind(&TestController_multithread_bombardment_Test::randomBombardment, this, 500));
615  boost::thread bomb4(boost::bind(&TestController_multithread_bombardment_Test::randomBombardment, this, 500));
616  bombardment_started_ = true;
617  bomb1.join();
618  bomb2.join();
619  bomb3.join();
620  bomb4.join();
621 
622  SUCCEED();
623 }
624 
625 
626 int main(int argc, char** argv)
627 {
628  testing::InitGoogleTest(&argc, argv);
629  g_argc = argc;
630  g_argv = argv;
631 
632  ros::init(g_argc, g_argv, "testControllers");
633 
634  boost::thread spinner(boost::bind(&ros::spin));
635 
636  int res = RUN_ALL_TESTS();
637  spinner.interrupt();
638  spinner.join();
639 
640  return res;
641 }
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
unsigned int joint_diagnostic_counter_
Definition: test.cpp:71
unsigned int controllerState(const std::string &name)
Definition: test.cpp:151
unsigned int controller_diagnostic_counter_
Definition: test.cpp:71
void SetUp()
Definition: test.cpp:227
ROSCPP_DECL void start()
static const unsigned int _failure
Definition: test.cpp:51
ros::ServiceClient switch_srv_
Definition: test.cpp:67
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
XmlRpcServer s
bool sleep() const
unsigned int nrControllers()
Definition: test.cpp:143
void callbackJs(const sensor_msgs::JointStateConstPtr &msg)
Definition: test.cpp:88
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
std::vector< ros::Time > callback1_timing_
Definition: test.cpp:70
void callback4(const sensor_msgs::JointStateConstPtr &msg)
Definition: test.cpp:109
bool switchController(const std::vector< std::string > &start, const std::vector< std::string > &stop, int strictness)
Definition: test.cpp:132
ros::ServiceClient load_srv_
Definition: test.cpp:67
void callback1(const sensor_msgs::JointStateConstPtr &msg)
Definition: test.cpp:99
ros::NodeHandle node_
Definition: test.cpp:66
char ** g_argv
Definition: test.cpp:58
std::string callback4_name_
Definition: test.cpp:68
static bool bombardment_started_
Definition: test.cpp:60
int g_argc
Definition: test.cpp:57
~TestController()
Destructor.
Definition: test.cpp:223
unsigned int callback_ms_counter_
Definition: test.cpp:69
bool unloadController(const std::string &name)
Definition: test.cpp:123
TestController()
constructor
Definition: test.cpp:217
static const unsigned int _running
Definition: test.cpp:54
ROSCPP_DECL void spin()
std::string callback1_name_
Definition: test.cpp:68
void callbackDiagnostic(const diagnostic_msgs::DiagnosticArrayConstPtr &msg)
Definition: test.cpp:74
ros::ServiceClient unload_srv_
Definition: test.cpp:67
static const unsigned int _unloaded
Definition: test.cpp:52
int main(int argc, char **argv)
Definition: test.cpp:626
void callbackMs(const pr2_mechanism_msgs::MechanismStatisticsConstPtr &msg)
Definition: test.cpp:94
TEST_F(TestController, spawner)
Definition: test.cpp:251
static Time now()
bool loadController(const std::string &name)
Definition: test.cpp:114
void TearDown()
Definition: test.cpp:241
unsigned int callback_js_counter_
Definition: test.cpp:69
std::string randomController()
Definition: test.cpp:166
#define ROS_ERROR(...)
IMETHOD void random(Vector &a)
void randomBombardment(unsigned int times)
Definition: test.cpp:175
double callback1_effort_
Definition: test.cpp:72
ROSCPP_DECL bool waitForService(const std::string &service_name, int32_t timeout)
ros::ServiceClient list_srv_
Definition: test.cpp:67
unsigned int callback1_counter_
Definition: test.cpp:69
static const unsigned int _stopped
Definition: test.cpp:53


pr2_controller_manager
Author(s): Eric Berger berger@willowgarage.com, Stuart Glaser, Wim Meeussen
autogenerated on Fri Jun 7 2019 22:04:28