From 8398c1dfe24391ee18b6147d22415f30f7b82f2a Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 3 Oct 2017 02:27:33 +0000 Subject: [PATCH] ztest.c: #include . * ztest.c: #include . (TEST_TIMING): Don't define, don't test. (xclock_gettime, xclockid_t): Define if !HAVE_CLOCK_GETTIME. (clockid_t, clock_gettime, CLOCK_REALTIME): Likewise. (ZLIB_CLOCK_GETTIME_ARG): Define. * configure.ac: Change clock_gettime_link to CLOCK_GETTIME_LINK. * Makefile.am: Likewise. * configure, Makefile.in: Rebuild. From-SVN: r253377 --- libbacktrace/ChangeLog | 11 ++++++++++ libbacktrace/Makefile.am | 2 +- libbacktrace/Makefile.in | 4 ++-- libbacktrace/configure | 4 ++-- libbacktrace/configure.ac | 4 ++-- libbacktrace/ztest.c | 45 ++++++++++++++++++++++++++------------- 6 files changed, 48 insertions(+), 22 deletions(-) diff --git a/libbacktrace/ChangeLog b/libbacktrace/ChangeLog index fde5a1bf6b5..27024b7ea40 100644 --- a/libbacktrace/ChangeLog +++ b/libbacktrace/ChangeLog @@ -1,3 +1,14 @@ +2017-10-02 Ian Lance Taylor + + * ztest.c: #include . + (TEST_TIMING): Don't define, don't test. + (xclock_gettime, xclockid_t): Define if !HAVE_CLOCK_GETTIME. + (clockid_t, clock_gettime, CLOCK_REALTIME): Likewise. + (ZLIB_CLOCK_GETTIME_ARG): Define. + * configure.ac: Change clock_gettime_link to CLOCK_GETTIME_LINK. + * Makefile.am: Likewise. + * configure, Makefile.in: Rebuild. + 2017-10-02 Thomas Schwinge PR other/67165 diff --git a/libbacktrace/Makefile.am b/libbacktrace/Makefile.am index b4f4df4ff02..7c0fab167b7 100644 --- a/libbacktrace/Makefile.am +++ b/libbacktrace/Makefile.am @@ -108,7 +108,7 @@ ztest_LDADD = libbacktrace.la if HAVE_ZLIB ztest_LDADD += -lz endif -ztest_LDADD += $(clock_gettime_link) +ztest_LDADD += $(CLOCK_GETTIME_LINK) check_PROGRAMS += ztest diff --git a/libbacktrace/Makefile.in b/libbacktrace/Makefile.in index 30a1442454a..407098ab9e0 100644 --- a/libbacktrace/Makefile.in +++ b/libbacktrace/Makefile.in @@ -215,6 +215,7 @@ BACKTRACE_SUPPORTS_THREADS = @BACKTRACE_SUPPORTS_THREADS@ BACKTRACE_USES_MALLOC = @BACKTRACE_USES_MALLOC@ CC = @CC@ CFLAGS = @CFLAGS@ +CLOCK_GETTIME_LINK = @CLOCK_GETTIME_LINK@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CYGPATH_W = @CYGPATH_W@ @@ -287,7 +288,6 @@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ -clock_gettime_link = @clock_gettime_link@ datadir = @datadir@ datarootdir = @datarootdir@ docdir = @docdir@ @@ -385,7 +385,7 @@ TESTS = $(check_PROGRAMS) $(am__append_4) @NATIVE_TRUE@ztest_SOURCES = ztest.c testlib.c @NATIVE_TRUE@ztest_CFLAGS = -DSRCDIR=\"$(srcdir)\" @NATIVE_TRUE@ztest_LDADD = libbacktrace.la $(am__append_2) \ -@NATIVE_TRUE@ $(clock_gettime_link) +@NATIVE_TRUE@ $(CLOCK_GETTIME_LINK) @NATIVE_TRUE@edtest_SOURCES = edtest.c edtest2_build.c testlib.c @NATIVE_TRUE@edtest_LDADD = libbacktrace.la @HAVE_PTHREAD_TRUE@@NATIVE_TRUE@ttest_SOURCES = ttest.c testlib.c diff --git a/libbacktrace/configure b/libbacktrace/configure index 57ca5eb22a8..7ed9509291c 100755 --- a/libbacktrace/configure +++ b/libbacktrace/configure @@ -614,7 +614,7 @@ HAVE_ZLIB_TRUE HAVE_PTHREAD_FALSE HAVE_PTHREAD_TRUE PTHREAD_CFLAGS -clock_gettime_link +CLOCK_GETTIME_LINK BACKTRACE_USES_MALLOC ALLOC_FILE VIEW_FILE @@ -12803,7 +12803,7 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_clock_gettime" >&5 $as_echo "$ac_cv_lib_rt_clock_gettime" >&6; } if test "x$ac_cv_lib_rt_clock_gettime" = x""yes; then : - clock_gettime_link=-lrt + CLOCK_GETTIME_LINK=-lrt $as_echo "#define HAVE_CLOCK_GETTIME 1" >>confdefs.h diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac index ad5368a9c04..9bc1d0f8464 100644 --- a/libbacktrace/configure.ac +++ b/libbacktrace/configure.ac @@ -397,11 +397,11 @@ clock_gettime_link= # we're using this for test timing only. if test "$ac_cv_func_clock_gettime" = no; then AC_CHECK_LIB(rt, clock_gettime, - [clock_gettime_link=-lrt + [CLOCK_GETTIME_LINK=-lrt AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [Define to 1 if you have the `clock_gettime' function.])]) fi -AC_SUBST(clock_gettime_link) +AC_SUBST(CLOCK_GETTIME_LINK) dnl Test whether the compiler supports the -pthread option. AC_CACHE_CHECK([whether -pthread is supported], diff --git a/libbacktrace/ztest.c b/libbacktrace/ztest.c index 0b1cbc35f0c..e2ab524825c 100644 --- a/libbacktrace/ztest.c +++ b/libbacktrace/ztest.c @@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE. */ #include "config.h" +#include #include #include #include @@ -43,16 +44,37 @@ POSSIBILITY OF SUCH DAMAGE. */ #include #endif -#ifdef HAVE_CLOCK_GETTIME -# define TEST_TIMING -#endif - #include "backtrace.h" #include "backtrace-supported.h" #include "internal.h" #include "testlib.h" +#ifndef HAVE_CLOCK_GETTIME + +typedef int xclockid_t; + +static int +xclock_gettime (xclockid_t id ATTRIBUTE_UNUSED, + struct timespec *ts ATTRIBUTE_UNUSED) +{ + errno = EINVAL; + return -1; +} + +#define clockid_t xclockid_t +#define clock_gettime xclock_gettime +#undef CLOCK_REALTIME +#define CLOCK_REALTIME 0 + +#endif /* !defined(HAVE_CLOCK_GETTIME) */ + +#ifdef CLOCK_PROCESS_CPUTIME_ID +#define ZLIB_CLOCK_GETTIME_ARG CLOCK_PROCESS_CPUTIME_ID +#else +#define ZLIB_CLOCK_GETTIME_ARG CLOCK_REALTIME +#endif + /* Some tests for the local zlib inflation code. */ struct zlib_test @@ -161,7 +183,7 @@ test_samples (struct backtrace_state *state) } } -#if defined HAVE_ZLIB && defined TEST_TIMING +#ifdef HAVE_ZLIB /* Given a set of TRIALS timings, discard the lowest and highest values and return the mean average of the rest. */ @@ -220,7 +242,6 @@ test_large (struct backtrace_state *state) unsigned char *uncompressed_buf; size_t uncompressed_bufsize; int r; -# ifdef TEST_TIMING clockid_t cid; struct timespec ts1; struct timespec ts2; @@ -229,7 +250,6 @@ test_large (struct backtrace_state *state) const size_t trials = 16; size_t ctimes[16]; size_t ztimes[16]; -# endif /* TEST_TIMING */ static const char * const names[] = { "Mark.Twain-Tom.Sawyer.txt", "../libgo/go/compress/testdata/Mark.Twain-Tom.Sawyer.txt" @@ -347,16 +367,13 @@ test_large (struct backtrace_state *state) printf ("PASS: inflate large\n"); -# ifdef TEST_TIMING - for (i = 0; i < trials; ++i) { - cid = CLOCK_REALTIME; -#ifdef CLOCK_PROCESS_CPUTIME_ID - cid = CLOCK_PROCESS_CPUTIME_ID; -#endif + cid = ZLIB_CLOCK_GETTIME_ARG; if (clock_gettime (cid, &ts1) < 0) { + if (errno == EINVAL) + return; perror ("clock_gettime"); return; } @@ -419,8 +436,6 @@ test_large (struct backtrace_state *state) printf ("zlib time: : %zu ns\n", ztime); printf ("percentage : %g\n", (double) ztime / (double) ctime); -# endif /* TEST_TIMING */ - return; fail: -- 2.30.2