Tests: cleanly exit from test apps on reception of SIGTERM
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 15 Feb 2018 16:53:17 +0000 (11:53 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 15 Feb 2018 20:37:23 +0000 (15:37 -0500)
There is a known lttng-ust limitation that can cause a buffer
to become unreadable if an application is killed or preempted
indefinitely between the reserve and commit operations in
while trying to record to a subbuffer.

A buffer being unreadable will cause some tests to fail since
events that are expected to be visible in a given stream
may not be shown by the trace viewers as the consumer was
unable to "get" that subbuffer.

It was fairly easy to reproduce this failure scenario using
the test_ust_fast snapshot test, in the "post_mortem" case.

This test case performs the following sequence of operations:

* setup a tracing session in snapshot mode
* launch an app
* kill(1) it after one event is known to have been produced
* record a snapshot
* try to read the resulting snapshot

Adding logging allowed the confirmation that the "get"
operation was indeed failing on the subbuffer to which the
application had run. This resulted in an empty stream
(file size == 0) being produced by the snapshot record operation.
The test was then failing because babeltrace reported that no
events were contained in the resulting trace.

Since there are no concrete solution to this limitation yet,
the test suite must ensure that the applications exit cleanly
on reception of a signal.

This patch introduces a SIGTERM signal handler in the test
applications which sets a "should_quit" flag to 1 and is
tested between every iteration of their event production loop.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
tests/utils/testapp/Makefile.am
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
tests/utils/testapp/gen-ust-tracef/Makefile.am
tests/utils/testapp/gen-ust-tracef/gen-ust-tracef.c
tests/utils/testapp/signal-helper.h [new file with mode: 0644]

index 0341de42b3879cf4e9a69b134625d9ecf306e2b5..c77fcb8b0b90fd2f5a7fa9756743bfb0f2d02cb8 100644 (file)
@@ -1,2 +1,3 @@
 SUBDIRS = gen-ust-events gen-ust-nevents gen-ust-tracef
 
+noinst_HEADERS = signal-helper.h
index 0cc7575d7cd0b6c96d9f8f1008caf6d66b9920cc..3945f779f4b8227d83b13b663df04f66897da7f4 100644 (file)
@@ -1,5 +1,6 @@
 AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src \
-               -I$(top_srcdir)/tests/utils -I$(srcdir) -O2 -g
+               -I$(top_srcdir)/tests/utils -I$(top_srcdir)/tests/utils/testapp \
+               -I$(srcdir) -O2 -g
 
 if LTTNG_TOOLS_BUILD_WITH_LIBDL
 LIBS += -ldl
index 3cfadbe9976a70aa6bdc16240707d49160ca01b0..c5dd31a355e1294229529a4ff20c3a3026bf8347 100644 (file)
@@ -32,6 +32,7 @@
 #include <poll.h>
 #include <errno.h>
 #include "utils.h"
+#include "signal-helper.h"
 
 #define TRACEPOINT_DEFINE
 #include "tp.h"
@@ -90,6 +91,11 @@ int main(int argc, char **argv)
        char *after_first_event_file_path = NULL;
        char *before_last_event_file_path = NULL;
 
+       if (set_signal_handler()) {
+               ret = -1;
+               goto end;
+       }
+
        if (argc >= 2) {
                /*
                 * If nr_iter is negative, do an infinite tracing loop.
@@ -133,6 +139,9 @@ int main(int argc, char **argv)
                                goto end;
                        }
                }
+               if (should_quit) {
+                       break;
+               }
        }
 
 end:
index b3212228fe2a6a852c6e125a4ba4ee9cd486e321..321630dc7e8b4e914e12d463a47a8cbd83700032 100644 (file)
@@ -1,5 +1,6 @@
 AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -I$(srcdir) \
-               -I$(top_srcdir)/tests/utils -O2 -g
+               -I$(top_srcdir)/tests/utils -I$(top_srcdir)/tests/utils/testapp \
+               -O2 -g
 
 if LTTNG_TOOLS_BUILD_WITH_LIBDL
 LIBS += -ldl
index 9d9f171b4616425b99116088306dedb9d16d7990..17fd8626ca5e03b14852a5c1466313aa5fc5924b 100644 (file)
@@ -26,6 +26,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 #include "utils.h"
+#include "signal-helper.h"
 
 #define TRACEPOINT_DEFINE
 #include "tp.h"
@@ -40,6 +41,11 @@ int main(int argc, char **argv)
        unsigned int nr_iter = 100;
        useconds_t nr_usec = 0;
 
+       if (set_signal_handler()) {
+               ret = -1;
+               goto end;
+       }
+
        if (argc >= 2) {
                nr_iter = atoi(argv[1]);
        }
@@ -67,6 +73,9 @@ int main(int argc, char **argv)
                                goto end;
                        }
                }
+               if (should_quit) {
+                       break;
+               }
        }
 
 end:
index 06171fa927c26d34d2b5da39a57d36683ef671ec..6b6099662eb9d3954b3103caa18777d0bbb7c214 100644 (file)
@@ -1,4 +1,5 @@
-AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -I$(srcdir) -O2 -g
+AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -I$(srcdir) -O2 -g \
+       -I$(top_srcdir)/tests/utils/testapp
 AM_LDFLAGS =
 
 if LTTNG_TOOLS_BUILD_WITH_LIBDL
index 0f70ef0f32134acc4e9aa81f3898a2bab24476cc..971bfd8d16a5f6d82de2481a5657f7a19c6db1b5 100644 (file)
@@ -29,6 +29,7 @@
 #include <unistd.h>
 
 #include <lttng/tracef.h>
+#include "signal-helper.h"
 
 const char *str = "test string";
 
@@ -54,6 +55,10 @@ int main(int argc, char **argv)
        useconds_t nr_usec = 0;
        char *tmp_file_path = NULL;
 
+       if (set_signal_handler()) {
+               return 1;
+       }
+
        if (argc >= 2) {
                nr_iter = atoi(argv[1]);
        }
@@ -78,6 +83,9 @@ int main(int argc, char **argv)
                        create_file(tmp_file_path);
                }
                usleep(nr_usec);
+               if (should_quit) {
+                       break;
+               }
        }
 
        return 0;
diff --git a/tests/utils/testapp/signal-helper.h b/tests/utils/testapp/signal-helper.h
new file mode 100644 (file)
index 0000000..4169e15
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) - 2018 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#ifndef LTTNG_TESTAPP_SIGNAL_HELPER_H
+#define LTTNG_TESTAPP_SIGNAL_HELPER_H
+
+#include <signal.h>
+
+static volatile int should_quit;
+
+static
+void sighandler(int sig)
+{
+       if (sig == SIGTERM) {
+               should_quit = 1;
+       }
+}
+
+static
+int set_signal_handler(void)
+{
+       int ret;
+       struct sigaction sa = {
+               .sa_flags = 0,
+               .sa_handler = sighandler,
+       };
+
+       ret = sigemptyset(&sa.sa_mask);
+       if (ret) {
+               perror("sigemptyset");
+               goto end;
+       }
+
+       ret = sigaction(SIGTERM, &sa, NULL);
+       if (ret) {
+               perror("sigaction");
+               goto end;
+       }
+end:
+       return ret;
+}
+
+#endif /* LTTNG_TESTAPP_SIGNAL_HELPER_H */
This page took 0.02889 seconds and 4 git commands to generate.