[Intel-gfx] [PATCH i-g-t] lib: print a stack trace when a test assertion fails

Daniel Vetter daniel at ffwll.ch
Fri Mar 13 10:25:36 PDT 2015


On Fri, Mar 13, 2015 at 05:04:40PM +0000, Thomas Wood wrote:
> Add an optional dependency on libunwind to print stack traces when a
> test assertion fails.
> 
> Signed-off-by: Thomas Wood <thomas.wood at intel.com>

Awesome. Also ack from me (too lazy to dig out manpages on friday evening
for proper review, but looks good).

Cheers, Daniel
> ---
>  benchmarks/Makefile.am |  4 ++--
>  configure.ac           | 10 ++++++++++
>  debugger/Makefile.am   |  3 ++-
>  demos/Makefile.am      |  4 ++--
>  lib/Makefile.am        |  5 ++---
>  lib/igt_core.c         | 31 +++++++++++++++++++++++++++++++
>  tests/Makefile.am      |  3 ++-
>  tools/Makefile.am      |  4 ++--
>  8 files changed, 53 insertions(+), 11 deletions(-)
> 
> diff --git a/benchmarks/Makefile.am b/benchmarks/Makefile.am
> index 86f755a..8473b18 100644
> --- a/benchmarks/Makefile.am
> +++ b/benchmarks/Makefile.am
> @@ -2,5 +2,5 @@
>  include Makefile.sources
>  
>  AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/lib
> -AM_CFLAGS = $(DRM_CFLAGS) $(CWARNFLAGS) $(CAIRO_CFLAGS)
> -LDADD = $(top_builddir)/lib/libintel_tools.la $(DRM_LIBS) $(PCIACCESS_LIBS) $(CAIRO_LIBS)
> +AM_CFLAGS = $(DRM_CFLAGS) $(CWARNFLAGS) $(CAIRO_CFLAGS) $(LIBUNWIND_CFLAGS)
> +LDADD = $(top_builddir)/lib/libintel_tools.la $(DRM_LIBS) $(PCIACCESS_LIBS) $(CAIRO_LIBS) $(LIBUNWIND_LIBS)
> diff --git a/configure.ac b/configure.ac
> index 9b646dd..b9ecef8 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -187,6 +187,15 @@ AM_CONDITIONAL(BUILD_SHADER_DEBUGGER, [test "x$BUILD_SHADER_DEBUGGER" != xno])
>  AS_IF([test "x$BUILD_SHADER_DEBUGGER" != xno],
>        [enable_debugger=yes], [enable_debugger=no])
>  
> +AC_ARG_WITH(libunwind,
> +	    AS_HELP_STRING([--without-libunwind],
> +			   [Build tests without libunwind support]),
> +	    [], [with_libunwind=yes])
> +if test "x$with_libunwind" = xyes; then
> +	PKG_CHECK_MODULES(LIBUNWIND, libunwind, AC_DEFINE(HAVE_LIBUNWIND, 1, [libunwind support]),
> +			  AC_MSG_ERROR([libunwind not found. Use --without-libunwind to disable libunwind support.]))
> +fi
> +
>  # -----------------------------------------------------------------------------
>  
>  # To build multithread code, gcc uses -pthread, Solaris Studio cc uses -mt
> @@ -243,6 +252,7 @@ echo ""
>  echo " • Tests:"
>  echo "       Build tests        : ${BUILD_TESTS}"
>  echo "       Compile prime tests: ${NOUVEAU}"
> +echo "       Print stack traces : ${with_libunwind}"
>  echo ""
>  echo " • Tools:"
>  echo "       Assembler          : ${enable_assembler}"
> diff --git a/debugger/Makefile.am b/debugger/Makefile.am
> index f1e49b9..0b6028b 100644
> --- a/debugger/Makefile.am
> +++ b/debugger/Makefile.am
> @@ -12,6 +12,7 @@ AM_CFLAGS = 			\
>  	$(DRM_CFLAGS) 		\
>  	$(PCIACCESS_CFLAGS) 	\
>  	$(CAIRO_CFLAGS)		\
> +	$(LIBUNWIND_CFLAGS)	\
>  	$(CWARNFLAGS)
>  
> -LDADD = $(top_builddir)/lib/libintel_tools.la $(DRM_LIBS) $(PCIACCESS_LIBS) $(CAIRO_LIBS)
> +LDADD = $(top_builddir)/lib/libintel_tools.la $(DRM_LIBS) $(PCIACCESS_LIBS) $(CAIRO_LIBS) $(LIBUNWIND_LIBS)
> diff --git a/demos/Makefile.am b/demos/Makefile.am
> index 49804d7..029581a 100644
> --- a/demos/Makefile.am
> +++ b/demos/Makefile.am
> @@ -3,5 +3,5 @@ bin_PROGRAMS = 				\
>  	$(NULL)
>  
>  AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/lib
> -AM_CFLAGS = $(DRM_CFLAGS) $(PCIACCESS_CFLAGS) $(CWARNFLAGS) $(CAIRO_CFLAGS)
> -LDADD = $(top_builddir)/lib/libintel_tools.la $(DRM_LIBS) $(PCIACCESS_LIBS) $(CAIRO_LIBS)
> +AM_CFLAGS = $(DRM_CFLAGS) $(PCIACCESS_CFLAGS) $(CWARNFLAGS) $(CAIRO_CFLAGS) $(LIBUNWIND_CFLAGS)
> +LDADD = $(top_builddir)/lib/libintel_tools.la $(DRM_LIBS) $(PCIACCESS_LIBS) $(CAIRO_LIBS) $(LIBUNWIND_LIBS)
> diff --git a/lib/Makefile.am b/lib/Makefile.am
> index a5a4390..4db90d4 100644
> --- a/lib/Makefile.am
> +++ b/lib/Makefile.am
> @@ -9,12 +9,11 @@ noinst_LTLIBRARIES = libintel_tools.la
>  noinst_HEADERS = check-ndebug.h
>  
>  AM_CPPFLAGS = -I$(top_srcdir)
> -AM_CFLAGS = $(DRM_CFLAGS) $(CWARNFLAGS)  \
> +AM_CFLAGS = $(DRM_CFLAGS) $(CWARNFLAGS) $(LIBUNWIND_CFLAGS) \
>  	    -DIGT_DATADIR=\""$(abs_top_srcdir)/tests"\" \
>  	    -DIGT_LOG_DOMAIN=\""$(subst _,-,$*)"\" \
>  	    -pthread
>  
> -
> -LDADD = $(CAIRO_LIBS)
> +LDADD = $(CAIRO_LIBS) $(LIBUNWIND_LIBS)
>  AM_CFLAGS += $(CAIRO_CFLAGS)
>  
> diff --git a/lib/igt_core.c b/lib/igt_core.c
> index 4ae3524..7f879aa 100644
> --- a/lib/igt_core.c
> +++ b/lib/igt_core.c
> @@ -955,6 +955,33 @@ static bool run_under_gdb(void)
>  		strncmp(basename(buf), "gdb", 3) == 0);
>  }
>  
> +#ifdef HAVE_LIBUNWIND
> +#define UNW_LOCAL_ONLY
> +#include <libunwind.h>
> +
> +static void print_backtrace(void)
> +{
> +	unw_cursor_t cursor;
> +	unw_context_t uc;
> +	int stack_num = 0;
> +
> +	printf("Stack trace:\n");
> +
> +	unw_getcontext(&uc);
> +	unw_init_local(&cursor, &uc);
> +	while (unw_step(&cursor) > 0) {
> +		char name[255];
> +		unw_word_t off;
> +
> +		if (unw_get_proc_name(&cursor, name, 255, &off) < 0)
> +			strcpy(name, "<unknown>");
> +
> +		printf("  #%d [%s+0x%x]\n", stack_num++, name,
> +		       (unsigned int) off);
> +	}
> +}
> +#endif
> +
>  void __igt_fail_assert(int exitcode, const char *domain, const char *file,
>  		       const int line, const char *func, const char *assertion,
>  		       const char *f, ...)
> @@ -976,6 +1003,10 @@ void __igt_fail_assert(int exitcode, const char *domain, const char *file,
>  		va_end(args);
>  	}
>  
> +#ifdef HAVE_LIBUNWIND
> +	print_backtrace();
> +#endif
> +
>  	if (run_under_gdb())
>  		abort();
>  	igt_fail(exitcode);
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index d808973..bc514ae 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -22,9 +22,10 @@ AM_CFLAGS = $(DRM_CFLAGS) $(CWARNFLAGS) \
>  	-I$(srcdir)/../lib \
>  	-include "$(srcdir)/../lib/check-ndebug.h" \
>  	-DIGT_DATADIR=\""$(abs_srcdir)"\" \
> +	$(LIBUNWIND_CFLAGS) \
>  	$(NULL)
>  
> -LDADD = ../lib/libintel_tools.la $(PCIACCESS_LIBS) $(DRM_LIBS) 
> +LDADD = ../lib/libintel_tools.la $(PCIACCESS_LIBS) $(DRM_LIBS) $(LIBUNWIND_LIBS)
>  
>  LDADD += $(CAIRO_LIBS) $(LIBUDEV_LIBS) $(GLIB_LIBS)
>  AM_CFLAGS += $(CAIRO_CFLAGS) $(LIBUDEV_CFLAGS) $(GLIB_CFLAGS)
> diff --git a/tools/Makefile.am b/tools/Makefile.am
> index 64fa060..04bfd12 100644
> --- a/tools/Makefile.am
> +++ b/tools/Makefile.am
> @@ -7,6 +7,6 @@ SUBDIRS += quick_dump
>  endif
>  
>  AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/lib
> -AM_CFLAGS = $(DRM_CFLAGS) $(PCIACCESS_CFLAGS) $(CWARNFLAGS) $(CAIRO_CFLAGS)
> -LDADD = $(top_builddir)/lib/libintel_tools.la $(DRM_LIBS) $(PCIACCESS_LIBS) $(CAIRO_LIBS) $(LIBUDEV_LIBS)
> +AM_CFLAGS = $(DRM_CFLAGS) $(PCIACCESS_CFLAGS) $(CWARNFLAGS) $(CAIRO_CFLAGS) $(LIBUNWIND_CFLAGS)
> +LDADD = $(top_builddir)/lib/libintel_tools.la $(DRM_LIBS) $(PCIACCESS_LIBS) $(CAIRO_LIBS) $(LIBUDEV_LIBS) $(LIBUNWIND_LIBS)
>  
> -- 
> 2.1.0
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch


More information about the Intel-gfx mailing list