Commit | Line | Data |
---|---|---|
1cc00241 JG |
1 | /* |
2 | * trigger_name.c | |
3 | * | |
4 | * Test that hidden triggers are not visible to liblttng-ctl. | |
5 | * | |
6 | * Copyright (C) 2021 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
7 | * | |
8 | * SPDX-License-Identifier: MIT | |
9 | * | |
10 | */ | |
11 | ||
12 | #include <assert.h> | |
13 | #include <stdint.h> | |
14 | #include <stdio.h> | |
15 | #include <stdlib.h> | |
16 | #include <string.h> | |
17 | #include <unistd.h> | |
18 | ||
19 | #include <tap/tap.h> | |
20 | ||
21 | #include <common/macros.h> | |
22 | #include <lttng/lttng.h> | |
23 | ||
24 | #define TEST_COUNT 1 | |
25 | ||
26 | #define TEST_SESSION_NAME "test_session" | |
27 | #define TEST_CHANNEL_NAME "test_channel" | |
28 | ||
29 | static | |
30 | int get_registered_triggers_count(void) | |
31 | { | |
32 | int ret; | |
33 | enum lttng_error_code ret_code; | |
34 | enum lttng_trigger_status trigger_status; | |
35 | struct lttng_triggers *triggers = NULL; | |
36 | unsigned int trigger_count; | |
37 | ||
38 | ret_code = lttng_list_triggers(&triggers); | |
39 | if (ret_code != LTTNG_OK) { | |
40 | fail("Failed to list triggers"); | |
41 | ret = -1; | |
42 | goto end; | |
43 | } | |
44 | ||
45 | trigger_status = lttng_triggers_get_count(triggers, &trigger_count); | |
46 | if (trigger_status != LTTNG_TRIGGER_STATUS_OK) { | |
47 | fail("Failed to get count of triggers returned by listing"); | |
48 | ret = -1; | |
49 | goto end; | |
50 | } | |
51 | ||
52 | ret = (int) trigger_count; | |
53 | ||
54 | end: | |
55 | lttng_triggers_destroy(triggers); | |
56 | return ret; | |
57 | } | |
58 | ||
59 | static | |
60 | int setup_session_with_size_rotation_schedule(const char *session_output_path) | |
61 | { | |
62 | int ret; | |
63 | struct lttng_session_descriptor *session_desriptor = NULL; | |
64 | enum lttng_error_code ret_code; | |
65 | struct lttng_handle ust_channel_handle = { | |
66 | .session_name = TEST_SESSION_NAME, | |
67 | .domain.type = LTTNG_DOMAIN_UST, | |
68 | .domain.buf_type = LTTNG_BUFFER_PER_UID, | |
69 | }; | |
70 | struct lttng_channel channel_cfg = { | |
71 | .name = TEST_CHANNEL_NAME, | |
72 | .enabled = 1, | |
73 | .attr.overwrite = -1, | |
74 | .attr.subbuf_size = sysconf(_SC_PAGESIZE) * 8, | |
75 | .attr.num_subbuf = 8, | |
76 | .attr.output = LTTNG_EVENT_MMAP, | |
77 | }; | |
78 | enum lttng_rotation_status rotation_status; | |
79 | struct lttng_rotation_schedule *rotation_schedule = NULL; | |
80 | ||
81 | session_desriptor = lttng_session_descriptor_local_create( | |
82 | TEST_SESSION_NAME, session_output_path); | |
83 | if (!session_desriptor) { | |
84 | fail("Failed to create session descriptor for session `%s`", | |
85 | TEST_SESSION_NAME); | |
86 | ret = -1; | |
87 | goto end; | |
88 | } | |
89 | ||
90 | ret_code = lttng_create_session_ext(session_desriptor); | |
91 | if (ret_code != LTTNG_OK) { | |
92 | fail("Failed to create session `%s`: %s", TEST_SESSION_NAME, | |
93 | lttng_strerror(-ret_code)); | |
94 | ret = -1; | |
95 | goto end; | |
96 | } | |
97 | ||
98 | ret = lttng_enable_channel(&ust_channel_handle, &channel_cfg); | |
99 | if (ret) { | |
100 | fail("Failed to enable channel `%s`: %s", TEST_CHANNEL_NAME, | |
101 | lttng_strerror(ret)); | |
102 | ret = -1; | |
103 | goto end; | |
104 | } | |
105 | ||
106 | ret = lttng_start_tracing(TEST_SESSION_NAME); | |
107 | if (ret) { | |
108 | fail("Failed to start session `%s`: %s", TEST_SESSION_NAME, | |
109 | lttng_strerror(ret)); | |
110 | ret = -1; | |
111 | goto end; | |
112 | } | |
113 | ||
114 | rotation_schedule = lttng_rotation_schedule_size_threshold_create(); | |
115 | if (!rotation_schedule) { | |
116 | fail("Failed to create rotation schedule descriptor"); | |
117 | ret = -1; | |
118 | goto end; | |
119 | } | |
120 | ||
121 | /* | |
122 | * The rotation schedule size threshold doesn't matter; no event rules | |
123 | * were specified so the session consumed size should not grow over | |
124 | * time. | |
125 | */ | |
126 | rotation_status = lttng_rotation_schedule_size_threshold_set_threshold( | |
127 | rotation_schedule, sysconf(_SC_PAGESIZE) * 4096); | |
128 | if (rotation_status != LTTNG_ROTATION_STATUS_OK) { | |
129 | fail("Failed to set size threshold of session rotation schedule"); | |
130 | ret = -1; | |
131 | goto end; | |
132 | } | |
133 | ||
134 | rotation_status = lttng_session_add_rotation_schedule( | |
135 | TEST_SESSION_NAME, rotation_schedule); | |
136 | if (rotation_status != LTTNG_ROTATION_STATUS_OK) { | |
137 | fail("Failed to set size-based rotation schedule on session `%s`", | |
138 | TEST_SESSION_NAME); | |
139 | ret = -1; | |
140 | goto end; | |
141 | } | |
142 | ||
143 | ret = 0; | |
144 | end: | |
145 | lttng_session_descriptor_destroy(session_desriptor); | |
146 | lttng_rotation_schedule_destroy(rotation_schedule); | |
147 | return ret; | |
148 | } | |
149 | ||
150 | int main(int argc, const char **argv) | |
151 | { | |
152 | int ret; | |
153 | ||
154 | if (argc != 2) { | |
155 | fail("Missing trace path"); | |
156 | goto end; | |
157 | } | |
158 | ||
159 | plan_tests(TEST_COUNT); | |
160 | ||
161 | if (get_registered_triggers_count() != 0) { | |
162 | fail("Session daemon already has registered triggers, bailing out"); | |
163 | goto end; | |
164 | } | |
165 | ||
166 | ret = setup_session_with_size_rotation_schedule(argv[1]); | |
167 | if (ret) { | |
168 | goto end; | |
169 | } | |
170 | ||
171 | ok(get_registered_triggers_count() == 0, | |
172 | "No triggers visible while session has an enabled size-based rotation schedule"); | |
173 | ||
174 | ret = lttng_destroy_session(TEST_SESSION_NAME); | |
175 | if (ret) { | |
176 | fail("Failed to destroy session `%s`", TEST_SESSION_NAME); | |
177 | goto end; | |
178 | } | |
179 | end: | |
180 | return exit_status(); | |
181 | } |