- added verbose option to print traces
- added sync-before-first-event to wait on file before first event
- added help option
- added missing short option "-e"
- don't allow negative wait times

Signed-off-by: Anders Wallin <walli...@gmail.com>
---
 .../testapp/gen-ust-events/gen-ust-events.c   | 95 ++++++++++++++++---
 1 file changed, 82 insertions(+), 13 deletions(-)

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 df1e58e4..5fefb2d8 100644
--- a/tests/utils/testapp/gen-ust-events/gen-ust-events.c
+++ b/tests/utils/testapp/gen-ust-events/gen-ust-events.c
@@ -28,6 +28,15 @@
 #define TRACEPOINT_DEFINE
 #include "tp.h"
 
+/* #define NDEBUG */
+
+#ifndef NDEBUG
+int verbose;
+#define TRACE(format, ...) { if (verbose) printf(" ---TRACE: " format, 
__VA_ARGS__); }
+#else
+#define TRACE(format, ...)
+#endif
+
 static struct option long_options[] =
 {
        /* These options set a flag. */
@@ -38,9 +47,33 @@ static struct option long_options[] =
        {"sync-before-last-event-touch", required_argument, 0, 'c'},
        {"sync-before-exit", required_argument, 0, 'd'},
        {"sync-before-exit-touch", required_argument, 0, 'e'},
+       {"sync-before-first-event", required_argument, 0, 'f'},
+       {"help", no_argument, 0, 'h'},
+#ifndef NDEBUG
+       {"verbose", no_argument, 0, 'v'},
+#endif
        {0, 0, 0, 0}
 };
 
+const char *program_name;
+
+static void print_usage(void)
+{
+       printf("Usage:  %s options\n", program_name);
+       printf("  -h  --help                                    Display this 
usage information\n"
+#ifndef NDEBUG
+              "  -v  --verbose                                 Print verbose 
messages\n"
+#endif
+              "  -i  --iter [iterations]                       Number of 
iterations, default=100, forever=-1\n"
+              "  -w  --wait [usec]                             Time in usec 
between events, default=0\n"
+              "  -a  --sync-after-first-event [filename]       Create file 
after first event\n"
+              "  -b  --sync-before-last-event [filename]       Wait for file 
before writing last event\n"
+              "  -c  --sync-before-last-event-touch [filename] Create file 
after last event\n"
+              "  -d  --sync-before-exit [filename]             Wait for file 
before exit\n"
+              "  -e  --sync-before-exit-touch [filename]       Create file 
before exit\n"
+              "  -f  --sync-before-first-event [filename]      Wait for file 
before creating the first event\n");
+}
+
 int main(int argc, char **argv)
 {
        unsigned int i, netint;
@@ -54,7 +87,7 @@ 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 *after_first_event_file_path_touch = NULL;
        char *before_last_event_file_path = NULL;
        /*
         * Touch a file to indicate that all events except one were
@@ -65,16 +98,20 @@ int main(int argc, char **argv)
        char *before_exit_file_path_touch = NULL;
        /* Wait on file before exiting */
        char *before_exit_file_path = NULL;
+       /* Wait on file before starting */
+       char *before_first_event_file_path = NULL;
+
+       program_name = argv[0];
 
        for (i = 0; i < 3; i++) {
                net_values[i] = htonl(net_values[i]);
        }
 
-       while ((option = getopt_long(argc, argv, "i:w:a:b:c:d:",
+       while ((option = getopt_long(argc, argv, "i:w:a:b:c:d:e:f:hv",
                        long_options, &option_index)) != -1) {
                switch (option) {
                case 'a':
-                       after_first_event_file_path = strdup(optarg);
+                       after_first_event_file_path_touch = strdup(optarg);
                        break;
                case 'b':
                        before_last_event_file_path = strdup(optarg);
@@ -88,22 +125,30 @@ int main(int argc, char **argv)
                case 'e':
                        before_exit_file_path_touch = strdup(optarg);
                        break;
+               case 'f':
+                       before_first_event_file_path = strdup(optarg);
+                       break;
                case 'i':
                        nr_iter = atoi(optarg);
                        break;
+#ifndef NDEBUG
+               case 'v':
+                       verbose = 1;
+                       break;
+#endif
                case 'w':
-                       nr_usec = atoi(optarg);
+                       /* only postive values are valid */
+                       nr_usec = (atoi(optarg) < 0) ? 0 : atoi(optarg);
                        break;
-               case '?':
-                       /* getopt_long already printed an error message. */
+               case 'h':
                default:
-                       ret = -1;
+                       print_usage();
                        goto end;
                }
        }
 
        if (optind != argc) {
-               fprintf(stderr, "Error: takes long options only.\n");
+               fprintf(stderr, "Error: takes options only.\n");
 
                /*
                 * Aborting the test program for now because callers typically 
don't check
@@ -113,6 +158,7 @@ int main(int argc, char **argv)
                 * we should eventually ensure that all scripts test and report 
the test
                 * app return values.
                 */
+               print_usage();
                abort();
 
                ret = -1;
@@ -125,9 +171,23 @@ int main(int argc, char **argv)
                goto end;
        }
 
+       TRACE("iter: %i\n", nr_iter);
+       TRACE("wait: %i (usec)\n", nr_usec);
+
+       if (before_first_event_file_path) {
+               TRACE("before_first_event_file_path(%i): %s\n",
+                     -1, before_first_event_file_path);
+               ret = wait_on_file(before_first_event_file_path);
+               if (ret != 0) {
+                       goto end;
+               }
+       }
+
        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) {
+                               TRACE("before_last_event_file_path_touch(%i): 
%s\n",
+                                     i, before_last_event_file_path_touch);
                                ret = 
create_file(before_last_event_file_path_touch);
                                if (ret != 0) {
                                        goto end;
@@ -139,6 +199,8 @@ int main(int argc, char **argv)
                         * event.
                         */
                        if (before_last_event_file_path) {
+                               TRACE("before_last_event_file_path(%i): %s\n",
+                                     i, before_last_event_file_path);
                                ret = wait_on_file(before_last_event_file_path);
                                if (ret != 0) {
                                        goto end;
@@ -153,9 +215,10 @@ int main(int argc, char **argv)
                 * First loop we create the file if asked to indicate
                 * that at least one tracepoint has been hit.
                 */
-               if (after_first_event_file_path && first_event_file_created == 
0) {
-                       ret = create_file(after_first_event_file_path);
-
+               if (after_first_event_file_path_touch && 
first_event_file_created == 0) {
+                       TRACE("after_first_event_file_path_touch(%i): %s\n",
+                             i, after_first_event_file_path_touch);
+                       ret = create_file(after_first_event_file_path_touch);
                        if (ret != 0) {
                                goto end;
                        } else {
@@ -164,7 +227,7 @@ int main(int argc, char **argv)
                }
 
                if (nr_usec) {
-                       if (usleep_safe(nr_usec)) {
+                       if (usleep_safe(nr_usec)) {
                                ret = -1;
                                goto end;
                        }
@@ -175,22 +238,28 @@ int main(int argc, char **argv)
        }
 
        if (before_exit_file_path_touch) {
+               TRACE("before_exit_file_path_touch(%i): %s\n",
+                     i, before_exit_file_path_touch);
                ret = create_file(before_exit_file_path_touch);
                if (ret != 0) {
                        goto end;
                }
        }
        if (before_exit_file_path) {
+               TRACE("before_exit_file_path(%i): %s\n",
+                     i, before_exit_file_path);
                ret = wait_on_file(before_exit_file_path);
                if (ret != 0) {
                        goto end;
                }
        }
 end:
-       free(after_first_event_file_path);
+       TRACE("end status: %i\n", ret);
+       free(after_first_event_file_path_touch);
        free(before_last_event_file_path);
        free(before_last_event_file_path_touch);
        free(before_exit_file_path);
        free(before_exit_file_path_touch);
+       free(before_first_event_file_path);
        exit(!ret ? EXIT_SUCCESS : EXIT_FAILURE);
 }
-- 
2.31.1

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

Reply via email to