From: Jérémie Galarneau Date: Thu, 12 Nov 2015 21:43:12 +0000 (-0500) Subject: Tests: Switch test apps to use usleep_safe() X-Git-Tag: v2.8.0-rc1~212 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=ae941114b338a4e6afb683345ee5f4fcc4296e01;p=lttng-tools.git Tests: Switch test apps to use usleep_safe() usleep_safe() ensures that usleep honors its timing guarantees (which it, according to the man pages, does not strictly enforce). Some tests need to make ensure no events are emitted at the same timestamp since Babeltrace does not define an ordering which can be relied upon in such a case. Signed-off-by: Jérémie Galarneau --- diff --git a/tests/utils/testapp/gen-ust-events/Makefile.am b/tests/utils/testapp/gen-ust-events/Makefile.am index 9372423b3..0cc7575d7 100644 --- a/tests/utils/testapp/gen-ust-events/Makefile.am +++ b/tests/utils/testapp/gen-ust-events/Makefile.am @@ -1,5 +1,5 @@ -AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -I$(srcdir) -O2 -g -AM_LDFLAGS = +AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src \ + -I$(top_srcdir)/tests/utils -I$(srcdir) -O2 -g if LTTNG_TOOLS_BUILD_WITH_LIBDL LIBS += -ldl @@ -11,5 +11,6 @@ endif if HAVE_LIBLTTNG_UST_CTL noinst_PROGRAMS = gen-ust-events gen_ust_events_SOURCES = gen-ust-events.c tp.c tp.h -gen_ust_events_LDADD = -llttng-ust -lurcu-bp +gen_ust_events_LDADD = -llttng-ust -lurcu-bp \ + $(top_builddir)/tests/utils/libtestutils.la endif diff --git a/tests/utils/testapp/gen-ust-events/gen-ust-events.c b/tests/utils/testapp/gen-ust-events/gen-ust-events.c index f1eb18f52..3cfadbe99 100644 --- a/tests/utils/testapp/gen-ust-events/gen-ust-events.c +++ b/tests/utils/testapp/gen-ust-events/gen-ust-events.c @@ -31,6 +31,7 @@ #include #include #include +#include "utils.h" #define TRACEPOINT_DEFINE #include "tp.h" @@ -84,7 +85,7 @@ int main(int argc, char **argv) char text[10] = "test"; double dbl = 2.0; float flt = 2222.0; - int nr_iter = 100; + int nr_iter = 100, ret = 0; useconds_t nr_usec = 0; char *after_first_event_file_path = NULL; char *before_last_event_file_path = NULL; @@ -127,9 +128,13 @@ int main(int argc, char **argv) */ create_file(after_first_event_file_path); if (nr_usec) { - usleep(nr_usec); + if (usleep_safe(nr_usec)) { + ret = -1; + goto end; + } } } - return 0; +end: + exit(!ret ? EXIT_SUCCESS : EXIT_FAILURE); } diff --git a/tests/utils/testapp/gen-ust-nevents/Makefile.am b/tests/utils/testapp/gen-ust-nevents/Makefile.am index ace00160b..b3212228f 100644 --- a/tests/utils/testapp/gen-ust-nevents/Makefile.am +++ b/tests/utils/testapp/gen-ust-nevents/Makefile.am @@ -1,5 +1,5 @@ -AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -I$(srcdir) -O2 -g -AM_LDFLAGS = +AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -I$(srcdir) \ + -I$(top_srcdir)/tests/utils -O2 -g if LTTNG_TOOLS_BUILD_WITH_LIBDL LIBS += -ldl @@ -11,5 +11,6 @@ endif if HAVE_LIBLTTNG_UST_CTL noinst_PROGRAMS = gen-ust-nevents gen_ust_nevents_SOURCES = gen-ust-nevents.c tp.c tp.h -gen_ust_nevents_LDADD = -llttng-ust -lurcu-bp +gen_ust_nevents_LDADD = -llttng-ust -lurcu-bp \ + $(top_builddir)/tests/utils/libtestutils.la endif diff --git a/tests/utils/testapp/gen-ust-nevents/gen-ust-nevents.c b/tests/utils/testapp/gen-ust-nevents/gen-ust-nevents.c index 9e5a1d1f2..9d9f171b4 100644 --- a/tests/utils/testapp/gen-ust-nevents/gen-ust-nevents.c +++ b/tests/utils/testapp/gen-ust-nevents/gen-ust-nevents.c @@ -25,13 +25,14 @@ #include #include #include +#include "utils.h" #define TRACEPOINT_DEFINE #include "tp.h" int main(int argc, char **argv) { - int i, netint; + int i, netint, ret = 0; long values[] = { 1, 2, 3 }; char text[10] = "test"; double dbl = 2.0; @@ -60,8 +61,14 @@ int main(int argc, char **argv) dbl, flt); tracepoint(tp, tptest5, i, netint, values, text, strlen(text), dbl, flt); - usleep(nr_usec); + if (nr_usec) { + if (usleep_safe(nr_usec)) { + ret = -1; + goto end; + } + } } - return 0; +end: + exit(!ret ? EXIT_SUCCESS : EXIT_FAILURE); }