RCF and boost.test

RCF support and general discussion.
Post Reply
Volker
Posts: 26
Joined: Wed May 23, 2012 3:27 pm

RCF and boost.test

Post by Volker »

Hi Jarl,

I'm not quite sure whether this is a problem with RCF or boost.test. The following simple boost.test fails unexpectedly :

Code: Select all


#include <iostream>
#include <RCF/RCF.hpp>

#define BOOST_TEST_MODULE RCFTest

#include <boost/test/unit_test.hpp>


RCF_BEGIN(I_Echo, "I_Echo")
    RCF_METHOD_R1(std::string, Echo, const std::string &)
RCF_END(I_Echo)

struct EchoImpl
{
    static int counter ;

    std::string Echo(const std::string & s)
    {
        ++counter ;
        if( counter < 3 )
        {
            return s ;
        }
        else
        {
            return "123" ;
        }
    }

};

int EchoImpl::counter = 0 ;

BOOST_AUTO_TEST_CASE( simple_test )
{
    RCF::RcfInitDeinit rcfInit;

    EchoImpl echo;
    RCF::RcfServer server( RCF::TcpEndpoint(50001) );
    server.bind<I_Echo>(echo);
    server.start();

    RcfClient<I_Echo> client( RCF::TcpEndpoint(50001) );

    BOOST_CHECK( std::string("ABC") == client.Echo("ABC") );
    BOOST_CHECK_EQUAL( std::string("ABC"), client.Echo("ABC") );
    BOOST_CHECK( std::string("ABC") == client.Echo("ABC") );
    BOOST_CHECK_EQUAL( std::string("ABC"), client.Echo("ABC") );
}

The output is as follows :

Code: Select all


volker@hubuntu64:~/test/RCF-2.0.0.2678$ ./m 
Running 1 test case...
main.cpp(47): error in "simple_test": check std::string("ABC") == client.Echo("ABC") failed
main.cpp(48): error in "simple_test": check std::string("ABC") == client.Echo("ABC") failed [ABC != 
unknown location(0): fatal error in "simple_test": memory access violation at address: 0x00000000: no mapping at fault address
main.cpp(48): last checkpoint

I would guess BOOST_CHECK_EQUAL makes some special trickery to format the output but I have no idea whats going on.

My environment : Ubuntu 12.04 x86_64, gcc 4.6.3, boost 1.52.0, RCF 2.0.0.2678.

Regards,

Volker

jarl
Posts: 238
Joined: Mon Oct 03, 2011 4:53 am
Contact:

Re: RCF and boost.test

Post by jarl »

I'm not sure what's going on here. The boost.test code is almost impenetrable. The problem is that when the test fails, it is trying to print out the failed value, thus evaluating the arguments again and causing a second (failing) remote call.

The client.Echo() call returns a special proxy object (RCF::FutureImpl<>), which is designed to function in both synchronous and asynchronous contexts, using operator conversions to direct the code down the right path. The boost.test code seems to be exercising an unusual code path, but the test code is so convoluted that I have trouble seeing what it is up to.

In any case, I found that if you write the tests like this, it works:

BOOST_CHECK( "ABC" == (std::string) client.Echo("ABC") );
BOOST_CHECK_EQUAL( "ABC", (std::string) client.Echo("ABC") );
BOOST_CHECK( "ABC" == (std::string) client.Echo("ABC") );
BOOST_CHECK_EQUAL( "ABC", (std::string) client.Echo("ABC") );
Kind Regards

Jarl Lindrud
Delta V Software
http://www.deltavsoft.com

Volker
Posts: 26
Joined: Wed May 23, 2012 3:27 pm

Re: RCF and boost.test

Post by Volker »

I agree, I also tried to understand what boost.test is doing. Even worse is that boost.test seems to lack a bit of maintenance - as far as I remember the thread in boost.devel.

Post Reply