Commit | Line | Data |
---|---|---|
ffb08a8c | 1 | /* |
9d16b343 | 2 | * Copyright (C) 2012 David Goulet <dgoulet@efficios.com> |
ffb08a8c | 3 | * |
9d16b343 | 4 | * SPDX-License-Identifier: LGPL-2.1-only |
ffb08a8c | 5 | * |
ffb08a8c JD |
6 | */ |
7 | ||
70dac0d7 | 8 | #define _LGPL_SOURCE |
ffb08a8c | 9 | #include <arpa/inet.h> |
8db430e7 | 10 | #include <getopt.h> |
ffb08a8c JD |
11 | #include <stdarg.h> |
12 | #include <stdio.h> | |
13 | #include <stdlib.h> | |
14 | #include <string.h> | |
15 | #include <sys/mman.h> | |
16 | #include <sys/stat.h> | |
17 | #include <sys/types.h> | |
18 | #include <unistd.h> | |
ae941114 | 19 | #include "utils.h" |
95983a02 | 20 | #include "signal-helper.h" |
ffb08a8c JD |
21 | |
22 | #define TRACEPOINT_DEFINE | |
23 | #include "tp.h" | |
24 | ||
8db430e7 FD |
25 | static struct option long_options[] = |
26 | { | |
27 | /* These options set a flag. */ | |
28 | {"iter", required_argument, 0, 'i'}, | |
29 | {"wait", required_argument, 0, 'w'}, | |
4bb5f0b0 FD |
30 | {"create-in-main", required_argument, 0, 'm'}, |
31 | {"wait-before-first-event", required_argument, 0, 'b'}, | |
8db430e7 FD |
32 | {0, 0, 0, 0} |
33 | }; | |
34 | ||
ffb08a8c JD |
35 | int main(int argc, char **argv) |
36 | { | |
8db430e7 | 37 | int i, netint, ret = 0, option_index, option; |
ffb08a8c JD |
38 | long values[] = { 1, 2, 3 }; |
39 | char text[10] = "test"; | |
40 | double dbl = 2.0; | |
41 | float flt = 2222.0; | |
42 | unsigned int nr_iter = 100; | |
43 | useconds_t nr_usec = 0; | |
4bb5f0b0 FD |
44 | char *wait_before_first_event_file_path = NULL; |
45 | char *create_in_main_file_path = NULL; | |
ffb08a8c | 46 | |
4bb5f0b0 | 47 | while ((option = getopt_long(argc, argv, "i:w:b:m:", |
8db430e7 FD |
48 | long_options, &option_index)) != -1) { |
49 | switch (option) { | |
4bb5f0b0 FD |
50 | case 'b': |
51 | wait_before_first_event_file_path = strdup(optarg); | |
52 | break; | |
53 | case 'm': | |
54 | create_in_main_file_path = strdup(optarg); | |
55 | break; | |
8db430e7 FD |
56 | case 'i': |
57 | nr_iter = atoi(optarg); | |
58 | break; | |
59 | case 'w': | |
60 | nr_usec = atoi(optarg); | |
61 | break; | |
62 | case '?': | |
63 | /* getopt_long already printed an error message. */ | |
8db430e7 FD |
64 | default: |
65 | ret = -1; | |
66 | goto end; | |
67 | } | |
68 | } | |
69 | ||
95983a02 JG |
70 | if (set_signal_handler()) { |
71 | ret = -1; | |
72 | goto end; | |
73 | } | |
74 | ||
4bb5f0b0 FD |
75 | /* |
76 | * The two following sync points allow for tests to do work after the | |
77 | * app has started BUT before it generates any events. | |
78 | */ | |
79 | if (create_in_main_file_path) { | |
80 | ret = create_file(create_in_main_file_path); | |
81 | if (ret != 0) { | |
82 | goto end; | |
83 | } | |
84 | } | |
85 | ||
86 | if (wait_before_first_event_file_path) { | |
87 | ret = wait_on_file(wait_before_first_event_file_path); | |
88 | if (ret != 0) { | |
89 | goto end; | |
90 | } | |
91 | } | |
ffb08a8c JD |
92 | |
93 | for (i = 0; i < nr_iter; i++) { | |
94 | netint = htonl(i); | |
95 | tracepoint(tp, tptest1, i, netint, values, text, strlen(text), | |
96 | dbl, flt); | |
97 | tracepoint(tp, tptest2, i, netint, values, text, strlen(text), | |
98 | dbl, flt); | |
99 | tracepoint(tp, tptest3, i, netint, values, text, strlen(text), | |
100 | dbl, flt); | |
101 | tracepoint(tp, tptest4, i, netint, values, text, strlen(text), | |
102 | dbl, flt); | |
103 | tracepoint(tp, tptest5, i, netint, values, text, strlen(text), | |
104 | dbl, flt); | |
ae941114 JG |
105 | if (nr_usec) { |
106 | if (usleep_safe(nr_usec)) { | |
107 | ret = -1; | |
108 | goto end; | |
109 | } | |
110 | } | |
95983a02 JG |
111 | if (should_quit) { |
112 | break; | |
113 | } | |
ffb08a8c JD |
114 | } |
115 | ||
ae941114 | 116 | end: |
4bb5f0b0 FD |
117 | free(create_in_main_file_path); |
118 | free(wait_before_first_event_file_path); | |
119 | exit(!ret ? EXIT_SUCCESS : EXIT_FAILURE); | |
ffb08a8c | 120 | } |