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>
36 /* This path will NEVER be created in this test */
37 #define PATH1 "/tmp/.test-junk-lttng"
39 #define RANDOM_STRING_LEN 11
41 /* Number of TAP tests in this file */
45 int lttng_opt_quiet
= 1;
46 int lttng_opt_verbose
;
49 int ust_consumerd32_fd
;
50 int ust_consumerd64_fd
;
52 /* Global variable required by sessiond objects being linked-in */
53 struct lttng_ht
*agent_apps_ht_by_sock
;
55 static const char alphanum
[] =
57 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
58 "abcdefghijklmnopqrstuvwxyz";
59 static char random_string
[RANDOM_STRING_LEN
];
61 static struct ltt_ust_session
*usess
;
62 static struct lttng_domain dom
;
65 * Return random string of 10 characters.
68 static char *get_random_string(void)
72 for (i
= 0; i
< RANDOM_STRING_LEN
- 1; i
++) {
73 random_string
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
76 random_string
[RANDOM_STRING_LEN
- 1] = '\0';
81 static void test_create_one_ust_session(void)
83 dom
.type
= LTTNG_DOMAIN_UST
;
85 usess
= trace_ust_create_session(42);
86 ok(usess
!= NULL
, "Create UST session");
89 skip(1, "UST session is null");
95 usess
->domain_global
.channels
!= NULL
&&
98 "Validate UST session");
100 trace_ust_destroy_session(usess
);
103 static void test_create_ust_channel(void)
105 struct ltt_ust_channel
*uchan
;
106 struct lttng_channel attr
;
108 memset(&attr
, 0, sizeof(attr
));
110 ok(lttng_strncpy(attr
.name
, "channel0", sizeof(attr
.name
)) == 0,
111 "Validate channel name length");
112 uchan
= trace_ust_create_channel(&attr
, LTTNG_DOMAIN_UST
);
113 ok(uchan
!= NULL
, "Create UST channel");
116 skip(1, "UST session is null");
120 ok(uchan
->enabled
== 0 &&
121 strncmp(uchan
->name
, "channel0", 8) == 0 &&
122 uchan
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0' &&
123 uchan
->ctx
!= NULL
&&
124 uchan
->events
!= NULL
&&
125 uchan
->attr
.overwrite
== attr
.attr
.overwrite
,
126 "Validate UST channel");
128 trace_ust_destroy_channel(uchan
);
131 static void test_create_ust_event(void)
133 struct ltt_ust_event
*event
;
134 struct lttng_event ev
;
136 memset(&ev
, 0, sizeof(ev
));
137 ok(lttng_strncpy(ev
.name
, get_random_string(),
138 LTTNG_SYMBOL_NAME_LEN
) == 0,
139 "Validate string length");
140 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
141 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
143 event
= trace_ust_create_event(&ev
, NULL
, NULL
, NULL
, false);
145 ok(event
!= NULL
, "Create UST event");
148 skip(1, "UST event is null");
152 ok(event
->enabled
== 0 &&
153 event
->attr
.instrumentation
== LTTNG_UST_TRACEPOINT
&&
154 strcmp(event
->attr
.name
, ev
.name
) == 0 &&
155 event
->attr
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0',
156 "Validate UST event");
158 trace_ust_destroy_event(event
);
161 static void test_create_ust_event_exclusion(void)
163 struct ltt_ust_event
*event
;
164 struct lttng_event ev
;
167 struct lttng_event_exclusion
*exclusion
;
168 const int exclusion_count
= 2;
170 memset(&ev
, 0, sizeof(ev
));
172 /* make a wildcarded event name */
173 name
= get_random_string();
174 name
[strlen(name
) - 1] = '*';
175 ok(lttng_strncpy(ev
.name
, name
, LTTNG_SYMBOL_NAME_LEN
) == 0,
176 "Validate string length");
178 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
179 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
181 /* set up an exclusion set */
182 exclusion
= zmalloc(sizeof(*exclusion
) +
183 LTTNG_SYMBOL_NAME_LEN
* exclusion_count
);
184 ok(exclusion
!= NULL
, "Create UST exclusion");
186 skip(4, "zmalloc failed");
190 exclusion
->count
= exclusion_count
;
191 random_name
= get_random_string();
192 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 0), random_name
,
193 LTTNG_SYMBOL_NAME_LEN
);
194 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 1), random_name
,
195 LTTNG_SYMBOL_NAME_LEN
);
197 event
= trace_ust_create_event(&ev
, NULL
, NULL
, exclusion
, false);
200 ok(!event
, "Create UST event with identical exclusion names fails");
202 exclusion
= zmalloc(sizeof(*exclusion
) +
203 LTTNG_SYMBOL_NAME_LEN
* exclusion_count
);
204 ok(exclusion
!= NULL
, "Create UST exclusion");
206 skip(2, "zmalloc failed");
210 exclusion
->count
= exclusion_count
;
211 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 0),
212 get_random_string(), LTTNG_SYMBOL_NAME_LEN
);
213 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 1),
214 get_random_string(), LTTNG_SYMBOL_NAME_LEN
);
216 event
= trace_ust_create_event(&ev
, NULL
, NULL
, exclusion
, false);
217 ok(event
!= NULL
, "Create UST event with different exclusion names");
220 skip(1, "UST event with exclusion is null");
224 ok(event
->enabled
== 0 &&
225 event
->attr
.instrumentation
== LTTNG_UST_TRACEPOINT
&&
226 strcmp(event
->attr
.name
, ev
.name
) == 0 &&
227 event
->exclusion
!= NULL
&&
228 event
->exclusion
->count
== exclusion_count
&&
229 !memcmp(event
->exclusion
->names
, exclusion
->names
,
230 LTTNG_SYMBOL_NAME_LEN
* exclusion_count
) &&
231 event
->attr
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0',
232 "Validate UST event and exclusion");
234 trace_ust_destroy_event(event
);
240 static void test_create_ust_context(void)
242 struct lttng_event_context ectx
;
243 struct ltt_ust_context
*uctx
;
245 ectx
.ctx
= LTTNG_EVENT_CONTEXT_VTID
;
247 uctx
= trace_ust_create_context(&ectx
);
248 ok(uctx
!= NULL
, "Create UST context");
250 ok((int) uctx
->ctx
.ctx
== LTTNG_UST_CONTEXT_VTID
,
251 "Validate UST context");
255 int main(int argc
, char **argv
)
257 plan_tests(NUM_TESTS
);
259 diag("UST data structures unit test");
261 rcu_register_thread();
263 test_create_one_ust_session();
264 test_create_ust_channel();
265 test_create_ust_event();
266 test_create_ust_context();
267 test_create_ust_event_exclusion();
269 rcu_unregister_thread();
271 return exit_status();
This page took 0.046725 seconds and 4 git commands to generate.