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'},
51 int main(int argc
, char **argv
)
53 unsigned int i
, netint
;
56 long values
[] = { 1, 2, 3 };
57 char text
[10] = "test";
60 int nr_iter
= 100, ret
= 0, first_event_file_created
= 0;
61 useconds_t nr_usec
= 0;
62 char *after_first_event_file_path
= NULL
;
63 char *before_last_event_file_path
= NULL
;
65 while ((option
= getopt_long(argc
, argv
, "i:w:a:b:c:d:",
66 long_options
, &option_index
)) != -1) {
69 after_first_event_file_path
= strdup(optarg
);
72 before_last_event_file_path
= strdup(optarg
);
75 nr_iter
= atoi(optarg
);
78 nr_usec
= atoi(optarg
);
81 /* getopt_long already printed an error message. */
90 fprintf(stderr
, "Error: takes long options only.\n");
96 if (set_signal_handler()) {
101 for (i
= 0; nr_iter
< 0 || i
< nr_iter
; i
++) {
102 if (nr_iter
>= 0 && i
== nr_iter
- 1) {
104 * Wait on synchronization before writing last
107 if (before_last_event_file_path
) {
108 ret
= wait_on_file(before_last_event_file_path
);
115 tracepoint(tp
, tptest
, i
, netint
, values
, text
,
116 strlen(text
), dbl
, flt
);
119 * First loop we create the file if asked to indicate
120 * that at least one tracepoint has been hit.
122 if (after_first_event_file_path
&& first_event_file_created
== 0) {
123 ret
= create_file(after_first_event_file_path
);
128 first_event_file_created
= 1;
133 if (usleep_safe(nr_usec
)) {
144 free(after_first_event_file_path
);
145 free(before_last_event_file_path
);
146 exit(!ret
? EXIT_SUCCESS
: EXIT_FAILURE
);