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 * Return random string of 10 characters.
70 static char *get_random_string(void)
74 for (i
= 0; i
< RANDOM_STRING_LEN
- 1; i
++) {
75 random_string
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
78 random_string
[RANDOM_STRING_LEN
- 1] = '\0';
83 static void test_create_one_ust_session(void)
85 dom
.type
= LTTNG_DOMAIN_UST
;
87 usess
= trace_ust_create_session(42);
88 ok(usess
!= NULL
, "Create UST session");
91 skip(1, "UST session is null");
97 usess
->domain_global
.channels
!= NULL
&&
100 "Validate UST session");
102 trace_ust_destroy_session(usess
);
105 static void test_create_ust_channel(void)
107 struct ltt_ust_channel
*uchan
;
108 struct lttng_channel attr
;
109 struct lttng_channel_extended extended
;
111 memset(&attr
, 0, sizeof(attr
));
112 memset(&extended
, 0, sizeof(extended
));
113 attr
.attr
.extended
.ptr
= &extended
;
115 ok(lttng_strncpy(attr
.name
, "channel0", sizeof(attr
.name
)) == 0,
116 "Validate channel name length");
117 uchan
= trace_ust_create_channel(&attr
, LTTNG_DOMAIN_UST
);
118 ok(uchan
!= NULL
, "Create UST channel");
121 skip(1, "UST session is null");
125 ok(uchan
->enabled
== 0 &&
126 strncmp(uchan
->name
, "channel0", 8) == 0 &&
127 uchan
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0' &&
128 uchan
->ctx
!= NULL
&&
129 uchan
->events
!= NULL
&&
130 uchan
->attr
.overwrite
== attr
.attr
.overwrite
,
131 "Validate UST channel");
133 trace_ust_destroy_channel(uchan
);
136 static void test_create_ust_event(void)
138 struct ltt_ust_event
*event
;
139 struct lttng_event ev
;
140 enum lttng_error_code ret
;
142 memset(&ev
, 0, sizeof(ev
));
143 ok(lttng_strncpy(ev
.name
, get_random_string(),
144 LTTNG_SYMBOL_NAME_LEN
) == 0,
145 "Validate string length");
146 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
147 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
149 ret
= trace_ust_create_event(&ev
, NULL
, NULL
, NULL
, false, &event
);
151 ok(ret
== LTTNG_OK
, "Create UST event");
154 skip(1, "UST event is null");
158 ok(event
->enabled
== 0 &&
159 event
->attr
.instrumentation
== LTTNG_UST_TRACEPOINT
&&
160 strcmp(event
->attr
.name
, ev
.name
) == 0 &&
161 event
->attr
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0',
162 "Validate UST event");
164 trace_ust_destroy_event(event
);
167 static void test_create_ust_event_exclusion(void)
169 enum lttng_error_code ret
;
170 struct ltt_ust_event
*event
;
171 struct lttng_event ev
;
174 struct lttng_event_exclusion
*exclusion
= NULL
;
175 struct lttng_event_exclusion
*exclusion_copy
= NULL
;
176 const int exclusion_count
= 2;
178 memset(&ev
, 0, sizeof(ev
));
180 /* make a wildcarded event name */
181 name
= get_random_string();
182 name
[strlen(name
) - 1] = '*';
183 ok(lttng_strncpy(ev
.name
, name
, LTTNG_SYMBOL_NAME_LEN
) == 0,
184 "Validate string length");
186 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
187 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
189 /* set up an exclusion set */
190 exclusion
= zmalloc(sizeof(*exclusion
) +
191 LTTNG_SYMBOL_NAME_LEN
* exclusion_count
);
192 ok(exclusion
!= NULL
, "Create UST exclusion");
194 skip(4, "zmalloc failed");
198 exclusion
->count
= exclusion_count
;
199 random_name
= get_random_string();
200 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 0), random_name
,
201 LTTNG_SYMBOL_NAME_LEN
);
202 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 1), random_name
,
203 LTTNG_SYMBOL_NAME_LEN
);
205 ret
= trace_ust_create_event(&ev
, NULL
, NULL
, exclusion
, false, &event
);
208 ok(ret
!= LTTNG_OK
, "Create UST event with identical exclusion names fails");
210 exclusion
= zmalloc(sizeof(*exclusion
) +
211 LTTNG_SYMBOL_NAME_LEN
* exclusion_count
);
212 ok(exclusion
!= NULL
, "Create UST exclusion");
214 skip(2, "zmalloc failed");
218 exclusion_copy
= zmalloc(sizeof(*exclusion
) +
219 LTTNG_SYMBOL_NAME_LEN
* exclusion_count
);
220 if (!exclusion_copy
) {
221 skip(2, "zmalloc failed");
226 * We are giving ownership of the exclusion struct to the
227 * trace_ust_create_event() function. Make a copy of the exclusion struct
228 * so we can compare it later.
231 exclusion
->count
= exclusion_count
;
232 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 0),
233 get_random_string(), LTTNG_SYMBOL_NAME_LEN
);
234 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 1),
235 get_random_string(), LTTNG_SYMBOL_NAME_LEN
);
237 exclusion_copy
->count
= exclusion_count
;
238 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion_copy
, 0),
239 LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 0), LTTNG_SYMBOL_NAME_LEN
);
240 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion_copy
, 1),
241 LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 1), LTTNG_SYMBOL_NAME_LEN
);
243 ret
= trace_ust_create_event(&ev
, NULL
, NULL
, exclusion
, false, &event
);
245 ok(ret
== LTTNG_OK
, "Create UST event with different exclusion names");
248 skip(1, "UST event with exclusion is null");
252 ok(event
->enabled
== 0 &&
253 event
->attr
.instrumentation
== LTTNG_UST_TRACEPOINT
&&
254 strcmp(event
->attr
.name
, ev
.name
) == 0 &&
255 event
->exclusion
!= NULL
&&
256 event
->exclusion
->count
== exclusion_count
&&
257 !memcmp(event
->exclusion
->names
, exclusion_copy
->names
,
258 LTTNG_SYMBOL_NAME_LEN
* exclusion_count
) &&
259 event
->attr
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0',
260 "Validate UST event and exclusion");
262 trace_ust_destroy_event(event
);
265 free(exclusion_copy
);
270 static void test_create_ust_context(void)
272 struct lttng_event_context ectx
;
273 struct ltt_ust_context
*uctx
;
275 ectx
.ctx
= LTTNG_EVENT_CONTEXT_VTID
;
277 uctx
= trace_ust_create_context(&ectx
);
278 ok(uctx
!= NULL
, "Create UST context");
280 ok((int) uctx
->ctx
.ctx
== LTTNG_UST_CONTEXT_VTID
,
281 "Validate UST context");
285 int main(int argc
, char **argv
)
287 plan_tests(NUM_TESTS
);
289 diag("UST data structures unit test");
291 rcu_register_thread();
293 test_create_one_ust_session();
294 test_create_ust_channel();
295 test_create_ust_event();
296 test_create_ust_context();
297 test_create_ust_event_exclusion();
299 rcu_unregister_thread();
301 return exit_status();