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 "lttng-sessiond/lttng-ust-abi.h"
30 #include "lttng-share.h"
31 #include "lttng-sessiond/trace-ust.h"
34 /* This path will NEVER be created in this test */
35 #define PATH1 "/tmp/.test-junk-lttng"
41 static const char alphanum
[] =
43 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
44 "abcdefghijklmnopqrstuvwxyz";
46 static struct ltt_ust_session
*usess
;
47 static struct lttng_domain dom
;
50 * Return random string of 10 characters.
52 static char *get_random_string(void)
55 char *str
= malloc(11);
57 for (i
= 0; i
< 10; i
++) {
58 str
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
66 static void create_one_ust_session(void)
68 printf("Create UST session: ");
70 dom
.type
= LTTNG_DOMAIN_UST
;
72 usess
= trace_ust_create_session(PATH1
, 42, &dom
);
73 assert(usess
!= NULL
);
76 printf("Validating UST session: ");
77 assert(usess
->id
== 42);
78 assert(usess
->start_trace
== 0);
79 assert(usess
->domain_global
.channels
!= NULL
);
80 assert(usess
->domain_pid
!= NULL
);
81 assert(usess
->domain_exec
!= NULL
);
82 assert(usess
->uid
== 0);
83 assert(usess
->gid
== 0);
86 trace_ust_destroy_session(usess
);
89 static void create_ust_metadata(void)
91 struct ltt_ust_metadata
*metadata
;
93 assert(usess
!= NULL
);
95 printf("Create UST metadata: ");
96 metadata
= trace_ust_create_metadata(PATH1
);
97 assert(metadata
!= NULL
);
100 printf("Validating UST session metadata: ");
101 assert(metadata
->handle
== -1);
102 assert(strlen(metadata
->pathname
));
103 assert(metadata
->attr
.overwrite
104 == DEFAULT_CHANNEL_OVERWRITE
);
105 assert(metadata
->attr
.subbuf_size
106 == DEFAULT_METADATA_SUBBUF_SIZE
);
107 assert(metadata
->attr
.num_subbuf
108 == DEFAULT_METADATA_SUBBUF_NUM
);
109 assert(metadata
->attr
.switch_timer_interval
110 == DEFAULT_CHANNEL_SWITCH_TIMER
);
111 assert(metadata
->attr
.read_timer_interval
112 == DEFAULT_CHANNEL_READ_TIMER
);
113 assert(metadata
->attr
.output
== LTTNG_UST_MMAP
);
116 trace_ust_destroy_metadata(metadata
);
119 static void create_ust_channel(void)
121 struct ltt_ust_channel
*uchan
;
122 struct lttng_channel attr
;
124 strncpy(attr
.name
, "channel0", 8);
126 printf("Creating UST channel: ");
127 uchan
= trace_ust_create_channel(&attr
, PATH1
);
128 assert(uchan
!= NULL
);
131 printf("Validating UST channel: ");
132 assert(uchan
->enabled
== 0);
133 assert(strcmp(PATH1
, uchan
->pathname
) == 0);
134 assert(strncmp(uchan
->name
, "channel0", 8) == 0);
135 assert(uchan
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0');
136 assert(uchan
->ctx
!= NULL
);
137 assert(uchan
->events
!= NULL
);
138 assert(uchan
->attr
.overwrite
== attr
.attr
.overwrite
);
141 trace_ust_destroy_channel(uchan
);
144 static void create_ust_event(void)
146 struct ltt_ust_event
*event
;
147 struct lttng_event ev
;
149 strncpy(ev
.name
, get_random_string(), LTTNG_SYMBOL_NAME_LEN
);
150 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
152 printf("Creating UST event: ");
153 event
= trace_ust_create_event(&ev
);
154 assert(event
!= NULL
);
157 printf("Validating UST event: ");
158 assert(event
->enabled
== 0);
159 assert(event
->ctx
!= NULL
);
160 assert(event
->attr
.instrumentation
== LTTNG_UST_TRACEPOINT
);
161 assert(strcmp(event
->attr
.name
, ev
.name
) == 0);
162 assert(event
->attr
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0');
165 trace_ust_destroy_event(event
);
168 static void create_ust_context(void)
170 struct lttng_event_context ctx
;
171 struct ltt_ust_context
*uctx
;
173 printf("Creating UST context: ");
174 uctx
= trace_ust_create_context(&ctx
);
175 assert(uctx
!= NULL
);
178 printf("Validating UST context: ");
179 assert(ctx
.ctx
== uctx
->ctx
.ctx
);
183 int main(int argc
, char **argv
)
185 printf("\nTesting UST data structures:\n-----------\n");
187 create_one_ust_session();
188 create_ust_metadata();
189 create_ust_channel();
191 create_ust_context();