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-sessiond/trace-kernel.h"
31 /* This path will NEVER be created in this test */
32 #define PATH1 "/tmp/.test-junk-lttng"
38 static const char alphanum
[] =
40 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
41 "abcdefghijklmnopqrstuvwxyz";
43 static struct ltt_kernel_session
*kern
;
46 * Return random string of 10 characters.
48 static char *get_random_string(void)
51 char *str
= malloc(11);
53 for (i
= 0; i
< 10; i
++) {
54 str
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
62 static void create_one_kernel_session(void)
64 printf("Create kernel session: ");
65 kern
= trace_kernel_create_session(PATH1
);
69 printf("Validating kernel session: ");
70 assert(kern
->fd
== 0);
71 assert(kern
->metadata_stream_fd
== 0);
72 assert(kern
->consumer_fds_sent
== 0);
73 assert(kern
->channel_count
== 0);
74 assert(kern
->stream_count_global
== 0);
75 assert(kern
->metadata
== NULL
);
76 assert(kern
->consumer_fd
== 0);
79 /* Init list in order to avoid sefaults from cds_list_del */
80 trace_kernel_destroy_session(kern
);
83 static void create_kernel_metadata(void)
87 printf("Create kernel metadata: ");
88 kern
->metadata
= trace_kernel_create_metadata(PATH1
);
89 assert(kern
->metadata
!= NULL
);
92 printf("Validating kernel session metadata: ");
93 assert(kern
->metadata
->fd
== 0);
94 assert(strlen(kern
->metadata
->pathname
));
95 assert(kern
->metadata
->conf
!= NULL
);
96 assert(kern
->metadata
->conf
->attr
.overwrite
97 == DEFAULT_CHANNEL_OVERWRITE
);
98 assert(kern
->metadata
->conf
->attr
.subbuf_size
99 == DEFAULT_METADATA_SUBBUF_SIZE
);
100 assert(kern
->metadata
->conf
->attr
.num_subbuf
101 == DEFAULT_METADATA_SUBBUF_NUM
);
102 assert(kern
->metadata
->conf
->attr
.switch_timer_interval
103 == DEFAULT_CHANNEL_SWITCH_TIMER
);
104 assert(kern
->metadata
->conf
->attr
.read_timer_interval
105 == DEFAULT_CHANNEL_READ_TIMER
);
106 assert(kern
->metadata
->conf
->attr
.output
107 == DEFAULT_KERNEL_CHANNEL_OUTPUT
);
110 trace_kernel_destroy_metadata(kern
->metadata
);
113 static void create_kernel_channel(void)
115 struct ltt_kernel_channel
*chan
;
116 struct lttng_channel attr
;
118 printf("Creating kernel channel: ");
119 chan
= trace_kernel_create_channel(&attr
, PATH1
);
120 assert(chan
!= NULL
);
123 printf("Validating kernel channel: ");
124 assert(chan
->fd
== 0);
125 assert(chan
->enabled
== 1);
126 assert(strcmp(PATH1
, chan
->pathname
) == 0);
127 assert(chan
->stream_count
== 0);
128 assert(chan
->ctx
== NULL
);
129 assert(chan
->channel
->attr
.overwrite
== attr
.attr
.overwrite
);
132 /* Init list in order to avoid sefaults from cds_list_del */
133 CDS_INIT_LIST_HEAD(&chan
->list
);
134 trace_kernel_destroy_channel(chan
);
137 static void create_kernel_event(void)
139 struct ltt_kernel_event
*event
;
140 struct lttng_event ev
;
142 strncpy(ev
.name
, get_random_string(), LTTNG_SYM_NAME_LEN
);
143 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
145 printf("Creating kernel event: ");
146 event
= trace_kernel_create_event(&ev
);
147 assert(event
!= NULL
);
150 printf("Validating kernel event: ");
151 assert(event
->fd
== 0);
152 assert(event
->enabled
== 1);
153 assert(event
->ctx
== NULL
);
154 assert(event
->event
->instrumentation
== LTTNG_KERNEL_TRACEPOINT
);
155 assert(strlen(event
->event
->name
));
158 /* Init list in order to avoid sefaults from cds_list_del */
159 CDS_INIT_LIST_HEAD(&event
->list
);
160 trace_kernel_destroy_event(event
);
163 static void create_kernel_stream(void)
165 struct ltt_kernel_stream
*stream
;
167 printf("Creating kernel stream: ");
168 stream
= trace_kernel_create_stream();
169 assert(stream
!= NULL
);
172 printf("Validating kernel stream: ");
173 assert(stream
->fd
== 0);
174 assert(stream
->pathname
== NULL
);
175 assert(stream
->state
== 0);
178 /* Init list in order to avoid sefaults from cds_list_del */
179 CDS_INIT_LIST_HEAD(&stream
->list
);
180 trace_kernel_destroy_stream(stream
);
183 int main(int argc
, char **argv
)
185 printf("\nTesting kernel data structures:\n-----------\n");
187 create_one_kernel_session();
189 create_kernel_metadata();
190 create_kernel_channel();
193 create_kernel_event();
195 create_kernel_stream();