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>
29 #include "ltt-sessiond/session.h"
32 #define SESSION1 "test1"
34 /* This path will NEVER be created in this test */
35 #define PATH1 "/tmp/.test-junk-lttng"
37 #define MAX_SESSIONS 10000
40 * String of 263 caracters. NAME_MAX + "OVERFLOW". If OVERFLOW appears in the
41 * session name, we have a problem.
45 #define OVERFLOW_SESSION_NAME \
46 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \
47 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \
48 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \
49 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc" \
52 static struct ltt_session_list
*session_list
;
58 static const char alphanum
[] =
60 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
61 "abcdefghijklmnopqrstuvwxyz";
64 * Return random string of 10 characters.
66 static char *get_random_string(void)
69 char *str
= malloc(11);
71 for (i
= 0; i
< 10; i
++) {
72 str
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
81 * Return 0 if session name is found, else -1
83 static int find_session_name(char *name
)
85 struct ltt_session
*iter
;
87 cds_list_for_each_entry(iter
, &session_list
->head
, list
) {
88 if (strcmp(iter
->name
, name
) == 0) {
97 * Empty session list manually.
99 static void empty_session_list(void)
101 struct ltt_session
*iter
, *tmp
;
103 cds_list_for_each_entry_safe(iter
, tmp
, &session_list
->head
, list
) {
104 cds_list_del(&iter
->list
);
105 session_list
->count
--;
109 /* Session list must be 0 */
110 assert(!session_list
->count
);
114 * Test creation of 1 session
116 static int create_one_session(char *name
, char *path
)
120 ret
= session_create(name
, path
);
121 if (ret
== LTTCOMM_OK
) {
123 ret
= find_session_name(name
);
125 /* Session not found by name */
126 printf("session not found after creation\n");
133 if (ret
== LTTCOMM_EXIST_SESS
) {
134 printf("(session already exists) ");
143 * Test deletion of 1 session
145 static int destroy_one_session(struct ltt_session
*session
)
149 ret
= session_destroy(session
);
151 if (ret
== LTTCOMM_OK
) {
153 if (session
== NULL
) {
156 ret
= find_session_name(session
->name
);
158 /* Success, -1 means that the sesion is NOT found */
169 static int fuzzing_create_args(void)
173 ret
= create_one_session(NULL
, NULL
);
175 printf("Session created with (null),(null)\n");
179 ret
= create_one_session(NULL
, PATH1
);
181 printf("Session created with (null), %s)\n", PATH1
);
185 ret
= create_one_session(SESSION1
, NULL
);
187 printf("Session created with %s, (null)\n", SESSION1
);
191 /* Session list must be 0 */
192 assert(!session_list
->count
);
197 static int fuzzing_destroy_args(void)
201 ret
= destroy_one_session(NULL
);
203 printf("Session destroyed with (null)\n");
207 /* Session list must be 0 */
208 assert(!session_list
->count
);
214 * This test is supposed to fail at the second create call. If so, return 0 for
215 * test success, else -1.
217 static int two_session_same_name(void)
221 ret
= create_one_session(SESSION1
, PATH1
);
227 ret
= create_one_session(SESSION1
, PATH1
);
237 int main(int argc
, char **argv
)
241 struct ltt_session
*iter
, *tmp
;
245 printf("\nTesting Sessions:\n-----------\n");
247 session_list
= session_get_list();
248 if (session_list
== NULL
) {
252 printf("Create 1 session %s: ", SESSION1
);
253 ret
= create_one_session(SESSION1
, PATH1
);
259 printf("Validating created session %s: ", SESSION1
);
260 tmp
= session_find_by_name(SESSION1
);
264 /* Basic init session values */
265 assert(tmp
->kernel_session
== NULL
);
266 assert(tmp
->ust_session_list
.count
== 0);
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.070752 seconds and 5 git commands to generate.