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>
34 #define SESSION1 "test1"
36 /* This path will NEVER be created in this test */
37 #define PATH1 "/tmp/.test-junk-lttng"
39 #define MAX_SESSIONS 10000
40 #define RANDOM_STRING_LEN 11
43 * String of 263 caracters. NAME_MAX + "OVERFLOW". If OVERFLOW appears in the
44 * session name, we have a problem.
48 #define OVERFLOW_SESSION_NAME \
49 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \
50 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \
51 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \
52 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc" \
55 static struct ltt_session_list
*session_list
;
58 int lttng_opt_quiet
= 1;
59 int lttng_opt_verbose
= 0;
61 static const char alphanum
[] =
63 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
64 "abcdefghijklmnopqrstuvwxyz";
65 static char random_string
[RANDOM_STRING_LEN
];
68 * Return random string of 10 characters.
71 static char *get_random_string(void)
75 for (i
= 0; i
< RANDOM_STRING_LEN
- 1; i
++) {
76 random_string
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
79 random_string
[RANDOM_STRING_LEN
- 1] = '\0';
85 * Return 0 if session name is found, else -1
87 static int find_session_name(char *name
)
89 struct ltt_session
*iter
;
91 cds_list_for_each_entry(iter
, &session_list
->head
, list
) {
92 if (strcmp(iter
->name
, name
) == 0) {
101 * Empty session list manually.
103 static void empty_session_list(void)
105 struct ltt_session
*iter
, *tmp
;
107 cds_list_for_each_entry_safe(iter
, tmp
, &session_list
->head
, list
) {
108 cds_list_del(&iter
->list
);
109 session_list
->count
--;
113 /* Session list must be 0 */
114 assert(!session_list
->count
);
118 * Test creation of 1 session
120 static int create_one_session(char *name
, char *path
)
124 ret
= session_create(name
, path
, geteuid(), getegid());
125 if (ret
== LTTCOMM_OK
) {
127 ret
= find_session_name(name
);
129 /* Session not found by name */
130 printf("session not found after creation\n");
137 if (ret
== LTTCOMM_EXIST_SESS
) {
138 printf("(session already exists) ");
147 * Test deletion of 1 session
149 static int destroy_one_session(struct ltt_session
*session
)
153 ret
= session_destroy(session
);
155 if (ret
== LTTCOMM_OK
) {
157 if (session
== NULL
) {
160 ret
= find_session_name(session
->name
);
162 /* Success, -1 means that the sesion is NOT found */
173 static int fuzzing_create_args(void)
177 ret
= create_one_session(NULL
, NULL
);
179 printf("Session created with (null),(null)\n");
183 ret
= create_one_session(NULL
, PATH1
);
185 printf("Session created with (null), %s)\n", PATH1
);
189 ret
= create_one_session(SESSION1
, NULL
);
191 printf("Session created with %s, (null)\n", SESSION1
);
195 /* Session list must be 0 */
196 assert(!session_list
->count
);
201 static int fuzzing_destroy_args(void)
205 ret
= destroy_one_session(NULL
);
207 printf("Session destroyed with (null)\n");
211 /* Session list must be 0 */
212 assert(!session_list
->count
);
218 * This test is supposed to fail at the second create call. If so, return 0 for
219 * test success, else -1.
221 static int two_session_same_name(void)
225 ret
= create_one_session(SESSION1
, PATH1
);
231 ret
= create_one_session(SESSION1
, PATH1
);
241 int main(int argc
, char **argv
)
244 struct ltt_session
*iter
, *tmp
;
248 printf("\nTesting Sessions:\n-----------\n");
250 session_list
= session_get_list();
251 if (session_list
== NULL
) {
255 printf("Create 1 session %s: ", SESSION1
);
257 ret
= create_one_session(SESSION1
, PATH1
);
263 printf("Validating created session %s: ", SESSION1
);
265 tmp
= session_find_by_name(SESSION1
);
269 /* Basic init session values */
270 assert(tmp
->kernel_session
== NULL
);
271 assert(strlen(tmp
->path
));
272 assert(strlen(tmp
->name
));
278 printf("Destroy 1 session %s: ", SESSION1
);
280 ret
= destroy_one_session(tmp
);
286 printf("Two session with same name: ");
288 ret
= two_session_same_name();
294 empty_session_list();
296 printf("Fuzzing create_session arguments: ");
298 ret
= fuzzing_create_args();
304 printf("Fuzzing destroy_session argument: ");
306 ret
= fuzzing_destroy_args();
312 printf("Creating %d sessions: ", MAX_SESSIONS
);
314 for (i
= 0; i
< MAX_SESSIONS
; i
++) {
315 char *tmp_name
= get_random_string();
317 ret
= create_one_session(tmp_name
, PATH1
);
319 printf("session %d (name: %s) creation failed\n", i
, tmp_name
);
323 if ((i
% 1000) == 0) {
324 fprintf(stdout
, "%d..", i
);
330 printf("Destroying %d sessions: ", MAX_SESSIONS
);
332 for (i
= 0; i
< MAX_SESSIONS
; i
++) {
333 cds_list_for_each_entry_safe(iter
, tmp
, &session_list
->head
, list
) {
334 ret
= destroy_one_session(iter
);
336 printf("session %d (name: %s) creation failed\n", i
, iter
->name
);
343 /* Session list must be 0 */
344 assert(!session_list
->count
);
This page took 0.039659 seconds and 4 git commands to generate.