Initialize all stack variables to zero, fix uninitialized loglevel variables
[lttng-tools.git] / tests / test_ust_data_trace.c
CommitLineData
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 */
39int opt_quiet = 1;
40int opt_verbose = 0;
41
42static const char alphanum[] =
43 "0123456789"
44 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
45 "abcdefghijklmnopqrstuvwxyz";
46
47static struct ltt_ust_session *usess;
48static struct lttng_domain dom;
49
50/*
51 * Return random string of 10 characters.
52 */
53static 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
67static 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
90static 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
120static void create_ust_channel(void)
121{
122 struct ltt_ust_channel *uchan;
123 struct lttng_channel attr;
124
441c16a7
MD
125 memset(&attr, 0, sizeof(attr));
126
d3e8f6bb
DG
127 strncpy(attr.name, "channel0", 8);
128
129 printf("Creating UST channel: ");
130 uchan = trace_ust_create_channel(&attr, PATH1);
131 assert(uchan != NULL);
132 PRINT_OK();
133
134 printf("Validating UST channel: ");
135 assert(uchan->enabled == 0);
136 assert(strcmp(PATH1, uchan->pathname) == 0);
137 assert(strncmp(uchan->name, "channel0", 8) == 0);
138 assert(uchan->name[LTTNG_UST_SYM_NAME_LEN - 1] == '\0');
139 assert(uchan->ctx != NULL);
140 assert(uchan->events != NULL);
141 assert(uchan->attr.overwrite == attr.attr.overwrite);
142 PRINT_OK();
143
144 trace_ust_destroy_channel(uchan);
145}
146
147static void create_ust_event(void)
148{
149 struct ltt_ust_event *event;
150 struct lttng_event ev;
151
441c16a7 152 memset(&ev, 0, sizeof(ev));
d3e8f6bb
DG
153 strncpy(ev.name, get_random_string(), LTTNG_SYMBOL_NAME_LEN);
154 ev.type = LTTNG_EVENT_TRACEPOINT;
441c16a7 155 ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
d3e8f6bb
DG
156
157 printf("Creating UST event: ");
158 event = trace_ust_create_event(&ev);
159 assert(event != NULL);
160 PRINT_OK();
161
162 printf("Validating UST event: ");
163 assert(event->enabled == 0);
164 assert(event->ctx != NULL);
165 assert(event->attr.instrumentation == LTTNG_UST_TRACEPOINT);
166 assert(strcmp(event->attr.name, ev.name) == 0);
167 assert(event->attr.name[LTTNG_UST_SYM_NAME_LEN - 1] == '\0');
168 PRINT_OK();
169
170 trace_ust_destroy_event(event);
171}
172
173static void create_ust_context(void)
174{
e38021f8 175 struct lttng_event_context ectx;
d3e8f6bb
DG
176 struct ltt_ust_context *uctx;
177
e38021f8
DG
178 ectx.ctx = LTTNG_EVENT_CONTEXT_VTID;
179
d3e8f6bb 180 printf("Creating UST context: ");
e38021f8 181 uctx = trace_ust_create_context(&ectx);
d3e8f6bb
DG
182 assert(uctx != NULL);
183 PRINT_OK();
184
185 printf("Validating UST context: ");
e38021f8 186 assert((int) uctx->ctx.ctx == LTTNG_UST_CONTEXT_VTID);
d3e8f6bb
DG
187 PRINT_OK();
188}
189
190int main(int argc, char **argv)
191{
192 printf("\nTesting UST data structures:\n-----------\n");
193
194 create_one_ust_session();
195 create_ust_metadata();
196 create_ust_channel();
197 create_ust_event();
198 create_ust_context();
199
200 /* Success */
201 return 0;
202}
This page took 0.044976 seconds and 4 git commands to generate.