Tests: Add test to check shared-memory FD leaks after relayd dies
[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
28ab034a 8#include <common/uri.hpp>
de9a8b41 9
28ab034a 10#include <string.h>
c291fb24 11#include <tap/tap.h>
de9a8b41 12
ad7c9c18 13/* For error.h */
de9a8b41 14int lttng_opt_quiet = 1;
a4b92340 15int lttng_opt_verbose = 3;
c7e35b03 16int lttng_opt_mi;
de9a8b41 17
c291fb24
CB
18/* Number of TAP tests in this file */
19#define NUM_TESTS 11
20
cd9adb8b 21static void test_uri_parsing()
de9a8b41
DG
22{
23 ssize_t size;
24 const char *s_uri1;
cd9adb8b 25 struct lttng_uri *uri = nullptr;
de9a8b41
DG
26
27 s_uri1 = "net://localhost";
c291fb24 28
de9a8b41 29 size = uri_parse(s_uri1, &uri);
c291fb24 30
28ab034a
JG
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,
c291fb24
CB
36 "URI set to net://localhost");
37
38 if (uri) {
39 uri_free(uri);
cd9adb8b 40 uri = nullptr;
c291fb24 41 }
de9a8b41
DG
42
43 s_uri1 = "net://localhost:8989:4242/my/test/path";
c291fb24 44
de9a8b41 45 size = uri_parse(s_uri1, &uri);
c291fb24 46
28ab034a
JG
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,
c291fb24
CB
53 "URI set to net://localhost:8989:4242/my/test/path");
54
55 if (uri) {
56 uri_free(uri);
cd9adb8b 57 uri = nullptr;
c291fb24 58 }
de9a8b41
DG
59
60 s_uri1 = "net://localhost:8989:4242";
c291fb24 61
de9a8b41 62 size = uri_parse(s_uri1, &uri);
c291fb24 63
28ab034a
JG
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,
c291fb24
CB
69 "URI set to net://localhost:8989:4242");
70
71 if (uri) {
72 uri_free(uri);
cd9adb8b 73 uri = nullptr;
c291fb24 74 }
de9a8b41 75
5d7ba9b6 76 s_uri1 = "net6://[::1]:8989";
c291fb24 77
de9a8b41 78 size = uri_parse(s_uri1, &uri);
c291fb24 79
28ab034a
JG
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,
5d7ba9b6 85 "URI set to net6://[::1]:8989");
c291fb24
CB
86
87 if (uri) {
88 uri_free(uri);
cd9adb8b 89 uri = nullptr;
c291fb24 90 }
de9a8b41
DG
91
92 s_uri1 = "tcp://42.42.42.42/my/test/path";
c291fb24 93
de9a8b41 94 size = uri_parse(s_uri1, &uri);
c291fb24 95
28ab034a
JG
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,
c291fb24
CB
100 "URI set to tcp://42.42.42.42/my/test/path");
101
102 if (uri) {
103 uri_free(uri);
cd9adb8b 104 uri = nullptr;
c291fb24 105 }
de9a8b41 106
a4b92340 107 s_uri1 = "tcp6://[fe80::f66d:4ff:fe53:d220]/my/test/path";
c291fb24 108
de9a8b41 109 size = uri_parse(s_uri1, &uri);
c291fb24 110
28ab034a
JG
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,
c291fb24
CB
115 "URI set to tcp6://[fe80::f66d:4ff:fe53:d220]/my/test/path");
116
117 if (uri) {
118 uri_free(uri);
cd9adb8b 119 uri = nullptr;
c291fb24 120 }
de9a8b41
DG
121
122 s_uri1 = "file:///my/test/path";
c291fb24 123
de9a8b41 124 size = uri_parse(s_uri1, &uri);
de9a8b41 125
28ab034a
JG
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,
c291fb24
CB
129 "URI set to file:///my/test/path");
130
131 if (uri) {
132 uri_free(uri);
cd9adb8b 133 uri = nullptr;
c291fb24
CB
134 }
135
136 /* FIXME: Noisy on stdout */
de9a8b41 137 s_uri1 = "file/my/test/path";
de9a8b41 138 size = uri_parse(s_uri1, &uri);
c291fb24 139 ok(size == -1, "Bad URI set to file/my/test/path");
a0377dfe 140 LTTNG_ASSERT(!uri);
de9a8b41
DG
141
142 s_uri1 = "net://:8999";
de9a8b41 143 size = uri_parse(s_uri1, &uri);
c291fb24 144 ok(size == -1, "Bad URI set to net://:8999");
a0377dfe 145 LTTNG_ASSERT(!uri);
3cb37009 146}
de9a8b41 147
cd9adb8b 148static void test_uri_cmp()
3cb37009
CB
149{
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;
154 int res;
155
156 size1 = uri_parse(s_uri1, &uri1);
157
158 /* Sanity checks */
a0377dfe
FD
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);
3cb37009
CB
172
173 size2 = uri_parse(s_uri2, &uri2);
174
a0377dfe
FD
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);
3cb37009 188
3cb37009 189 res = uri_compare(uri1, uri1);
c291fb24 190
28ab034a 191 ok(res == 0, "URI compare net://localhost == net://localhost");
3cb37009
CB
192
193 res = uri_compare(uri1, uri2);
c291fb24 194
28ab034a 195 ok(res != 0, "URI compare net://localhost != net://localhost:8989:4242");
3cb37009
CB
196
197 uri_free(uri1);
198 uri_free(uri2);
de9a8b41
DG
199}
200
cd9adb8b 201int main()
de9a8b41 202{
c291fb24 203 plan_tests(NUM_TESTS);
de9a8b41 204
e3bef725
CB
205 diag("URI unit tests");
206
3cb37009 207 test_uri_parsing();
c291fb24 208
3cb37009 209 test_uri_cmp();
de9a8b41 210
c291fb24 211 return exit_status();
de9a8b41 212}
This page took 0.068333 seconds and 4 git commands to generate.