Add time measurement for test-is-public-all.c

This commit is contained in:
Tim Rühsen 2015-12-03 10:08:04 +01:00
parent d14ada235c
commit 519b8c9d17
2 changed files with 34 additions and 2 deletions

View File

@ -216,6 +216,9 @@ elif test -n "$NEEDS_NSL" ; then
LIBS="$LIBS -lnsl" LIBS="$LIBS -lnsl"
fi fi
# Check for clock_gettime() used for performance measurement
AC_SEARCH_LIBS(clock_gettime, rt)
# Check for valgrind # Check for valgrind
ac_enable_valgrind=no ac_enable_valgrind=no
AC_ARG_ENABLE(valgrind-tests, AC_ARG_ENABLE(valgrind-tests,
@ -252,7 +255,7 @@ AC_SUBST(PSL_TESTFILE)
# check for alloca / alloca.h # check for alloca / alloca.h
AC_FUNC_ALLOCA AC_FUNC_ALLOCA
AC_CHECK_FUNCS([strndup]) AC_CHECK_FUNCS([strndup clock_gettime])
# Override the template file name of the generated .pc file, so that there # Override the template file name of the generated .pc file, so that there
# is no need to rename the template file when the API version changes. # is no need to rename the template file when the API version changes.

View File

@ -45,6 +45,9 @@
static int static int
ok, ok,
failed; failed;
#ifdef HAVE_CLOCK_GETTIME
struct timespec ts1, ts2;
#endif
static inline int _isspace_ascii(const char c) static inline int _isspace_ascii(const char c)
{ {
@ -63,6 +66,10 @@ static void test_psl(void)
printf("loaded %d suffixes and %d exceptions\n", psl_suffix_count(psl), psl_suffix_exception_count(psl)); printf("loaded %d suffixes and %d exceptions\n", psl_suffix_count(psl), psl_suffix_exception_count(psl));
if ((fp = fopen(PSL_FILE, "r"))) { if ((fp = fopen(PSL_FILE, "r"))) {
#ifdef HAVE_CLOCK_GETTIME
clock_gettime(CLOCK_REALTIME, &ts1);
#endif
while ((linep = fgets(buf, sizeof(buf), fp))) { while ((linep = fgets(buf, sizeof(buf), fp))) {
while (_isspace_ascii(*linep)) linep++; /* ignore leading whitespace */ while (_isspace_ascii(*linep)) linep++; /* ignore leading whitespace */
if (!*linep) continue; /* skip empty lines */ if (!*linep) continue; /* skip empty lines */
@ -107,6 +114,9 @@ static void test_psl(void)
} }
} }
#ifdef HAVE_CLOCK_GETTIME
clock_gettime(CLOCK_REALTIME, &ts2);
#endif
fclose(fp); fclose(fp);
} else { } else {
printf("Failed to open %s\n", PSL_FILE); printf("Failed to open %s\n", PSL_FILE);
@ -118,6 +128,10 @@ static void test_psl(void)
int main(int argc, const char * const *argv) int main(int argc, const char * const *argv)
{ {
#ifdef HAVE_CLOCK_GETTIME
long ns;
#endif
/* if VALGRIND testing is enabled, we have to call ourselves with valgrind checking */ /* if VALGRIND testing is enabled, we have to call ourselves with valgrind checking */
if (argc == 1) { if (argc == 1) {
const char *valgrind = getenv("TESTS_VALGRIND"); const char *valgrind = getenv("TESTS_VALGRIND");
@ -138,6 +152,21 @@ int main(int argc, const char * const *argv)
return 1; return 1;
} }
printf("Summary: All %d tests passed\n", ok + failed); #ifdef HAVE_CLOCK_GETTIME
if (ts1.tv_sec == ts2.tv_sec)
ns = ts2.tv_nsec - ts1.tv_nsec;
else if (ts1.tv_sec == ts2.tv_sec - 1)
ns = 1000000000L - (ts2.tv_nsec - ts1.tv_nsec);
else
ns = 0; /* let's assume something is wrong and skip outputting measured time */
if (ns)
printf("Summary: All %d tests passed in %ld.%06ld ms\n", ok, ns / 1000000, ns % 1000000000);
else
printf("Summary: All %d tests passed\n", ok);
#else
printf("Summary: All %d tests passed\n", ok);
#endif
return 0; return 0;
} }