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 <bin/lttng-sessiond/trace-kernel.h>
29 #include <common/lttng-share.h>
33 /* This path will NEVER be created in this test */
34 #define PATH1 "/tmp/.test-junk-lttng"
40 static const char alphanum
[] =
42 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
43 "abcdefghijklmnopqrstuvwxyz";
45 static struct ltt_kernel_session
*kern
;
48 * Return random string of 10 characters.
50 static char *get_random_string(void)
53 char *str
= malloc(11);
55 for (i
= 0; i
< 10; i
++) {
56 str
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
64 static void create_one_kernel_session(void)
66 printf("Create kernel session: ");
67 kern
= trace_kernel_create_session(PATH1
);
71 printf("Validating kernel session: ");
72 assert(kern
->fd
== 0);
73 assert(kern
->metadata_stream_fd
== 0);
74 assert(kern
->consumer_fds_sent
== 0);
75 assert(kern
->channel_count
== 0);
76 assert(kern
->stream_count_global
== 0);
77 assert(kern
->metadata
== NULL
);
78 assert(kern
->consumer_fd
== 0);
81 /* Init list in order to avoid sefaults from cds_list_del */
82 trace_kernel_destroy_session(kern
);
85 static void create_kernel_metadata(void)
89 printf("Create kernel metadata: ");
90 kern
->metadata
= trace_kernel_create_metadata(PATH1
);
91 assert(kern
->metadata
!= NULL
);
94 printf("Validating kernel session metadata: ");
95 assert(kern
->metadata
->fd
== 0);
96 assert(strlen(kern
->metadata
->pathname
));
97 assert(kern
->metadata
->conf
!= NULL
);
98 assert(kern
->metadata
->conf
->attr
.overwrite
99 == DEFAULT_CHANNEL_OVERWRITE
);
100 assert(kern
->metadata
->conf
->attr
.subbuf_size
101 == DEFAULT_METADATA_SUBBUF_SIZE
);
102 assert(kern
->metadata
->conf
->attr
.num_subbuf
103 == DEFAULT_METADATA_SUBBUF_NUM
);
104 assert(kern
->metadata
->conf
->attr
.switch_timer_interval
105 == DEFAULT_CHANNEL_SWITCH_TIMER
);
106 assert(kern
->metadata
->conf
->attr
.read_timer_interval
107 == DEFAULT_CHANNEL_READ_TIMER
);
108 assert(kern
->metadata
->conf
->attr
.output
109 == DEFAULT_KERNEL_CHANNEL_OUTPUT
);
112 trace_kernel_destroy_metadata(kern
->metadata
);
115 static void create_kernel_channel(void)
117 struct ltt_kernel_channel
*chan
;
118 struct lttng_channel attr
;
120 printf("Creating kernel channel: ");
121 chan
= trace_kernel_create_channel(&attr
, PATH1
);
122 assert(chan
!= NULL
);
125 printf("Validating kernel channel: ");
126 assert(chan
->fd
== 0);
127 assert(chan
->enabled
== 1);
128 assert(strcmp(PATH1
, chan
->pathname
) == 0);
129 assert(chan
->stream_count
== 0);
130 assert(chan
->ctx
== NULL
);
131 assert(chan
->channel
->attr
.overwrite
== attr
.attr
.overwrite
);
134 /* Init list in order to avoid sefaults from cds_list_del */
135 CDS_INIT_LIST_HEAD(&chan
->list
);
136 trace_kernel_destroy_channel(chan
);
139 static void create_kernel_event(void)
141 struct ltt_kernel_event
*event
;
142 struct lttng_event ev
;
144 strncpy(ev
.name
, get_random_string(), LTTNG_SYM_NAME_LEN
);
145 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
147 printf("Creating kernel event: ");
148 event
= trace_kernel_create_event(&ev
);
149 assert(event
!= NULL
);
152 printf("Validating kernel event: ");
153 assert(event
->fd
== 0);
154 assert(event
->enabled
== 1);
155 assert(event
->ctx
== NULL
);
156 assert(event
->event
->instrumentation
== LTTNG_KERNEL_TRACEPOINT
);
157 assert(strlen(event
->event
->name
));
160 /* Init list in order to avoid sefaults from cds_list_del */
161 CDS_INIT_LIST_HEAD(&event
->list
);
162 trace_kernel_destroy_event(event
);
165 static void create_kernel_stream(void)
167 struct ltt_kernel_stream
*stream
;
169 printf("Creating kernel stream: ");
170 stream
= trace_kernel_create_stream();
171 assert(stream
!= NULL
);
174 printf("Validating kernel stream: ");
175 assert(stream
->fd
== 0);
176 assert(stream
->pathname
== NULL
);
177 assert(stream
->state
== 0);
180 /* Init list in order to avoid sefaults from cds_list_del */
181 CDS_INIT_LIST_HEAD(&stream
->list
);
182 trace_kernel_destroy_stream(stream
);
185 int main(int argc
, char **argv
)
187 printf("\nTesting kernel data structures:\n-----------\n");
189 create_one_kernel_session();
191 create_kernel_metadata();
192 create_kernel_channel();
195 create_kernel_event();
197 create_kernel_stream();