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
;
110 memset(&attr
, 0, sizeof(attr
));
112 ok(lttng_strncpy(attr
.name
, "channel0", sizeof(attr
.name
)) == 0,
113 "Validate channel name length");
114 uchan
= trace_ust_create_channel(&attr
, LTTNG_DOMAIN_UST
);
115 ok(uchan
!= NULL
, "Create UST channel");
118 skip(1, "UST session is null");
122 ok(uchan
->enabled
== 0 &&
123 strncmp(uchan
->name
, "channel0", 8) == 0 &&
124 uchan
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0' &&
125 uchan
->ctx
!= NULL
&&
126 uchan
->events
!= NULL
&&
127 uchan
->attr
.overwrite
== attr
.attr
.overwrite
,
128 "Validate UST channel");
130 trace_ust_destroy_channel(uchan
);
133 static void test_create_ust_event(void)
135 struct ltt_ust_event
*event
;
136 struct lttng_event ev
;
138 memset(&ev
, 0, sizeof(ev
));
139 ok(lttng_strncpy(ev
.name
, get_random_string(),
140 LTTNG_SYMBOL_NAME_LEN
) == 0,
141 "Validate string length");
142 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
143 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
145 event
= trace_ust_create_event(&ev
, NULL
, NULL
, NULL
, false);
147 ok(event
!= NULL
, "Create UST event");
150 skip(1, "UST event is null");
154 ok(event
->enabled
== 0 &&
155 event
->attr
.instrumentation
== LTTNG_UST_TRACEPOINT
&&
156 strcmp(event
->attr
.name
, ev
.name
) == 0 &&
157 event
->attr
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0',
158 "Validate UST event");
160 trace_ust_destroy_event(event
);
163 static void test_create_ust_event_exclusion(void)
165 struct ltt_ust_event
*event
;
166 struct lttng_event ev
;
169 struct lttng_event_exclusion
*exclusion
;
170 const int exclusion_count
= 2;
172 memset(&ev
, 0, sizeof(ev
));
174 /* make a wildcarded event name */
175 name
= get_random_string();
176 name
[strlen(name
) - 1] = '*';
177 ok(lttng_strncpy(ev
.name
, name
, LTTNG_SYMBOL_NAME_LEN
) == 0,
178 "Validate string length");
180 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
181 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
183 /* set up an exclusion set */
184 exclusion
= zmalloc(sizeof(*exclusion
) +
185 LTTNG_SYMBOL_NAME_LEN
* exclusion_count
);
186 ok(exclusion
!= NULL
, "Create UST exclusion");
188 skip(4, "zmalloc failed");
192 exclusion
->count
= exclusion_count
;
193 random_name
= get_random_string();
194 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 0), random_name
,
195 LTTNG_SYMBOL_NAME_LEN
);
196 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 1), random_name
,
197 LTTNG_SYMBOL_NAME_LEN
);
199 event
= trace_ust_create_event(&ev
, NULL
, NULL
, exclusion
, false);
202 ok(!event
, "Create UST event with identical exclusion names fails");
204 exclusion
= zmalloc(sizeof(*exclusion
) +
205 LTTNG_SYMBOL_NAME_LEN
* exclusion_count
);
206 ok(exclusion
!= NULL
, "Create UST exclusion");
208 skip(2, "zmalloc failed");
212 exclusion
->count
= exclusion_count
;
213 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 0),
214 get_random_string(), LTTNG_SYMBOL_NAME_LEN
);
215 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 1),
216 get_random_string(), LTTNG_SYMBOL_NAME_LEN
);
218 event
= trace_ust_create_event(&ev
, NULL
, NULL
, exclusion
, false);
219 ok(event
!= NULL
, "Create UST event with different exclusion names");
222 skip(1, "UST event with exclusion is null");
226 ok(event
->enabled
== 0 &&
227 event
->attr
.instrumentation
== LTTNG_UST_TRACEPOINT
&&
228 strcmp(event
->attr
.name
, ev
.name
) == 0 &&
229 event
->exclusion
!= NULL
&&
230 event
->exclusion
->count
== exclusion_count
&&
231 !memcmp(event
->exclusion
->names
, exclusion
->names
,
232 LTTNG_SYMBOL_NAME_LEN
* exclusion_count
) &&
233 event
->attr
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0',
234 "Validate UST event and exclusion");
236 trace_ust_destroy_event(event
);
242 static void test_create_ust_context(void)
244 struct lttng_event_context ectx
;
245 struct ltt_ust_context
*uctx
;
247 ectx
.ctx
= LTTNG_EVENT_CONTEXT_VTID
;
249 uctx
= trace_ust_create_context(&ectx
);
250 ok(uctx
!= NULL
, "Create UST context");
252 ok((int) uctx
->ctx
.ctx
== LTTNG_UST_CONTEXT_VTID
,
253 "Validate UST context");
257 int main(int argc
, char **argv
)
259 plan_tests(NUM_TESTS
);
261 diag("UST data structures unit test");
263 rcu_register_thread();
265 test_create_one_ust_session();
266 test_create_ust_channel();
267 test_create_ust_event();
268 test_create_ust_context();
269 test_create_ust_event_exclusion();
271 rcu_unregister_thread();
273 return exit_status();