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