Fix: Tests: `gen-ust-events` doesn't error out on invalid option
[lttng-tools.git] / tests / utils / testapp / gen-ust-nevents / gen-ust-nevents.c
CommitLineData
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
25static struct option long_options[] =
26{
27 /* These options set a flag. */
28 {"iter", required_argument, 0, 'i'},
29 {"wait", required_argument, 0, 'w'},
30 {0, 0, 0, 0}
31};
32
ffb08a8c
JD
33int main(int argc, char **argv)
34{
8db430e7 35 int i, netint, ret = 0, option_index, option;
ffb08a8c
JD
36 long values[] = { 1, 2, 3 };
37 char text[10] = "test";
38 double dbl = 2.0;
39 float flt = 2222.0;
40 unsigned int nr_iter = 100;
41 useconds_t nr_usec = 0;
42
8db430e7
FD
43 while ((option = getopt_long(argc, argv, "i:w:",
44 long_options, &option_index)) != -1) {
45 switch (option) {
46 case 'i':
47 nr_iter = atoi(optarg);
48 break;
49 case 'w':
50 nr_usec = atoi(optarg);
51 break;
52 case '?':
53 /* getopt_long already printed an error message. */
8db430e7
FD
54 default:
55 ret = -1;
56 goto end;
57 }
58 }
59
95983a02
JG
60 if (set_signal_handler()) {
61 ret = -1;
62 goto end;
63 }
64
ffb08a8c
JD
65
66 for (i = 0; i < nr_iter; i++) {
67 netint = htonl(i);
68 tracepoint(tp, tptest1, i, netint, values, text, strlen(text),
69 dbl, flt);
70 tracepoint(tp, tptest2, i, netint, values, text, strlen(text),
71 dbl, flt);
72 tracepoint(tp, tptest3, i, netint, values, text, strlen(text),
73 dbl, flt);
74 tracepoint(tp, tptest4, i, netint, values, text, strlen(text),
75 dbl, flt);
76 tracepoint(tp, tptest5, i, netint, values, text, strlen(text),
77 dbl, flt);
ae941114
JG
78 if (nr_usec) {
79 if (usleep_safe(nr_usec)) {
80 ret = -1;
81 goto end;
82 }
83 }
95983a02
JG
84 if (should_quit) {
85 break;
86 }
ffb08a8c
JD
87 }
88
ae941114
JG
89end:
90 exit(!ret ? EXIT_SUCCESS : EXIT_FAILURE);
ffb08a8c 91}
This page took 0.059855 seconds and 4 git commands to generate.