Commit ace031dc authored by Petri Latvala's avatar Petri Latvala

lib: Help static analyzers figure out the execution flow

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.

v2:
 - Hack not needed for igt_subtest()
 - Make sure igt_fixture is entered once instead of an infinite loop

v3:
 - Rebase properly...
Signed-off-by: Petri Latvala's avatarPetri Latvala <petri.latvala@intel.com>
Reviewed-by: Daniel Vetter's avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent f882a542
Pipeline #7265 passed with stages
in 3 minutes and 15 seconds
......@@ -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;
......@@ -110,8 +118,9 @@ void __igt_fixture_end(void) __attribute__((noreturn));
*/
#define igt_fixture for (volatile int igt_tokencat(__tmpint,__LINE__) = 0; \
igt_tokencat(__tmpint,__LINE__) < 1 && \
__igt_fixture() && \
(sigsetjmp(igt_subtest_jmpbuf, 1) == 0); \
(STATIC_ANALYSIS_BUILD || \
(__igt_fixture() && \
(sigsetjmp(igt_subtest_jmpbuf, 1) == 0))); \
igt_tokencat(__tmpint,__LINE__) ++, \
__igt_fixture_complete())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment