From 8203c955c8bde94bba609d20abb39c576acf3e38 Mon Sep 17 00:00:00 2001 From: Tommi Rantala Date: Fri, 31 Aug 2012 11:29:26 +0300 Subject: [PATCH] Change test-varargs to check libunwind backtracing test-varargs is checking how `backtrace()' provided by the system behaves when varargs are used. Let's make the test more useful by changing it to test the `backtrace()' provided by libunwind. Change the testcase to return 0/1 for success/failure, and add it to the set of checks, so that it gets run on `make check'. Also call `unw_backtrace()' explicitly so that we do not need to bother with `execinfo.h' and `backtrace()' prototype. --- configure.in | 2 -- tests/Makefile.am | 6 +++--- tests/test-varargs.c | 45 ++++++++++++++++++++++++++++++++++++-------- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/configure.in b/configure.in index f577bc71..0a7577b6 100644 --- a/configure.in +++ b/configure.in @@ -303,7 +303,6 @@ old_LIBS="$LIBS" LIBS="" AC_SEARCH_LIBS(backtrace, execinfo) AM_CONDITIONAL(HAVE_BACKTRACE, test "x$ac_cv_search_backtrace" != xno) -BACKTRACELIB="$LIBS" LIBS="$old_LIBS" AC_SUBST(build_arch) @@ -319,7 +318,6 @@ AC_SUBST(PKG_MAINTAINER) AC_SUBST(enable_cxx_exceptions) AC_SUBST(enable_debug_frame) AC_SUBST(DLLIB) -AC_SUBST(BACKTRACELIB) AC_CONFIG_FILES(Makefile src/Makefile tests/Makefile tests/check-namespace.sh doc/Makefile doc/common.tex include/libunwind-common.h diff --git a/tests/Makefile.am b/tests/Makefile.am index 987f22b1..c96d8a58 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -46,13 +46,13 @@ endif #ARCH_IA64 Gtest-dyn1 Ltest-dyn1 \ Gtest-trace Ltest-trace \ test-async-sig test-flush-cache test-init-remote \ - test-mem test-setjmp test-ptrace \ + test-mem test-setjmp test-ptrace test-varargs \ Ltest-nomalloc Ltest-nocalloc rs-race noinst_PROGRAMS_cdep = forker crasher mapper test-ptrace-misc \ Gperf-simple Lperf-simple if HAVE_BACKTRACE - noinst_PROGRAMS_cdep += Gperf-trace Lperf-trace test-varargs + noinst_PROGRAMS_cdep += Gperf-trace Lperf-trace endif if SUPPORT_CXX_EXCEPTIONS @@ -148,7 +148,7 @@ test_proc_info_LDADD = $(LIBUNWIND) test_static_link_LDADD = $(LIBUNWIND) test_strerror_LDADD = $(LIBUNWIND) rs_race_LDADD = $(LIBUNWIND) -lpthread -test_varargs_LDADD = @BACKTRACELIB@ +test_varargs_LDADD = $(LIBUNWIND_local) Gtest_bt_LDADD = $(LIBUNWIND) $(LIBUNWIND_local) Gtest_concurrent_LDADD = $(LIBUNWIND) $(LIBUNWIND_local) -lpthread diff --git a/tests/test-varargs.c b/tests/test-varargs.c index 9366461e..bf5cee30 100644 --- a/tests/test-varargs.c +++ b/tests/test-varargs.c @@ -1,28 +1,44 @@ +#include #include #include #include #include -extern int backtrace (void **, int); +int ok; +int verbose; -static void +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 3) +void a (int, ...) __attribute__((noinline, optimize(0))); +void b (void) __attribute__((noinline, optimize(0))); +void c (void) __attribute__((noinline, optimize(0))); +#endif + +void b (void) { void *v[20]; int i, n; - n = backtrace(v, 20); - for (i = 0; i < n; ++i) - printf ("[%d] %p\n", i, v[i]); + n = unw_backtrace(v, 20); + + /* Check that the number of addresses given by unw_backtrace() looks + * reasonable. If the compiler inlined everything, then this check will also + * break. */ + if (n >= 7) + ok = 1; + + if (verbose) + for (i = 0; i < n; ++i) + printf ("[%d] %p\n", i, v[i]); } -static void +void c (void) { b (); } -static void +void a (int d, ...) { switch (d) @@ -45,8 +61,21 @@ a (int d, ...) } int -main (void) +main (int argc, char **argv __attribute__((unused))) { + if (argc > 1) + verbose = 1; + a (5, 3, 4, 5, 6); + + if (!ok) + { + fprintf (stderr, "FAILURE: expected deeper backtrace.\n"); + return 1; + } + + if (verbose) + printf ("SUCCESS.\n"); + return 0; }