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