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