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>
35 /* This path will NEVER be created in this test */
36 #define PATH1 "/tmp/.test-junk-lttng"
42 static const char alphanum
[] =
44 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
45 "abcdefghijklmnopqrstuvwxyz";
47 static struct ltt_ust_session
*usess
;
48 static struct lttng_domain dom
;
51 * Return random string of 10 characters.
53 static char *get_random_string(void)
56 char *str
= malloc(11);
58 for (i
= 0; i
< 10; i
++) {
59 str
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
67 static void create_one_ust_session(void)
69 printf("Create UST session: ");
71 dom
.type
= LTTNG_DOMAIN_UST
;
73 usess
= trace_ust_create_session(PATH1
, 42, &dom
);
74 assert(usess
!= NULL
);
77 printf("Validating UST session: ");
78 assert(usess
->id
== 42);
79 assert(usess
->start_trace
== 0);
80 assert(usess
->domain_global
.channels
!= NULL
);
81 assert(usess
->domain_pid
!= NULL
);
82 assert(usess
->domain_exec
!= NULL
);
83 assert(usess
->uid
== 0);
84 assert(usess
->gid
== 0);
87 trace_ust_destroy_session(usess
);
90 static void create_ust_metadata(void)
92 struct ltt_ust_metadata
*metadata
;
94 assert(usess
!= NULL
);
96 printf("Create UST metadata: ");
97 metadata
= trace_ust_create_metadata(PATH1
);
98 assert(metadata
!= NULL
);
101 printf("Validating UST session metadata: ");
102 assert(metadata
->handle
== -1);
103 assert(strlen(metadata
->pathname
));
104 assert(metadata
->attr
.overwrite
105 == DEFAULT_CHANNEL_OVERWRITE
);
106 assert(metadata
->attr
.subbuf_size
107 == DEFAULT_METADATA_SUBBUF_SIZE
);
108 assert(metadata
->attr
.num_subbuf
109 == DEFAULT_METADATA_SUBBUF_NUM
);
110 assert(metadata
->attr
.switch_timer_interval
111 == DEFAULT_CHANNEL_SWITCH_TIMER
);
112 assert(metadata
->attr
.read_timer_interval
113 == DEFAULT_CHANNEL_READ_TIMER
);
114 assert(metadata
->attr
.output
== LTTNG_UST_MMAP
);
117 trace_ust_destroy_metadata(metadata
);
120 static void create_ust_channel(void)
122 struct ltt_ust_channel
*uchan
;
123 struct lttng_channel attr
;
125 strncpy(attr
.name
, "channel0", 8);
127 printf("Creating UST channel: ");
128 uchan
= trace_ust_create_channel(&attr
, PATH1
);
129 assert(uchan
!= NULL
);
132 printf("Validating UST channel: ");
133 assert(uchan
->enabled
== 0);
134 assert(strcmp(PATH1
, uchan
->pathname
) == 0);
135 assert(strncmp(uchan
->name
, "channel0", 8) == 0);
136 assert(uchan
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0');
137 assert(uchan
->ctx
!= NULL
);
138 assert(uchan
->events
!= NULL
);
139 assert(uchan
->attr
.overwrite
== attr
.attr
.overwrite
);
142 trace_ust_destroy_channel(uchan
);
145 static void create_ust_event(void)
147 struct ltt_ust_event
*event
;
148 struct lttng_event ev
;
150 strncpy(ev
.name
, get_random_string(), LTTNG_SYMBOL_NAME_LEN
);
151 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
153 printf("Creating UST event: ");
154 event
= trace_ust_create_event(&ev
);
155 assert(event
!= NULL
);
158 printf("Validating UST event: ");
159 assert(event
->enabled
== 0);
160 assert(event
->ctx
!= NULL
);
161 assert(event
->attr
.instrumentation
== LTTNG_UST_TRACEPOINT
);
162 assert(strcmp(event
->attr
.name
, ev
.name
) == 0);
163 assert(event
->attr
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0');
166 trace_ust_destroy_event(event
);
169 static void create_ust_context(void)
171 struct lttng_event_context ectx
;
172 struct ltt_ust_context
*uctx
;
174 ectx
.ctx
= LTTNG_EVENT_CONTEXT_VTID
;
176 printf("Creating UST context: ");
177 uctx
= trace_ust_create_context(&ectx
);
178 assert(uctx
!= NULL
);
181 printf("Validating UST context: ");
182 assert((int) uctx
->ctx
.ctx
== LTTNG_UST_CONTEXT_VTID
);
186 int main(int argc
, char **argv
)
188 printf("\nTesting UST data structures:\n-----------\n");
190 create_one_ust_session();
191 create_ust_metadata();
192 create_ust_channel();
194 create_ust_context();