[igt-dev] [PATCH i-g-t] tests: close(fd) without igt_fixture considered harmful

Daniel Vetter daniel at ffwll.ch
Mon Nov 26 14:26:06 UTC 2018


On Mon, Nov 26, 2018 at 02:10:08PM +0200, Jani Nikula wrote:
> On Mon, 26 Nov 2018, Daniel Vetter <daniel.vetter at ffwll.ch> wrote:
> > Some tests assume that close on an unopened fd is fine, except it's
> > not just unopened but actually stack garbage. There's a good chance we
> > end up running close(0), which wreaks the testcase enumeration. Fix
> > this.
> >
> > Not sure there's a better way to catch this than git grep plus lots of
> > manual auditing ... The unit tests only catch it by accident (x86
> > works fine, I hit it in one testcase only cross-building to aarch64).
> >
> > Signed-off-by: Daniel Vetter <daniel.vetter at intel.com>
> > ---
> >  tests/i915/gem_pread_after_blit.c  | 3 ++-
> >  tests/i915/gem_tiled_fence_blits.c | 3 ++-
> >  tests/i915/gem_tiled_swapping.c    | 3 ++-
> >  3 files changed, 6 insertions(+), 3 deletions(-)
> >
> > diff --git a/tests/i915/gem_pread_after_blit.c b/tests/i915/gem_pread_after_blit.c
> > index 6ef3ca200776..cee9212749d6 100644
> > --- a/tests/i915/gem_pread_after_blit.c
> > +++ b/tests/i915/gem_pread_after_blit.c
> > @@ -248,5 +248,6 @@ igt_main
> >  		drm_intel_bufmgr_destroy(bufmgr);
> >  	}
> >  
> > -	close(fd);
> 
> This one isn't stack garbage, it's guaranteed to be 0 for
> !igt_fixture. The other two are garbage on stack.
> 
> The change is
> 
> Reviewed-by: Jani Nikula <jani.nikula at intel.com>
> 
> but please update the commit message.

Indeed! Noted in the commit message and pushed, thanks for your review.
-Daniel

> 
> > +	igt_fixture
> > +		close(fd);
> >  }
> > diff --git a/tests/i915/gem_tiled_fence_blits.c b/tests/i915/gem_tiled_fence_blits.c
> > index c02e35a5fe4c..2453bcc0b271 100644
> > --- a/tests/i915/gem_tiled_fence_blits.c
> > +++ b/tests/i915/gem_tiled_fence_blits.c
> > @@ -230,5 +230,6 @@ igt_main
> >  		run_test(fd, count);
> >  	}
> >  
> > -	close(fd);
> > +	igt_fixture
> > +		close(fd);
> >  }
> > diff --git a/tests/i915/gem_tiled_swapping.c b/tests/i915/gem_tiled_swapping.c
> > index dce668063014..ddf2a748fc84 100644
> > --- a/tests/i915/gem_tiled_swapping.c
> > +++ b/tests/i915/gem_tiled_swapping.c
> > @@ -235,5 +235,6 @@ igt_main
> >  			thread_fini(&threads[n]);
> >  	}
> >  
> > -	close(fd);
> > +	igt_fixture
> > +		close(fd);
> >  }
> 
> -- 
> Jani Nikula, Intel Open Source Graphics Center

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


More information about the igt-dev mailing list