public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Petri Latvala <petri.latvala@intel.com>
Cc: igt-dev@lists.freedesktop.org
Subject: Re: [igt-dev] [PATCH i-g-t 1/1] lib: Help static analyzers figure out the execution flow
Date: Tue, 30 Oct 2018 16:29:44 +0100	[thread overview]
Message-ID: <20181030152944.GS21967@phenom.ffwll.local> (raw)
In-Reply-To: <20181030141508.12451-1-petri.latvala@intel.com>

On Tue, Oct 30, 2018 at 04:15:08PM +0200, Petri Latvala wrote:
> When running any kind of static analysis on IGT, one tends to drown in
> warnings about using uninitialized variables in subtests, because
> static analysis is unable to figure out that igt_fixture blocks are
> always entered if a subtest block is entered. Aid the discovery of
> correct execution flow by making static analysis always enter all
> igt_fixture blocks and all subtest blocks.
> 
> Automatic discovery of static analyzers is done for Clang, Coverity
> and Klocwork, using macros found by quick googling. For explicit
> control on possible other analyzers, defining STATIC_ANALYSIS_BUILD=1
> manually will activate this hack.
> 
> Signed-off-by: Petri Latvala <petri.latvala@intel.com>

I guess if it helps, this makes sense.

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>

> ---
> lib/igt_core.h | 25 ++++++++++++++++++-------
>  1 file changed, 18 insertions(+), 7 deletions(-)
> 
> diff --git a/lib/igt_core.h b/lib/igt_core.h
> index b80e1702..0f643f6b 100644
> --- a/lib/igt_core.h
> +++ b/lib/igt_core.h
> @@ -46,6 +46,14 @@
>  #endif
>  
>  
> +#ifndef STATIC_ANALYSIS_BUILD
> +#if defined(__clang_analyzer__) || defined(__COVERITY__) || defined(__KLOCWORK__)
> +#define STATIC_ANALYSIS_BUILD 1
> +#else
> +#define STATIC_ANALYSIS_BUILD 0
> +#endif
> +#endif
> +
>  extern const char* __igt_test_description __attribute__((weak));
>  extern bool __igt_plain_output;
>  extern char *igt_frame_dump_path;
> @@ -109,9 +117,10 @@ void __igt_fixture_end(void) __attribute__((noreturn));
>   * blocks should be annotated with igt_fixture.
>   */
>  #define igt_fixture for (volatile int igt_tokencat(__tmpint,__LINE__) = 0; \
> +                         STATIC_ANALYSIS_BUILD || ( \
>  			 igt_tokencat(__tmpint,__LINE__) < 1 && \
>  			 __igt_fixture() && \
> -			 (sigsetjmp(igt_subtest_jmpbuf, 1) == 0); \
> +			 (sigsetjmp(igt_subtest_jmpbuf, 1) == 0)); \
>  			 igt_tokencat(__tmpint,__LINE__) ++, \
>  			 __igt_fixture_complete())
>  
> @@ -169,15 +178,17 @@ bool __igt_run_subtest(const char *subtest_name);
>   *
>   * This is a simpler version of igt_subtest_f()
>   */
> -#define igt_subtest(name) for (; __igt_run_subtest((name)) && \
> -				   (sigsetjmp(igt_subtest_jmpbuf, 1) == 0); \
> -				   igt_success())
> +#define igt_subtest(name) for (; STATIC_ANALYSIS_BUILD ||		\
> +				       (__igt_run_subtest((name)) &&	\
> +					(sigsetjmp(igt_subtest_jmpbuf, 1) == 0)); \
> +                                  igt_success())
>  #define __igt_subtest_f(tmp, format...) \
>  	for (char tmp [256]; \
> -	     snprintf( tmp , sizeof( tmp ), \
> +	     STATIC_ANALYSIS_BUILD || \
> +	     ((snprintf( tmp , sizeof( tmp ), \
>  		      format), \
> -	     __igt_run_subtest( tmp ) && \
> -	     (sigsetjmp(igt_subtest_jmpbuf, 1) == 0); \
> +	       __igt_run_subtest( tmp )) && \
> +	      (sigsetjmp(igt_subtest_jmpbuf, 1) == 0)); \
>  	     igt_success())
>  
>  /**
> -- 
> 2.18.0
> 
> _______________________________________________
> igt-dev mailing list
> igt-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/igt-dev

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  reply	other threads:[~2018-10-30 15:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-30 14:15 [igt-dev] [PATCH i-g-t 1/1] lib: Help static analyzers figure out the execution flow Petri Latvala
2018-10-30 15:29 ` Daniel Vetter [this message]
2018-10-30 15:38 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/1] " Patchwork
2018-10-30 19:26 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2018-10-31 11:30 ` [igt-dev] [PATCH i-g-t v2 1/1] " Petri Latvala
2018-10-31 11:32   ` [igt-dev] [PATCH i-g-t v3 " Petri Latvala
2018-10-31 15:38 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,v3,1/1] lib: Help static analyzers figure out the execution flow (rev3) Patchwork
2018-10-31 21:25 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181030152944.GS21967@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=petri.latvala@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox