Fix: test flaky sleep and wait patterns
[lttng-tools.git] / tests / utils / testapp / gen-ust-events / gen-ust-events.c
CommitLineData
7e0cc23b
CB
1/*
2 * Copyright (C) - 2012 David Goulet <dgoulet@efficios.com>
3 *
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.
7 *
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
11 * for more details.
12 *
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
16 */
17
209b934f 18#include <assert.h>
7e0cc23b 19#include <arpa/inet.h>
209b934f 20#include <fcntl.h>
7e0cc23b
CB
21#include <stdarg.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include <sys/mman.h>
26#include <sys/stat.h>
27#include <sys/types.h>
28#include <unistd.h>
d4607bc6 29#include <stdbool.h>
7e0cc23b
CB
30
31#define TRACEPOINT_DEFINE
32#include "tp.h"
33
209b934f
DG
34void create_file(const char *path)
35{
36 int ret;
37
38 assert(path);
39
40 ret = creat(path, S_IRWXU);
41 if (ret < 0) {
42 fprintf(stderr, "Failed to create file %s\n", path);
43 return;
44 }
45
46 (void) close(ret);
47}
48
7e0cc23b
CB
49int main(int argc, char **argv)
50{
d4607bc6 51 unsigned int i, netint;
7e0cc23b
CB
52 long values[] = { 1, 2, 3 };
53 char text[10] = "test";
54 double dbl = 2.0;
55 float flt = 2222.0;
d4607bc6 56 int nr_iter = 100;
7e0cc23b 57 useconds_t nr_usec = 0;
209b934f 58 char *tmp_file_path = NULL;
d4607bc6 59 bool file_created = false;
7e0cc23b
CB
60
61 if (argc >= 2) {
d4607bc6
MD
62 /*
63 * If nr_iter is negative, do an infinite tracing loop.
64 */
7e0cc23b
CB
65 nr_iter = atoi(argv[1]);
66 }
67
2c34b645 68 if (argc >= 3) {
7e0cc23b
CB
69 /* By default, don't wait unless user specifies. */
70 nr_usec = atoi(argv[2]);
71 }
72
2c34b645 73 if (argc >= 4) {
209b934f
DG
74 tmp_file_path = argv[3];
75 }
76
d4607bc6 77 for (i = 0; nr_iter < 0 || i < nr_iter; i++) {
7e0cc23b 78 netint = htonl(i);
209b934f
DG
79 tracepoint(tp, tptest, i, netint, values, text, strlen(text), dbl,
80 flt);
81
82 /*
83 * First loop we create the file if asked to indicate that at least one
84 * tracepoint has been hit.
85 */
d4607bc6 86 if (!file_created && tmp_file_path) {
209b934f 87 create_file(tmp_file_path);
d4607bc6 88 file_created = true;
209b934f 89 }
7e0cc23b
CB
90 usleep(nr_usec);
91 }
92
93 return 0;
94}
This page took 0.030692 seconds and 4 git commands to generate.