6fea139c30f61415920575cbc0ef8f3aa10fda40
[lttng-tools.git] / tests / tools / streaming / unit_tests.c
1 /*
2 * Copyright (C) - 2012 David Goulet <dgoulet@efficios.com>
3 *
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.
7 *
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
11 * more details.
12 *
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.
16 */
17
18 #define _GNU_SOURCE
19 #include <assert.h>
20 #include <errno.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <unistd.h>
25 #include <time.h>
26 #include <sys/types.h>
27
28 #include <common/sessiond-comm/sessiond-comm.h>
29 #include <common/uri.h>
30
31 #include "utils.h"
32
33 /* This path will NEVER be created in this test */
34 #define PATH1 "tmp/.test-junk-lttng"
35
36 #define RANDOM_STRING_LEN 16
37
38 /* For lttngerr.h */
39 int lttng_opt_quiet = 1;
40 int lttng_opt_verbose = 0;
41
42 /*
43 * Test string URI and if uri_parse works well.
44 */
45 int test_uri(void)
46 {
47 ssize_t size;
48 const char *s_uri1;
49 struct lttng_uri *uri;
50
51 fprintf(stdout, "Testing URIs...\n");
52
53 s_uri1 = "net://localhost";
54 fprintf(stdout, " [+] URI set to %s ", s_uri1);
55 size = uri_parse(s_uri1, &uri);
56 assert(size == 2);
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);
63
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);
70 PRINT_OK();
71
72 s_uri1 = "net://localhost:8989:4242/my/test/path";
73 fprintf(stdout, " [+] URI set to %s ", s_uri1);
74 size = uri_parse(s_uri1, &uri);
75 assert(size == 2);
76 assert(uri[0].dtype == LTTNG_DST_IPV4);
77 assert(uri[0].utype == LTTNG_URI_DST);
78 assert(uri[0].stype == 0);
79 assert(uri[0].port == 8989);
80 assert(strcmp(uri[0].subdir, "my/test/path") == 0);
81 assert(strcmp(uri[0].dst.ipv4, "127.0.0.1") == 0);
82
83 assert(uri[1].dtype == LTTNG_DST_IPV4);
84 assert(uri[1].utype == LTTNG_URI_DST);
85 assert(uri[1].stype == 0);
86 assert(uri[1].port == 4242);
87 assert(strcmp(uri[0].subdir, "my/test/path") == 0);
88 assert(strcmp(uri[1].dst.ipv4, "127.0.0.1") == 0);
89 PRINT_OK();
90
91 s_uri1 = "net://localhost:8989:4242";
92 fprintf(stdout, " [+] URI set to %s ", s_uri1);
93 size = uri_parse(s_uri1, &uri);
94 assert(size == 2);
95 assert(uri[0].dtype == LTTNG_DST_IPV4);
96 assert(uri[0].utype == LTTNG_URI_DST);
97 assert(uri[0].stype == 0);
98 assert(uri[0].port == 8989);
99 assert(strlen(uri[1].subdir) == 0);
100 assert(strcmp(uri[0].dst.ipv4, "127.0.0.1") == 0);
101
102 assert(uri[1].dtype == LTTNG_DST_IPV4);
103 assert(uri[1].utype == LTTNG_URI_DST);
104 assert(uri[1].stype == 0);
105 assert(uri[1].port == 4242);
106 assert(strlen(uri[1].subdir) == 0);
107 assert(strcmp(uri[1].dst.ipv4, "127.0.0.1") == 0);
108 PRINT_OK();
109
110 s_uri1 = "net6://localhost:8989";
111 fprintf(stdout, " [+] URI set to %s ", s_uri1);
112 size = uri_parse(s_uri1, &uri);
113 assert(size == 2);
114 assert(uri[0].dtype == LTTNG_DST_IPV6);
115 assert(uri[0].utype == LTTNG_URI_DST);
116 assert(uri[0].stype == 0);
117 assert(uri[0].port == 8989);
118 assert(strlen(uri[1].subdir) == 0);
119 assert(strcmp(uri[0].dst.ipv6, "::1") == 0);
120
121 assert(uri[1].dtype == LTTNG_DST_IPV6);
122 assert(uri[1].utype == LTTNG_URI_DST);
123 assert(uri[1].stype == 0);
124 assert(uri[1].port == 0);
125 assert(strlen(uri[1].subdir) == 0);
126 assert(strcmp(uri[0].dst.ipv6, "::1") == 0);
127 PRINT_OK();
128
129 s_uri1 = "tcp://42.42.42.42/my/test/path";
130 fprintf(stdout, " [+] URI set to %s ", s_uri1);
131 size = uri_parse(s_uri1, &uri);
132 assert(size == 1);
133 assert(uri[0].dtype == LTTNG_DST_IPV4);
134 assert(uri[0].utype == LTTNG_URI_DST);
135 assert(uri[0].stype == 0);
136 assert(uri[0].port == 0);
137 assert(strcmp(uri[0].subdir, "my/test/path") == 0);
138 assert(strcmp(uri[0].dst.ipv4, "42.42.42.42") == 0);
139 PRINT_OK();
140
141 s_uri1 = "tcp6://fe80::f66d:4ff:fe53:d220/my/test/path";
142 fprintf(stdout, " [+] URI set to %s ", s_uri1);
143 size = uri_parse(s_uri1, &uri);
144 assert(size == 1);
145 assert(uri[0].dtype == LTTNG_DST_IPV6);
146 assert(uri[0].utype == LTTNG_URI_DST);
147 assert(uri[0].stype == 0);
148 assert(uri[0].port == 0);
149 assert(strcmp(uri[0].subdir, "my/test/path") == 0);
150 assert(strcmp(uri[0].dst.ipv6, "fe80::f66d:4ff:fe53:d220") == 0);
151 PRINT_OK();
152
153 s_uri1 = "file:///my/test/path";
154 fprintf(stdout, " [+] URI set to %s ", s_uri1);
155 size = uri_parse(s_uri1, &uri);
156 assert(size == 1);
157 assert(uri[0].dtype == LTTNG_DST_PATH);
158 assert(uri[0].utype == LTTNG_URI_DST);
159 assert(uri[0].stype == 0);
160 assert(uri[0].port == 0);
161 assert(strlen(uri[1].subdir) == 0);
162 assert(strcmp(uri[0].dst.path, "/my/test/path") == 0);
163 PRINT_OK();
164
165 s_uri1 = "file/my/test/path";
166 fprintf(stdout, " [+] Bad URI set to %s ", s_uri1);
167 size = uri_parse(s_uri1, &uri);
168 assert(size == -1);
169 PRINT_OK();
170
171 s_uri1 = "net://:8999";
172 fprintf(stdout, " [+] Bad URI set to %s ", s_uri1);
173 size = uri_parse(s_uri1, &uri);
174 assert(size == -1);
175 PRINT_OK();
176
177 s_uri1 = "net://localhost/";
178 fprintf(stdout, " [+] Bad URI set to %s ", s_uri1);
179 size = uri_parse(s_uri1, &uri);
180 assert(size == -1);
181 PRINT_OK();
182
183 return 0;
184 }
185
186 int main(int argc, char **argv)
187 {
188 int ret;
189
190 srand(time(NULL));
191
192 printf("\nStreaming unit tests\n-----------\n");
193
194 ret = test_uri();
195 if (ret < 0) {
196 goto error;
197 }
198
199 /* Success */
200 return 0;
201
202 error:
203 return -1;
204 }
This page took 0.034136 seconds and 3 git commands to generate.