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 static const char alphanum
[] =
52 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
53 "abcdefghijklmnopqrstuvwxyz";
54 static char random_string
[RANDOM_STRING_LEN
];
57 * Return random string of 10 characters.
60 static char *get_random_string(void)
64 for (i
= 0; i
< RANDOM_STRING_LEN
- 1; i
++) {
65 random_string
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
68 random_string
[RANDOM_STRING_LEN
- 1] = '\0';
73 static void test_create_one_ust_session(void)
75 struct ltt_ust_session
*usess
=
76 trace_ust_create_session(42);
78 ok(usess
!= NULL
, "Create UST session");
81 skip(1, "UST session is null");
87 usess
->domain_global
.channels
!= NULL
&&
90 "Validate UST session");
92 trace_ust_destroy_session(usess
);
95 static void test_create_ust_channel(void)
97 struct ltt_ust_channel
*uchan
;
98 struct lttng_channel attr
;
99 struct lttng_channel_extended extended
;
101 memset(&attr
, 0, sizeof(attr
));
102 memset(&extended
, 0, sizeof(extended
));
103 attr
.attr
.extended
.ptr
= &extended
;
105 ok(lttng_strncpy(attr
.name
, "channel0", sizeof(attr
.name
)) == 0,
106 "Validate channel name length");
107 uchan
= trace_ust_create_channel(&attr
, LTTNG_DOMAIN_UST
);
108 ok(uchan
!= NULL
, "Create UST channel");
111 skip(1, "UST channel is null");
115 ok(uchan
->enabled
== 0 &&
116 strncmp(uchan
->name
, "channel0", 8) == 0 &&
117 uchan
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0' &&
118 uchan
->ctx
!= NULL
&&
119 uchan
->events
!= NULL
&&
120 uchan
->attr
.overwrite
== attr
.attr
.overwrite
,
121 "Validate UST channel");
123 trace_ust_destroy_channel(uchan
);
126 static void test_create_ust_event(void)
128 struct ltt_ust_event
*event
;
129 struct lttng_event ev
;
130 enum lttng_error_code ret
;
132 memset(&ev
, 0, sizeof(ev
));
133 ok(lttng_strncpy(ev
.name
, get_random_string(),
134 LTTNG_SYMBOL_NAME_LEN
) == 0,
135 "Validate string length");
136 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
137 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
139 ret
= trace_ust_create_event(&ev
, NULL
, NULL
, NULL
, false, &event
);
141 ok(ret
== LTTNG_OK
, "Create UST event");
144 skip(1, "UST event is null");
148 ok(event
->enabled
== 0 &&
149 event
->attr
.instrumentation
== LTTNG_UST_TRACEPOINT
&&
150 strcmp(event
->attr
.name
, ev
.name
) == 0 &&
151 event
->attr
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0',
152 "Validate UST event");
154 trace_ust_destroy_event(event
);
157 static void test_create_ust_event_exclusion(void)
159 enum lttng_error_code ret
;
160 struct ltt_ust_event
*event
;
161 struct lttng_event ev
;
164 struct lttng_event_exclusion
*exclusion
= NULL
;
165 struct lttng_event_exclusion
*exclusion_copy
= NULL
;
166 const int exclusion_count
= 2;
168 memset(&ev
, 0, sizeof(ev
));
170 /* make a wildcarded event name */
171 name
= get_random_string();
172 name
[strlen(name
) - 1] = '*';
173 ok(lttng_strncpy(ev
.name
, name
, LTTNG_SYMBOL_NAME_LEN
) == 0,
174 "Validate string length");
176 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
177 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
179 /* set up an exclusion set */
180 exclusion
= zmalloc(sizeof(*exclusion
) +
181 LTTNG_SYMBOL_NAME_LEN
* exclusion_count
);
182 ok(exclusion
!= NULL
, "Create UST exclusion");
184 skip(4, "zmalloc failed");
188 exclusion
->count
= exclusion_count
;
189 random_name
= get_random_string();
190 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 0), random_name
,
191 LTTNG_SYMBOL_NAME_LEN
);
192 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 1), random_name
,
193 LTTNG_SYMBOL_NAME_LEN
);
195 ret
= trace_ust_create_event(&ev
, NULL
, NULL
, exclusion
, false, &event
);
198 ok(ret
!= LTTNG_OK
, "Create UST event with identical exclusion names fails");
200 exclusion
= zmalloc(sizeof(*exclusion
) +
201 LTTNG_SYMBOL_NAME_LEN
* exclusion_count
);
202 ok(exclusion
!= NULL
, "Create UST exclusion");
204 skip(2, "zmalloc failed");
208 exclusion_copy
= zmalloc(sizeof(*exclusion
) +
209 LTTNG_SYMBOL_NAME_LEN
* exclusion_count
);
210 if (!exclusion_copy
) {
211 skip(2, "zmalloc failed");
216 * We are giving ownership of the exclusion struct to the
217 * trace_ust_create_event() function. Make a copy of the exclusion struct
218 * so we can compare it later.
221 exclusion
->count
= exclusion_count
;
222 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 0),
223 get_random_string(), LTTNG_SYMBOL_NAME_LEN
);
224 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 1),
225 get_random_string(), LTTNG_SYMBOL_NAME_LEN
);
227 exclusion_copy
->count
= exclusion_count
;
228 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion_copy
, 0),
229 LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 0), LTTNG_SYMBOL_NAME_LEN
);
230 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion_copy
, 1),
231 LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 1), LTTNG_SYMBOL_NAME_LEN
);
233 ret
= trace_ust_create_event(&ev
, NULL
, NULL
, exclusion
, false, &event
);
235 ok(ret
== LTTNG_OK
, "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_copy
->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
);
255 free(exclusion_copy
);
260 static void test_create_ust_context(void)
262 struct lttng_event_context ectx
;
263 struct ltt_ust_context
*uctx
;
265 ectx
.ctx
= LTTNG_EVENT_CONTEXT_VTID
;
267 uctx
= trace_ust_create_context(&ectx
);
268 ok(uctx
!= NULL
, "Create UST context");
271 ok((int) uctx
->ctx
.ctx
== LTTNG_UST_CONTEXT_VTID
,
272 "Validate UST context");
274 skip(1, "Skipping UST context validation as creation failed");
279 int main(int argc
, char **argv
)
281 plan_tests(NUM_TESTS
);
283 diag("UST data structures unit test");
285 rcu_register_thread();
287 test_create_one_ust_session();
288 test_create_ust_channel();
289 test_create_ust_event();
290 test_create_ust_context();
291 test_create_ust_event_exclusion();
293 rcu_unregister_thread();
295 return exit_status();