41c74203dd035d263b4750c8f845c9f5a6c17ff5
2 * Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
8 #include <common/uri.hpp>
14 int lttng_opt_quiet
= 1;
15 int lttng_opt_verbose
= 3;
18 /* Number of TAP tests in this file */
21 static void test_uri_parsing()
25 struct lttng_uri
*uri
= nullptr;
27 s_uri1
= "net://localhost";
29 size
= uri_parse(s_uri1
, &uri
);
31 ok(size
== 2 && uri
[0].dtype
== LTTNG_DST_IPV4
&& uri
[0].utype
== LTTNG_URI_DST
&&
32 uri
[0].stype
== 0 && uri
[0].port
== 0 && strlen(uri
[0].subdir
) == 0 &&
33 strcmp(uri
[0].dst
.ipv4
, "127.0.0.1") == 0 && uri
[1].dtype
== LTTNG_DST_IPV4
&&
34 uri
[1].utype
== LTTNG_URI_DST
&& uri
[1].stype
== 0 && uri
[1].port
== 0 &&
35 strlen(uri
[1].subdir
) == 0 && strcmp(uri
[1].dst
.ipv4
, "127.0.0.1") == 0,
36 "URI set to net://localhost");
43 s_uri1
= "net://localhost:8989:4242/my/test/path";
45 size
= uri_parse(s_uri1
, &uri
);
47 ok(size
== 2 && uri
[0].dtype
== LTTNG_DST_IPV4
&& uri
[0].utype
== LTTNG_URI_DST
&&
48 uri
[0].stype
== 0 && uri
[0].port
== 8989 &&
49 strcmp(uri
[0].subdir
, "my/test/path") == 0 &&
50 strcmp(uri
[0].dst
.ipv4
, "127.0.0.1") == 0 && uri
[1].dtype
== LTTNG_DST_IPV4
&&
51 uri
[1].utype
== LTTNG_URI_DST
&& uri
[1].stype
== 0 && uri
[1].port
== 4242 &&
52 strlen(uri
[1].subdir
) == 0 && strcmp(uri
[1].dst
.ipv4
, "127.0.0.1") == 0,
53 "URI set to net://localhost:8989:4242/my/test/path");
60 s_uri1
= "net://localhost:8989:4242";
62 size
= uri_parse(s_uri1
, &uri
);
64 ok(size
== 2 && uri
[0].dtype
== LTTNG_DST_IPV4
&& uri
[0].utype
== LTTNG_URI_DST
&&
65 uri
[0].stype
== 0 && uri
[0].port
== 8989 && strlen(uri
[0].subdir
) == 0 &&
66 strcmp(uri
[0].dst
.ipv4
, "127.0.0.1") == 0 && uri
[1].dtype
== LTTNG_DST_IPV4
&&
67 uri
[1].utype
== LTTNG_URI_DST
&& uri
[1].stype
== 0 && uri
[1].port
== 4242 &&
68 strlen(uri
[1].subdir
) == 0 && strcmp(uri
[1].dst
.ipv4
, "127.0.0.1") == 0,
69 "URI set to net://localhost:8989:4242");
76 s_uri1
= "net6://[::1]:8989";
78 size
= uri_parse(s_uri1
, &uri
);
80 ok(size
== 2 && uri
[0].dtype
== LTTNG_DST_IPV6
&& uri
[0].utype
== LTTNG_URI_DST
&&
81 uri
[0].stype
== 0 && uri
[0].port
== 8989 && strlen(uri
[0].subdir
) == 0 &&
82 strcmp(uri
[0].dst
.ipv6
, "::1") == 0 && uri
[1].dtype
== LTTNG_DST_IPV6
&&
83 uri
[1].utype
== LTTNG_URI_DST
&& uri
[1].stype
== 0 && uri
[1].port
== 0 &&
84 strlen(uri
[1].subdir
) == 0 && strcmp(uri
[1].dst
.ipv6
, "::1") == 0,
85 "URI set to net6://[::1]:8989");
92 s_uri1
= "tcp://42.42.42.42/my/test/path";
94 size
= uri_parse(s_uri1
, &uri
);
96 ok(size
== 1 && uri
[0].dtype
== LTTNG_DST_IPV4
&& uri
[0].utype
== LTTNG_URI_DST
&&
97 uri
[0].stype
== 0 && uri
[0].port
== 0 &&
98 strcmp(uri
[0].subdir
, "my/test/path") == 0 &&
99 strcmp(uri
[0].dst
.ipv4
, "42.42.42.42") == 0,
100 "URI set to tcp://42.42.42.42/my/test/path");
107 s_uri1
= "tcp6://[fe80::f66d:4ff:fe53:d220]/my/test/path";
109 size
= uri_parse(s_uri1
, &uri
);
111 ok(size
== 1 && uri
[0].dtype
== LTTNG_DST_IPV6
&& uri
[0].utype
== LTTNG_URI_DST
&&
112 uri
[0].stype
== 0 && uri
[0].port
== 0 &&
113 strcmp(uri
[0].subdir
, "my/test/path") == 0 &&
114 strcmp(uri
[0].dst
.ipv6
, "fe80::f66d:4ff:fe53:d220") == 0,
115 "URI set to tcp6://[fe80::f66d:4ff:fe53:d220]/my/test/path");
122 s_uri1
= "file:///my/test/path";
124 size
= uri_parse(s_uri1
, &uri
);
126 ok(size
== 1 && uri
[0].dtype
== LTTNG_DST_PATH
&& uri
[0].utype
== LTTNG_URI_DST
&&
127 uri
[0].stype
== 0 && uri
[0].port
== 0 && strlen(uri
[0].subdir
) == 0 &&
128 strcmp(uri
[0].dst
.path
, "/my/test/path") == 0,
129 "URI set to file:///my/test/path");
136 /* FIXME: Noisy on stdout */
137 s_uri1
= "file/my/test/path";
138 size
= uri_parse(s_uri1
, &uri
);
139 ok(size
== -1, "Bad URI set to file/my/test/path");
142 s_uri1
= "net://:8999";
143 size
= uri_parse(s_uri1
, &uri
);
144 ok(size
== -1, "Bad URI set to net://:8999");
148 static void test_uri_cmp()
150 struct lttng_uri
*uri1
, *uri2
;
151 const char *s_uri1
= "net://localhost";
152 const char *s_uri2
= "net://localhost:8989:4242";
153 ssize_t size1
, size2
;
156 size1
= uri_parse(s_uri1
, &uri1
);
159 LTTNG_ASSERT(size1
== 2);
160 LTTNG_ASSERT(uri1
[0].dtype
== LTTNG_DST_IPV4
);
161 LTTNG_ASSERT(uri1
[0].utype
== LTTNG_URI_DST
);
162 LTTNG_ASSERT(uri1
[0].stype
== 0);
163 LTTNG_ASSERT(uri1
[0].port
== 0);
164 LTTNG_ASSERT(strlen(uri1
[0].subdir
) == 0);
165 LTTNG_ASSERT(strcmp(uri1
[0].dst
.ipv4
, "127.0.0.1") == 0);
166 LTTNG_ASSERT(uri1
[1].dtype
== LTTNG_DST_IPV4
);
167 LTTNG_ASSERT(uri1
[1].utype
== LTTNG_URI_DST
);
168 LTTNG_ASSERT(uri1
[1].stype
== 0);
169 LTTNG_ASSERT(uri1
[1].port
== 0);
170 LTTNG_ASSERT(strlen(uri1
[1].subdir
) == 0);
171 LTTNG_ASSERT(strcmp(uri1
[1].dst
.ipv4
, "127.0.0.1") == 0);
173 size2
= uri_parse(s_uri2
, &uri2
);
175 LTTNG_ASSERT(size2
== 2);
176 LTTNG_ASSERT(uri2
[0].dtype
== LTTNG_DST_IPV4
);
177 LTTNG_ASSERT(uri2
[0].utype
== LTTNG_URI_DST
);
178 LTTNG_ASSERT(uri2
[0].stype
== 0);
179 LTTNG_ASSERT(uri2
[0].port
== 8989);
180 LTTNG_ASSERT(strlen(uri2
[0].subdir
) == 0);
181 LTTNG_ASSERT(strcmp(uri2
[0].dst
.ipv4
, "127.0.0.1") == 0);
182 LTTNG_ASSERT(uri2
[1].dtype
== LTTNG_DST_IPV4
);
183 LTTNG_ASSERT(uri2
[1].utype
== LTTNG_URI_DST
);
184 LTTNG_ASSERT(uri2
[1].stype
== 0);
185 LTTNG_ASSERT(uri2
[1].port
== 4242);
186 LTTNG_ASSERT(strlen(uri2
[1].subdir
) == 0);
187 LTTNG_ASSERT(strcmp(uri2
[1].dst
.ipv4
, "127.0.0.1") == 0);
189 res
= uri_compare(uri1
, uri1
);
191 ok(res
== 0, "URI compare net://localhost == net://localhost");
193 res
= uri_compare(uri1
, uri2
);
195 ok(res
!= 0, "URI compare net://localhost != net://localhost:8989:4242");
203 plan_tests(NUM_TESTS
);
205 diag("URI unit tests");
211 return exit_status();
This page took 0.037741 seconds and 5 git commands to generate.