3e45c21b669563846e41dbfd0e624496cf95b9df
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.
28 #include <lttng-sessiond-comm.h>
30 #include <lttng-sessiond/session.h>
33 #define SESSION1 "test1"
35 /* This path will NEVER be created in this test */
36 #define PATH1 "/tmp/.test-junk-lttng"
38 #define MAX_SESSIONS 10000
41 * String of 263 caracters. NAME_MAX + "OVERFLOW". If OVERFLOW appears in the
42 * session name, we have a problem.
46 #define OVERFLOW_SESSION_NAME \
47 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \
48 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \
49 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \
50 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc" \
53 static struct ltt_session_list
*session_list
;
59 static const char alphanum
[] =
61 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
62 "abcdefghijklmnopqrstuvwxyz";
65 * Return random string of 10 characters.
67 static char *get_random_string(void)
70 char *str
= malloc(11);
72 for (i
= 0; i
< 10; i
++) {
73 str
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
82 * Return 0 if session name is found, else -1
84 static int find_session_name(char *name
)
86 struct ltt_session
*iter
;
88 cds_list_for_each_entry(iter
, &session_list
->head
, list
) {
89 if (strcmp(iter
->name
, name
) == 0) {
98 * Empty session list manually.
100 static void empty_session_list(void)
102 struct ltt_session
*iter
, *tmp
;
104 cds_list_for_each_entry_safe(iter
, tmp
, &session_list
->head
, list
) {
105 cds_list_del(&iter
->list
);
106 session_list
->count
--;
110 /* Session list must be 0 */
111 assert(!session_list
->count
);
115 * Test creation of 1 session
117 static int create_one_session(char *name
, char *path
)
121 ret
= session_create(name
, path
);
122 if (ret
== LTTCOMM_OK
) {
124 ret
= find_session_name(name
);
126 /* Session not found by name */
127 printf("session not found after creation\n");
134 if (ret
== LTTCOMM_EXIST_SESS
) {
135 printf("(session already exists) ");
144 * Test deletion of 1 session
146 static int destroy_one_session(struct ltt_session
*session
)
150 ret
= session_destroy(session
);
152 if (ret
== LTTCOMM_OK
) {
154 if (session
== NULL
) {
157 ret
= find_session_name(session
->name
);
159 /* Success, -1 means that the sesion is NOT found */
170 static int fuzzing_create_args(void)
174 ret
= create_one_session(NULL
, NULL
);
176 printf("Session created with (null),(null)\n");
180 ret
= create_one_session(NULL
, PATH1
);
182 printf("Session created with (null), %s)\n", PATH1
);
186 ret
= create_one_session(SESSION1
, NULL
);
188 printf("Session created with %s, (null)\n", SESSION1
);
192 /* Session list must be 0 */
193 assert(!session_list
->count
);
198 static int fuzzing_destroy_args(void)
202 ret
= destroy_one_session(NULL
);
204 printf("Session destroyed with (null)\n");
208 /* Session list must be 0 */
209 assert(!session_list
->count
);
215 * This test is supposed to fail at the second create call. If so, return 0 for
216 * test success, else -1.
218 static int two_session_same_name(void)
222 ret
= create_one_session(SESSION1
, PATH1
);
228 ret
= create_one_session(SESSION1
, PATH1
);
238 int main(int argc
, char **argv
)
242 struct ltt_session
*iter
, *tmp
;
246 printf("\nTesting Sessions:\n-----------\n");
248 session_list
= session_get_list();
249 if (session_list
== NULL
) {
253 printf("Create 1 session %s: ", SESSION1
);
254 ret
= create_one_session(SESSION1
, PATH1
);
260 printf("Validating created session %s: ", SESSION1
);
261 tmp
= session_find_by_name(SESSION1
);
265 /* Basic init session values */
266 assert(tmp
->kernel_session
== NULL
);
267 assert(strlen(tmp
->path
));
268 assert(strlen(tmp
->name
));
274 printf("Destroy 1 session %s: ", SESSION1
);
275 ret
= destroy_one_session(tmp
);
281 printf("Two session with same name: ");
282 ret
= two_session_same_name();
288 empty_session_list();
290 printf("Fuzzing create_session arguments: ");
291 ret
= fuzzing_create_args();
297 printf("Fuzzing destroy_session argument: ");
298 ret
= fuzzing_destroy_args();
304 printf("Creating %d sessions: ", MAX_SESSIONS
);
305 for (i
= 0; i
< MAX_SESSIONS
; i
++) {
306 tmp_name
= get_random_string();
307 ret
= create_one_session(tmp_name
, PATH1
);
309 printf("session %d (name: %s) creation failed\n", i
, tmp_name
);
316 printf("Destroying %d sessions: ", MAX_SESSIONS
);
317 for (i
= 0; i
< MAX_SESSIONS
; i
++) {
318 cds_list_for_each_entry_safe(iter
, tmp
, &session_list
->head
, list
) {
319 ret
= destroy_one_session(iter
);
321 printf("session %d (name: %s) creation failed\n", i
, iter
->name
);
328 /* Session list must be 0 */
329 assert(!session_list
->count
);
This page took 0.036234 seconds and 3 git commands to generate.