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 "ltt-sessiond/trace.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_create_kernel_session();
69 printf("Validating kernel session: ");
70 assert(kern
->fd
== 0);
71 assert(kern
->metadata_stream_fd
== 0);
72 assert(kern
->kconsumer_fds_sent
== 0);
73 assert(kern
->channel_count
== 0);
74 assert(kern
->stream_count_global
== 0);
75 assert(kern
->metadata
== NULL
);
78 /* Init list in order to avoid sefaults from cds_list_del */
79 trace_destroy_kernel_session(kern
);
82 static void create_kernel_metadata(void)
86 printf("Create kernel metadata: ");
87 kern
->metadata
= trace_create_kernel_metadata(PATH1
);
88 assert(kern
->metadata
!= NULL
);
91 printf("Validating kernel session metadata: ");
92 assert(kern
->metadata
->fd
== 0);
93 assert(strlen(kern
->metadata
->pathname
));
94 assert(kern
->metadata
->conf
!= NULL
);
95 assert(kern
->metadata
->conf
->attr
.overwrite
96 == DEFAULT_CHANNEL_OVERWRITE
);
97 assert(kern
->metadata
->conf
->attr
.subbuf_size
98 == DEFAULT_CHANNEL_SUBBUF_SIZE
);
99 assert(kern
->metadata
->conf
->attr
.num_subbuf
100 == DEFAULT_CHANNEL_SUBBUF_NUM
);
101 assert(kern
->metadata
->conf
->attr
.switch_timer_interval
102 == DEFAULT_CHANNEL_SWITCH_TIMER
);
103 assert(kern
->metadata
->conf
->attr
.read_timer_interval
104 == DEFAULT_CHANNEL_READ_TIMER
);
105 assert(kern
->metadata
->conf
->attr
.output
106 == DEFAULT_KERNEL_CHANNEL_OUTPUT
);
109 trace_destroy_kernel_metadata(kern
->metadata
);
112 static void create_kernel_channel(void)
114 struct ltt_kernel_channel
*chan
;
115 struct lttng_channel attr
;
117 printf("Creating kernel channel: ");
118 chan
= trace_create_kernel_channel(&attr
, PATH1
);
119 assert(chan
!= NULL
);
122 printf("Validating kernel channel: ");
123 assert(chan
->fd
== 0);
124 assert(chan
->enabled
== 1);
125 assert(strcmp(PATH1
, chan
->pathname
) == 0);
126 assert(chan
->stream_count
== 0);
127 assert(chan
->ctx
== NULL
);
128 assert(chan
->channel
->attr
.overwrite
== attr
.attr
.overwrite
);
131 /* Init list in order to avoid sefaults from cds_list_del */
132 CDS_INIT_LIST_HEAD(&chan
->list
);
133 trace_destroy_kernel_channel(chan
);
136 static void create_kernel_event(void)
138 struct ltt_kernel_event
*event
;
139 struct lttng_event ev
;
141 strncpy(ev
.name
, get_random_string(), LTTNG_SYM_NAME_LEN
);
142 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
144 printf("Creating kernel event: ");
145 event
= trace_create_kernel_event(&ev
);
146 assert(event
!= NULL
);
149 printf("Validating kernel event: ");
150 assert(event
->fd
== 0);
151 assert(event
->enabled
== 1);
152 assert(event
->ctx
== NULL
);
153 assert(event
->event
->instrumentation
== LTTNG_KERNEL_TRACEPOINT
);
154 assert(strlen(event
->event
->name
));
157 /* Init list in order to avoid sefaults from cds_list_del */
158 CDS_INIT_LIST_HEAD(&event
->list
);
159 trace_destroy_kernel_event(event
);
162 static void create_kernel_stream(void)
164 struct ltt_kernel_stream
*stream
;
166 printf("Creating kernel stream: ");
167 stream
= trace_create_kernel_stream();
168 assert(stream
!= NULL
);
171 printf("Validating kernel stream: ");
172 assert(stream
->fd
== 0);
173 assert(stream
->pathname
== NULL
);
174 assert(stream
->state
== 0);
177 /* Init list in order to avoid sefaults from cds_list_del */
178 CDS_INIT_LIST_HEAD(&stream
->list
);
179 trace_destroy_kernel_stream(stream
);
182 int main(int argc
, char **argv
)
184 printf("\nTesting kernel data structures:\n-----------\n");
186 create_one_kernel_session();
188 create_kernel_metadata();
189 create_kernel_channel();
192 create_kernel_event();
194 create_kernel_stream();