2 * Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
11 #include <arpa/inet.h>
19 #include <sys/types.h>
26 #include "signal-helper.h"
28 #define TRACEPOINT_DEFINE
31 static struct option long_options
[] =
33 /* These options set a flag. */
34 {"iter", required_argument
, 0, 'i'},
35 {"wait", required_argument
, 0, 'w'},
36 {"sync-after-first-event", required_argument
, 0, 'a'},
37 {"sync-before-last-event", required_argument
, 0, 'b'},
38 {"sync-before-last-event-touch", required_argument
, 0, 'c'},
39 {"sync-before-exit", required_argument
, 0, 'd'},
40 {"sync-before-exit-touch", required_argument
, 0, 'e'},
41 {"emit-end-event", no_argument
, 0, 'f'},
45 int main(int argc
, char **argv
)
47 unsigned int i
, netint
;
50 long values
[] = { 1, 2, 3 };
51 char text
[10] = "test";
52 char escape
[10] = "\\*";
55 uint32_t net_values
[] = { 1, 2, 3 };
56 int nr_iter
= 100, ret
= 0, first_event_file_created
= 0;
57 useconds_t nr_usec
= 0;
58 char *after_first_event_file_path
= NULL
;
59 char *before_last_event_file_path
= NULL
;
61 * Touch a file to indicate that all events except one were
64 char *before_last_event_file_path_touch
= NULL
;
65 /* Touch file when we are exiting */
66 char *before_exit_file_path_touch
= NULL
;
67 /* Wait on file before exiting */
68 char *before_exit_file_path
= NULL
;
69 /* Emit an end event */
70 bool emit_end_event
= false;
72 for (i
= 0; i
< 3; i
++) {
73 net_values
[i
] = htonl(net_values
[i
]);
76 while ((option
= getopt_long(argc
, argv
, "i:w:a:b:c:d:e:f",
77 long_options
, &option_index
)) != -1) {
80 after_first_event_file_path
= strdup(optarg
);
83 before_last_event_file_path
= strdup(optarg
);
86 before_last_event_file_path_touch
= strdup(optarg
);
89 before_exit_file_path
= strdup(optarg
);
92 before_exit_file_path_touch
= strdup(optarg
);
95 emit_end_event
= true;
98 nr_iter
= atoi(optarg
);
101 nr_usec
= atoi(optarg
);
104 /* getopt_long already printed an error message. */
111 if (optind
!= argc
) {
112 fprintf(stderr
, "Error: takes long options only.\n");
115 * Aborting the test program for now because callers typically don't check
116 * the test program return value, and the transition from positional
117 * arguments to getopt causes hangs when caller scripts are not updated.
118 * An abort is easier to diagnose and fix. This is a temporary solution:
119 * we should eventually ensure that all scripts test and report the test
129 if (set_signal_handler()) {
134 for (i
= 0; nr_iter
< 0 || i
< nr_iter
; i
++) {
135 if (nr_iter
>= 0 && i
== nr_iter
- 1) {
136 if (before_last_event_file_path_touch
) {
137 ret
= create_file(before_last_event_file_path_touch
);
144 * Wait on synchronization before writing last
147 if (before_last_event_file_path
) {
148 ret
= wait_on_file(before_last_event_file_path
);
155 tracepoint(tp
, tptest
, i
, netint
, values
, text
,
156 strlen(text
), escape
, net_values
, dbl
, flt
);
159 * First loop we create the file if asked to indicate
160 * that at least one tracepoint has been hit.
162 if (after_first_event_file_path
&& first_event_file_created
== 0) {
163 ret
= create_file(after_first_event_file_path
);
168 first_event_file_created
= 1;
173 if (usleep_safe(nr_usec
)) {
183 if (emit_end_event
) {
187 if (before_exit_file_path_touch
) {
188 ret
= create_file(before_exit_file_path_touch
);
193 if (before_exit_file_path
) {
194 ret
= wait_on_file(before_exit_file_path
);
200 free(after_first_event_file_path
);
201 free(before_last_event_file_path
);
202 free(before_last_event_file_path_touch
);
203 free(before_exit_file_path
);
204 free(before_exit_file_path_touch
);
205 exit(!ret
? EXIT_SUCCESS
: EXIT_FAILURE
);