2 * Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
9 #include "signal-helper.hpp"
12 #include <arpa/inet.h>
25 #include <sys/types.h>
28 #define TRACEPOINT_DEFINE
31 static struct option long_options
[] = {
32 /* These options set a flag. */
33 { "iter", required_argument
, nullptr, 'i' },
34 { "wait", required_argument
, nullptr, 'w' },
35 { "sync-after-first-event", required_argument
, nullptr, 'a' },
36 { "sync-before-last-event", required_argument
, nullptr, 'b' },
37 { "sync-before-last-event-touch", required_argument
, nullptr, 'c' },
38 { "sync-before-exit", required_argument
, nullptr, 'd' },
39 { "sync-before-exit-touch", required_argument
, nullptr, 'e' },
40 { "emit-end-event", no_argument
, nullptr, 'f' },
41 { nullptr, 0, nullptr, 0 }
44 int main(int argc
, char **argv
)
46 unsigned int i
, netint
;
49 long values
[] = { 1, 2, 3 };
50 char text
[10] = "test";
51 char escape
[10] = "\\*";
54 uint32_t net_values
[] = { 1, 2, 3 };
55 int nr_iter
= 100, ret
= 0, first_event_file_created
= 0;
56 useconds_t nr_usec
= 0;
57 char *after_first_event_file_path
= nullptr;
58 char *before_last_event_file_path
= nullptr;
60 * Touch a file to indicate that all events except one were
63 char *before_last_event_file_path_touch
= nullptr;
64 /* Touch file when we are exiting */
65 char *before_exit_file_path_touch
= nullptr;
66 /* Wait on file before exiting */
67 char *before_exit_file_path
= nullptr;
68 /* Emit an end event */
69 bool emit_end_event
= false;
71 for (i
= 0; i
< 3; i
++) {
72 net_values
[i
] = htonl(net_values
[i
]);
75 while ((option
= getopt_long(argc
, argv
, "i:w:a:b:c:d:e:f", long_options
, &option_index
)) !=
79 after_first_event_file_path
= strdup(optarg
);
82 before_last_event_file_path
= strdup(optarg
);
85 before_last_event_file_path_touch
= strdup(optarg
);
88 before_exit_file_path
= strdup(optarg
);
91 before_exit_file_path_touch
= strdup(optarg
);
94 emit_end_event
= true;
97 nr_iter
= atoi(optarg
);
100 nr_usec
= atoi(optarg
);
103 /* getopt_long already printed an error message. */
110 if (optind
!= argc
) {
111 fprintf(stderr
, "Error: takes long options only.\n");
114 * Aborting the test program for now because callers typically don't check
115 * the test program return value, and the transition from positional
116 * arguments to getopt causes hangs when caller scripts are not updated.
117 * An abort is easier to diagnose and fix. This is a temporary solution:
118 * we should eventually ensure that all scripts test and report the test
127 if (set_signal_handler()) {
132 for (i
= 0; nr_iter
< 0 || i
< nr_iter
; i
++) {
133 if (nr_iter
>= 0 && i
== nr_iter
- 1) {
134 if (before_last_event_file_path_touch
) {
135 ret
= create_file(before_last_event_file_path_touch
);
142 * Wait on synchronization before writing last
145 if (before_last_event_file_path
) {
146 ret
= wait_on_file(before_last_event_file_path
);
166 * First loop we create the file if asked to indicate
167 * that at least one tracepoint has been hit.
169 if (after_first_event_file_path
&& first_event_file_created
== 0) {
170 ret
= create_file(after_first_event_file_path
);
175 first_event_file_created
= 1;
180 if (usleep_safe(nr_usec
)) {
190 if (emit_end_event
) {
194 if (before_exit_file_path_touch
) {
195 ret
= create_file(before_exit_file_path_touch
);
200 if (before_exit_file_path
) {
201 ret
= wait_on_file(before_exit_file_path
);
207 free(after_first_event_file_path
);
208 free(before_last_event_file_path
);
209 free(before_last_event_file_path_touch
);
210 free(before_exit_file_path
);
211 free(before_exit_file_path_touch
);
212 exit(!ret
? EXIT_SUCCESS
: EXIT_FAILURE
);