fix: relayd: unaligned access in trace_chunk_registry_ht_key_hash
[lttng-tools.git] / tests / utils / testapp / gen-ust-tracef / gen-ust-tracef.cpp
1 /*
2 * Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
3 * Copyright (C) 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
5 * SPDX-License-Identifier: LGPL-2.1-only
6 *
7 */
8
9 #define _LGPL_SOURCE
10 #include "signal-helper.hpp"
11
12 #include <common/macros.hpp>
13
14 #include <lttng/tracef.h>
15
16 #include <fcntl.h>
17 #include <stdarg.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <sys/mman.h>
22 #include <sys/stat.h>
23 #include <sys/types.h>
24 #include <unistd.h>
25
26 const char *str = "test string";
27
28 static void create_file(const char *path)
29 {
30 int ret;
31
32 LTTNG_ASSERT(path);
33
34 ret = creat(path, S_IRWXU);
35 if (ret < 0) {
36 fprintf(stderr, "Failed to create file %s\n", path);
37 return;
38 }
39
40 (void) close(ret);
41 }
42
43 int main(int argc, char **argv)
44 {
45 int i;
46 unsigned int nr_iter = 100;
47 useconds_t nr_usec = 0;
48 char *tmp_file_path = nullptr;
49
50 if (set_signal_handler()) {
51 return 1;
52 }
53
54 if (argc >= 2) {
55 nr_iter = atoi(argv[1]);
56 }
57
58 if (argc >= 3) {
59 /* By default, don't wait unless user specifies. */
60 nr_usec = atoi(argv[2]);
61 }
62
63 if (argc >= 4) {
64 tmp_file_path = argv[3];
65 }
66
67 for (i = 0; i < nr_iter; i++) {
68 tracef("Test message %d with string \"%s\"", i, str);
69
70 /*
71 * First loop we create the file if asked to indicate
72 * that at least one tracepoint has been hit.
73 */
74 if (i == 0 && tmp_file_path) {
75 create_file(tmp_file_path);
76 }
77 usleep(nr_usec);
78 if (should_quit) {
79 break;
80 }
81 }
82
83 return 0;
84 }
This page took 0.03181 seconds and 4 git commands to generate.