2 * Copyright (C) - 2012 David Goulet <dgoulet@efficios.com>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by as
6 * published by the Free Software Foundation; only version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <sys/types.h>
28 #include <common/sessiond-comm/sessiond-comm.h>
29 #include <common/uri.h>
33 /* This path will NEVER be created in this test */
34 #define PATH1 "tmp/.test-junk-lttng"
36 #define RANDOM_STRING_LEN 16
39 int lttng_opt_quiet
= 1;
40 int lttng_opt_verbose
= 3;
43 * Test string URI and if uri_parse works well.
45 void test_uri_parsing(void)
49 struct lttng_uri
*uri
;
51 fprintf(stdout
, "Testing URIs...\n");
53 s_uri1
= "net://localhost";
54 fprintf(stdout
, " [+] URI set to %s ", s_uri1
);
55 size
= uri_parse(s_uri1
, &uri
);
57 assert(uri
[0].dtype
== LTTNG_DST_IPV4
);
58 assert(uri
[0].utype
== LTTNG_URI_DST
);
59 assert(uri
[0].stype
== 0);
60 assert(uri
[0].port
== 0);
61 assert(strlen(uri
[0].subdir
) == 0);
62 assert(strcmp(uri
[0].dst
.ipv4
, "127.0.0.1") == 0);
64 assert(uri
[1].dtype
== LTTNG_DST_IPV4
);
65 assert(uri
[1].utype
== LTTNG_URI_DST
);
66 assert(uri
[1].stype
== 0);
67 assert(uri
[1].port
== 0);
68 assert(strlen(uri
[1].subdir
) == 0);
69 assert(strcmp(uri
[1].dst
.ipv4
, "127.0.0.1") == 0);
73 s_uri1
= "net://localhost:8989:4242/my/test/path";
74 fprintf(stdout
, " [+] URI set to %s ", s_uri1
);
75 size
= uri_parse(s_uri1
, &uri
);
77 assert(uri
[0].dtype
== LTTNG_DST_IPV4
);
78 assert(uri
[0].utype
== LTTNG_URI_DST
);
79 assert(uri
[0].stype
== 0);
80 assert(uri
[0].port
== 8989);
81 assert(strcmp(uri
[0].subdir
, "my/test/path") == 0);
82 assert(strcmp(uri
[0].dst
.ipv4
, "127.0.0.1") == 0);
84 assert(uri
[1].dtype
== LTTNG_DST_IPV4
);
85 assert(uri
[1].utype
== LTTNG_URI_DST
);
86 assert(uri
[1].stype
== 0);
87 assert(uri
[1].port
== 4242);
88 assert(strcmp(uri
[0].subdir
, "my/test/path") == 0);
89 assert(strcmp(uri
[1].dst
.ipv4
, "127.0.0.1") == 0);
93 s_uri1
= "net://localhost:8989:4242";
94 fprintf(stdout
, " [+] URI set to %s ", s_uri1
);
95 size
= uri_parse(s_uri1
, &uri
);
97 assert(uri
[0].dtype
== LTTNG_DST_IPV4
);
98 assert(uri
[0].utype
== LTTNG_URI_DST
);
99 assert(uri
[0].stype
== 0);
100 assert(uri
[0].port
== 8989);
101 assert(strlen(uri
[1].subdir
) == 0);
102 assert(strcmp(uri
[0].dst
.ipv4
, "127.0.0.1") == 0);
104 assert(uri
[1].dtype
== LTTNG_DST_IPV4
);
105 assert(uri
[1].utype
== LTTNG_URI_DST
);
106 assert(uri
[1].stype
== 0);
107 assert(uri
[1].port
== 4242);
108 assert(strlen(uri
[1].subdir
) == 0);
109 assert(strcmp(uri
[1].dst
.ipv4
, "127.0.0.1") == 0);
113 s_uri1
= "net6://localhost:8989";
114 fprintf(stdout
, " [+] URI set to %s ", s_uri1
);
115 size
= uri_parse(s_uri1
, &uri
);
117 assert(uri
[0].dtype
== LTTNG_DST_IPV6
);
118 assert(uri
[0].utype
== LTTNG_URI_DST
);
119 assert(uri
[0].stype
== 0);
120 assert(uri
[0].port
== 8989);
121 assert(strlen(uri
[1].subdir
) == 0);
122 assert(strcmp(uri
[0].dst
.ipv6
, "::1") == 0);
124 assert(uri
[1].dtype
== LTTNG_DST_IPV6
);
125 assert(uri
[1].utype
== LTTNG_URI_DST
);
126 assert(uri
[1].stype
== 0);
127 assert(uri
[1].port
== 0);
128 assert(strlen(uri
[1].subdir
) == 0);
129 assert(strcmp(uri
[0].dst
.ipv6
, "::1") == 0);
133 s_uri1
= "tcp://42.42.42.42/my/test/path";
134 fprintf(stdout
, " [+] URI set to %s ", s_uri1
);
135 size
= uri_parse(s_uri1
, &uri
);
137 assert(uri
[0].dtype
== LTTNG_DST_IPV4
);
138 assert(uri
[0].utype
== LTTNG_URI_DST
);
139 assert(uri
[0].stype
== 0);
140 assert(uri
[0].port
== 0);
141 assert(strcmp(uri
[0].subdir
, "my/test/path") == 0);
142 assert(strcmp(uri
[0].dst
.ipv4
, "42.42.42.42") == 0);
146 s_uri1
= "tcp6://[fe80::f66d:4ff:fe53:d220]/my/test/path";
147 fprintf(stdout
, " [+] URI set to %s ", s_uri1
);
148 size
= uri_parse(s_uri1
, &uri
);
150 assert(uri
[0].dtype
== LTTNG_DST_IPV6
);
151 assert(uri
[0].utype
== LTTNG_URI_DST
);
152 assert(uri
[0].stype
== 0);
153 assert(uri
[0].port
== 0);
154 assert(strcmp(uri
[0].subdir
, "my/test/path") == 0);
155 assert(strcmp(uri
[0].dst
.ipv6
, "fe80::f66d:4ff:fe53:d220") == 0);
159 s_uri1
= "file:///my/test/path";
160 fprintf(stdout
, " [+] URI set to %s ", s_uri1
);
161 size
= uri_parse(s_uri1
, &uri
);
163 assert(uri
[0].dtype
== LTTNG_DST_PATH
);
164 assert(uri
[0].utype
== LTTNG_URI_DST
);
165 assert(uri
[0].stype
== 0);
166 assert(uri
[0].port
== 0);
167 assert(strlen(uri
[0].subdir
) == 0);
168 assert(strcmp(uri
[0].dst
.path
, "/my/test/path") == 0);
172 s_uri1
= "file/my/test/path";
173 fprintf(stdout
, " [+] Bad URI set to %s ", s_uri1
);
174 size
= uri_parse(s_uri1
, &uri
);
178 s_uri1
= "net://:8999";
179 fprintf(stdout
, " [+] Bad URI set to %s ", s_uri1
);
180 size
= uri_parse(s_uri1
, &uri
);
187 struct lttng_uri
*uri1
, *uri2
;
188 const char *s_uri1
= "net://localhost";
189 const char *s_uri2
= "net://localhost:8989:4242";
190 ssize_t size1
, size2
;
193 size1
= uri_parse(s_uri1
, &uri1
);
197 assert(uri1
[0].dtype
== LTTNG_DST_IPV4
);
198 assert(uri1
[0].utype
== LTTNG_URI_DST
);
199 assert(uri1
[0].stype
== 0);
200 assert(uri1
[0].port
== 0);
201 assert(strlen(uri1
[0].subdir
) == 0);
202 assert(strcmp(uri1
[0].dst
.ipv4
, "127.0.0.1") == 0);
203 assert(uri1
[1].dtype
== LTTNG_DST_IPV4
);
204 assert(uri1
[1].utype
== LTTNG_URI_DST
);
205 assert(uri1
[1].stype
== 0);
206 assert(uri1
[1].port
== 0);
207 assert(strlen(uri1
[1].subdir
) == 0);
208 assert(strcmp(uri1
[1].dst
.ipv4
, "127.0.0.1") == 0);
210 size2
= uri_parse(s_uri2
, &uri2
);
213 assert(uri2
[0].dtype
== LTTNG_DST_IPV4
);
214 assert(uri2
[0].utype
== LTTNG_URI_DST
);
215 assert(uri2
[0].stype
== 0);
216 assert(uri2
[0].port
== 8989);
217 assert(strlen(uri2
[1].subdir
) == 0);
218 assert(strcmp(uri2
[0].dst
.ipv4
, "127.0.0.1") == 0);
219 assert(uri2
[1].dtype
== LTTNG_DST_IPV4
);
220 assert(uri2
[1].utype
== LTTNG_URI_DST
);
221 assert(uri2
[1].stype
== 0);
222 assert(uri2
[1].port
== 4242);
223 assert(strlen(uri2
[1].subdir
) == 0);
224 assert(strcmp(uri2
[1].dst
.ipv4
, "127.0.0.1") == 0);
227 res
= uri_compare(uri1
, uri1
);
228 fprintf(stdout
, " [+] %s == %s ", s_uri1
, s_uri1
);
232 res
= uri_compare(uri1
, uri2
);
233 fprintf(stdout
, " [+] %s != %s ", s_uri1
, s_uri2
);
241 int main(int argc
, char **argv
)
245 printf("\nStreaming unit tests\n-----------\n");
This page took 0.046384 seconds and 4 git commands to generate.