Tests: Convert the UST data structures unit test output to TAP
[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
DG
31#include <bin/lttng-sessiond/trace-ust.h>
32
657270a4
CB
33#include <tap/tap.h>
34
d3e8f6bb
DG
35#include "utils.h"
36
37/* This path will NEVER be created in this test */
38#define PATH1 "/tmp/.test-junk-lttng"
39
98612240
MD
40#define RANDOM_STRING_LEN 11
41
657270a4
CB
42/* Number of TAP tests in this file */
43#define NUM_TESTS 10
44
d3e8f6bb 45/* For lttngerr.h */
97e19046
DG
46int lttng_opt_quiet = 1;
47int lttng_opt_verbose;
d3e8f6bb
DG
48
49static const char alphanum[] =
50 "0123456789"
51 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
52 "abcdefghijklmnopqrstuvwxyz";
98612240 53static char random_string[RANDOM_STRING_LEN];
d3e8f6bb
DG
54
55static struct ltt_ust_session *usess;
56static struct lttng_domain dom;
57
58/*
59 * Return random string of 10 characters.
98612240 60 * Not thread-safe.
d3e8f6bb
DG
61 */
62static char *get_random_string(void)
63{
64 int i;
d3e8f6bb 65
98612240
MD
66 for (i = 0; i < RANDOM_STRING_LEN - 1; i++) {
67 random_string[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
d3e8f6bb
DG
68 }
69
98612240 70 random_string[RANDOM_STRING_LEN - 1] = '\0';
d3e8f6bb 71
98612240 72 return random_string;
d3e8f6bb
DG
73}
74
657270a4 75static void test_create_one_ust_session(void)
d3e8f6bb 76{
d3e8f6bb
DG
77 dom.type = LTTNG_DOMAIN_UST;
78
fdd9eb17 79 usess = trace_ust_create_session(PATH1, 42);
657270a4
CB
80 ok(usess != NULL, "Create UST session");
81
82 ok(usess->id == 42 &&
83 usess->start_trace == 0 &&
84 usess->domain_global.channels != NULL &&
85 usess->domain_pid != NULL &&
86 usess->domain_exec != NULL &&
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_metadata(void)
d3e8f6bb
DG
95{
96 struct ltt_ust_metadata *metadata;
97
98 assert(usess != NULL);
99
d3e8f6bb 100 metadata = trace_ust_create_metadata(PATH1);
657270a4
CB
101 ok(metadata != NULL, "Create UST metadata");
102
103 ok(metadata->handle == -1 &&
104 strlen(metadata->pathname) &&
105 metadata->attr.overwrite
106 == DEFAULT_CHANNEL_OVERWRITE &&
107 metadata->attr.subbuf_size
108 == default_get_metadata_subbuf_size() &&
109 metadata->attr.num_subbuf
110 == DEFAULT_METADATA_SUBBUF_NUM &&
111 metadata->attr.switch_timer_interval
112 == DEFAULT_CHANNEL_SWITCH_TIMER &&
113 metadata->attr.read_timer_interval
114 == DEFAULT_CHANNEL_READ_TIMER &&
115 metadata->attr.output == LTTNG_UST_MMAP,
116 "Validate UST session metadata");
d3e8f6bb
DG
117
118 trace_ust_destroy_metadata(metadata);
119}
120
657270a4 121static void test_create_ust_channel(void)
d3e8f6bb
DG
122{
123 struct ltt_ust_channel *uchan;
124 struct lttng_channel attr;
125
441c16a7
MD
126 memset(&attr, 0, sizeof(attr));
127
d3e8f6bb
DG
128 strncpy(attr.name, "channel0", 8);
129
d3e8f6bb 130 uchan = trace_ust_create_channel(&attr, PATH1);
657270a4
CB
131 ok(uchan != NULL, "Create UST channel");
132
133 ok(uchan->enabled == 0 &&
134 strcmp(PATH1, uchan->pathname) == 0 &&
135 strncmp(uchan->name, "channel0", 8) == 0 &&
136 uchan->name[LTTNG_UST_SYM_NAME_LEN - 1] == '\0' &&
137 uchan->ctx != NULL &&
138 uchan->events != NULL &&
139 uchan->attr.overwrite == attr.attr.overwrite,
140 "Validate UST channel");
d3e8f6bb
DG
141
142 trace_ust_destroy_channel(uchan);
143}
144
657270a4 145static void test_create_ust_event(void)
d3e8f6bb
DG
146{
147 struct ltt_ust_event *event;
148 struct lttng_event ev;
149
441c16a7 150 memset(&ev, 0, sizeof(ev));
d3e8f6bb
DG
151 strncpy(ev.name, get_random_string(), LTTNG_SYMBOL_NAME_LEN);
152 ev.type = LTTNG_EVENT_TRACEPOINT;
441c16a7 153 ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
d3e8f6bb 154
025faf73 155 event = trace_ust_create_event(&ev, NULL);
d3e8f6bb 156
657270a4
CB
157 ok(event != NULL, "Create UST event");
158
159 ok(event->enabled == 0 &&
160 event->attr.instrumentation == LTTNG_UST_TRACEPOINT &&
161 strcmp(event->attr.name, ev.name) == 0 &&
162 event->attr.name[LTTNG_UST_SYM_NAME_LEN - 1] == '\0',
163 "Validate UST event");
d3e8f6bb
DG
164
165 trace_ust_destroy_event(event);
166}
167
657270a4 168static void test_create_ust_context(void)
d3e8f6bb 169{
e38021f8 170 struct lttng_event_context ectx;
d3e8f6bb
DG
171 struct ltt_ust_context *uctx;
172
e38021f8
DG
173 ectx.ctx = LTTNG_EVENT_CONTEXT_VTID;
174
e38021f8 175 uctx = trace_ust_create_context(&ectx);
657270a4 176 ok(uctx != NULL, "Create UST context");
d3e8f6bb 177
657270a4
CB
178 ok((int) uctx->ctx.ctx == LTTNG_UST_CONTEXT_VTID,
179 "Validate UST context");
d3e8f6bb
DG
180}
181
182int main(int argc, char **argv)
183{
657270a4
CB
184 diag("UST data structures unit test");
185
186 plan_tests(NUM_TESTS);
d3e8f6bb 187
657270a4
CB
188 test_create_one_ust_session();
189 test_create_ust_metadata();
190 test_create_ust_channel();
191 test_create_ust_event();
192 test_create_ust_context();
d3e8f6bb 193
657270a4 194 return exit_status();
d3e8f6bb 195}
This page took 0.052573 seconds and 4 git commands to generate.