.gitignore: ignore local vscode workspace settings file
[lttng-tools.git] / tests / utils / testapp / gen-ust-events / gen-ust-events.cpp
index cf8819977dc79d83596b1da1d31a746d6b271cb9..3b62ed0dfee9a80baa82b6cb50c0c05dcd0232ec 100644 (file)
@@ -6,10 +6,17 @@
  */
 
 #define _LGPL_SOURCE
-#include <getopt.h>
+#include "signal-helper.hpp"
+#include "utils.h"
+
 #include <arpa/inet.h>
+#include <errno.h>
 #include <fcntl.h>
+#include <getopt.h>
+#include <poll.h>
+#include <signal.h>
 #include <stdarg.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
-#include <stdbool.h>
-#include <signal.h>
-#include <poll.h>
-#include <errno.h>
-#include "utils.h"
-#include "signal-helper.h"
 
 #define TRACEPOINT_DEFINE
 #include "tp.h"
 
-static struct option long_options[] =
-{
+static struct option long_options[] = {
        /* These options set a flag. */
-       {"iter", required_argument, 0, 'i'},
-       {"wait", required_argument, 0, 'w'},
-       {"sync-after-first-event", required_argument, 0, 'a'},
-       {"sync-before-last-event", required_argument, 0, 'b'},
-       {"sync-before-last-event-touch", required_argument, 0, 'c'},
-       {"sync-before-exit", required_argument, 0, 'd'},
-       {"sync-before-exit-touch", required_argument, 0, 'e'},
-       {"emit-end-event", no_argument, 0, 'f'},
-       {0, 0, 0, 0}
+       { "iter", required_argument, nullptr, 'i' },
+       { "wait", required_argument, nullptr, 'w' },
+       { "sync-application-in-main-touch", required_argument, nullptr, 'a' },
+       { "sync-before-first-event", required_argument, nullptr, 'b' },
+       { "sync-after-first-event", required_argument, nullptr, 'c' },
+       { "sync-before-last-event", required_argument, nullptr, 'd' },
+       { "sync-before-last-event-touch", required_argument, nullptr, 'e' },
+       { "sync-before-exit", required_argument, nullptr, 'f' },
+       { "sync-before-exit-touch", required_argument, nullptr, 'g' },
+       { "emit-end-event", no_argument, nullptr, 'h' },
+       { nullptr, 0, nullptr, 0 }
 };
 
 int main(int argc, char **argv)
@@ -54,17 +56,19 @@ int main(int argc, char **argv)
        uint32_t net_values[] = { 1, 2, 3 };
        int nr_iter = 100, ret = 0, first_event_file_created = 0;
        useconds_t nr_usec = 0;
-       char *after_first_event_file_path = NULL;
-       char *before_last_event_file_path = NULL;
+       char *application_in_main_file_path = nullptr;
+       char *before_first_event_file_path = nullptr;
+       char *after_first_event_file_path = nullptr;
+       char *before_last_event_file_path = nullptr;
        /*
         * Touch a file to indicate that all events except one were
         * generated.
         */
-       char *before_last_event_file_path_touch = NULL;
+       char *before_last_event_file_path_touch = nullptr;
        /* Touch file when we are exiting */
-       char *before_exit_file_path_touch = NULL;
+       char *before_exit_file_path_touch = nullptr;
        /* Wait on file before exiting */
-       char *before_exit_file_path = NULL;
+       char *before_exit_file_path = nullptr;
        /* Emit an end event */
        bool emit_end_event = false;
 
@@ -72,25 +76,31 @@ int main(int argc, char **argv)
                net_values[i] = htonl(net_values[i]);
        }
 
-       while ((option = getopt_long(argc, argv, "i:w:a:b:c:d:e:f",
-                               long_options, &option_index)) != -1) {
+       while ((option = getopt_long(
+                       argc, argv, "i:w:a:b:c:d:e:f:g:h", long_options, &option_index)) != -1) {
                switch (option) {
                case 'a':
-                       after_first_event_file_path = strdup(optarg);
+                       application_in_main_file_path = strdup(optarg);
                        break;
                case 'b':
-                       before_last_event_file_path = strdup(optarg);
+                       before_first_event_file_path = strdup(optarg);
                        break;
                case 'c':
-                       before_last_event_file_path_touch = strdup(optarg);
+                       after_first_event_file_path = strdup(optarg);
                        break;
                case 'd':
-                       before_exit_file_path = strdup(optarg);
+                       before_last_event_file_path = strdup(optarg);
                        break;
                case 'e':
-                       before_exit_file_path_touch = strdup(optarg);
+                       before_last_event_file_path_touch = strdup(optarg);
                        break;
                case 'f':
+                       before_exit_file_path = strdup(optarg);
+                       break;
+               case 'g':
+                       before_exit_file_path_touch = strdup(optarg);
+                       break;
+               case 'h':
                        emit_end_event = true;
                        break;
                case 'i':
@@ -124,12 +134,19 @@ int main(int argc, char **argv)
                goto end;
        }
 
-
        if (set_signal_handler()) {
                ret = -1;
                goto end;
        }
 
+       if (application_in_main_file_path) {
+               create_file(application_in_main_file_path);
+       }
+
+       if (before_first_event_file_path) {
+               wait_on_file(before_first_event_file_path);
+       }
+
        for (i = 0; nr_iter < 0 || i < nr_iter; i++) {
                if (nr_iter >= 0 && i == nr_iter - 1) {
                        if (before_last_event_file_path_touch) {
@@ -151,8 +168,17 @@ int main(int argc, char **argv)
                        }
                }
                netint = htonl(i);
-               tracepoint(tp, tptest, i, netint, values, text,
-                       strlen(text), escape, net_values, dbl, flt);
+               tracepoint(tp,
+                          tptest,
+                          i,
+                          netint,
+                          values,
+                          text,
+                          strlen(text),
+                          escape,
+                          net_values,
+                          dbl,
+                          flt);
 
                /*
                 * First loop we create the file if asked to indicate
@@ -169,7 +195,7 @@ int main(int argc, char **argv)
                }
 
                if (nr_usec) {
-                       if (usleep_safe(nr_usec)) {
+                       if (usleep_safe(nr_usec)) {
                                ret = -1;
                                goto end;
                        }
@@ -196,6 +222,8 @@ int main(int argc, char **argv)
                }
        }
 end:
+       free(application_in_main_file_path);
+       free(before_first_event_file_path);
        free(after_first_event_file_path);
        free(before_last_event_file_path);
        free(before_last_event_file_path_touch);
This page took 0.026819 seconds and 4 git commands to generate.