Tests: cleanly exit from test apps on reception of SIGTERM
[lttng-tools.git] / tests / utils / testapp / gen-ust-nevents / gen-ust-nevents.c
CommitLineData
ffb08a8c
JD
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
ffb08a8c
JD
19#include <arpa/inet.h>
20#include <stdarg.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <sys/mman.h>
25#include <sys/stat.h>
26#include <sys/types.h>
27#include <unistd.h>
ae941114 28#include "utils.h"
95983a02 29#include "signal-helper.h"
ffb08a8c
JD
30
31#define TRACEPOINT_DEFINE
32#include "tp.h"
33
34int main(int argc, char **argv)
35{
ae941114 36 int i, netint, ret = 0;
ffb08a8c
JD
37 long values[] = { 1, 2, 3 };
38 char text[10] = "test";
39 double dbl = 2.0;
40 float flt = 2222.0;
41 unsigned int nr_iter = 100;
42 useconds_t nr_usec = 0;
43
95983a02
JG
44 if (set_signal_handler()) {
45 ret = -1;
46 goto end;
47 }
48
ffb08a8c
JD
49 if (argc >= 2) {
50 nr_iter = atoi(argv[1]);
51 }
52
53 if (argc == 3) {
54 /* By default, don't wait unless user specifies. */
55 nr_usec = atoi(argv[2]);
56 }
57
58 for (i = 0; i < nr_iter; i++) {
59 netint = htonl(i);
60 tracepoint(tp, tptest1, i, netint, values, text, strlen(text),
61 dbl, flt);
62 tracepoint(tp, tptest2, i, netint, values, text, strlen(text),
63 dbl, flt);
64 tracepoint(tp, tptest3, i, netint, values, text, strlen(text),
65 dbl, flt);
66 tracepoint(tp, tptest4, i, netint, values, text, strlen(text),
67 dbl, flt);
68 tracepoint(tp, tptest5, i, netint, values, text, strlen(text),
69 dbl, flt);
ae941114
JG
70 if (nr_usec) {
71 if (usleep_safe(nr_usec)) {
72 ret = -1;
73 goto end;
74 }
75 }
95983a02
JG
76 if (should_quit) {
77 break;
78 }
ffb08a8c
JD
79 }
80
ae941114
JG
81end:
82 exit(!ret ? EXIT_SUCCESS : EXIT_FAILURE);
ffb08a8c 83}
This page took 0.042813 seconds and 5 git commands to generate.