Tests: Switch test apps to use usleep_safe()
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 12 Nov 2015 21:43:12 +0000 (16:43 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 12 Nov 2015 22:16:07 +0000 (17:16 -0500)
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 <jeremie.galarneau@efficios.com>
tests/utils/testapp/gen-ust-events/Makefile.am
tests/utils/testapp/gen-ust-events/gen-ust-events.c
tests/utils/testapp/gen-ust-nevents/Makefile.am
tests/utils/testapp/gen-ust-nevents/gen-ust-nevents.c

index 9372423b33c8f5ef531f3f8800fba674f8000acc..0cc7575d7cd0b6c96d9f8f1008caf6d66b9920cc 100644 (file)
@@ -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
index f1eb18f52f927cb7ffd6181d11f2d19666768e42..3cfadbe9976a70aa6bdc16240707d49160ca01b0 100644 (file)
@@ -31,6 +31,7 @@
 #include <signal.h>
 #include <poll.h>
 #include <errno.h>
+#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);
 }
index ace00160b2511cd98402a4196d3dfd8a7b711aca..b3212228fe2a6a852c6e125a4ba4ee9cd486e321 100644 (file)
@@ -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
index 9e5a1d1f287871f32af22e3f9f943feba471236b..9d9f171b4616425b99116088306dedb9d16d7990 100644 (file)
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
+#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);
 }
This page took 0.028863 seconds and 5 git commands to generate.