Comments fix: lttngerr.h -> error.h (./Changelog:754)
[lttng-tools.git] / tests / unit / test_ust_data.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 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/* This path will NEVER be created in this test */
37#define PATH1 "/tmp/.test-junk-lttng"
38
98612240
MD
39#define RANDOM_STRING_LEN 11
40
657270a4 41/* Number of TAP tests in this file */
d28f6a94 42#define NUM_TESTS 10
657270a4 43
ad7c9c18 44/* For error.h */
97e19046
DG
45int lttng_opt_quiet = 1;
46int lttng_opt_verbose;
d3e8f6bb 47
7972aab2
DG
48int ust_consumerd32_fd;
49int ust_consumerd64_fd;
50
d3e8f6bb
DG
51static const char alphanum[] =
52 "0123456789"
53 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
54 "abcdefghijklmnopqrstuvwxyz";
98612240 55static char random_string[RANDOM_STRING_LEN];
d3e8f6bb
DG
56
57static struct ltt_ust_session *usess;
58static struct lttng_domain dom;
59
60/*
61 * Return random string of 10 characters.
98612240 62 * Not thread-safe.
d3e8f6bb
DG
63 */
64static char *get_random_string(void)
65{
66 int i;
d3e8f6bb 67
98612240
MD
68 for (i = 0; i < RANDOM_STRING_LEN - 1; i++) {
69 random_string[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
d3e8f6bb
DG
70 }
71
98612240 72 random_string[RANDOM_STRING_LEN - 1] = '\0';
d3e8f6bb 73
98612240 74 return random_string;
d3e8f6bb
DG
75}
76
657270a4 77static void test_create_one_ust_session(void)
d3e8f6bb 78{
d3e8f6bb
DG
79 dom.type = LTTNG_DOMAIN_UST;
80
dec56f6c 81 usess = trace_ust_create_session(42);
657270a4
CB
82 ok(usess != NULL, "Create UST session");
83
84 ok(usess->id == 42 &&
85 usess->start_trace == 0 &&
86 usess->domain_global.channels != NULL &&
657270a4
CB
87 usess->uid == 0 &&
88 usess->gid == 0,
89 "Validate UST session");
d3e8f6bb
DG
90
91 trace_ust_destroy_session(usess);
92}
93
657270a4 94static void test_create_ust_channel(void)
d3e8f6bb
DG
95{
96 struct ltt_ust_channel *uchan;
97 struct lttng_channel attr;
98
441c16a7
MD
99 memset(&attr, 0, sizeof(attr));
100
d3e8f6bb
DG
101 strncpy(attr.name, "channel0", 8);
102
dec56f6c 103 uchan = trace_ust_create_channel(&attr);
657270a4
CB
104 ok(uchan != NULL, "Create UST channel");
105
106 ok(uchan->enabled == 0 &&
657270a4
CB
107 strncmp(uchan->name, "channel0", 8) == 0 &&
108 uchan->name[LTTNG_UST_SYM_NAME_LEN - 1] == '\0' &&
109 uchan->ctx != NULL &&
110 uchan->events != NULL &&
111 uchan->attr.overwrite == attr.attr.overwrite,
112 "Validate UST channel");
d3e8f6bb
DG
113
114 trace_ust_destroy_channel(uchan);
115}
116
657270a4 117static void test_create_ust_event(void)
d3e8f6bb
DG
118{
119 struct ltt_ust_event *event;
120 struct lttng_event ev;
121
441c16a7 122 memset(&ev, 0, sizeof(ev));
d3e8f6bb
DG
123 strncpy(ev.name, get_random_string(), LTTNG_SYMBOL_NAME_LEN);
124 ev.type = LTTNG_EVENT_TRACEPOINT;
441c16a7 125 ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
d3e8f6bb 126
561c6897 127 event = trace_ust_create_event(&ev, NULL, NULL);
d3e8f6bb 128
657270a4
CB
129 ok(event != NULL, "Create UST event");
130
131 ok(event->enabled == 0 &&
132 event->attr.instrumentation == LTTNG_UST_TRACEPOINT &&
133 strcmp(event->attr.name, ev.name) == 0 &&
134 event->attr.name[LTTNG_UST_SYM_NAME_LEN - 1] == '\0',
135 "Validate UST event");
d3e8f6bb
DG
136
137 trace_ust_destroy_event(event);
138}
139
41d7b959
JI
140static void test_create_ust_event_exclusion(void)
141{
142 struct ltt_ust_event *event;
143 struct lttng_event ev;
144 char *name;
145 struct lttng_event_exclusion *exclusion;
146
147 memset(&ev, 0, sizeof(ev));
148
149 /* make a wildcarded event name */
150 name = get_random_string();
151 name[strlen(name) - 1] = '*';
152 strncpy(ev.name, name, LTTNG_SYMBOL_NAME_LEN);
153
154 ev.type = LTTNG_EVENT_TRACEPOINT;
155 ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
156
157 /* set up an exclusion set */
158 exclusion = zmalloc(sizeof(*exclusion) + LTTNG_SYMBOL_NAME_LEN);
159 exclusion->count = 1;
160 strncpy((char *)(exclusion->names), get_random_string(), LTTNG_SYMBOL_NAME_LEN);
161
162 event = trace_ust_create_event(&ev, NULL, exclusion);
163
164 ok(event != NULL, "Create UST event with exclusion");
165
166 ok(event->enabled == 0 &&
167 event->attr.instrumentation == LTTNG_UST_TRACEPOINT &&
168 strcmp(event->attr.name, ev.name) == 0 &&
169 event->exclusion != NULL &&
170 event->exclusion->count == 1 &&
171 strcmp((char *)(event->exclusion->names), (char *)(exclusion->names)) == 0 &&
172 event->attr.name[LTTNG_UST_SYM_NAME_LEN - 1] == '\0',
173 "Validate UST event and exclusion");
174
41d7b959
JI
175 trace_ust_destroy_event(event);
176}
177
178
657270a4 179static void test_create_ust_context(void)
d3e8f6bb 180{
e38021f8 181 struct lttng_event_context ectx;
d3e8f6bb
DG
182 struct ltt_ust_context *uctx;
183
e38021f8
DG
184 ectx.ctx = LTTNG_EVENT_CONTEXT_VTID;
185
e38021f8 186 uctx = trace_ust_create_context(&ectx);
657270a4 187 ok(uctx != NULL, "Create UST context");
d3e8f6bb 188
657270a4
CB
189 ok((int) uctx->ctx.ctx == LTTNG_UST_CONTEXT_VTID,
190 "Validate UST context");
f949b23e 191 free(uctx);
d3e8f6bb
DG
192}
193
194int main(int argc, char **argv)
195{
657270a4 196 plan_tests(NUM_TESTS);
d3e8f6bb 197
e3bef725
CB
198 diag("UST data structures unit test");
199
657270a4 200 test_create_one_ust_session();
657270a4
CB
201 test_create_ust_channel();
202 test_create_ust_event();
203 test_create_ust_context();
41d7b959 204 test_create_ust_event_exclusion();
d3e8f6bb 205
657270a4 206 return exit_status();
d3e8f6bb 207}
This page took 0.03801 seconds and 4 git commands to generate.