2 * Copyright (c) 2011 David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * as published by the Free Software Foundation; only version 2
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <sys/types.h>
29 #include <bin/lttng-sessiond/session.h>
30 #include <common/sessiond-comm/sessiond-comm.h>
31 #include <common/common.h>
35 #define SESSION1 "test1"
37 /* This path will NEVER be created in this test */
38 #define PATH1 "/tmp/.test-junk-lttng"
40 #define MAX_SESSIONS 10000
41 #define RANDOM_STRING_LEN 11
44 * String of 263 caracters. NAME_MAX + "OVERFLOW". If OVERFLOW appears in the
45 * session name, we have a problem.
49 #define OVERFLOW_SESSION_NAME \
50 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \
51 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \
52 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \
53 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc" \
56 static struct ltt_session_list
*session_list
;
59 int lttng_opt_quiet
= 1;
60 int lttng_opt_verbose
= 0;
62 static const char alphanum
[] =
64 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
65 "abcdefghijklmnopqrstuvwxyz";
66 static char random_string
[RANDOM_STRING_LEN
];
69 * Return random string of 10 characters.
72 static char *get_random_string(void)
76 for (i
= 0; i
< RANDOM_STRING_LEN
- 1; i
++) {
77 random_string
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
80 random_string
[RANDOM_STRING_LEN
- 1] = '\0';
86 * Return 0 if session name is found, else -1
88 static int find_session_name(char *name
)
90 struct ltt_session
*iter
;
92 cds_list_for_each_entry(iter
, &session_list
->head
, list
) {
93 if (strcmp(iter
->name
, name
) == 0) {
101 static int session_list_count(void)
104 struct ltt_session
*iter
;
106 cds_list_for_each_entry(iter
, &session_list
->head
, list
) {
113 * Empty session list manually.
115 static void empty_session_list(void)
117 struct ltt_session
*iter
, *tmp
;
119 cds_list_for_each_entry_safe(iter
, tmp
, &session_list
->head
, list
) {
120 cds_list_del(&iter
->list
);
124 /* Session list must be 0 */
125 assert(!session_list_count());
129 * Test creation of 1 session
131 static int create_one_session(char *name
, char *path
)
135 ret
= session_create(name
, path
, geteuid(), getegid());
136 if (ret
== LTTNG_OK
) {
138 ret
= find_session_name(name
);
140 /* Session not found by name */
141 printf("session not found after creation\n");
148 if (ret
== LTTNG_ERR_EXIST_SESS
) {
149 printf("(session already exists) ");
158 * Test deletion of 1 session
160 static int destroy_one_session(struct ltt_session
*session
)
164 ret
= session_destroy(session
);
166 if (ret
== LTTNG_OK
) {
168 if (session
== NULL
) {
171 ret
= find_session_name(session
->name
);
173 /* Success, -1 means that the sesion is NOT found */
184 static int fuzzing_create_args(void)
188 ret
= create_one_session(NULL
, NULL
);
190 printf("Session created with (null),(null)\n");
194 ret
= create_one_session(NULL
, PATH1
);
196 printf("Session created with (null), %s)\n", PATH1
);
200 /* Session list must be 0 */
201 assert(!session_list_count());
206 static int fuzzing_destroy_args(void)
210 ret
= destroy_one_session(NULL
);
212 printf("Session destroyed with (null)\n");
216 /* Session list must be 0 */
217 assert(!session_list_count());
223 * This test is supposed to fail at the second create call. If so, return 0 for
224 * test success, else -1.
226 static int two_session_same_name(void)
229 struct ltt_session
*sess
;
231 ret
= create_one_session(SESSION1
, PATH1
);
237 sess
= session_find_by_name(SESSION1
);
247 int main(int argc
, char **argv
)
250 struct ltt_session
*iter
, *tmp
;
254 printf("\nTesting Sessions:\n-----------\n");
256 session_list
= session_get_list();
257 if (session_list
== NULL
) {
261 printf("Create 1 session %s: ", SESSION1
);
263 ret
= create_one_session(SESSION1
, PATH1
);
269 printf("Validating created session %s: ", SESSION1
);
271 tmp
= session_find_by_name(SESSION1
);
275 /* Basic init session values */
276 assert(tmp
->kernel_session
== NULL
);
277 assert(strlen(tmp
->path
));
278 assert(strlen(tmp
->name
));
284 printf("Destroy 1 session %s: ", SESSION1
);
286 ret
= destroy_one_session(tmp
);
292 printf("Two session with same name: ");
294 ret
= two_session_same_name();
300 empty_session_list();
302 printf("Fuzzing create_session arguments: ");
304 ret
= fuzzing_create_args();
310 printf("Fuzzing destroy_session argument: ");
312 ret
= fuzzing_destroy_args();
318 printf("Creating %d sessions: ", MAX_SESSIONS
);
320 for (i
= 0; i
< MAX_SESSIONS
; i
++) {
321 char *tmp_name
= get_random_string();
323 ret
= create_one_session(tmp_name
, PATH1
);
325 printf("session %d (name: %s) creation failed\n", i
, tmp_name
);
329 if ((i
% 1000) == 0) {
330 fprintf(stdout
, "%d..", i
);
336 printf("Destroying %d sessions: ", MAX_SESSIONS
);
338 for (i
= 0; i
< MAX_SESSIONS
; i
++) {
339 cds_list_for_each_entry_safe(iter
, tmp
, &session_list
->head
, list
) {
340 ret
= destroy_one_session(iter
);
342 printf("session %d (name: %s) creation failed\n", i
, iter
->name
);
349 /* Session list must be 0 */
350 assert(!session_list_count());
This page took 0.037289 seconds and 4 git commands to generate.