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