| 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 <common/macros.hpp> |
| 13 | |
| 14 | #include <lttng/lttng.h> |
| 15 | |
| 16 | #include <stdint.h> |
| 17 | #include <stdio.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <string.h> |
| 20 | #include <tap/tap.h> |
| 21 | #include <unistd.h> |
| 22 | |
| 23 | #define TEST_COUNT 1 |
| 24 | |
| 25 | #define TEST_SESSION_NAME "test_session" |
| 26 | #define TEST_CHANNEL_NAME "test_channel" |
| 27 | |
| 28 | static int get_registered_triggers_count() |
| 29 | { |
| 30 | int ret; |
| 31 | enum lttng_error_code ret_code; |
| 32 | enum lttng_trigger_status trigger_status; |
| 33 | struct lttng_triggers *triggers = nullptr; |
| 34 | unsigned int trigger_count; |
| 35 | |
| 36 | ret_code = lttng_list_triggers(&triggers); |
| 37 | if (ret_code != LTTNG_OK) { |
| 38 | fail("Failed to list triggers"); |
| 39 | ret = -1; |
| 40 | goto end; |
| 41 | } |
| 42 | |
| 43 | trigger_status = lttng_triggers_get_count(triggers, &trigger_count); |
| 44 | if (trigger_status != LTTNG_TRIGGER_STATUS_OK) { |
| 45 | fail("Failed to get count of triggers returned by listing"); |
| 46 | ret = -1; |
| 47 | goto end; |
| 48 | } |
| 49 | |
| 50 | ret = (int) trigger_count; |
| 51 | |
| 52 | end: |
| 53 | lttng_triggers_destroy(triggers); |
| 54 | return ret; |
| 55 | } |
| 56 | |
| 57 | static int setup_session_with_size_rotation_schedule(const char *session_output_path) |
| 58 | { |
| 59 | int ret; |
| 60 | struct lttng_session_descriptor *session_desriptor = nullptr; |
| 61 | enum lttng_error_code ret_code; |
| 62 | struct lttng_handle ust_channel_handle = { TEST_SESSION_NAME, |
| 63 | { |
| 64 | .type = LTTNG_DOMAIN_UST, |
| 65 | .buf_type = LTTNG_BUFFER_PER_UID, |
| 66 | .padding = {}, |
| 67 | .attr = {}, |
| 68 | }, |
| 69 | {} }; |
| 70 | |
| 71 | lttng_channel channel_cfg{}; |
| 72 | strcpy(channel_cfg.name, TEST_CHANNEL_NAME); |
| 73 | channel_cfg.enabled = 1; |
| 74 | channel_cfg.attr.overwrite = -1; |
| 75 | channel_cfg.attr.subbuf_size = (uint64_t) sysconf(_SC_PAGE_SIZE) * 8; |
| 76 | channel_cfg.attr.num_subbuf = 8; |
| 77 | channel_cfg.attr.output = LTTNG_EVENT_MMAP; |
| 78 | |
| 79 | enum lttng_rotation_status rotation_status; |
| 80 | struct lttng_rotation_schedule *rotation_schedule = nullptr; |
| 81 | |
| 82 | session_desriptor = |
| 83 | lttng_session_descriptor_local_create(TEST_SESSION_NAME, session_output_path); |
| 84 | if (!session_desriptor) { |
| 85 | fail("Failed to create session descriptor for session `%s`", 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", |
| 93 | TEST_SESSION_NAME, |
| 94 | lttng_strerror(-ret_code)); |
| 95 | ret = -1; |
| 96 | goto end; |
| 97 | } |
| 98 | |
| 99 | ret = lttng_enable_channel(&ust_channel_handle, &channel_cfg); |
| 100 | if (ret) { |
| 101 | fail("Failed to enable channel `%s`: %s", TEST_CHANNEL_NAME, 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, 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( |
| 126 | rotation_schedule, sysconf(_SC_PAGE_SIZE) * 4096); |
| 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(TEST_SESSION_NAME, rotation_schedule); |
| 134 | if (rotation_status != LTTNG_ROTATION_STATUS_OK) { |
| 135 | fail("Failed to set size-based rotation schedule on session `%s`", |
| 136 | TEST_SESSION_NAME); |
| 137 | ret = -1; |
| 138 | goto end; |
| 139 | } |
| 140 | |
| 141 | ret = 0; |
| 142 | end: |
| 143 | lttng_session_descriptor_destroy(session_desriptor); |
| 144 | lttng_rotation_schedule_destroy(rotation_schedule); |
| 145 | return ret; |
| 146 | } |
| 147 | |
| 148 | int main(int argc, const char **argv) |
| 149 | { |
| 150 | int ret; |
| 151 | |
| 152 | if (argc != 2) { |
| 153 | fail("Missing trace path"); |
| 154 | goto end; |
| 155 | } |
| 156 | |
| 157 | plan_tests(TEST_COUNT); |
| 158 | |
| 159 | if (get_registered_triggers_count() != 0) { |
| 160 | fail("Session daemon already has registered triggers, bailing out"); |
| 161 | goto end; |
| 162 | } |
| 163 | |
| 164 | ret = setup_session_with_size_rotation_schedule(argv[1]); |
| 165 | if (ret) { |
| 166 | goto end; |
| 167 | } |
| 168 | |
| 169 | ok(get_registered_triggers_count() == 0, |
| 170 | "No triggers visible while session has an enabled size-based rotation schedule"); |
| 171 | |
| 172 | ret = lttng_destroy_session(TEST_SESSION_NAME); |
| 173 | if (ret) { |
| 174 | fail("Failed to destroy session `%s`", TEST_SESSION_NAME); |
| 175 | goto end; |
| 176 | } |
| 177 | end: |
| 178 | return exit_status(); |
| 179 | } |