Add important DEBUG statement
[lttng-tools.git] / tests / test_kernel_data_trace.c
1 /*
2 * Copyright (c) 2011 David Goulet <david.goulet@polymtl.ca>
3 *
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
7 * of the License.
8 *
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.
13 *
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.
17 */
18
19 #define _GNU_SOURCE
20 #include <assert.h>
21 #include <errno.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <time.h>
27
28 #include "lttng-sessiond/trace-kernel.h"
29 #include "utils.h"
30
31 /* This path will NEVER be created in this test */
32 #define PATH1 "/tmp/.test-junk-lttng"
33
34 /* For lttngerr.h */
35 int opt_quiet = 1;
36 int opt_verbose = 0;
37
38 static const char alphanum[] =
39 "0123456789"
40 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
41 "abcdefghijklmnopqrstuvwxyz";
42
43 static struct ltt_kernel_session *kern;
44
45 /*
46 * Return random string of 10 characters.
47 */
48 static char *get_random_string(void)
49 {
50 int i;
51 char *str = malloc(11);
52
53 for (i = 0; i < 10; i++) {
54 str[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
55 }
56
57 str[10] = '\0';
58
59 return str;
60 }
61
62 static void create_one_kernel_session(void)
63 {
64 printf("Create kernel session: ");
65 kern = trace_kernel_create_session(PATH1);
66 assert(kern != NULL);
67 PRINT_OK();
68
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);
77 PRINT_OK();
78
79 /* Init list in order to avoid sefaults from cds_list_del */
80 trace_kernel_destroy_session(kern);
81 }
82
83 static void create_kernel_metadata(void)
84 {
85 assert(kern != NULL);
86
87 printf("Create kernel metadata: ");
88 kern->metadata = trace_kernel_create_metadata(PATH1);
89 assert(kern->metadata != NULL);
90 PRINT_OK();
91
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);
108 PRINT_OK();
109
110 trace_kernel_destroy_metadata(kern->metadata);
111 }
112
113 static void create_kernel_channel(void)
114 {
115 struct ltt_kernel_channel *chan;
116 struct lttng_channel attr;
117
118 printf("Creating kernel channel: ");
119 chan = trace_kernel_create_channel(&attr, PATH1);
120 assert(chan != NULL);
121 PRINT_OK();
122
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);
130 PRINT_OK();
131
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);
135 }
136
137 static void create_kernel_event(void)
138 {
139 struct ltt_kernel_event *event;
140 struct lttng_event ev;
141
142 strncpy(ev.name, get_random_string(), LTTNG_SYM_NAME_LEN);
143 ev.type = LTTNG_EVENT_TRACEPOINT;
144
145 printf("Creating kernel event: ");
146 event = trace_kernel_create_event(&ev);
147 assert(event != NULL);
148 PRINT_OK();
149
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));
156 PRINT_OK();
157
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);
161 }
162
163 static void create_kernel_stream(void)
164 {
165 struct ltt_kernel_stream *stream;
166
167 printf("Creating kernel stream: ");
168 stream = trace_kernel_create_stream();
169 assert(stream != NULL);
170 PRINT_OK();
171
172 printf("Validating kernel stream: ");
173 assert(stream->fd == 0);
174 assert(stream->pathname == NULL);
175 assert(stream->state == 0);
176 PRINT_OK();
177
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);
181 }
182
183 int main(int argc, char **argv)
184 {
185 printf("\nTesting kernel data structures:\n-----------\n");
186
187 create_one_kernel_session();
188
189 create_kernel_metadata();
190 create_kernel_channel();
191
192
193 create_kernel_event();
194
195 create_kernel_stream();
196
197 /* Success */
198 return 0;
199 }
This page took 0.032395 seconds and 4 git commands to generate.