Commit | Line | Data |
---|---|---|
d3e8f6bb DG |
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 | ||
10a8a223 DG |
28 | #include <lttng/lttng.h> |
29 | #include <bin/lttng-sessiond/lttng-ust-abi.h> | |
990570ed | 30 | #include <common/defaults.h> |
10a8a223 | 31 | #include <bin/lttng-sessiond/trace-ust.h> |
7972aab2 | 32 | #include <bin/lttng-sessiond/ust-app.h> |
10a8a223 | 33 | |
657270a4 CB |
34 | #include <tap/tap.h> |
35 | ||
d3e8f6bb DG |
36 | #include "utils.h" |
37 | ||
38 | /* This path will NEVER be created in this test */ | |
39 | #define PATH1 "/tmp/.test-junk-lttng" | |
40 | ||
98612240 MD |
41 | #define RANDOM_STRING_LEN 11 |
42 | ||
657270a4 CB |
43 | /* Number of TAP tests in this file */ |
44 | #define NUM_TESTS 10 | |
45 | ||
d3e8f6bb | 46 | /* For lttngerr.h */ |
97e19046 DG |
47 | int lttng_opt_quiet = 1; |
48 | int lttng_opt_verbose; | |
d3e8f6bb | 49 | |
7972aab2 DG |
50 | int ust_consumerd32_fd; |
51 | int ust_consumerd64_fd; | |
52 | ||
d3e8f6bb DG |
53 | static const char alphanum[] = |
54 | "0123456789" | |
55 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
56 | "abcdefghijklmnopqrstuvwxyz"; | |
98612240 | 57 | static char random_string[RANDOM_STRING_LEN]; |
d3e8f6bb DG |
58 | |
59 | static struct ltt_ust_session *usess; | |
60 | static struct lttng_domain dom; | |
61 | ||
62 | /* | |
63 | * Return random string of 10 characters. | |
98612240 | 64 | * Not thread-safe. |
d3e8f6bb DG |
65 | */ |
66 | static char *get_random_string(void) | |
67 | { | |
68 | int i; | |
d3e8f6bb | 69 | |
98612240 MD |
70 | for (i = 0; i < RANDOM_STRING_LEN - 1; i++) { |
71 | random_string[i] = alphanum[rand() % (sizeof(alphanum) - 1)]; | |
d3e8f6bb DG |
72 | } |
73 | ||
98612240 | 74 | random_string[RANDOM_STRING_LEN - 1] = '\0'; |
d3e8f6bb | 75 | |
98612240 | 76 | return random_string; |
d3e8f6bb DG |
77 | } |
78 | ||
657270a4 | 79 | static void test_create_one_ust_session(void) |
d3e8f6bb | 80 | { |
d3e8f6bb DG |
81 | dom.type = LTTNG_DOMAIN_UST; |
82 | ||
dec56f6c | 83 | usess = trace_ust_create_session(42); |
657270a4 CB |
84 | ok(usess != NULL, "Create UST session"); |
85 | ||
86 | ok(usess->id == 42 && | |
87 | usess->start_trace == 0 && | |
88 | usess->domain_global.channels != NULL && | |
657270a4 CB |
89 | usess->uid == 0 && |
90 | usess->gid == 0, | |
91 | "Validate UST session"); | |
d3e8f6bb DG |
92 | |
93 | trace_ust_destroy_session(usess); | |
94 | } | |
95 | ||
657270a4 | 96 | static void test_create_ust_metadata(void) |
d3e8f6bb DG |
97 | { |
98 | struct ltt_ust_metadata *metadata; | |
99 | ||
100 | assert(usess != NULL); | |
101 | ||
d3e8f6bb | 102 | metadata = trace_ust_create_metadata(PATH1); |
657270a4 CB |
103 | ok(metadata != NULL, "Create UST metadata"); |
104 | ||
105 | ok(metadata->handle == -1 && | |
106 | strlen(metadata->pathname) && | |
107 | metadata->attr.overwrite | |
108 | == DEFAULT_CHANNEL_OVERWRITE && | |
109 | metadata->attr.subbuf_size | |
110 | == default_get_metadata_subbuf_size() && | |
111 | metadata->attr.num_subbuf | |
112 | == DEFAULT_METADATA_SUBBUF_NUM && | |
113 | metadata->attr.switch_timer_interval | |
5d2e1e66 | 114 | == DEFAULT_UST_CHANNEL_SWITCH_TIMER && |
657270a4 | 115 | metadata->attr.read_timer_interval |
5d2e1e66 | 116 | == DEFAULT_UST_CHANNEL_READ_TIMER && |
657270a4 CB |
117 | metadata->attr.output == LTTNG_UST_MMAP, |
118 | "Validate UST session metadata"); | |
d3e8f6bb DG |
119 | |
120 | trace_ust_destroy_metadata(metadata); | |
121 | } | |
122 | ||
657270a4 | 123 | static void test_create_ust_channel(void) |
d3e8f6bb DG |
124 | { |
125 | struct ltt_ust_channel *uchan; | |
126 | struct lttng_channel attr; | |
127 | ||
441c16a7 MD |
128 | memset(&attr, 0, sizeof(attr)); |
129 | ||
d3e8f6bb DG |
130 | strncpy(attr.name, "channel0", 8); |
131 | ||
dec56f6c | 132 | uchan = trace_ust_create_channel(&attr); |
657270a4 CB |
133 | ok(uchan != NULL, "Create UST channel"); |
134 | ||
135 | ok(uchan->enabled == 0 && | |
657270a4 CB |
136 | strncmp(uchan->name, "channel0", 8) == 0 && |
137 | uchan->name[LTTNG_UST_SYM_NAME_LEN - 1] == '\0' && | |
138 | uchan->ctx != NULL && | |
139 | uchan->events != NULL && | |
140 | uchan->attr.overwrite == attr.attr.overwrite, | |
141 | "Validate UST channel"); | |
d3e8f6bb DG |
142 | |
143 | trace_ust_destroy_channel(uchan); | |
144 | } | |
145 | ||
657270a4 | 146 | static void test_create_ust_event(void) |
d3e8f6bb DG |
147 | { |
148 | struct ltt_ust_event *event; | |
149 | struct lttng_event ev; | |
150 | ||
441c16a7 | 151 | memset(&ev, 0, sizeof(ev)); |
d3e8f6bb DG |
152 | strncpy(ev.name, get_random_string(), LTTNG_SYMBOL_NAME_LEN); |
153 | ev.type = LTTNG_EVENT_TRACEPOINT; | |
441c16a7 | 154 | ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; |
d3e8f6bb | 155 | |
025faf73 | 156 | event = trace_ust_create_event(&ev, NULL); |
d3e8f6bb | 157 | |
657270a4 CB |
158 | ok(event != NULL, "Create UST event"); |
159 | ||
160 | ok(event->enabled == 0 && | |
161 | event->attr.instrumentation == LTTNG_UST_TRACEPOINT && | |
162 | strcmp(event->attr.name, ev.name) == 0 && | |
163 | event->attr.name[LTTNG_UST_SYM_NAME_LEN - 1] == '\0', | |
164 | "Validate UST event"); | |
d3e8f6bb DG |
165 | |
166 | trace_ust_destroy_event(event); | |
167 | } | |
168 | ||
657270a4 | 169 | static void test_create_ust_context(void) |
d3e8f6bb | 170 | { |
e38021f8 | 171 | struct lttng_event_context ectx; |
d3e8f6bb DG |
172 | struct ltt_ust_context *uctx; |
173 | ||
e38021f8 DG |
174 | ectx.ctx = LTTNG_EVENT_CONTEXT_VTID; |
175 | ||
e38021f8 | 176 | uctx = trace_ust_create_context(&ectx); |
657270a4 | 177 | ok(uctx != NULL, "Create UST context"); |
d3e8f6bb | 178 | |
657270a4 CB |
179 | ok((int) uctx->ctx.ctx == LTTNG_UST_CONTEXT_VTID, |
180 | "Validate UST context"); | |
d3e8f6bb DG |
181 | } |
182 | ||
183 | int main(int argc, char **argv) | |
184 | { | |
657270a4 | 185 | plan_tests(NUM_TESTS); |
d3e8f6bb | 186 | |
e3bef725 CB |
187 | diag("UST data structures unit test"); |
188 | ||
657270a4 CB |
189 | test_create_one_ust_session(); |
190 | test_create_ust_metadata(); | |
191 | test_create_ust_channel(); | |
192 | test_create_ust_event(); | |
193 | test_create_ust_context(); | |
d3e8f6bb | 194 | |
657270a4 | 195 | return exit_status(); |
d3e8f6bb | 196 | } |