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 static const char alphanum
[] =
54 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
55 "abcdefghijklmnopqrstuvwxyz";
56 static char random_string
[RANDOM_STRING_LEN
];
58 static struct ltt_ust_session
*usess
;
59 static struct lttng_domain dom
;
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 dom
.type
= LTTNG_DOMAIN_UST
;
82 usess
= trace_ust_create_session(42);
83 ok(usess
!= NULL
, "Create UST session");
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
;
100 memset(&attr
, 0, sizeof(attr
));
102 strncpy(attr
.name
, "channel0", 8);
104 uchan
= trace_ust_create_channel(&attr
, LTTNG_DOMAIN_UST
);
105 ok(uchan
!= NULL
, "Create UST channel");
107 ok(uchan
->enabled
== 0 &&
108 strncmp(uchan
->name
, "channel0", 8) == 0 &&
109 uchan
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0' &&
110 uchan
->ctx
!= NULL
&&
111 uchan
->events
!= NULL
&&
112 uchan
->attr
.overwrite
== attr
.attr
.overwrite
,
113 "Validate UST channel");
115 trace_ust_destroy_channel(uchan
);
118 static void test_create_ust_event(void)
120 struct ltt_ust_event
*event
;
121 struct lttng_event ev
;
123 memset(&ev
, 0, sizeof(ev
));
124 strncpy(ev
.name
, get_random_string(), LTTNG_SYMBOL_NAME_LEN
);
125 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
126 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
128 event
= trace_ust_create_event(&ev
, NULL
, NULL
, NULL
, false);
130 ok(event
!= NULL
, "Create UST event");
132 ok(event
->enabled
== 0 &&
133 event
->attr
.instrumentation
== LTTNG_UST_TRACEPOINT
&&
134 strcmp(event
->attr
.name
, ev
.name
) == 0 &&
135 event
->attr
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0',
136 "Validate UST event");
138 trace_ust_destroy_event(event
);
141 static void test_create_ust_event_exclusion(void)
143 struct ltt_ust_event
*event
;
144 struct lttng_event ev
;
146 struct lttng_event_exclusion
*exclusion
;
148 memset(&ev
, 0, sizeof(ev
));
150 /* make a wildcarded event name */
151 name
= get_random_string();
152 name
[strlen(name
) - 1] = '*';
153 strncpy(ev
.name
, name
, LTTNG_SYMBOL_NAME_LEN
);
155 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
156 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
158 /* set up an exclusion set */
159 exclusion
= zmalloc(sizeof(*exclusion
) + LTTNG_SYMBOL_NAME_LEN
);
164 ok(exclusion
!= NULL
, "Create UST exclusion");
166 exclusion
->count
= 1;
167 strncpy((char *)(exclusion
->names
), get_random_string(), LTTNG_SYMBOL_NAME_LEN
);
169 event
= trace_ust_create_event(&ev
, NULL
, NULL
, exclusion
, false);
171 ok(event
!= NULL
, "Create UST event with exclusion");
173 ok(event
->enabled
== 0 &&
174 event
->attr
.instrumentation
== LTTNG_UST_TRACEPOINT
&&
175 strcmp(event
->attr
.name
, ev
.name
) == 0 &&
176 event
->exclusion
!= NULL
&&
177 event
->exclusion
->count
== 1 &&
178 strcmp((char *)(event
->exclusion
->names
), (char *)(exclusion
->names
)) == 0 &&
179 event
->attr
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0',
180 "Validate UST event and exclusion");
182 trace_ust_destroy_event(event
);
186 static void test_create_ust_context(void)
188 struct lttng_event_context ectx
;
189 struct ltt_ust_context
*uctx
;
191 ectx
.ctx
= LTTNG_EVENT_CONTEXT_VTID
;
193 uctx
= trace_ust_create_context(&ectx
);
194 ok(uctx
!= NULL
, "Create UST context");
196 ok((int) uctx
->ctx
.ctx
== LTTNG_UST_CONTEXT_VTID
,
197 "Validate UST context");
201 int main(int argc
, char **argv
)
203 plan_tests(NUM_TESTS
);
205 diag("UST data structures unit test");
207 test_create_one_ust_session();
208 test_create_ust_channel();
209 test_create_ust_event();
210 test_create_ust_context();
211 test_create_ust_event_exclusion();
213 return exit_status();
This page took 0.042721 seconds and 4 git commands to generate.