X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=tests%2Futils%2Ftap%2Ftap.c;h=1ef417fed34a70b4897918815c2c783db4840fd5;hb=2a69bf1437eb7e81979a1410b1a66a960b52caeb;hp=a7ec3db2c4ada41c9d23aedb951711818f6e3ca7;hpb=e73b293111eacc3c0f6eca0009ac3afa51ea85f1;p=lttng-tools.git diff --git a/tests/utils/tap/tap.c b/tests/utils/tap/tap.c index a7ec3db2c..1ef417fed 100644 --- a/tests/utils/tap/tap.c +++ b/tests/utils/tap/tap.c @@ -5,6 +5,8 @@ * Copyright (C) 2017 Jérémie Galarneau */ +#include "../utils.h" +#include "common/compat/time.hpp" #include "tap.h" #include @@ -14,6 +16,7 @@ #include #include #include +#include static int no_plan = 0; static int skip_all = 0; @@ -25,6 +28,8 @@ static char *todo_msg = NULL; static const char *todo_msg_fixed = "libtap malloc issue"; static int todo = 0; static int test_died = 0; +static int time_tests = 1; +struct timespec last_time; /* Encapsulate the pthread code in a conditional. In the absence of libpthread the code does nothing */ @@ -141,6 +146,7 @@ unsigned int _gen_result( } printf("\n"); + _output_test_time(); if (!ok) { if (getenv("HARNESS_ACTIVE") != NULL) @@ -176,8 +182,18 @@ void _tap_init(void) in the same place relative to stderr output as it does with Test::Harness */ setbuf(stdout, 0); + + char *autotime_env = getenv("TAP_AUTOTIME"); + if (autotime_env != NULL) { + time_tests = atoi(autotime_env); + if (time_tests != 0) { + time_tests = 1; + } + } + run_once = 1; } + lttng_clock_gettime(CLOCK_MONOTONIC, &last_time); } /* @@ -319,6 +335,7 @@ int skip(unsigned int n, const char *fmt, ...) printf("ok %d # skip %s\n", test_count, skip_msg != NULL ? skip_msg : "libtap():malloc() failed"); + _output_test_time(); } free(skip_msg); @@ -328,6 +345,20 @@ int skip(unsigned int n, const char *fmt, ...) return 1; } +void _output_test_time(void) +{ + struct timespec new_time; + int64_t time_ns; + if (time_tests) { + lttng_clock_gettime(CLOCK_MONOTONIC, &new_time); + time_ns = elapsed_time_ns(&last_time, &new_time); + printf(" ---\n duration_ms: %ld.%ld\n ...\n", + time_ns / 1000000, + time_ns % 1000000); + } + lttng_clock_gettime(CLOCK_MONOTONIC, &last_time); +} + void todo_start(const char *fmt, ...) { va_list ap;