[libcamera-devel] [PATCH] tests: call the derived Test class cleanup() function

Laurent Pinchart laurent.pinchart at ideasonboard.com
Sat Dec 22 11:34:22 CET 2018


Hi Jacopo,

On Friday, 21 December 2018 18:26:42 EET jacopo mondi wrote:
> On Fri, Dec 21, 2018 at 01:53:29AM +0100, Niklas Söderlund wrote:
> > Calling the cleanup() function in the base class Test destructor only
> > calls the base class empty cleanup() function, not the overloaded one.
> > This results in tests not cleaning up after themself. Solve this by
> > explicitly calling the cleanup() function from execute().
> > 
> > This was discovered while running valgrind on tests where objects where
> > allocated in init() and freed in cleanup().
> > 
> > Signed-off-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
> > ---
> > 
> >  test/test.cpp | 7 +++++--
> >  1 file changed, 5 insertions(+), 2 deletions(-)
> > 
> > diff --git a/test/test.cpp b/test/test.cpp
> > index 4e7779e750d56687..1bb6ebcb9e8acf18 100644
> > --- a/test/test.cpp
> > +++ b/test/test.cpp
> > @@ -13,7 +13,6 @@ Test::Test()
> >  Test::~Test()
> >  {
> > -	cleanup();
> >  }
> >  
> >  int Test::execute()
> > @@ -24,5 +23,9 @@ int Test::execute()
> >  	if (ret < 0)
> 
> Shouldn't the same be done here?

It's a good question. Shouldn't the init() method clean after itself if it 
fails ? What's your opinion on this generally ?

> >  		return ret;
> > 
> > -	return run();
> > +	ret = run();
> > +
> > +	cleanup();
> > +
> > +	return ret;
> >  }

-- 
Regards,

Laurent Pinchart





More information about the libcamera-devel mailing list