Index: Makefile.am =================================================================== --- Makefile.am (revision 253376) +++ Makefile.am (working copy) @@ -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 Index: configure.ac =================================================================== --- configure.ac (revision 253376) +++ configure.ac (working copy) @@ -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], Index: ztest.c =================================================================== --- ztest.c (revision 253376) +++ ztest.c (working copy) @@ -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 *st } } -#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 *stat 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 *stat 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 *stat 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 *stat printf ("zlib time: : %zu ns\n", ztime); printf ("percentage : %g\n", (double) ztime / (double) ctime); -# endif /* TEST_TIMING */ - return; fail: