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 DG |
31 | #include <bin/lttng-sessiond/trace-ust.h> |
32 | ||
d3e8f6bb DG |
33 | #include "utils.h" |
34 | ||
35 | /* This path will NEVER be created in this test */ | |
36 | #define PATH1 "/tmp/.test-junk-lttng" | |
37 | ||
38 | /* For lttngerr.h */ | |
39 | int opt_quiet = 1; | |
40 | int opt_verbose = 0; | |
41 | ||
42 | static const char alphanum[] = | |
43 | "0123456789" | |
44 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
45 | "abcdefghijklmnopqrstuvwxyz"; | |
46 | ||
47 | static struct ltt_ust_session *usess; | |
48 | static struct lttng_domain dom; | |
49 | ||
50 | /* | |
51 | * Return random string of 10 characters. | |
52 | */ | |
53 | static char *get_random_string(void) | |
54 | { | |
55 | int i; | |
56 | char *str = malloc(11); | |
57 | ||
58 | for (i = 0; i < 10; i++) { | |
59 | str[i] = alphanum[rand() % (sizeof(alphanum) - 1)]; | |
60 | } | |
61 | ||
62 | str[10] = '\0'; | |
63 | ||
64 | return str; | |
65 | } | |
66 | ||
67 | static void create_one_ust_session(void) | |
68 | { | |
69 | printf("Create UST session: "); | |
70 | ||
71 | dom.type = LTTNG_DOMAIN_UST; | |
72 | ||
73 | usess = trace_ust_create_session(PATH1, 42, &dom); | |
74 | assert(usess != NULL); | |
75 | PRINT_OK(); | |
76 | ||
77 | printf("Validating UST session: "); | |
78 | assert(usess->id == 42); | |
79 | assert(usess->start_trace == 0); | |
80 | assert(usess->domain_global.channels != NULL); | |
81 | assert(usess->domain_pid != NULL); | |
82 | assert(usess->domain_exec != NULL); | |
83 | assert(usess->uid == 0); | |
84 | assert(usess->gid == 0); | |
85 | PRINT_OK(); | |
86 | ||
87 | trace_ust_destroy_session(usess); | |
88 | } | |
89 | ||
90 | static void create_ust_metadata(void) | |
91 | { | |
92 | struct ltt_ust_metadata *metadata; | |
93 | ||
94 | assert(usess != NULL); | |
95 | ||
96 | printf("Create UST metadata: "); | |
97 | metadata = trace_ust_create_metadata(PATH1); | |
98 | assert(metadata != NULL); | |
99 | PRINT_OK(); | |
100 | ||
101 | printf("Validating UST session metadata: "); | |
102 | assert(metadata->handle == -1); | |
103 | assert(strlen(metadata->pathname)); | |
104 | assert(metadata->attr.overwrite | |
105 | == DEFAULT_CHANNEL_OVERWRITE); | |
106 | assert(metadata->attr.subbuf_size | |
107 | == DEFAULT_METADATA_SUBBUF_SIZE); | |
108 | assert(metadata->attr.num_subbuf | |
109 | == DEFAULT_METADATA_SUBBUF_NUM); | |
110 | assert(metadata->attr.switch_timer_interval | |
111 | == DEFAULT_CHANNEL_SWITCH_TIMER); | |
112 | assert(metadata->attr.read_timer_interval | |
113 | == DEFAULT_CHANNEL_READ_TIMER); | |
114 | assert(metadata->attr.output == LTTNG_UST_MMAP); | |
115 | PRINT_OK(); | |
116 | ||
117 | trace_ust_destroy_metadata(metadata); | |
118 | } | |
119 | ||
120 | static void create_ust_channel(void) | |
121 | { | |
122 | struct ltt_ust_channel *uchan; | |
123 | struct lttng_channel attr; | |
124 | ||
125 | strncpy(attr.name, "channel0", 8); | |
126 | ||
127 | printf("Creating UST channel: "); | |
128 | uchan = trace_ust_create_channel(&attr, PATH1); | |
129 | assert(uchan != NULL); | |
130 | PRINT_OK(); | |
131 | ||
132 | printf("Validating UST channel: "); | |
133 | assert(uchan->enabled == 0); | |
134 | assert(strcmp(PATH1, uchan->pathname) == 0); | |
135 | assert(strncmp(uchan->name, "channel0", 8) == 0); | |
136 | assert(uchan->name[LTTNG_UST_SYM_NAME_LEN - 1] == '\0'); | |
137 | assert(uchan->ctx != NULL); | |
138 | assert(uchan->events != NULL); | |
139 | assert(uchan->attr.overwrite == attr.attr.overwrite); | |
140 | PRINT_OK(); | |
141 | ||
142 | trace_ust_destroy_channel(uchan); | |
143 | } | |
144 | ||
145 | static void create_ust_event(void) | |
146 | { | |
147 | struct ltt_ust_event *event; | |
148 | struct lttng_event ev; | |
149 | ||
150 | strncpy(ev.name, get_random_string(), LTTNG_SYMBOL_NAME_LEN); | |
151 | ev.type = LTTNG_EVENT_TRACEPOINT; | |
152 | ||
153 | printf("Creating UST event: "); | |
154 | event = trace_ust_create_event(&ev); | |
155 | assert(event != NULL); | |
156 | PRINT_OK(); | |
157 | ||
158 | printf("Validating UST event: "); | |
159 | assert(event->enabled == 0); | |
160 | assert(event->ctx != NULL); | |
161 | assert(event->attr.instrumentation == LTTNG_UST_TRACEPOINT); | |
162 | assert(strcmp(event->attr.name, ev.name) == 0); | |
163 | assert(event->attr.name[LTTNG_UST_SYM_NAME_LEN - 1] == '\0'); | |
164 | PRINT_OK(); | |
165 | ||
166 | trace_ust_destroy_event(event); | |
167 | } | |
168 | ||
169 | static void create_ust_context(void) | |
170 | { | |
171 | struct lttng_event_context ctx; | |
172 | struct ltt_ust_context *uctx; | |
173 | ||
174 | printf("Creating UST context: "); | |
175 | uctx = trace_ust_create_context(&ctx); | |
176 | assert(uctx != NULL); | |
177 | PRINT_OK(); | |
178 | ||
179 | printf("Validating UST context: "); | |
10a8a223 | 180 | assert((int) ctx.ctx == (int)uctx->ctx.ctx); |
d3e8f6bb DG |
181 | PRINT_OK(); |
182 | } | |
183 | ||
184 | int main(int argc, char **argv) | |
185 | { | |
186 | printf("\nTesting UST data structures:\n-----------\n"); | |
187 | ||
188 | create_one_ust_session(); | |
189 | create_ust_metadata(); | |
190 | create_ust_channel(); | |
191 | create_ust_event(); | |
192 | create_ust_context(); | |
193 | ||
194 | /* Success */ | |
195 | return 0; | |
196 | } |