Clean-up: sessiond: cmd_enable_channel_internal
[lttng-tools.git] / tests / unit / test_uri.cpp
CommitLineData
de9a8b41 1/*
9d16b343 2 * Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
de9a8b41 3 *
9d16b343 4 * SPDX-License-Identifier: GPL-2.0-only
de9a8b41 5 *
de9a8b41
DG
6 */
7
de9a8b41 8#include <string.h>
de9a8b41 9
c291fb24 10#include <tap/tap.h>
de9a8b41 11
c291fb24 12#include <common/uri.h>
de9a8b41 13
ad7c9c18 14/* For error.h */
de9a8b41 15int lttng_opt_quiet = 1;
a4b92340 16int lttng_opt_verbose = 3;
c7e35b03 17int lttng_opt_mi;
de9a8b41 18
c291fb24
CB
19/* Number of TAP tests in this file */
20#define NUM_TESTS 11
21
8fa8ae59 22static void test_uri_parsing(void)
de9a8b41
DG
23{
24 ssize_t size;
25 const char *s_uri1;
c291fb24 26 struct lttng_uri *uri = NULL;
de9a8b41
DG
27
28 s_uri1 = "net://localhost";
c291fb24 29
de9a8b41 30 size = uri_parse(s_uri1, &uri);
c291fb24
CB
31
32 ok(size == 2 &&
33 uri[0].dtype == LTTNG_DST_IPV4 &&
34 uri[0].utype == LTTNG_URI_DST &&
35 uri[0].stype == 0 &&
36 uri[0].port == 0 &&
37 strlen(uri[0].subdir) == 0 &&
38 strcmp(uri[0].dst.ipv4, "127.0.0.1") == 0 &&
39 uri[1].dtype == LTTNG_DST_IPV4 &&
40 uri[1].utype == LTTNG_URI_DST &&
41 uri[1].stype == 0 &&
42 uri[1].port == 0 &&
43 strlen(uri[1].subdir) == 0 &&
44 strcmp(uri[1].dst.ipv4, "127.0.0.1") == 0,
45 "URI set to net://localhost");
46
47 if (uri) {
48 uri_free(uri);
49 uri = NULL;
50 }
de9a8b41
DG
51
52 s_uri1 = "net://localhost:8989:4242/my/test/path";
c291fb24 53
de9a8b41 54 size = uri_parse(s_uri1, &uri);
c291fb24
CB
55
56 ok(size == 2 &&
57 uri[0].dtype == LTTNG_DST_IPV4 &&
58 uri[0].utype == LTTNG_URI_DST &&
59 uri[0].stype == 0 &&
60 uri[0].port == 8989 &&
61 strcmp(uri[0].subdir, "my/test/path") == 0 &&
62 strcmp(uri[0].dst.ipv4, "127.0.0.1") == 0 &&
63 uri[1].dtype == LTTNG_DST_IPV4 &&
64 uri[1].utype == LTTNG_URI_DST &&
65 uri[1].stype == 0 &&
66 uri[1].port == 4242 &&
ee059b98 67 strlen(uri[1].subdir) == 0 &&
c291fb24
CB
68 strcmp(uri[1].dst.ipv4, "127.0.0.1") == 0,
69 "URI set to net://localhost:8989:4242/my/test/path");
70
71 if (uri) {
72 uri_free(uri);
73 uri = NULL;
74 }
de9a8b41
DG
75
76 s_uri1 = "net://localhost:8989:4242";
c291fb24 77
de9a8b41 78 size = uri_parse(s_uri1, &uri);
c291fb24
CB
79
80 ok(size == 2 &&
81 uri[0].dtype == LTTNG_DST_IPV4 &&
82 uri[0].utype == LTTNG_URI_DST &&
83 uri[0].stype == 0 &&
84 uri[0].port == 8989 &&
ee059b98 85 strlen(uri[0].subdir) == 0 &&
c291fb24
CB
86 strcmp(uri[0].dst.ipv4, "127.0.0.1") == 0 &&
87 uri[1].dtype == LTTNG_DST_IPV4 &&
88 uri[1].utype == LTTNG_URI_DST &&
89 uri[1].stype == 0 &&
90 uri[1].port == 4242 &&
91 strlen(uri[1].subdir) == 0 &&
92 strcmp(uri[1].dst.ipv4, "127.0.0.1") == 0,
93 "URI set to net://localhost:8989:4242");
94
95 if (uri) {
96 uri_free(uri);
97 uri = NULL;
98 }
de9a8b41 99
5d7ba9b6 100 s_uri1 = "net6://[::1]:8989";
c291fb24 101
de9a8b41 102 size = uri_parse(s_uri1, &uri);
c291fb24
CB
103
104 ok(size == 2 &&
105 uri[0].dtype == LTTNG_DST_IPV6 &&
106 uri[0].utype == LTTNG_URI_DST &&
107 uri[0].stype == 0 &&
108 uri[0].port == 8989 &&
ee059b98 109 strlen(uri[0].subdir) == 0 &&
c291fb24
CB
110 strcmp(uri[0].dst.ipv6, "::1") == 0 &&
111 uri[1].dtype == LTTNG_DST_IPV6 &&
112 uri[1].utype == LTTNG_URI_DST &&
113 uri[1].stype == 0 &&
114 uri[1].port == 0 &&
115 strlen(uri[1].subdir) == 0 &&
ee059b98 116 strcmp(uri[1].dst.ipv6, "::1") == 0,
5d7ba9b6 117 "URI set to net6://[::1]:8989");
c291fb24
CB
118
119 if (uri) {
120 uri_free(uri);
121 uri = NULL;
122 }
de9a8b41
DG
123
124 s_uri1 = "tcp://42.42.42.42/my/test/path";
c291fb24 125
de9a8b41 126 size = uri_parse(s_uri1, &uri);
c291fb24
CB
127
128 ok(size == 1 &&
129 uri[0].dtype == LTTNG_DST_IPV4 &&
130 uri[0].utype == LTTNG_URI_DST &&
131 uri[0].stype == 0 &&
132 uri[0].port == 0 &&
133 strcmp(uri[0].subdir, "my/test/path") == 0 &&
134 strcmp(uri[0].dst.ipv4, "42.42.42.42") == 0,
135 "URI set to tcp://42.42.42.42/my/test/path");
136
137 if (uri) {
138 uri_free(uri);
139 uri = NULL;
140 }
de9a8b41 141
a4b92340 142 s_uri1 = "tcp6://[fe80::f66d:4ff:fe53:d220]/my/test/path";
c291fb24 143
de9a8b41 144 size = uri_parse(s_uri1, &uri);
c291fb24
CB
145
146 ok(size == 1 &&
147 uri[0].dtype == LTTNG_DST_IPV6 &&
148 uri[0].utype == LTTNG_URI_DST &&
149 uri[0].stype == 0 &&
150 uri[0].port == 0 &&
151 strcmp(uri[0].subdir, "my/test/path") == 0 &&
152 strcmp(uri[0].dst.ipv6, "fe80::f66d:4ff:fe53:d220") == 0,
153 "URI set to tcp6://[fe80::f66d:4ff:fe53:d220]/my/test/path");
154
155 if (uri) {
156 uri_free(uri);
157 uri = NULL;
158 }
de9a8b41
DG
159
160 s_uri1 = "file:///my/test/path";
c291fb24 161
de9a8b41 162 size = uri_parse(s_uri1, &uri);
de9a8b41 163
c291fb24
CB
164 ok(size == 1 &&
165 uri[0].dtype == LTTNG_DST_PATH &&
166 uri[0].utype == LTTNG_URI_DST &&
167 uri[0].stype == 0 &&
168 uri[0].port == 0 &&
169 strlen(uri[0].subdir) == 0 &&
170 strcmp(uri[0].dst.path, "/my/test/path") == 0,
171 "URI set to file:///my/test/path");
172
173 if (uri) {
174 uri_free(uri);
175 uri = NULL;
176 }
177
178 /* FIXME: Noisy on stdout */
de9a8b41 179 s_uri1 = "file/my/test/path";
de9a8b41 180 size = uri_parse(s_uri1, &uri);
c291fb24 181 ok(size == -1, "Bad URI set to file/my/test/path");
a0377dfe 182 LTTNG_ASSERT(!uri);
de9a8b41
DG
183
184 s_uri1 = "net://:8999";
de9a8b41 185 size = uri_parse(s_uri1, &uri);
c291fb24 186 ok(size == -1, "Bad URI set to net://:8999");
a0377dfe 187 LTTNG_ASSERT(!uri);
3cb37009 188}
de9a8b41 189
a3ecaea8 190static void test_uri_cmp(void)
3cb37009
CB
191{
192 struct lttng_uri *uri1, *uri2;
193 const char *s_uri1 = "net://localhost";
194 const char *s_uri2 = "net://localhost:8989:4242";
195 ssize_t size1, size2;
196 int res;
197
198 size1 = uri_parse(s_uri1, &uri1);
199
200 /* Sanity checks */
a0377dfe
FD
201 LTTNG_ASSERT(size1 == 2);
202 LTTNG_ASSERT(uri1[0].dtype == LTTNG_DST_IPV4);
203 LTTNG_ASSERT(uri1[0].utype == LTTNG_URI_DST);
204 LTTNG_ASSERT(uri1[0].stype == 0);
205 LTTNG_ASSERT(uri1[0].port == 0);
206 LTTNG_ASSERT(strlen(uri1[0].subdir) == 0);
207 LTTNG_ASSERT(strcmp(uri1[0].dst.ipv4, "127.0.0.1") == 0);
208 LTTNG_ASSERT(uri1[1].dtype == LTTNG_DST_IPV4);
209 LTTNG_ASSERT(uri1[1].utype == LTTNG_URI_DST);
210 LTTNG_ASSERT(uri1[1].stype == 0);
211 LTTNG_ASSERT(uri1[1].port == 0);
212 LTTNG_ASSERT(strlen(uri1[1].subdir) == 0);
213 LTTNG_ASSERT(strcmp(uri1[1].dst.ipv4, "127.0.0.1") == 0);
3cb37009
CB
214
215 size2 = uri_parse(s_uri2, &uri2);
216
a0377dfe
FD
217 LTTNG_ASSERT(size2 == 2);
218 LTTNG_ASSERT(uri2[0].dtype == LTTNG_DST_IPV4);
219 LTTNG_ASSERT(uri2[0].utype == LTTNG_URI_DST);
220 LTTNG_ASSERT(uri2[0].stype == 0);
221 LTTNG_ASSERT(uri2[0].port == 8989);
222 LTTNG_ASSERT(strlen(uri2[0].subdir) == 0);
223 LTTNG_ASSERT(strcmp(uri2[0].dst.ipv4, "127.0.0.1") == 0);
224 LTTNG_ASSERT(uri2[1].dtype == LTTNG_DST_IPV4);
225 LTTNG_ASSERT(uri2[1].utype == LTTNG_URI_DST);
226 LTTNG_ASSERT(uri2[1].stype == 0);
227 LTTNG_ASSERT(uri2[1].port == 4242);
228 LTTNG_ASSERT(strlen(uri2[1].subdir) == 0);
229 LTTNG_ASSERT(strcmp(uri2[1].dst.ipv4, "127.0.0.1") == 0);
3cb37009 230
3cb37009 231 res = uri_compare(uri1, uri1);
c291fb24
CB
232
233 ok(res == 0,
234 "URI compare net://localhost == net://localhost");
3cb37009
CB
235
236 res = uri_compare(uri1, uri2);
c291fb24
CB
237
238 ok(res != 0,
239 "URI compare net://localhost != net://localhost:8989:4242");
3cb37009
CB
240
241 uri_free(uri1);
242 uri_free(uri2);
de9a8b41
DG
243}
244
f46376a1 245int main(void)
de9a8b41 246{
c291fb24 247 plan_tests(NUM_TESTS);
de9a8b41 248
e3bef725
CB
249 diag("URI unit tests");
250
3cb37009 251 test_uri_parsing();
c291fb24 252
3cb37009 253 test_uri_cmp();
de9a8b41 254
c291fb24 255 return exit_status();
de9a8b41 256}
This page took 0.05625 seconds and 4 git commands to generate.