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/defaults.h>
33 /* This path will NEVER be created in this test */
34 #define PATH1 "/tmp/.test-junk-lttng"
36 #define RANDOM_STRING_LEN 11
39 int lttng_opt_quiet
= 1;
40 int lttng_opt_verbose
;
42 static const char alphanum
[] =
44 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
45 "abcdefghijklmnopqrstuvwxyz";
47 static struct ltt_kernel_session
*kern
;
48 static char random_string
[RANDOM_STRING_LEN
];
51 * Return random string of 10 characters.
54 static char *get_random_string(void)
58 for (i
= 0; i
< RANDOM_STRING_LEN
- 1; i
++) {
59 random_string
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
62 random_string
[RANDOM_STRING_LEN
- 1] = '\0';
67 static void create_one_kernel_session(void)
69 printf("Create kernel session: ");
70 kern
= trace_kernel_create_session(PATH1
);
74 printf("Validating kernel session: ");
75 assert(kern
->fd
== -1);
76 assert(kern
->metadata_stream_fd
== -1);
77 assert(kern
->consumer_fds_sent
== 0);
78 assert(kern
->channel_count
== 0);
79 assert(kern
->stream_count_global
== 0);
80 assert(kern
->metadata
== NULL
);
83 /* Init list in order to avoid sefaults from cds_list_del */
84 trace_kernel_destroy_session(kern
);
87 static void create_kernel_metadata(void)
91 printf("Create kernel metadata: ");
92 kern
->metadata
= trace_kernel_create_metadata();
93 assert(kern
->metadata
!= NULL
);
96 printf("Validating kernel session metadata: ");
97 assert(kern
->metadata
->fd
== -1);
98 assert(kern
->metadata
->conf
!= NULL
);
99 assert(kern
->metadata
->conf
->attr
.overwrite
100 == DEFAULT_CHANNEL_OVERWRITE
);
101 assert(kern
->metadata
->conf
->attr
.subbuf_size
102 == default_get_metadata_subbuf_size());
103 assert(kern
->metadata
->conf
->attr
.num_subbuf
104 == DEFAULT_METADATA_SUBBUF_NUM
);
105 assert(kern
->metadata
->conf
->attr
.switch_timer_interval
106 == DEFAULT_CHANNEL_SWITCH_TIMER
);
107 assert(kern
->metadata
->conf
->attr
.read_timer_interval
108 == DEFAULT_CHANNEL_READ_TIMER
);
109 assert(kern
->metadata
->conf
->attr
.output
110 == DEFAULT_KERNEL_CHANNEL_OUTPUT
);
113 trace_kernel_destroy_metadata(kern
->metadata
);
116 static void create_kernel_channel(void)
118 struct ltt_kernel_channel
*chan
;
119 struct lttng_channel attr
;
121 memset(&attr
, 0, sizeof(attr
));
123 printf("Creating kernel channel: ");
124 chan
= trace_kernel_create_channel(&attr
);
125 assert(chan
!= NULL
);
128 printf("Validating kernel channel: ");
129 assert(chan
->fd
== -1);
130 assert(chan
->enabled
== 1);
131 assert(chan
->stream_count
== 0);
132 assert(chan
->ctx
== NULL
);
133 assert(chan
->channel
->attr
.overwrite
== attr
.attr
.overwrite
);
136 /* Init list in order to avoid sefaults from cds_list_del */
137 CDS_INIT_LIST_HEAD(&chan
->list
);
138 trace_kernel_destroy_channel(chan
);
141 static void create_kernel_event(void)
143 struct ltt_kernel_event
*event
;
144 struct lttng_event ev
;
146 memset(&ev
, 0, sizeof(ev
));
147 strncpy(ev
.name
, get_random_string(), LTTNG_KERNEL_SYM_NAME_LEN
);
148 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
149 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
151 printf("Creating kernel event: ");
152 event
= trace_kernel_create_event(&ev
);
153 assert(event
!= NULL
);
156 printf("Validating kernel event: ");
157 assert(event
->fd
== -1);
158 assert(event
->enabled
== 1);
159 assert(event
->event
->instrumentation
== LTTNG_KERNEL_TRACEPOINT
);
160 assert(strlen(event
->event
->name
));
163 /* Init list in order to avoid sefaults from cds_list_del */
164 CDS_INIT_LIST_HEAD(&event
->list
);
165 trace_kernel_destroy_event(event
);
168 static void create_kernel_stream(void)
170 struct ltt_kernel_stream
*stream
;
172 printf("Creating kernel stream: ");
173 stream
= trace_kernel_create_stream("stream1", 0);
174 assert(stream
!= NULL
);
177 printf("Validating kernel stream: ");
178 assert(stream
->fd
== -1);
179 assert(stream
->state
== 0);
182 /* Init list in order to avoid sefaults from cds_list_del */
183 CDS_INIT_LIST_HEAD(&stream
->list
);
184 trace_kernel_destroy_stream(stream
);
187 int main(int argc
, char **argv
)
189 printf("\nTesting kernel data structures:\n-----------\n");
191 create_one_kernel_session();
193 create_kernel_metadata();
194 create_kernel_channel();
197 create_kernel_event();
199 create_kernel_stream();