2 * Copyright (c) 2011 David Goulet <david.goulet@polymtl.ca>
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
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.
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.
28 #include <lttng/lttng.h>
29 #include <bin/lttng-sessiond/lttng-ust-abi.h>
30 #include <common/defaults.h>
31 #include <bin/lttng-sessiond/trace-ust.h>
32 #include <bin/lttng-sessiond/ust-app.h>
33 #include <bin/lttng-sessiond/notification-thread.h>
37 /* This path will NEVER be created in this test */
38 #define PATH1 "/tmp/.test-junk-lttng"
40 #define RANDOM_STRING_LEN 11
42 /* Number of TAP tests in this file */
46 int lttng_opt_quiet
= 1;
47 int lttng_opt_verbose
;
50 int ust_consumerd32_fd
;
51 int ust_consumerd64_fd
;
53 /* Global variables required by sessiond objects being linked-in */
54 struct lttng_ht
*agent_apps_ht_by_sock
;
55 struct notification_thread_handle
*notification_thread_handle
;
57 static const char alphanum
[] =
59 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
60 "abcdefghijklmnopqrstuvwxyz";
61 static char random_string
[RANDOM_STRING_LEN
];
63 static struct ltt_ust_session
*usess
;
64 static struct lttng_domain dom
;
67 * Stub to prevent an undefined reference in this test without having to link
68 * the entire tree because of a cascade of dependencies. This is not used,
69 * it is just there to prevent GCC from complaining.
71 int rotate_add_channel_pending(uint64_t key
, enum lttng_domain_type domain
,
72 struct ltt_session
*session
)
74 ERR("Stub called instead of the real function");
80 * Return random string of 10 characters.
83 static char *get_random_string(void)
87 for (i
= 0; i
< RANDOM_STRING_LEN
- 1; i
++) {
88 random_string
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
91 random_string
[RANDOM_STRING_LEN
- 1] = '\0';
96 static void test_create_one_ust_session(void)
98 dom
.type
= LTTNG_DOMAIN_UST
;
100 usess
= trace_ust_create_session(42);
101 ok(usess
!= NULL
, "Create UST session");
104 skip(1, "UST session is null");
108 ok(usess
->id
== 42 &&
109 usess
->active
== 0 &&
110 usess
->domain_global
.channels
!= NULL
&&
113 "Validate UST session");
115 trace_ust_destroy_session(usess
);
118 static void test_create_ust_channel(void)
120 struct ltt_ust_channel
*uchan
;
121 struct lttng_channel attr
;
122 struct lttng_channel_extended extended
;
124 memset(&attr
, 0, sizeof(attr
));
125 memset(&extended
, 0, sizeof(extended
));
126 attr
.attr
.extended
.ptr
= &extended
;
128 ok(lttng_strncpy(attr
.name
, "channel0", sizeof(attr
.name
)) == 0,
129 "Validate channel name length");
130 uchan
= trace_ust_create_channel(&attr
, LTTNG_DOMAIN_UST
);
131 ok(uchan
!= NULL
, "Create UST channel");
134 skip(1, "UST session is null");
138 ok(uchan
->enabled
== 0 &&
139 strncmp(uchan
->name
, "channel0", 8) == 0 &&
140 uchan
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0' &&
141 uchan
->ctx
!= NULL
&&
142 uchan
->events
!= NULL
&&
143 uchan
->attr
.overwrite
== attr
.attr
.overwrite
,
144 "Validate UST channel");
146 trace_ust_destroy_channel(uchan
);
149 static void test_create_ust_event(void)
151 struct ltt_ust_event
*event
;
152 struct lttng_event ev
;
154 memset(&ev
, 0, sizeof(ev
));
155 ok(lttng_strncpy(ev
.name
, get_random_string(),
156 LTTNG_SYMBOL_NAME_LEN
) == 0,
157 "Validate string length");
158 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
159 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
161 event
= trace_ust_create_event(&ev
, NULL
, NULL
, NULL
, false);
163 ok(event
!= NULL
, "Create UST event");
166 skip(1, "UST event is null");
170 ok(event
->enabled
== 0 &&
171 event
->attr
.instrumentation
== LTTNG_UST_TRACEPOINT
&&
172 strcmp(event
->attr
.name
, ev
.name
) == 0 &&
173 event
->attr
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0',
174 "Validate UST event");
176 trace_ust_destroy_event(event
);
179 static void test_create_ust_event_exclusion(void)
181 struct ltt_ust_event
*event
;
182 struct lttng_event ev
;
185 struct lttng_event_exclusion
*exclusion
;
186 const int exclusion_count
= 2;
188 memset(&ev
, 0, sizeof(ev
));
190 /* make a wildcarded event name */
191 name
= get_random_string();
192 name
[strlen(name
) - 1] = '*';
193 ok(lttng_strncpy(ev
.name
, name
, LTTNG_SYMBOL_NAME_LEN
) == 0,
194 "Validate string length");
196 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
197 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
199 /* set up an exclusion set */
200 exclusion
= zmalloc(sizeof(*exclusion
) +
201 LTTNG_SYMBOL_NAME_LEN
* exclusion_count
);
202 ok(exclusion
!= NULL
, "Create UST exclusion");
204 skip(4, "zmalloc failed");
208 exclusion
->count
= exclusion_count
;
209 random_name
= get_random_string();
210 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 0), random_name
,
211 LTTNG_SYMBOL_NAME_LEN
);
212 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 1), random_name
,
213 LTTNG_SYMBOL_NAME_LEN
);
215 event
= trace_ust_create_event(&ev
, NULL
, NULL
, exclusion
, false);
218 ok(!event
, "Create UST event with identical exclusion names fails");
220 exclusion
= zmalloc(sizeof(*exclusion
) +
221 LTTNG_SYMBOL_NAME_LEN
* exclusion_count
);
222 ok(exclusion
!= NULL
, "Create UST exclusion");
224 skip(2, "zmalloc failed");
228 exclusion
->count
= exclusion_count
;
229 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 0),
230 get_random_string(), LTTNG_SYMBOL_NAME_LEN
);
231 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 1),
232 get_random_string(), LTTNG_SYMBOL_NAME_LEN
);
234 event
= trace_ust_create_event(&ev
, NULL
, NULL
, exclusion
, false);
235 ok(event
!= NULL
, "Create UST event with different exclusion names");
238 skip(1, "UST event with exclusion is null");
242 ok(event
->enabled
== 0 &&
243 event
->attr
.instrumentation
== LTTNG_UST_TRACEPOINT
&&
244 strcmp(event
->attr
.name
, ev
.name
) == 0 &&
245 event
->exclusion
!= NULL
&&
246 event
->exclusion
->count
== exclusion_count
&&
247 !memcmp(event
->exclusion
->names
, exclusion
->names
,
248 LTTNG_SYMBOL_NAME_LEN
* exclusion_count
) &&
249 event
->attr
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0',
250 "Validate UST event and exclusion");
252 trace_ust_destroy_event(event
);
258 static void test_create_ust_context(void)
260 struct lttng_event_context ectx
;
261 struct ltt_ust_context
*uctx
;
263 ectx
.ctx
= LTTNG_EVENT_CONTEXT_VTID
;
265 uctx
= trace_ust_create_context(&ectx
);
266 ok(uctx
!= NULL
, "Create UST context");
268 ok((int) uctx
->ctx
.ctx
== LTTNG_UST_CONTEXT_VTID
,
269 "Validate UST context");
273 int main(int argc
, char **argv
)
275 plan_tests(NUM_TESTS
);
277 diag("UST data structures unit test");
279 rcu_register_thread();
281 test_create_one_ust_session();
282 test_create_ust_channel();
283 test_create_ust_event();
284 test_create_ust_context();
285 test_create_ust_event_exclusion();
287 rcu_unregister_thread();
289 return exit_status();