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-application-in-main-touch", required_argument
, nullptr, 'a' },
36 { "sync-before-first-event", required_argument
, nullptr, 'b' },
37 { "sync-after-first-event", required_argument
, nullptr, 'c' },
38 { "sync-before-last-event", required_argument
, nullptr, 'd' },
39 { "sync-before-last-event-touch", required_argument
, nullptr, 'e' },
40 { "sync-before-exit", required_argument
, nullptr, 'f' },
41 { "sync-before-exit-touch", required_argument
, nullptr, 'g' },
42 { "emit-end-event", no_argument
, nullptr, 'h' },
43 { nullptr, 0, nullptr, 0 }
46 int main(int argc
, char **argv
)
48 unsigned int i
, netint
;
51 long values
[] = { 1, 2, 3 };
52 char text
[10] = "test";
53 char escape
[10] = "\\*";
54 const double dbl
= 2.0;
55 const float flt
= 2222.0;
56 uint32_t net_values
[] = { 1, 2, 3 };
57 int nr_iter
= 100, ret
= 0, first_event_file_created
= 0;
58 useconds_t nr_usec
= 0;
59 char *application_in_main_file_path
= nullptr;
60 char *before_first_event_file_path
= nullptr;
61 char *after_first_event_file_path
= nullptr;
62 char *before_last_event_file_path
= nullptr;
64 * Touch a file to indicate that all events except one were
67 char *before_last_event_file_path_touch
= nullptr;
68 /* Touch file when we are exiting */
69 char *before_exit_file_path_touch
= nullptr;
70 /* Wait on file before exiting */
71 char *before_exit_file_path
= nullptr;
72 /* Emit an end event */
73 bool emit_end_event
= false;
75 for (i
= 0; i
< 3; i
++) {
76 net_values
[i
] = htonl(net_values
[i
]);
79 while ((option
= getopt_long(
80 argc
, argv
, "i:w:a:b:c:d:e:f:g:h", long_options
, &option_index
)) != -1) {
83 application_in_main_file_path
= strdup(optarg
);
86 before_first_event_file_path
= strdup(optarg
);
89 after_first_event_file_path
= strdup(optarg
);
92 before_last_event_file_path
= strdup(optarg
);
95 before_last_event_file_path_touch
= strdup(optarg
);
98 before_exit_file_path
= strdup(optarg
);
101 before_exit_file_path_touch
= strdup(optarg
);
104 emit_end_event
= true;
107 nr_iter
= atoi(optarg
);
110 nr_usec
= atoi(optarg
);
113 /* getopt_long already printed an error message. */
120 if (optind
!= argc
) {
121 fprintf(stderr
, "Error: takes long options only.\n");
124 * Aborting the test program for now because callers typically don't check
125 * the test program return value, and the transition from positional
126 * arguments to getopt causes hangs when caller scripts are not updated.
127 * An abort is easier to diagnose and fix. This is a temporary solution:
128 * we should eventually ensure that all scripts test and report the test
137 if (set_signal_handler()) {
142 if (application_in_main_file_path
) {
143 create_file(application_in_main_file_path
);
146 if (before_first_event_file_path
) {
147 wait_on_file(before_first_event_file_path
);
150 for (i
= 0; nr_iter
< 0 || i
< nr_iter
; i
++) {
151 if (nr_iter
>= 0 && i
== nr_iter
- 1) {
152 if (before_last_event_file_path_touch
) {
153 ret
= create_file(before_last_event_file_path_touch
);
160 * Wait on synchronization before writing last
163 if (before_last_event_file_path
) {
164 ret
= wait_on_file(before_last_event_file_path
);
184 * First loop we create the file if asked to indicate
185 * that at least one tracepoint has been hit.
187 if (after_first_event_file_path
&& first_event_file_created
== 0) {
188 ret
= create_file(after_first_event_file_path
);
193 first_event_file_created
= 1;
198 if (usleep_safe(nr_usec
)) {
208 if (emit_end_event
) {
212 if (before_exit_file_path_touch
) {
213 ret
= create_file(before_exit_file_path_touch
);
218 if (before_exit_file_path
) {
219 ret
= wait_on_file(before_exit_file_path
);
225 free(application_in_main_file_path
);
226 free(before_first_event_file_path
);
227 free(after_first_event_file_path
);
228 free(before_last_event_file_path
);
229 free(before_last_event_file_path_touch
);
230 free(before_exit_file_path
);
231 free(before_exit_file_path_touch
);
232 exit(!ret
? EXIT_SUCCESS
: EXIT_FAILURE
);