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
1/*
2 * Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-only
5 *
6 */
7
8#define _LGPL_SOURCE
9#include <arpa/inet.h>
10#include <getopt.h>
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>
19#include "utils.h"
20#include "signal-helper.h"
21
22#define TRACEPOINT_DEFINE
23#include "tp.h"
24
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
33int main(int argc, char **argv)
34{
35 int i, netint, ret = 0, option_index, option;
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
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. */
54 default:
55 ret = -1;
56 goto end;
57 }
58 }
59
60 if (set_signal_handler()) {
61 ret = -1;
62 goto end;
63 }
64
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);
78 if (nr_usec) {
79 if (usleep_safe(nr_usec)) {
80 ret = -1;
81 goto end;
82 }
83 }
84 if (should_quit) {
85 break;
86 }
87 }
88
89end:
90 exit(!ret ? EXIT_SUCCESS : EXIT_FAILURE);
91}
This page took 0.026042 seconds and 5 git commands to generate.