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