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.
27 #include <lttng/lttng.h>
28 #include <bin/lttng-sessiond/lttng-ust-abi.h>
29 #include <common/defaults.h>
30 #include <bin/lttng-sessiond/trace-ust.h>
31 #include <bin/lttng-sessiond/ust-app.h>
35 /* This path will NEVER be created in this test */
36 #define PATH1 "/tmp/.test-junk-lttng"
38 #define RANDOM_STRING_LEN 11
40 /* Number of TAP tests in this file */
44 int lttng_opt_quiet
= 1;
45 int lttng_opt_verbose
;
48 int ust_consumerd32_fd
;
49 int ust_consumerd64_fd
;
51 /* Global variable required by sessiond objects being linked-in */
52 struct lttng_ht
*agent_apps_ht_by_sock
;
54 static const char alphanum
[] =
56 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
57 "abcdefghijklmnopqrstuvwxyz";
58 static char random_string
[RANDOM_STRING_LEN
];
60 static struct ltt_ust_session
*usess
;
61 static struct lttng_domain dom
;
64 * Return random string of 10 characters.
67 static char *get_random_string(void)
71 for (i
= 0; i
< RANDOM_STRING_LEN
- 1; i
++) {
72 random_string
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
75 random_string
[RANDOM_STRING_LEN
- 1] = '\0';
80 static void test_create_one_ust_session(void)
82 dom
.type
= LTTNG_DOMAIN_UST
;
84 usess
= trace_ust_create_session(42);
85 ok(usess
!= NULL
, "Create UST session");
88 skip(1, "UST session is null");
94 usess
->domain_global
.channels
!= NULL
&&
97 "Validate UST session");
99 trace_ust_destroy_session(usess
);
102 static void test_create_ust_channel(void)
104 struct ltt_ust_channel
*uchan
;
105 struct lttng_channel attr
;
107 memset(&attr
, 0, sizeof(attr
));
109 ok(lttng_strncpy(attr
.name
, "channel0", sizeof(attr
.name
)) == 0,
110 "Validate channel name length");
111 uchan
= trace_ust_create_channel(&attr
, LTTNG_DOMAIN_UST
);
112 ok(uchan
!= NULL
, "Create UST channel");
115 skip(1, "UST session is null");
119 ok(uchan
->enabled
== 0 &&
120 strncmp(uchan
->name
, "channel0", 8) == 0 &&
121 uchan
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0' &&
122 uchan
->ctx
!= NULL
&&
123 uchan
->events
!= NULL
&&
124 uchan
->attr
.overwrite
== attr
.attr
.overwrite
,
125 "Validate UST channel");
127 trace_ust_destroy_channel(uchan
);
130 static void test_create_ust_event(void)
132 struct ltt_ust_event
*event
;
133 struct lttng_event ev
;
135 memset(&ev
, 0, sizeof(ev
));
136 ok(lttng_strncpy(ev
.name
, get_random_string(),
137 LTTNG_SYMBOL_NAME_LEN
) == 0,
138 "Validate string length");
139 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
140 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
142 event
= trace_ust_create_event(&ev
, NULL
, NULL
, NULL
, false);
144 ok(event
!= NULL
, "Create UST event");
147 skip(1, "UST event is null");
151 ok(event
->enabled
== 0 &&
152 event
->attr
.instrumentation
== LTTNG_UST_TRACEPOINT
&&
153 strcmp(event
->attr
.name
, ev
.name
) == 0 &&
154 event
->attr
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0',
155 "Validate UST event");
157 trace_ust_destroy_event(event
);
160 static void test_create_ust_event_exclusion(void)
162 struct ltt_ust_event
*event
;
163 struct lttng_event ev
;
166 struct lttng_event_exclusion
*exclusion
;
167 const int exclusion_count
= 2;
169 memset(&ev
, 0, sizeof(ev
));
171 /* make a wildcarded event name */
172 name
= get_random_string();
173 name
[strlen(name
) - 1] = '*';
174 ok(lttng_strncpy(ev
.name
, name
, LTTNG_SYMBOL_NAME_LEN
) == 0,
175 "Validate string length");
177 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
178 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
180 /* set up an exclusion set */
181 exclusion
= zmalloc(sizeof(*exclusion
) +
182 LTTNG_SYMBOL_NAME_LEN
* exclusion_count
);
183 ok(exclusion
!= NULL
, "Create UST exclusion");
185 skip(4, "zmalloc failed");
189 exclusion
->count
= exclusion_count
;
190 random_name
= get_random_string();
191 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 0), random_name
,
192 LTTNG_SYMBOL_NAME_LEN
);
193 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 1), random_name
,
194 LTTNG_SYMBOL_NAME_LEN
);
196 event
= trace_ust_create_event(&ev
, NULL
, NULL
, exclusion
, false);
199 ok(!event
, "Create UST event with identical exclusion names fails");
201 exclusion
= zmalloc(sizeof(*exclusion
) +
202 LTTNG_SYMBOL_NAME_LEN
* exclusion_count
);
203 ok(exclusion
!= NULL
, "Create UST exclusion");
205 skip(2, "zmalloc failed");
209 exclusion
->count
= exclusion_count
;
210 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 0),
211 get_random_string(), LTTNG_SYMBOL_NAME_LEN
);
212 strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion
, 1),
213 get_random_string(), LTTNG_SYMBOL_NAME_LEN
);
215 event
= trace_ust_create_event(&ev
, NULL
, NULL
, exclusion
, false);
216 ok(event
!= NULL
, "Create UST event with different exclusion names");
219 skip(1, "UST event with exclusion is null");
223 ok(event
->enabled
== 0 &&
224 event
->attr
.instrumentation
== LTTNG_UST_TRACEPOINT
&&
225 strcmp(event
->attr
.name
, ev
.name
) == 0 &&
226 event
->exclusion
!= NULL
&&
227 event
->exclusion
->count
== exclusion_count
&&
228 !memcmp(event
->exclusion
->names
, exclusion
->names
,
229 LTTNG_SYMBOL_NAME_LEN
* exclusion_count
) &&
230 event
->attr
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0',
231 "Validate UST event and exclusion");
233 trace_ust_destroy_event(event
);
239 static void test_create_ust_context(void)
241 struct lttng_event_context ectx
;
242 struct ltt_ust_context
*uctx
;
244 ectx
.ctx
= LTTNG_EVENT_CONTEXT_VTID
;
246 uctx
= trace_ust_create_context(&ectx
);
247 ok(uctx
!= NULL
, "Create UST context");
249 ok((int) uctx
->ctx
.ctx
== LTTNG_UST_CONTEXT_VTID
,
250 "Validate UST context");
254 int main(int argc
, char **argv
)
256 plan_tests(NUM_TESTS
);
258 diag("UST data structures unit test");
260 test_create_one_ust_session();
261 test_create_ust_channel();
262 test_create_ust_event();
263 test_create_ust_context();
264 test_create_ust_event_exclusion();
266 return exit_status();
This page took 0.038068 seconds and 5 git commands to generate.