2 * Copyright (C) - 2012 David Goulet <dgoulet@efficios.com>
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by the
6 * Free Software Foundation; version 2.1 of the License.
8 * This library is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <arpa/inet.h>
29 #include <sys/types.h>
36 #include "signal-helper.h"
38 #define TRACEPOINT_DEFINE
41 static struct option long_options
[] =
43 /* These options set a flag. */
44 {"iter", required_argument
, 0, 'i'},
45 {"wait", required_argument
, 0, 'w'},
46 {"sync-after-first-event", required_argument
, 0, 'a'},
47 {"sync-before-last-event", required_argument
, 0, 'b'},
48 {"sync-before-last-event-touch", required_argument
, 0, 'c'},
49 {"sync-before-exit", required_argument
, 0, 'd'},
50 {"sync-before-exit-touch", required_argument
, 0, 'e'},
54 int main(int argc
, char **argv
)
56 unsigned int i
, netint
;
59 long values
[] = { 1, 2, 3 };
60 char text
[10] = "test";
63 int nr_iter
= 100, ret
= 0, first_event_file_created
= 0;
64 useconds_t nr_usec
= 0;
65 char *after_first_event_file_path
= NULL
;
66 char *before_last_event_file_path
= NULL
;
68 * Touch a file to indicate that all events except one were
71 char *before_last_event_file_path_touch
= NULL
;
72 /* Touch file when we are exiting */
73 char *before_exit_file_path_touch
= NULL
;
74 /* Wait on file before exiting */
75 char *before_exit_file_path
= NULL
;
77 while ((option
= getopt_long(argc
, argv
, "i:w:a:b:c:d:",
78 long_options
, &option_index
)) != -1) {
81 after_first_event_file_path
= strdup(optarg
);
84 before_last_event_file_path
= strdup(optarg
);
87 before_last_event_file_path_touch
= strdup(optarg
);
90 before_exit_file_path
= strdup(optarg
);
93 before_exit_file_path_touch
= strdup(optarg
);
96 nr_iter
= atoi(optarg
);
99 nr_usec
= atoi(optarg
);
102 /* 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
128 if (set_signal_handler()) {
133 for (i
= 0; nr_iter
< 0 || i
< nr_iter
; i
++) {
134 if (nr_iter
>= 0 && i
== nr_iter
- 1) {
135 if (before_last_event_file_path_touch
) {
136 ret
= create_file(before_last_event_file_path_touch
);
143 * Wait on synchronization before writing last
146 if (before_last_event_file_path
) {
147 ret
= wait_on_file(before_last_event_file_path
);
154 tracepoint(tp
, tptest
, i
, netint
, values
, text
,
155 strlen(text
), dbl
, flt
);
158 * First loop we create the file if asked to indicate
159 * that at least one tracepoint has been hit.
161 if (after_first_event_file_path
&& first_event_file_created
== 0) {
162 ret
= create_file(after_first_event_file_path
);
167 first_event_file_created
= 1;
172 if (usleep_safe(nr_usec
)) {
182 if (before_exit_file_path_touch
) {
183 ret
= create_file(before_exit_file_path_touch
);
188 if (before_exit_file_path
) {
189 ret
= wait_on_file(before_exit_file_path
);
195 free(after_first_event_file_path
);
196 free(before_last_event_file_path
);
197 free(before_last_event_file_path_touch
);
198 free(before_exit_file_path
);
199 free(before_exit_file_path_touch
);
200 exit(!ret
? EXIT_SUCCESS
: EXIT_FAILURE
);