Commit | Line | Data |
---|---|---|
d3e8f6bb DG |
1 | /* |
2 | * Copyright (c) 2011 David Goulet <david.goulet@polymtl.ca> | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * as published by the Free Software Foundation; only version 2 | |
7 | * of the License. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License along | |
15 | * with this program; if not, write to the Free Software Foundation, Inc., | |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 | */ | |
18 | ||
19 | #define _GNU_SOURCE | |
20 | #include <assert.h> | |
21 | #include <errno.h> | |
22 | #include <stdio.h> | |
23 | #include <stdlib.h> | |
24 | #include <string.h> | |
25 | #include <unistd.h> | |
26 | #include <time.h> | |
27 | ||
10a8a223 DG |
28 | #include <lttng/lttng.h> |
29 | #include <bin/lttng-sessiond/lttng-ust-abi.h> | |
990570ed | 30 | #include <common/defaults.h> |
10a8a223 | 31 | #include <bin/lttng-sessiond/trace-ust.h> |
7972aab2 | 32 | #include <bin/lttng-sessiond/ust-app.h> |
10a8a223 | 33 | |
657270a4 CB |
34 | #include <tap/tap.h> |
35 | ||
d3e8f6bb DG |
36 | /* This path will NEVER be created in this test */ |
37 | #define PATH1 "/tmp/.test-junk-lttng" | |
38 | ||
98612240 MD |
39 | #define RANDOM_STRING_LEN 11 |
40 | ||
657270a4 | 41 | /* Number of TAP tests in this file */ |
c710ece7 | 42 | #define NUM_TESTS 11 |
657270a4 | 43 | |
ad7c9c18 | 44 | /* For error.h */ |
97e19046 DG |
45 | int lttng_opt_quiet = 1; |
46 | int lttng_opt_verbose; | |
c7e35b03 | 47 | int lttng_opt_mi; |
d3e8f6bb | 48 | |
7972aab2 DG |
49 | int ust_consumerd32_fd; |
50 | int ust_consumerd64_fd; | |
51 | ||
7c1d2758 JG |
52 | /* Global variable required by sessiond objects being linked-in */ |
53 | struct lttng_ht *agent_apps_ht_by_sock; | |
54 | ||
d3e8f6bb DG |
55 | static const char alphanum[] = |
56 | "0123456789" | |
57 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
58 | "abcdefghijklmnopqrstuvwxyz"; | |
98612240 | 59 | static char random_string[RANDOM_STRING_LEN]; |
d3e8f6bb DG |
60 | |
61 | static struct ltt_ust_session *usess; | |
62 | static struct lttng_domain dom; | |
63 | ||
64 | /* | |
65 | * Return random string of 10 characters. | |
98612240 | 66 | * Not thread-safe. |
d3e8f6bb DG |
67 | */ |
68 | static char *get_random_string(void) | |
69 | { | |
70 | int i; | |
d3e8f6bb | 71 | |
98612240 MD |
72 | for (i = 0; i < RANDOM_STRING_LEN - 1; i++) { |
73 | random_string[i] = alphanum[rand() % (sizeof(alphanum) - 1)]; | |
d3e8f6bb DG |
74 | } |
75 | ||
98612240 | 76 | random_string[RANDOM_STRING_LEN - 1] = '\0'; |
d3e8f6bb | 77 | |
98612240 | 78 | return random_string; |
d3e8f6bb DG |
79 | } |
80 | ||
657270a4 | 81 | static void test_create_one_ust_session(void) |
d3e8f6bb | 82 | { |
d3e8f6bb DG |
83 | dom.type = LTTNG_DOMAIN_UST; |
84 | ||
dec56f6c | 85 | usess = trace_ust_create_session(42); |
657270a4 CB |
86 | ok(usess != NULL, "Create UST session"); |
87 | ||
88 | ok(usess->id == 42 && | |
14fb1ebe | 89 | usess->active == 0 && |
657270a4 | 90 | usess->domain_global.channels != NULL && |
657270a4 CB |
91 | usess->uid == 0 && |
92 | usess->gid == 0, | |
93 | "Validate UST session"); | |
d3e8f6bb DG |
94 | |
95 | trace_ust_destroy_session(usess); | |
96 | } | |
97 | ||
657270a4 | 98 | static void test_create_ust_channel(void) |
d3e8f6bb DG |
99 | { |
100 | struct ltt_ust_channel *uchan; | |
101 | struct lttng_channel attr; | |
102 | ||
441c16a7 MD |
103 | memset(&attr, 0, sizeof(attr)); |
104 | ||
d3e8f6bb DG |
105 | strncpy(attr.name, "channel0", 8); |
106 | ||
dec56f6c | 107 | uchan = trace_ust_create_channel(&attr); |
657270a4 CB |
108 | ok(uchan != NULL, "Create UST channel"); |
109 | ||
110 | ok(uchan->enabled == 0 && | |
657270a4 CB |
111 | strncmp(uchan->name, "channel0", 8) == 0 && |
112 | uchan->name[LTTNG_UST_SYM_NAME_LEN - 1] == '\0' && | |
113 | uchan->ctx != NULL && | |
114 | uchan->events != NULL && | |
115 | uchan->attr.overwrite == attr.attr.overwrite, | |
116 | "Validate UST channel"); | |
d3e8f6bb DG |
117 | |
118 | trace_ust_destroy_channel(uchan); | |
119 | } | |
120 | ||
657270a4 | 121 | static void test_create_ust_event(void) |
d3e8f6bb DG |
122 | { |
123 | struct ltt_ust_event *event; | |
124 | struct lttng_event ev; | |
125 | ||
441c16a7 | 126 | memset(&ev, 0, sizeof(ev)); |
d3e8f6bb DG |
127 | strncpy(ev.name, get_random_string(), LTTNG_SYMBOL_NAME_LEN); |
128 | ev.type = LTTNG_EVENT_TRACEPOINT; | |
441c16a7 | 129 | ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; |
d3e8f6bb | 130 | |
88f06f15 | 131 | event = trace_ust_create_event(&ev, NULL, NULL, NULL, false); |
d3e8f6bb | 132 | |
657270a4 CB |
133 | ok(event != NULL, "Create UST event"); |
134 | ||
135 | ok(event->enabled == 0 && | |
136 | event->attr.instrumentation == LTTNG_UST_TRACEPOINT && | |
137 | strcmp(event->attr.name, ev.name) == 0 && | |
138 | event->attr.name[LTTNG_UST_SYM_NAME_LEN - 1] == '\0', | |
139 | "Validate UST event"); | |
d3e8f6bb DG |
140 | |
141 | trace_ust_destroy_event(event); | |
142 | } | |
143 | ||
41d7b959 JI |
144 | static void test_create_ust_event_exclusion(void) |
145 | { | |
146 | struct ltt_ust_event *event; | |
147 | struct lttng_event ev; | |
148 | char *name; | |
149 | struct lttng_event_exclusion *exclusion; | |
150 | ||
151 | memset(&ev, 0, sizeof(ev)); | |
152 | ||
153 | /* make a wildcarded event name */ | |
154 | name = get_random_string(); | |
155 | name[strlen(name) - 1] = '*'; | |
156 | strncpy(ev.name, name, LTTNG_SYMBOL_NAME_LEN); | |
157 | ||
158 | ev.type = LTTNG_EVENT_TRACEPOINT; | |
159 | ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; | |
160 | ||
161 | /* set up an exclusion set */ | |
162 | exclusion = zmalloc(sizeof(*exclusion) + LTTNG_SYMBOL_NAME_LEN); | |
c710ece7 MD |
163 | if (!exclusion) { |
164 | PERROR("zmalloc"); | |
165 | } | |
166 | ||
167 | ok(exclusion != NULL, "Create UST exclusion"); | |
168 | ||
41d7b959 JI |
169 | exclusion->count = 1; |
170 | strncpy((char *)(exclusion->names), get_random_string(), LTTNG_SYMBOL_NAME_LEN); | |
171 | ||
88f06f15 | 172 | event = trace_ust_create_event(&ev, NULL, NULL, exclusion, false); |
41d7b959 JI |
173 | |
174 | ok(event != NULL, "Create UST event with exclusion"); | |
175 | ||
176 | ok(event->enabled == 0 && | |
177 | event->attr.instrumentation == LTTNG_UST_TRACEPOINT && | |
178 | strcmp(event->attr.name, ev.name) == 0 && | |
179 | event->exclusion != NULL && | |
180 | event->exclusion->count == 1 && | |
181 | strcmp((char *)(event->exclusion->names), (char *)(exclusion->names)) == 0 && | |
182 | event->attr.name[LTTNG_UST_SYM_NAME_LEN - 1] == '\0', | |
183 | "Validate UST event and exclusion"); | |
184 | ||
41d7b959 JI |
185 | trace_ust_destroy_event(event); |
186 | } | |
187 | ||
188 | ||
657270a4 | 189 | static void test_create_ust_context(void) |
d3e8f6bb | 190 | { |
e38021f8 | 191 | struct lttng_event_context ectx; |
d3e8f6bb DG |
192 | struct ltt_ust_context *uctx; |
193 | ||
e38021f8 DG |
194 | ectx.ctx = LTTNG_EVENT_CONTEXT_VTID; |
195 | ||
e38021f8 | 196 | uctx = trace_ust_create_context(&ectx); |
657270a4 | 197 | ok(uctx != NULL, "Create UST context"); |
d3e8f6bb | 198 | |
657270a4 CB |
199 | ok((int) uctx->ctx.ctx == LTTNG_UST_CONTEXT_VTID, |
200 | "Validate UST context"); | |
f949b23e | 201 | free(uctx); |
d3e8f6bb DG |
202 | } |
203 | ||
204 | int main(int argc, char **argv) | |
205 | { | |
657270a4 | 206 | plan_tests(NUM_TESTS); |
d3e8f6bb | 207 | |
e3bef725 CB |
208 | diag("UST data structures unit test"); |
209 | ||
657270a4 | 210 | test_create_one_ust_session(); |
657270a4 CB |
211 | test_create_ust_channel(); |
212 | test_create_ust_event(); | |
213 | test_create_ust_context(); | |
41d7b959 | 214 | test_create_ust_event_exclusion(); |
d3e8f6bb | 215 | |
657270a4 | 216 | return exit_status(); |
d3e8f6bb | 217 | } |