Extend API and remove lttng_uri from lttng.h
[lttng-tools.git] / tests / tools / streaming / unit_tests.c
CommitLineData
de9a8b41
DG
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 */
39int lttng_opt_quiet = 1;
a4b92340 40int lttng_opt_verbose = 3;
de9a8b41
DG
41
42/*
43 * Test string URI and if uri_parse works well.
44 */
45int 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
a4b92340 141 s_uri1 = "tcp6://[fe80::f66d:4ff:fe53:d220]/my/test/path";
de9a8b41
DG
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
de9a8b41
DG
177 return 0;
178}
179
180int main(int argc, char **argv)
181{
182 int ret;
183
184 srand(time(NULL));
185
186 printf("\nStreaming unit tests\n-----------\n");
187
188 ret = test_uri();
189 if (ret < 0) {
190 goto error;
191 }
192
193 /* Success */
194 return 0;
195
196error:
197 return -1;
198}
This page took 0.04361 seconds and 4 git commands to generate.