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
38 /* Number of TAP tests in this file */
42 int lttng_opt_quiet
= 1;
43 int lttng_opt_verbose
;
45 static const char alphanum
[] =
47 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
48 "abcdefghijklmnopqrstuvwxyz";
50 static struct ltt_kernel_session
*kern
;
51 static char random_string
[RANDOM_STRING_LEN
];
54 * Return random string of 10 characters.
57 static char *get_random_string(void)
61 for (i
= 0; i
< RANDOM_STRING_LEN
- 1; i
++) {
62 random_string
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
65 random_string
[RANDOM_STRING_LEN
- 1] = '\0';
70 static void test_create_one_kernel_session(void)
72 kern
= trace_kernel_create_session(PATH1
);
73 ok(kern
!= NULL
, "Create kernel session");
76 kern
->metadata_stream_fd
== -1 &&
77 kern
->consumer_fds_sent
== 0 &&
78 kern
->channel_count
== 0 &&
79 kern
->stream_count_global
== 0 &&
80 kern
->metadata
== NULL
,
81 "Validate kernel session");
83 /* Init list in order to avoid sefaults from cds_list_del */
84 trace_kernel_destroy_session(kern
);
87 static void test_create_kernel_metadata(void)
91 kern
->metadata
= trace_kernel_create_metadata();
92 ok(kern
->metadata
!= NULL
, "Create kernel metadata");
94 ok(kern
->metadata
->fd
== -1 &&
95 kern
->metadata
->conf
!= NULL
&&
96 kern
->metadata
->conf
->attr
.overwrite
97 == DEFAULT_CHANNEL_OVERWRITE
&&
98 kern
->metadata
->conf
->attr
.subbuf_size
99 == default_get_metadata_subbuf_size() &&
100 kern
->metadata
->conf
->attr
.num_subbuf
101 == DEFAULT_METADATA_SUBBUF_NUM
&&
102 kern
->metadata
->conf
->attr
.switch_timer_interval
103 == DEFAULT_CHANNEL_SWITCH_TIMER
&&
104 kern
->metadata
->conf
->attr
.read_timer_interval
105 == DEFAULT_CHANNEL_READ_TIMER
&&
106 kern
->metadata
->conf
->attr
.output
107 == DEFAULT_KERNEL_CHANNEL_OUTPUT
,
108 "Validate kernel session metadata");
110 trace_kernel_destroy_metadata(kern
->metadata
);
113 static void test_create_kernel_channel(void)
115 struct ltt_kernel_channel
*chan
;
116 struct lttng_channel attr
;
118 memset(&attr
, 0, sizeof(attr
));
120 chan
= trace_kernel_create_channel(&attr
);
121 ok(chan
!= NULL
, "Create kernel channel");
124 chan
->enabled
== 1 &&
125 chan
->stream_count
== 0 &&
127 chan
->channel
->attr
.overwrite
== attr
.attr
.overwrite
,
128 "Validate kernel channel");
130 /* Init list in order to avoid sefaults from cds_list_del */
131 CDS_INIT_LIST_HEAD(&chan
->list
);
132 trace_kernel_destroy_channel(chan
);
135 static void test_create_kernel_event(void)
137 struct ltt_kernel_event
*event
;
138 struct lttng_event ev
;
140 memset(&ev
, 0, sizeof(ev
));
141 strncpy(ev
.name
, get_random_string(), LTTNG_KERNEL_SYM_NAME_LEN
);
142 ev
.type
= LTTNG_EVENT_TRACEPOINT
;
143 ev
.loglevel_type
= LTTNG_EVENT_LOGLEVEL_ALL
;
145 event
= trace_kernel_create_event(&ev
);
146 ok(event
!= NULL
, "Create kernel event");
148 ok(event
->fd
== -1 &&
149 event
->enabled
== 1 &&
150 event
->event
->instrumentation
== LTTNG_KERNEL_TRACEPOINT
&&
151 strlen(event
->event
->name
),
152 "Validate kernel event");
154 /* Init list in order to avoid sefaults from cds_list_del */
155 CDS_INIT_LIST_HEAD(&event
->list
);
156 trace_kernel_destroy_event(event
);
159 static void test_create_kernel_stream(void)
161 struct ltt_kernel_stream
*stream
;
163 stream
= trace_kernel_create_stream("stream1", 0);
164 ok(stream
!= NULL
, "Create kernel stream");
166 ok(stream
->fd
== -1 &&
168 "Validate kernel stream");
170 /* Init list in order to avoid sefaults from cds_list_del */
171 CDS_INIT_LIST_HEAD(&stream
->list
);
172 trace_kernel_destroy_stream(stream
);
175 int main(int argc
, char **argv
)
177 diag("Kernel data structure unit test");
179 plan_tests(NUM_TESTS
);
181 test_create_one_kernel_session();
182 test_create_kernel_metadata();
183 test_create_kernel_channel();
184 test_create_kernel_event();
185 test_create_kernel_stream();