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
];
62 * Return random string of 10 characters.
65 static char *get_random_string(void)
69 for (i
= 0; i
< RANDOM_STRING_LEN
- 1; i
++) {
70 random_string
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
73 random_string
[RANDOM_STRING_LEN
- 1] = '\0';
78 static void test_create_one_ust_session(void)
80 struct ltt_ust_session
*usess
=
81 trace_ust_create_session(42);
83 ok(usess
!= NULL
, "Create UST session");
86 skip(1, "UST session is null");
92 usess
->domain_global
.channels
!= NULL
&&
95 "Validate UST session");
97 trace_ust_destroy_session(usess
);
100 static void test_create_ust_channel(void)
102 struct ltt_ust_channel
*uchan
;
103 struct lttng_channel attr
;
105 memset(&attr
, 0, sizeof(attr
));
107 ok(lttng_strncpy(attr
.name
, "channel0", sizeof(attr
.name
)) == 0,
108 "Validate channel name length");
109 uchan
= trace_ust_create_channel(&attr
, LTTNG_DOMAIN_UST
);
110 ok(uchan
!= NULL
, "Create UST channel");
113 skip(1, "UST channel is null");
117 ok(uchan
->enabled
== 0 &&
118 strncmp(uchan
->name
, "channel0", 8) == 0 &&
119 uchan
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0' &&
120 uchan
->ctx
!= NULL
&&
121 uchan
->events
!= NULL
&&
122 uchan
->attr
.overwrite
== attr
.attr
.overwrite
,
123 "Validate UST channel");
125 trace_ust_destroy_channel(uchan
);
128 static void test_create_ust_event(void)
130 struct ltt_ust_event
*event
;
131 struct lttng_event ev
;
133 memset(&ev
, 0, sizeof(ev
));
134 ok(lttng_strncpy(ev
.name
, get_random_string(),
135 LTTNG_SYMBOL_NAME_LEN
) == 0,
136 "Validate string length");
137 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
138 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
140 event
= trace_ust_create_event(&ev
, NULL
, NULL
, NULL
, false);
142 ok(event
!= NULL
, "Create UST event");
145 skip(1, "UST event is null");
149 ok(event
->enabled
== 0 &&
150 event
->attr
.instrumentation
== LTTNG_UST_TRACEPOINT
&&
151 strcmp(event
->attr
.name
, ev
.name
) == 0 &&
152 event
->attr
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0',
153 "Validate UST event");
155 trace_ust_destroy_event(event
);
158 static void test_create_ust_event_exclusion(void)
160 struct ltt_ust_event
*event
;
161 struct lttng_event ev
;
164 struct lttng_event_exclusion
*exclusion
;
165 const int exclusion_count
= 2;
167 memset(&ev
, 0, sizeof(ev
));
169 /* make a wildcarded event name */
170 name
= get_random_string();
171 name
[strlen(name
) - 1] = '*';
172 ok(lttng_strncpy(ev
.name
, name
, LTTNG_SYMBOL_NAME_LEN
) == 0,
173 "Validate string length");
175 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
176 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
178 /* set up an exclusion set */
179 exclusion
= zmalloc(sizeof(*exclusion
) +
180 LTTNG_SYMBOL_NAME_LEN
* exclusion_count
);
181 ok(exclusion
!= NULL
, "Create UST exclusion");
183 skip(4, "zmalloc failed");
187 exclusion
->count
= exclusion_count
;
188 random_name
= get_random_string();
189 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 0), random_name
,
190 LTTNG_SYMBOL_NAME_LEN
);
191 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 1), random_name
,
192 LTTNG_SYMBOL_NAME_LEN
);
194 event
= trace_ust_create_event(&ev
, NULL
, NULL
, exclusion
, false);
197 ok(!event
, "Create UST event with identical exclusion names fails");
199 exclusion
= zmalloc(sizeof(*exclusion
) +
200 LTTNG_SYMBOL_NAME_LEN
* exclusion_count
);
201 ok(exclusion
!= NULL
, "Create UST exclusion");
203 skip(2, "zmalloc failed");
207 exclusion
->count
= exclusion_count
;
208 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 0),
209 get_random_string(), LTTNG_SYMBOL_NAME_LEN
);
210 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 1),
211 get_random_string(), LTTNG_SYMBOL_NAME_LEN
);
213 event
= trace_ust_create_event(&ev
, NULL
, NULL
, exclusion
, false);
214 ok(event
!= NULL
, "Create UST event with different exclusion names");
217 skip(1, "UST event with exclusion is null");
221 ok(event
->enabled
== 0 &&
222 event
->attr
.instrumentation
== LTTNG_UST_TRACEPOINT
&&
223 strcmp(event
->attr
.name
, ev
.name
) == 0 &&
224 event
->exclusion
!= NULL
&&
225 event
->exclusion
->count
== exclusion_count
&&
226 !memcmp(event
->exclusion
->names
, exclusion
->names
,
227 LTTNG_SYMBOL_NAME_LEN
* exclusion_count
) &&
228 event
->attr
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0',
229 "Validate UST event and exclusion");
231 trace_ust_destroy_event(event
);
237 static void test_create_ust_context(void)
239 struct lttng_event_context ectx
;
240 struct ltt_ust_context
*uctx
;
242 ectx
.ctx
= LTTNG_EVENT_CONTEXT_VTID
;
244 uctx
= trace_ust_create_context(&ectx
);
245 ok(uctx
!= NULL
, "Create UST context");
248 ok((int) uctx
->ctx
.ctx
== LTTNG_UST_CONTEXT_VTID
,
249 "Validate UST context");
251 skip(1, "Skipping UST context validation as creation failed");
256 int main(int argc
, char **argv
)
258 plan_tests(NUM_TESTS
);
260 diag("UST data structures unit test");
262 rcu_register_thread();
264 test_create_one_ust_session();
265 test_create_ust_channel();
266 test_create_ust_event();
267 test_create_ust_context();
268 test_create_ust_event_exclusion();
270 rcu_unregister_thread();
272 return exit_status();
This page took 0.051843 seconds and 4 git commands to generate.