From patchwork Fri Mar 13 17:04:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Wood X-Patchwork-Id: 6007361 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B627B9F2A9 for ; Fri, 13 Mar 2015 17:04:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 91AAB20225 for ; Fri, 13 Mar 2015 17:04:46 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 4DEE02021A for ; Fri, 13 Mar 2015 17:04:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B97E16EAFE; Fri, 13 Mar 2015 10:04:44 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-we0-f182.google.com (mail-we0-f182.google.com [74.125.82.182]) by gabe.freedesktop.org (Postfix) with ESMTP id 138E96EAFE for ; Fri, 13 Mar 2015 10:04:43 -0700 (PDT) Received: by wesw62 with SMTP id w62so24712095wes.0 for ; Fri, 13 Mar 2015 10:04:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-type:content-transfer-encoding; bh=TTHI1TrMZ3Ns34qWuyGR/zdT0NJup2Ij6YJtEu26BqM=; b=mV7QzmA6PdcfRfaTw0zYOIIZZ4f7N3byF19N7ObFDIRl/2lNxJcEHVvZg9xh8Xf5B0 0qR1BdII9Kqq8QT4NSVxwV8LRlLj9mYVyYK0wmsLSAqzKEnHJaKtHgbak6bZlOEuK6lO DgdpScdD4CNTVNHAMxIov32HA23mOIDWhZ9uScnLDyYEAkxzmEtWO9XA/wsYTRnDIwtB o0O2Kvq2/lQa7r9m9wbZQ5h+MZgs+jA8Cu5LNaVhMtar67bE1M2yZTbqa2fAd4voQi+W 8IsRe05IqgEufT2jz3wmV2HhxyA2wU3oXIW84D9B8UdyQbfEl9pnMqWHtdqcE7RJWw6M BtXw== X-Gm-Message-State: ALoCoQlkGtcH/qL1rV80WssJ+cMyEdbPusqfxQ2oizHiDouyolR/taY5ipTxYL3TnOo6XKiqi3uO X-Received: by 10.180.79.35 with SMTP id g3mr16586133wix.42.1426266282026; Fri, 13 Mar 2015 10:04:42 -0700 (PDT) Received: from pistachio.icx.intel.com ([83.217.123.106]) by mx.google.com with ESMTPSA id r3sm3626627wjw.7.2015.03.13.10.04.40 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Mar 2015 10:04:41 -0700 (PDT) From: Thomas Wood To: intel-gfx@lists.freedesktop.org Date: Fri, 13 Mar 2015 17:04:40 +0000 Message-Id: <1426266280-30901-1-git-send-email-thomas.wood@intel.com> X-Mailer: git-send-email 2.1.0 MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t] lib: print a stack trace when a test assertion fails X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY, URIBL_BLACK autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add an optional dependency on libunwind to print stack traces when a test assertion fails. Signed-off-by: Thomas Wood --- 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 + +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, ""); + + 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)