2 * Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
12 #include <common/uri.h>
15 int lttng_opt_quiet
= 1;
16 int lttng_opt_verbose
= 3;
19 /* Number of TAP tests in this file */
22 static void test_uri_parsing(void)
26 struct lttng_uri
*uri
= NULL
;
28 s_uri1
= "net://localhost";
30 size
= uri_parse(s_uri1
, &uri
);
33 uri
[0].dtype
== LTTNG_DST_IPV4
&&
34 uri
[0].utype
== LTTNG_URI_DST
&&
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
&&
43 strlen(uri
[1].subdir
) == 0 &&
44 strcmp(uri
[1].dst
.ipv4
, "127.0.0.1") == 0,
45 "URI set to net://localhost");
52 s_uri1
= "net://localhost:8989:4242/my/test/path";
54 size
= uri_parse(s_uri1
, &uri
);
57 uri
[0].dtype
== LTTNG_DST_IPV4
&&
58 uri
[0].utype
== LTTNG_URI_DST
&&
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
&&
66 uri
[1].port
== 4242 &&
67 strlen(uri
[1].subdir
) == 0 &&
68 strcmp(uri
[1].dst
.ipv4
, "127.0.0.1") == 0,
69 "URI set to net://localhost:8989:4242/my/test/path");
76 s_uri1
= "net://localhost:8989:4242";
78 size
= uri_parse(s_uri1
, &uri
);
81 uri
[0].dtype
== LTTNG_DST_IPV4
&&
82 uri
[0].utype
== LTTNG_URI_DST
&&
84 uri
[0].port
== 8989 &&
85 strlen(uri
[0].subdir
) == 0 &&
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
&&
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");
100 s_uri1
= "net6://[::1]:8989";
102 size
= uri_parse(s_uri1
, &uri
);
105 uri
[0].dtype
== LTTNG_DST_IPV6
&&
106 uri
[0].utype
== LTTNG_URI_DST
&&
108 uri
[0].port
== 8989 &&
109 strlen(uri
[0].subdir
) == 0 &&
110 strcmp(uri
[0].dst
.ipv6
, "::1") == 0 &&
111 uri
[1].dtype
== LTTNG_DST_IPV6
&&
112 uri
[1].utype
== LTTNG_URI_DST
&&
115 strlen(uri
[1].subdir
) == 0 &&
116 strcmp(uri
[1].dst
.ipv6
, "::1") == 0,
117 "URI set to net6://[::1]:8989");
124 s_uri1
= "tcp://42.42.42.42/my/test/path";
126 size
= uri_parse(s_uri1
, &uri
);
129 uri
[0].dtype
== LTTNG_DST_IPV4
&&
130 uri
[0].utype
== LTTNG_URI_DST
&&
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");
142 s_uri1
= "tcp6://[fe80::f66d:4ff:fe53:d220]/my/test/path";
144 size
= uri_parse(s_uri1
, &uri
);
147 uri
[0].dtype
== LTTNG_DST_IPV6
&&
148 uri
[0].utype
== LTTNG_URI_DST
&&
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");
160 s_uri1
= "file:///my/test/path";
162 size
= uri_parse(s_uri1
, &uri
);
165 uri
[0].dtype
== LTTNG_DST_PATH
&&
166 uri
[0].utype
== LTTNG_URI_DST
&&
169 strlen(uri
[0].subdir
) == 0 &&
170 strcmp(uri
[0].dst
.path
, "/my/test/path") == 0,
171 "URI set to file:///my/test/path");
178 /* FIXME: Noisy on stdout */
179 s_uri1
= "file/my/test/path";
180 size
= uri_parse(s_uri1
, &uri
);
181 ok(size
== -1, "Bad URI set to file/my/test/path");
184 s_uri1
= "net://:8999";
185 size
= uri_parse(s_uri1
, &uri
);
186 ok(size
== -1, "Bad URI set to net://:8999");
190 static void test_uri_cmp(void)
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
;
198 size1
= uri_parse(s_uri1
, &uri1
);
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);
215 size2
= uri_parse(s_uri2
, &uri2
);
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);
231 res
= uri_compare(uri1
, uri1
);
234 "URI compare net://localhost == net://localhost");
236 res
= uri_compare(uri1
, uri2
);
239 "URI compare net://localhost != net://localhost:8989:4242");
245 int main(int argc
, char **argv
)
247 plan_tests(NUM_TESTS
);
249 diag("URI unit tests");
255 return exit_status();
This page took 0.035715 seconds and 4 git commands to generate.