[kea-dev] How to properly test callouts?

Marcin Wyszynski marcinw at fb.com
Wed Nov 5 18:01:34 UTC 2014


Hello Marcin,

thank you for a rapid response. Due to a build system constraints here at Facebook we are not able to create shared libraries - all binaries have to be statically linked. 

We essentially have:

extern "C" {

int pkt4_receive(CalloutHandle& handle) {
  // our implementation;
}

// other functions;

}  // extern

The question now is - if I want to test my pkt4_receive function, how do I create a CalloutHandle if the definition for CalloutManager needed for the only CalloutHandle constructor is explicitly not exported? It would be awesome if for our purposes CalloutManager could be created in a test suite:

class MyTest : public ::testing::Test {
 protected:
  virtual void SetUp() {
    manager_.reset(new CalloutManager(0));
    handle_.reset(new CalloutHandle(manager_));
  }
  boost::shared_ptr<::isc::hooks::CalloutManager> manager_;
  std::unique_ptr<::isc::hooks::CalloutHandle> handle_;
};

TEST_F(MyTest, Receive4) {
  // test our pkt4_receive function.
}

Hope that makes sense.

Best,
Marcin

On 5 November 2014 at 07:06:43, Marcin Siodelski (marcin at isc.org) wrote:
> Marcin,
>  
> The hook libraries are normally compiled as shared libraries and loaded
> by Kea from the specific location indicated in the Kea configuration.
>  
> I am not certain from your description, but it seems that you haven't
> built your library as a shared module so it cannot be dynamically loaded
> by Kea?
>  
> There is a good example of the hooks library, that we have implemented
> for our needs, in the source code. It is located in
> src/hooks/dhcp/user_chk. It comes along with the suitable Makefile.am
> which builds it as a shared library. It also has a bunch of unit tests
> for individual C++ classes and methods. I think it will be best for you
> to start from there. It is also well documented in the developer's
> guide:
> https://urldefense.proofpoint.com/v1/url?u=http://git.kea.isc.org/~tester/kea/doxygen/d8/db2/libdhcp_user_chk.html&k=ZVNjlDMF0FElm4dQtryO4A%3D%3D%0A&r=P7u4XlV5ewRTs6xgjSUnNg%3D%3D%0A&m=BpbaF5POloTn0uJU1FZdTj1%2Fg7VAFoiR4NvSUnS%2FnFY%3D%0A&s=7a37e891ddaeda41a3fe6cd37f30102686c9378cc2c9676fd5045b35cacdaa39  
>  
> Apart from this, the developer's guide comprises a collection of other
> documents about the hooks framework which you may find useful, e.g.
> https://urldefense.proofpoint.com/v1/url?u=http://git.kea.isc.org/~tester/kea/doxygen/df/d46/hooksdgDevelopersGuide.html&k=ZVNjlDMF0FElm4dQtryO4A%3D%3D%0A&r=P7u4XlV5ewRTs6xgjSUnNg%3D%3D%0A&m=BpbaF5POloTn0uJU1FZdTj1%2Fg7VAFoiR4NvSUnS%2FnFY%3D%0A&s=2cb582b0cd2ca63c8dae6a74b997289567372b181716c050181ef5950c1f2c90  
> or https://urldefense.proofpoint.com/v1/url?u=http://git.kea.isc.org/~tester/kea/doxygen/de/df3/dhcpv4Hooks.html&k=ZVNjlDMF0FElm4dQtryO4A%3D%3D%0A&r=P7u4XlV5ewRTs6xgjSUnNg%3D%3D%0A&m=BpbaF5POloTn0uJU1FZdTj1%2Fg7VAFoiR4NvSUnS%2FnFY%3D%0A&s=92d19ff5053799721a3a0b92eb5af0c33670faa5d873d04e1dad8b68da862ac6  
>  
> It is possible that I misunderstood your intent and you want to test
> your library in a different way than loading it as a shared library. If
> so, please be more specific what you're actually going to achieve.
>  
> Regards,
>  
> Marcin Siodelski
> DHCP Software Engineer
> at ISC
>  
>  
> On 11/05/14 00:43, Marcin Wyszynski wrote:
> > Dear KEA devs,
> >
> > I have a statically linked hook library which I’d like to test and I’d want to know what  
> the best approach would be. My naive attempt was to create an empty CalloutHandle object,  
> pass it to my hook function and compare the result with my expectations. However, that  
> is not so simple. CalloutHandle constructor expects at least a boost::shared_ptr.  
> Unfortunately I see no way to create an actual instance since hooks/callout_manager.h  
> header file is not explicitly exported.
> >
> > Please kindly advise on the best way of dealing with this problem.
> >
> > Thank you in advance!
> >
> > Best,
> > Marcin
> >
> > _______________________________________________
> > kea-dev mailing list
> > kea-dev at lists.isc.org
> > https://urldefense.proofpoint.com/v1/url?u=https://lists.isc.org/mailman/listinfo/kea-dev&k=ZVNjlDMF0FElm4dQtryO4A%3D%3D%0A&r=P7u4XlV5ewRTs6xgjSUnNg%3D%3D%0A&m=BpbaF5POloTn0uJU1FZdTj1%2Fg7VAFoiR4NvSUnS%2FnFY%3D%0A&s=c84130d2aa6d801db7a05b615ffe188342c9266a82f673ff8a906b72dfaee3d9  
> >
>  



More information about the kea-dev mailing list