ztest.c: #include <errno.h>.

* ztest.c: #include <errno.h>.
	(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
This commit is contained in:
Ian Lance Taylor 2017-10-03 02:27:33 +00:00 committed by Ian Lance Taylor
parent 0adaaf009b
commit 8398c1dfe2
6 changed files with 48 additions and 22 deletions

View File

@ -1,3 +1,14 @@
2017-10-02 Ian Lance Taylor <iant@golang.org>
* ztest.c: #include <errno.h>.
(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 <thomas@codesourcery.com>
PR other/67165

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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],

View File

@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE. */
#include "config.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -43,16 +44,37 @@ POSSIBILITY OF SUCH DAMAGE. */
#include <zlib.h>
#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: