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"
38 #define RANDOM_STRING_LEN 11
41 int lttng_opt_quiet
= 1;
42 int lttng_opt_verbose
;
44 static const char alphanum
[] =
46 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
47 "abcdefghijklmnopqrstuvwxyz";
48 static char random_string
[RANDOM_STRING_LEN
];
50 static struct ltt_ust_session
*usess
;
51 static struct lttng_domain dom
;
54 * Return random string of 10 characters.
57 static char *get_random_string(void)
61 for (i
= 0; i
< RANDOM_STRING_LEN
- 1; i
++) {
62 random_string
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
65 random_string
[RANDOM_STRING_LEN
- 1] = '\0';
70 static void create_one_ust_session(void)
72 printf("Create UST session: ");
74 dom
.type
= LTTNG_DOMAIN_UST
;
76 usess
= trace_ust_create_session(PATH1
, 42);
77 assert(usess
!= NULL
);
80 printf("Validating UST session: ");
81 assert(usess
->id
== 42);
82 assert(usess
->start_trace
== 0);
83 assert(usess
->domain_global
.channels
!= NULL
);
84 assert(usess
->domain_pid
!= NULL
);
85 assert(usess
->domain_exec
!= NULL
);
86 assert(usess
->uid
== 0);
87 assert(usess
->gid
== 0);
90 trace_ust_destroy_session(usess
);
93 static void create_ust_metadata(void)
95 struct ltt_ust_metadata
*metadata
;
97 assert(usess
!= NULL
);
99 printf("Create UST metadata: ");
100 metadata
= trace_ust_create_metadata(PATH1
);
101 assert(metadata
!= NULL
);
104 printf("Validating UST session metadata: ");
105 assert(metadata
->handle
== -1);
106 assert(strlen(metadata
->pathname
));
107 assert(metadata
->attr
.overwrite
108 == DEFAULT_CHANNEL_OVERWRITE
);
109 assert(metadata
->attr
.subbuf_size
110 == default_get_metadata_subbuf_size());
111 assert(metadata
->attr
.num_subbuf
112 == DEFAULT_METADATA_SUBBUF_NUM
);
113 assert(metadata
->attr
.switch_timer_interval
114 == DEFAULT_CHANNEL_SWITCH_TIMER
);
115 assert(metadata
->attr
.read_timer_interval
116 == DEFAULT_CHANNEL_READ_TIMER
);
117 assert(metadata
->attr
.output
== LTTNG_UST_MMAP
);
120 trace_ust_destroy_metadata(metadata
);
123 static void create_ust_channel(void)
125 struct ltt_ust_channel
*uchan
;
126 struct lttng_channel attr
;
128 memset(&attr
, 0, sizeof(attr
));
130 strncpy(attr
.name
, "channel0", 8);
132 printf("Creating UST channel: ");
133 uchan
= trace_ust_create_channel(&attr
, PATH1
);
134 assert(uchan
!= NULL
);
137 printf("Validating UST channel: ");
138 assert(uchan
->enabled
== 0);
139 assert(strcmp(PATH1
, uchan
->pathname
) == 0);
140 assert(strncmp(uchan
->name
, "channel0", 8) == 0);
141 assert(uchan
->name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0');
142 assert(uchan
->ctx
!= NULL
);
143 assert(uchan
->events
!= NULL
);
144 assert(uchan
->attr
.overwrite
== attr
.attr
.overwrite
);
147 trace_ust_destroy_channel(uchan
);
150 static void create_ust_event(void)
152 struct ltt_ust_event
*event
;
153 struct lttng_event ev
;
155 memset(&ev
, 0, sizeof(ev
));
156 strncpy(ev
.name
, get_random_string(), LTTNG_SYMBOL_NAME_LEN
);
157 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
158 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
160 printf("Creating UST event: ");
161 event
= trace_ust_create_event(&ev
, NULL
);
162 assert(event
!= NULL
);
165 printf("Validating UST event: ");
166 assert(event
->enabled
== 0);
167 assert(event
->attr
.instrumentation
== LTTNG_UST_TRACEPOINT
);
168 assert(strcmp(event
->attr
.name
, ev
.name
) == 0);
169 assert(event
->attr
.name
[LTTNG_UST_SYM_NAME_LEN
- 1] == '\0');
172 trace_ust_destroy_event(event
);
175 static void create_ust_context(void)
177 struct lttng_event_context ectx
;
178 struct ltt_ust_context
*uctx
;
180 ectx
.ctx
= LTTNG_EVENT_CONTEXT_VTID
;
182 printf("Creating UST context: ");
183 uctx
= trace_ust_create_context(&ectx
);
184 assert(uctx
!= NULL
);
187 printf("Validating UST context: ");
188 assert((int) uctx
->ctx
.ctx
== LTTNG_UST_CONTEXT_VTID
);
192 int main(int argc
, char **argv
)
194 printf("\nTesting UST data structures:\n-----------\n");
196 create_one_ust_session();
197 create_ust_metadata();
198 create_ust_channel();
200 create_ust_context();