Commit | Line | Data |
---|---|---|
b02dcdb8 | 1 | /* |
9d16b343 MJ |
2 | * Copyright (C) 2012 David Goulet <dgoulet@efficios.com> |
3 | * Copyright (C) 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
b02dcdb8 | 4 | * |
9d16b343 | 5 | * SPDX-License-Identifier: LGPL-2.1-only |
b02dcdb8 | 6 | * |
b02dcdb8 MD |
7 | */ |
8 | ||
70dac0d7 | 9 | #define _LGPL_SOURCE |
28ab034a JG |
10 | #include "signal-helper.hpp" |
11 | ||
12 | #include <common/macros.hpp> | |
13 | ||
14 | #include <lttng/tracef.h> | |
15 | ||
b02dcdb8 MD |
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 | ||
b02dcdb8 MD |
26 | const char *str = "test string"; |
27 | ||
28ab034a | 28 | static void create_file(const char *path) |
b02dcdb8 MD |
29 | { |
30 | int ret; | |
31 | ||
a0377dfe | 32 | LTTNG_ASSERT(path); |
b02dcdb8 MD |
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; | |
cd9adb8b | 48 | char *tmp_file_path = nullptr; |
b02dcdb8 | 49 | |
95983a02 JG |
50 | if (set_signal_handler()) { |
51 | return 1; | |
52 | } | |
53 | ||
b02dcdb8 MD |
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); | |
95983a02 JG |
78 | if (should_quit) { |
79 | break; | |
80 | } | |
b02dcdb8 MD |
81 | } |
82 | ||
83 | return 0; | |
84 | } |