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