corba_ipc_test.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon Jun 26 13:26:02 CEST 2006 generictask_test.cpp
3 
4  generictask_test.cpp - description
5  -------------------
6  begin : Mon June 26 2006
7  copyright : (C) 2006 Peter Soetens
8  email : peter.soetens@fmtc.be
9 
10  ***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 #include "unit.hpp"
20 
21 #include <iostream>
22 #include <memory>
23 
24 #include <rtt/OperationCaller.hpp>
25 #include <rtt/Service.hpp>
28 #include <transports/corba/ServiceC.h>
29 #include <transports/corba/corba.h>
31 #include <rtt/InputPort.hpp>
32 #include <rtt/OutputPort.hpp>
33 #include <rtt/TaskContext.hpp>
38 
39 #include <string>
40 #include <stdlib.h>
41 
42 using namespace RTT;
43 using namespace RTT::detail;
44 
45 class CorbaTest
46 {
47 public:
48  CorbaTest() { this->setUp(); }
49  ~CorbaTest() { this->tearDown(); }
50 
57  CTaskContext_ptr s;
58  CTaskContext_ptr s2;
59 
61  void new_data_listener(base::PortInterface* port);
62 
63  // Ports
66  enum { INITIAL, CALL, SEND, FINAL } callBackPeer_step;
69 
70  void setUp();
71  void tearDown();
72 
73  // helper test functions
74  void testPortDataConnection();
75  void testPortBufferConnection();
76  void testPortDisconnected();
77 
78  void callBackPeer(TaskContext* peer, string const& opname) {
80  OperationCaller<void()> resetCallBackPeer( peer->getOperation("resetCallBackPeer"), tc->engine() );
81  int count = ++callBackPeer_count;
82 
83  if (callBackPeer_step == INITIAL) {
84  log(Info) << "Test resets server." <<endlog();
85  resetCallBackPeer();
86  callBackPeer_step = CALL;
87  }
88 
89  log(Info) << "Test executes callBackPeer():"<< count <<endlog();
90  if (callBackPeer_step == CALL) {
91  callBackPeer_step = SEND;
92  log(Info) << "Test calls server:" << count <<endlog();
93  op1(tc, "callBackPeer");
94  log(Info) << "Test finishes server call:"<<count <<endlog();
95  }
96  else if (callBackPeer_step == SEND) {
97  callBackPeer_step = FINAL;
98  log(Info) << "Test sends server:"<<count <<endlog();
99  handle = op1.send(tc, "callBackPeerOwn");
100  log(Info) << "Test finishes server send:"<< count <<endlog();
101  }
102  log(Info) << "Test finishes callBackPeer():"<< count <<endlog();
103  }
104 
105 };
106 
107 using namespace std;
109 
110 void
112 {
113  // connect DataPorts
114  mi = new InputPort<double>("mi");
115  mo = new OutputPort<double>("mo");
116 
117  tc = new TaskContext( "root" );
118  tc->ports()->addEventPort( *mi,boost::bind(&CorbaTest::new_data_listener, this, _1) );
119  tc->ports()->addPort( *mo );
120 
121  t2 = 0;
122  ts2 = ts = 0;
123  tp2 = tp = 0;
124  callBackPeer_count = 0;
125  callBackPeer_step = INITIAL;
126 
127  tc->addOperation("callBackPeer", &CorbaTest::callBackPeer, this,ClientThread);
128  tc->addOperation("callBackPeerOwn", &CorbaTest::callBackPeer, this,OwnThread);
129 }
130 
131 
132 void
134 {
135  delete tp;
136  delete ts;
137  delete tp2;
138  delete ts2;
139  delete tc;
140  delete t2;
141 
142  delete mi;
143  delete mo;
144 }
145 
147 {
148  signalled_port = port;
149 }
150 
151 
152 #define ASSERT_PORT_SIGNALLING(code, read_port) do { \
153  signalled_port = 0; \
154  int wait = 0; \
155  code; \
156  while (read_port != signalled_port && wait++ != 5) \
157  usleep(100000); \
158  BOOST_CHECK( read_port == signalled_port ); \
159 } while(0)
160 
161 #define wait_for( cond, times ) do { \
162  bool wait_for_helper; \
163  int wait = 0; \
164  while( (wait_for_helper = !(cond)) && wait++ != times ) \
165  usleep(100000); \
166  if (wait_for_helper) BOOST_CHECK( cond ); \
167 } while(0)
168 
169 #define wait_for_equal( a, b, times ) do { \
170  bool wait_for_helper; \
171  int wait = 0; \
172  while( (wait_for_helper = ((a) != (b))) && wait++ != times ) \
173  usleep(100000); \
174  if (wait_for_helper) BOOST_CHECK_EQUAL( a, b ); \
175 } while(0)
176 
178 {
179  // This test assumes that there is a data connection mo => mi
180  // Check if connection succeeded both ways:
181  BOOST_CHECK( mo->connected() );
182  BOOST_CHECK( mi->connected() );
183 
184  double value = 0;
185 
186  // Check if no-data works
187  BOOST_CHECK_EQUAL( mi->read(value), NoData );
188 
189  // Check if writing works (including signalling)
190  ASSERT_PORT_SIGNALLING(mo->write(1.0), mi);
191  BOOST_CHECK( mi->read(value) );
192  BOOST_CHECK_EQUAL( 1.0, value );
193  ASSERT_PORT_SIGNALLING(mo->write(2.0), mi);
194  BOOST_CHECK( mi->read(value) );
195  BOOST_CHECK_EQUAL( 2.0, value );
196 }
197 
199 {
200  // This test assumes that there is a buffer connection mo => mi of size 3
201  // Check if connection succeeded both ways:
202  BOOST_CHECK( mo->connected() );
203  BOOST_CHECK( mi->connected() );
204 
205  double value = 0;
206 
207  // Check if no-data works
208  BOOST_CHECK_EQUAL( mi->read(value), NoData );
209 
210  // Check if writing works
211  ASSERT_PORT_SIGNALLING(mo->write(1.0), mi);
212  ASSERT_PORT_SIGNALLING(mo->write(2.0), mi);
213  ASSERT_PORT_SIGNALLING(mo->write(3.0), mi);
214  ASSERT_PORT_SIGNALLING(mo->write(4.0), 0);
215  BOOST_CHECK( mi->read(value) );
216  BOOST_CHECK_EQUAL( 1.0, value );
217  BOOST_CHECK( mi->read(value) );
218  BOOST_CHECK_EQUAL( 2.0, value );
219  BOOST_CHECK( mi->read(value) );
220  BOOST_CHECK_EQUAL( 3.0, value );
221  BOOST_CHECK_EQUAL( mi->read(value), OldData );
222 }
223 
225 {
226  BOOST_CHECK( !mo->connected() );
227  BOOST_CHECK( !mi->connected() );
228 }
229 
230 
231 // Registers the fixture into the 'registry'
232 BOOST_FIXTURE_TEST_SUITE( CorbaIPCTestSuite, CorbaTest )
233 
234 
235 BOOST_AUTO_TEST_CASE( testRemoteOperationCallerC )
236 {
237  tp = corba::TaskContextProxy::Create( "peerRMC", /* is_ior = */ false ); // no-ior
238  if (!tp )
239  tp = corba::TaskContextProxy::CreateFromFile( "peerRMC.ior");
240  BOOST_REQUIRE( tp );
241 
242  // This test tests 'transparant' remote invocation of Orocos internal::OperationCallerC objects.
244  double r = 0.0;
245  mc = tp->provides("methods")->create("vm0", tc->engine() );
246  BOOST_CHECK( mc.call() );
247  BOOST_CHECK( r == 0.0 );
248 
249  mc = tp->provides("methods")->create("m0", tc->engine() ).ret( r );
250  BOOST_CHECK( mc.call() );
251  BOOST_CHECK( r == -1.0 );
252 
253  mc = tp->provides("methods")->create("m2", tc->engine()).argC(1).argC(2.0).ret( r );
254  BOOST_CHECK( mc.call() );
255  BOOST_CHECK( r == -3.0 );
256 
257  mc = tp->provides("methods")->create("m3", tc->engine()).ret( r ).argC(1).argC(2.0).argC(true);
258  BOOST_CHECK( mc.call() );
259  BOOST_CHECK( r == -4.0 );
260 
261 }
262 
263 BOOST_AUTO_TEST_CASE( testRemoteOperationCaller )
264 {
265  tp = corba::TaskContextProxy::Create( "peerRM" , /* is_ior = */ false);
266  if (!tp )
267  tp = corba::TaskContextProxy::CreateFromFile( "peerRM.ior");
268  BOOST_REQUIRE(tp);
269  // This test tests 'transparant' remote invocation of Orocos methods.
270  // This requires the internal::RemoteOperationCaller class, which does not work yet.
271  RTT::OperationCaller<double(void)> m0 = tp->provides("methods")->getOperation("m0");
272  RTT::OperationCaller<double(int)> m1 = tp->provides("methods")->getOperation("m1");
273  RTT::OperationCaller<double(int,double)> m2 = tp->provides("methods")->getOperation("m2");
274  RTT::OperationCaller<double(int,double,bool)> m3 = tp->provides("methods")->getOperation("m3");
275  RTT::OperationCaller<double(int,double,bool,std::string)> m4 = tp->provides("methods")->getOperation("m4");
276 
277  BOOST_CHECK_EQUAL( -1.0, m0() );
278  BOOST_CHECK_EQUAL( -2.0, m1(1) );
279  BOOST_CHECK_EQUAL( -3.0, m2(1, 2.0) );
280  BOOST_CHECK_EQUAL( -4.0, m3(1, 2.0, true) );
281  BOOST_CHECK_EQUAL( -5.0, m4(1, 2.0, true,"hello") );
282 }
283 
288 BOOST_AUTO_TEST_CASE( testRemoteOperationCallerCallback )
289 {
290  tp = corba::TaskContextProxy::Create( "peerRMCb" , /* is_ior = */ false);
291  if (!tp )
292  tp = corba::TaskContextProxy::CreateFromFile( "peerRMC.ior");
293  BOOST_REQUIRE(tp);
294 
298 
299  BOOST_REQUIRE_EQUAL( (int) callBackPeer_step, (int) INITIAL );
300  this->callBackPeer(tp, "callBackPeer");
301  sleep(1); //asyncronous processing...
302  BOOST_CHECK_EQUAL( (int) callBackPeer_step, (int) FINAL );
303  BOOST_CHECK_EQUAL( callBackPeer_count, 3 );
304  BOOST_CHECK( handle.ready() );
305  BOOST_CHECK_EQUAL( handle.collectIfDone(), SendSuccess );
306 }
307 
308 BOOST_AUTO_TEST_CASE( testAnyOperationCaller )
309 {
310  double d;
311  tp = corba::TaskContextProxy::Create( "peerAM" , /* is_ior = */ false);
312  if (!tp )
313  tp = corba::TaskContextProxy::CreateFromFile( "peerAM.ior");
314 
315  BOOST_REQUIRE(tp);
316  s = tp->server();
317  BOOST_REQUIRE( s );
318  // This test tests the callOperation() function of the server.
319  corba::CService_var co = s->getProvider("methods");
320  BOOST_CHECK( co.in() );
321 
322  corba::CAnyArguments_var any_args = new corba::CAnyArguments(0);
323  CORBA::Any_var vm0 = co->callOperation("vm0", any_args.inout() );
324  //BOOST_CHECK( vm0.in() );
325 
326  CORBA::Any_var m0 = co->callOperation("m0", any_args.inout());
327  BOOST_CHECK( m0 >>= d );
328  BOOST_CHECK_EQUAL(d, -1.0 );
329 
330  any_args = new corba::CAnyArguments(1);
331  any_args->length(1);
332  unsigned int index = 0;
333  any_args[index] <<= (CORBA::Long) 1;
334  CORBA::Any_var m1;
335  BOOST_CHECK_NO_THROW( m1 = co->callOperation("m1", any_args.inout()));
336  BOOST_CHECK( m1 >>= d );
337  BOOST_CHECK_EQUAL(d, -2.0 );
338 
339 
340  any_args = new corba::CAnyArguments(2);
341  any_args->length(2);
342  index = 0;
343  any_args[index] <<= (CORBA::Long) 1;
344  ++index;
345  any_args[index] <<= (CORBA::Double) 2.0;
346  CORBA::Any_var m2;
347  BOOST_CHECK_NO_THROW( m2 = co->callOperation("m2", any_args.inout()));
348  BOOST_CHECK( m2 >>= d );
349  BOOST_CHECK_EQUAL(d, -3.0 );
350 
351  any_args = new corba::CAnyArguments(3);
352  any_args->length(3);
353  index = 0;
354  any_args[index] <<= (CORBA::Long) 1;
355  ++index;
356  any_args[index] <<= (CORBA::Double) 2.0;
357  ++index;
358  any_args[index] <<= CORBA::Any::from_boolean( true );
359  CORBA::Any_var m3;
360  BOOST_CHECK_NO_THROW( m3= co->callOperation("m3", any_args.inout()) );
361  BOOST_CHECK( m3 >>= d );
362  BOOST_CHECK_EQUAL(d, -4.0 );
363 
364  any_args = new corba::CAnyArguments(4);
365  any_args->length(4);
366  index = 0;
367  any_args[index] <<= (CORBA::Long) 1;
368  ++index;
369  any_args[index] <<= (CORBA::Double) 2.0;
370  ++index;
371  any_args[index] <<= CORBA::Any::from_boolean( true );
372  ++index;
373  any_args[index] <<= "hello";
374  CORBA::Any_var m4;
375  BOOST_CHECK_NO_THROW ( m4 = co->callOperation("m4", any_args.inout()) );
376  BOOST_CHECK( m4 >>= d );
377  BOOST_CHECK_EQUAL(d, -5.0 );
378 }
379 
380 BOOST_AUTO_TEST_CASE(testDataFlowInterface)
381 {
382  tp = corba::TaskContextProxy::Create( "peerDFI" , /* is_ior = */ false);
383  if (!tp )
384  tp = corba::TaskContextProxy::CreateFromFile( "peerDFI.ior");
385 
386  BOOST_REQUIRE(tp);
387  corba::CDataFlowInterface_var ports = tp->server()->ports();
388 
389  corba::CDataFlowInterface::CPortNames_var names =
390  ports->getPorts();
391 
392  BOOST_CHECK_EQUAL(CORBA::ULong(2), names->length());
393  BOOST_CHECK_EQUAL(string("mi"), string(names[CORBA::ULong(0)]));
394  BOOST_CHECK_EQUAL(string("mo"), string(names[CORBA::ULong(1)]));
395 
396  // Now check directions
397  BOOST_CHECK_EQUAL(RTT::corba::COutput,
398  ports->getPortType("mo"));
399  BOOST_CHECK_EQUAL(RTT::corba::CInput,
400  ports->getPortType("mi"));
401 
402  // And check type names
403  CORBA::String_var cstr = ports->getDataType("mo");
404  BOOST_CHECK_EQUAL(string("double"),
405  string(cstr.in()));
406 }
407 
408 BOOST_AUTO_TEST_CASE( testPortConnections )
409 {
410  // This test tests the differen port-to-port connections.
411  tp = corba::TaskContextProxy::Create( "peerPC", /* is_ior = */ false);
412  if (!tp )
413  tp = corba::TaskContextProxy::CreateFromFile( "peerPC.ior");
414 
415  BOOST_REQUIRE(tp);
416 
417  s = tp->server();
418  // server to our own tc.
419  ts2 = corba::TaskContextServer::Create( tc, /* use_naming = */ false );
420  s2 = ts2->server();
421 
422  // Create a default CORBA policy specification
423  RTT::corba::CConnPolicy policy = toCORBA(ConnPolicy::data());
424  policy.init = false;
425  policy.transport = ORO_CORBA_PROTOCOL_ID; // force creation of non-local connections
426 
427  corba::CDataFlowInterface_var ports = s->ports();
428  corba::CDataFlowInterface_var ports2 = s2->ports();
429 
430  // Test cases that should not connect
431  BOOST_CHECK_THROW( ports->createConnection("mo", ports2, "does_not_exist", policy), CNoSuchPortException );
432  BOOST_CHECK_THROW( ports->createConnection("does_not_exist", ports2, "mi", policy), CNoSuchPortException );
433  BOOST_CHECK_THROW( ports->createConnection("does_not_exist", ports2, "does_not_exist", policy), CNoSuchPortException );
434  BOOST_CHECK_THROW( ports->createConnection("mo", ports2, "mo", policy), CNoSuchPortException );
435  BOOST_CHECK_THROW( ports->createConnection("mi", ports2, "mi", policy), CNoSuchPortException );
436  BOOST_CHECK_THROW( ports->createConnection("mi", ports2, "mo", policy), CNoSuchPortException );
437 
438  // must be running to catch event port signalling.
439  BOOST_CHECK( tc->start() );
440  // WARNING: in the following, there is four configuration tested. There is
441  // also three different ways to disconnect. We need to test those three
442  // "disconnection methods", so beware when you change something ...
443 
444  // All these tests require the server app to round-trip the data to us.
445 
446  policy.type = RTT::corba::CData;
447  policy.pull = false;
448  BOOST_CHECK( ports->createConnection("mo", ports2, "mi", policy) );
449  BOOST_CHECK( ports2->createConnection("mo", ports, "mi", policy) );
450  testPortDataConnection();
451  ports->disconnectPort("mo");
452  ports->disconnectPort("mi");
453  testPortDisconnected();
454 
455  return;
456 
457  policy.type = RTT::corba::CData;
458  policy.pull = true;
459  BOOST_CHECK( ports2->createConnection("mo", ports, "mi", policy) );
460  BOOST_CHECK( ports2->createConnection("mo", ports, "mi", policy) );
461  testPortDataConnection();
462  ports2->disconnectPort("mi");
463  ports2->disconnectPort("mo");
464  testPortDisconnected();
465 
466  policy.type = RTT::corba::CBuffer;
467  policy.pull = false;
468  policy.size = 3;
469  BOOST_CHECK( ports->createConnection("mo", ports2, "mi", policy) );
470  BOOST_CHECK( ports2->createConnection("mo", ports, "mi", policy) );
471  testPortBufferConnection();
472  ports->disconnectPort("mo");
473  ports->disconnectPort("mi");
474  testPortDisconnected();
475 
476  policy.type = RTT::corba::CBuffer;
477  policy.pull = true;
478  BOOST_CHECK( ports->createConnection("mo", ports2, "mi", policy) );
479  BOOST_CHECK( ports2->createConnection("mo", ports, "mi", policy) );
480  testPortBufferConnection();
481  ports2->disconnectPort("mo");
482  ports2->disconnectPort("mi");
483  testPortDisconnected();
484 
485 #if 0
486  // Here, check removal of specific connections. So first add another
487  // connection ...
488  mo->createConnection(*mi);
489  // Remove the remote connection
490  ports->removeConnection("mo", ports2, "mi");
491  ports->removeConnection("mi", ports2, "mo");
492  // Check it is removed
493  BOOST_CHECK(mo->connected());
494  BOOST_CHECK(mi->connected());
495  BOOST_CHECK(!mi->connected());
496 #endif
497 }
498 
499 BOOST_AUTO_TEST_CASE( testPortProxying )
500 {
501  // This test creates connections between local and remote ports.
502  tp = corba::TaskContextProxy::Create( "peerPP" , /* is_ior = */ false);
503  if (!tp )
504  tp = corba::TaskContextProxy::CreateFromFile( "peerPP.ior");
505 
506  BOOST_REQUIRE(tp);
507 
508  base::PortInterface* untyped_port;
509 
510  untyped_port = tp->ports()->getPort("mi");
511  BOOST_CHECK(untyped_port);
512  base::InputPortInterface* read_port = dynamic_cast<base::InputPortInterface*>(tp->ports()->getPort("mi"));
513  BOOST_CHECK(read_port);
514 
515  untyped_port = tp->ports()->getPort("mo");
516  BOOST_CHECK(untyped_port);
517  base::OutputPortInterface* write_port = dynamic_cast<base::OutputPortInterface*>(tp->ports()->getPort("mo"));
518  BOOST_CHECK(write_port);
519 
520  // Just make sure 'read_port' and 'write_port' are actually proxies and not
521  // the real thing
522  BOOST_CHECK(dynamic_cast<corba::RemoteInputPort*>(read_port));
523  BOOST_CHECK(dynamic_cast<corba::RemoteOutputPort*>(write_port));
524 
525  BOOST_CHECK(!read_port->connected());
526  BOOST_CHECK(read_port->getTypeInfo() == mi->getTypeInfo());
527  BOOST_CHECK(!write_port->connected());
528  BOOST_CHECK(write_port->getTypeInfo() == mo->getTypeInfo());
529 
530  mo->createConnection(*read_port);
531  write_port->createConnection(*mi);
532  BOOST_CHECK(read_port->connected());
533  BOOST_CHECK(write_port->connected());
534  // XXX This currently does not work:
535  //read_port->disconnect(*mo);
536  //write_port->disconnect(*mi);
537  read_port->disconnect();
538  write_port->disconnect();
539  BOOST_CHECK(!read_port->connected());
540  BOOST_CHECK(!write_port->connected());
541 
542  mo->createConnection(*read_port);
543  write_port->createConnection(*mi);
544  BOOST_CHECK(read_port->connected());
545  BOOST_CHECK(write_port->connected());
546  write_port->disconnect();
547  read_port->disconnect();
548  BOOST_CHECK(!read_port->connected());
549  BOOST_CHECK(!write_port->connected());
550 
551  // Test cloning
552 #if __cplusplus > 199711L
553  unique_ptr<base::InputPortInterface>
554 #else
555  auto_ptr<base::InputPortInterface>
556 #endif
557  read_clone(dynamic_cast<base::InputPortInterface*>(read_port->clone()));
558  BOOST_CHECK(mo->createConnection(*read_clone));
559  BOOST_CHECK(read_clone->connected());
560  BOOST_CHECK(!read_port->connected());
561  mo->disconnect();
562 }
563 
564 BOOST_AUTO_TEST_CASE( testDataHalfs )
565 {
566  if(std::getenv("CI") != NULL) {
567  BOOST_TEST_MESSAGE("Skipping testDataHalfs because it can fail on integration servers.");
568  return;
569  }
570 
571  double result;
572  // This test tests the differen port-to-port connections.
573  tp = corba::TaskContextProxy::Create( "peerDH" , /* is_ior = */ false);
574  if (!tp )
575  tp = corba::TaskContextProxy::CreateFromFile( "peerDH.ior");
576 
577  BOOST_REQUIRE(tp);
578 
579  s = tp->server();
580 
581  // Create a default CORBA policy specification
582  RTT::corba::CConnPolicy policy = toCORBA(ConnPolicy::data());
583  policy.init = false;
584  policy.transport = ORO_CORBA_PROTOCOL_ID; // force creation of non-local connections
585 
586  corba::CDataFlowInterface_var ports = s->ports();
587  BOOST_REQUIRE( ports.in() );
588 
589  // test unbuffered C++ write --> Corba read
590  policy.pull = false; // note: buildChannelInput must correct policy to pull = true (adds a buffer).
591  mo->connectTo( tp->ports()->getPort("mi"), toRTT(policy) );
592  CChannelElement_var cce = ports->buildChannelInput("mo", policy);
593  CORBA::Any_var sample;
594  BOOST_REQUIRE( cce.in() );
595 
596  // Check read of new data
597  mo->write( 3.33 );
598  wait_for_equal( cce->read( sample.out(), true), CNewData, 5 );
599  sample >>= result;
600  BOOST_CHECK_EQUAL( result, 3.33);
601 
602  // Check re-read of old data.
603  sample <<= 0.0;
604  BOOST_CHECK_EQUAL( cce->read( sample.out(), true), COldData );
605  sample >>= result;
606  BOOST_CHECK_EQUAL( result, 3.33);
607 
608  cce->disconnect();
609  mo->disconnect();
610 
611  // test unbuffered Corba write --> C++ read
612  cce = ports->buildChannelOutput("mi", policy);
613  cce->channelReady(policy);
614 
615  mi->connectTo( tp->ports()->getPort("mo"), toRTT(policy) );
616  sample = new CORBA::Any();
617  BOOST_REQUIRE( cce.in() );
618 
619  // Check read of new data
620  result = 0.0;
621  sample <<= 4.44;
622  cce->write( sample.in() );
623  wait_for_equal( mi->read( result ), NewData, 5 );
624  BOOST_CHECK_EQUAL( result, 4.44 );
625 
626  // Check re-read of old data.
627  result = 0.0;
628  BOOST_CHECK_EQUAL( mi->read( result ), OldData );
629  BOOST_CHECK_EQUAL( result, 4.44);
630 }
631 
632 BOOST_AUTO_TEST_CASE( testBufferHalfs )
633 {
634  if(std::getenv("CI") != NULL) {
635  BOOST_TEST_MESSAGE("Skipping testBufferHalfs because it can fail on integration servers.");
636  return;
637  }
638 
639  double result;
640 
641  // This test tests the differen port-to-port connections.
642  tp = corba::TaskContextProxy::Create( "peerBH" , /* is_ior = */ false);
643  if (!tp )
644  tp = corba::TaskContextProxy::CreateFromFile( "peerBH.ior");
645 
646  BOOST_REQUIRE(tp);
647 
648  s = tp->server();
649 
650  // Create a default CORBA policy specification
651  RTT::corba::CConnPolicy policy = toCORBA(ConnPolicy::buffer(10));
652  policy.init = false;
653  policy.transport = ORO_CORBA_PROTOCOL_ID; // force creation of non-local connections
654 
655  corba::CDataFlowInterface_var ports = s->ports();
656  BOOST_REQUIRE( ports.in() );
657 
658  // test unbuffered C++ write --> Corba read
659  policy.pull = false; // note: buildChannelInput must correct policy to pull = true (adds a buffer).
660  mo->connectTo( tp->ports()->getPort("mi"), toRTT(policy) );
661  CChannelElement_var cce = ports->buildChannelInput("mo", policy);
662  CORBA::Any_var sample;
663  BOOST_REQUIRE( cce.in() );
664 
665  // Check read of new data
666  mo->write( 6.33 );
667  mo->write( 3.33 );
668  wait_for_equal( cce->read( sample.out(), true), CNewData, 10 );
669  sample >>= result;
670 #ifndef RTT_CORBA_PORTS_WRITE_ONEWAY
671  BOOST_CHECK_EQUAL( result, 6.33);
672 #else
673  BOOST_CHECK( (result == 6.33) || (result == 3.33) );
674 #endif
675  wait_for_equal( cce->read( sample.out(), true ), CNewData, 10 );
676  sample >>= result;
677 #ifndef RTT_CORBA_PORTS_WRITE_ONEWAY
678  BOOST_CHECK_EQUAL( result, 3.33);
679 #else
680  BOOST_CHECK( (result == 6.33) || (result == 3.33) );
681 #endif
682 
683  // Check re-read of old data.
684  sample <<= 0.0;
685  BOOST_CHECK_EQUAL( cce->read( sample.out(), true ), COldData );
686  sample >>= result;
687 #ifndef RTT_CORBA_PORTS_WRITE_ONEWAY
688  BOOST_CHECK_EQUAL( result, 3.33);
689 #else
690  BOOST_CHECK( (result == 6.33) || (result == 3.33) );
691 #endif
692 
693  cce->disconnect();
694  mo->disconnect();
695 
696  // test buffered Corba write --> C++ read
697  mi->connectTo( tp->ports()->getPort("mo"), toRTT(policy) );
698  cce = ports->buildChannelOutput("mi", policy);
699  cce->channelReady(policy);
700  sample = new CORBA::Any();
701  BOOST_REQUIRE( cce.in() );
702 
703  // Check read of new data
704  result = 0.0;
705  sample <<= 6.44;
706  cce->write( sample.in() );
707  sample <<= 4.44;
708  cce->write( sample.in() );
709  wait_for_equal( mi->read( result ), NewData, 5 );
710  BOOST_CHECK_EQUAL( result, 6.44 );
711  wait_for_equal( mi->read( result ), NewData, 5 );
712  BOOST_CHECK_EQUAL( result, 4.44 );
713 
714  // Check re-read of old data.
715  result = 0.0;
716  BOOST_CHECK_EQUAL( mi->read( result ), OldData );
717  BOOST_CHECK_EQUAL( result, 4.44);
718 }
719 
721 
virtual PortInterface * clone() const =0
static ConnPolicy data(int lock_policy=LOCK_FREE, bool init_connection=true, bool pull=false)
Definition: ConnPolicy.cpp:99
#define BOOST_FIXTURE_TEST_SUITE(suite_name, F)
void new_data_listener(base::PortInterface *port)
virtual const types::TypeInfo * getTypeInfo() const =0
#define wait_for_equal(a, b, times)
TaskContext * tc
#define ASSERT_PORT_SIGNALLING(code, read_port)
BOOST_AUTO_TEST_CASE(testRemoteOperationCallerC)
void callBackPeer(TaskContext *peer, string const &opname)
void testPortDisconnected()
#define BOOST_AUTO_TEST_SUITE_END()
Definition: mystd.hpp:163
SendHandle< void(TaskContext *, string const &)> handle
TaskContext * tp2
RTT::ConnPolicy toRTT(RTT::corba::CConnPolicy const &corba_policy)
InputPort< double > * mi
TaskContextProxy * tp
CTaskContext_ptr s2
static TaskContextServer * Create(TaskContext *tc, bool use_naming=true, bool require_name_service=false)
OutputPort< double > * mo
static TaskContextProxy * CreateFromFile(std::string filename)
bool createConnection(InputPortInterface &sink)
static ConnPolicy buffer(int size, int lock_policy=LOCK_FREE, bool init_connection=false, bool pull=false)
Definition: ConnPolicy.cpp:77
TaskContext * t2
void testPortBufferConnection()
int callBackPeer_count
OperationCallerC & ret(base::AttributeBase *r)
unsigned int sleep(unsigned int s)
Definition: fosi.cpp:51
RTT::corba::CConnPolicy toCORBA(RTT::ConnPolicy const &policy)
OperationInterfacePart * getOperation(std::string name)
#define ORO_CORBA_PROTOCOL_ID
Definition: CorbaLib.hpp:45
corba::TaskContextServer * ts
OperationCallerC & argC(const ArgT a)
corba::TaskContextServer * ts2
CTaskContext_ptr s
void testPortDataConnection()
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
base::PortInterface * signalled_port
static Logger & log()
Definition: Logger.hpp:350
static TaskContextProxy * Create(std::string name, bool is_ior=false)
const ExecutionEngine * engine() const
Definition: TaskCore.hpp:306
static Logger::LogFunction endlog()
Definition: Logger.hpp:362


rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:32