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 "ltt-sessiond/session.h"
31 #define SESSION1 "test1"
33 /* This path will NEVER be created in this test */
34 #define PATH1 "/tmp/.test-junk-lttng"
36 #define MAX_SESSIONS 10000
39 * String of 263 caracters. NAME_MAX + "OVERFLOW". If OVERFLOW appears in the
40 * session name, we have a problem.
44 #define OVERFLOW_SESSION_NAME \
45 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \
46 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \
47 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \
48 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc" \
51 static struct ltt_session_list
*session_list
;
57 static const char alphanum
[] =
59 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
60 "abcdefghijklmnopqrstuvwxyz";
63 * Return random string of 10 characters.
65 static char *get_random_string(void)
68 char *str
= malloc(11);
70 for (i
= 0; i
< 10; i
++) {
71 str
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
80 * Return 0 if session name is found, else -1
82 static int find_session_name(char *name
)
84 struct ltt_session
*iter
;
86 cds_list_for_each_entry(iter
, &session_list
->head
, list
) {
87 if (strcmp(iter
->name
, name
) == 0) {
96 * Empty session list manually.
98 static void empty_session_list(void)
100 struct ltt_session
*iter
, *tmp
;
102 cds_list_for_each_entry_safe(iter
, tmp
, &session_list
->head
, list
) {
103 cds_list_del(&iter
->list
);
104 session_list
->count
--;
108 /* Session list must be 0 */
109 assert(!session_list
->count
);
113 * Test creation of 1 session
115 static int create_one_session(char *name
, char *path
)
119 ret
= create_session(name
, path
);
122 ret
= find_session_name(name
);
124 /* Session not found by name */
125 printf("session not found after creation\n");
131 } else if (ret
< 0) {
132 if (ret
== -EEXIST
) {
133 printf("(session already exists) ");
142 * Test deletion of 1 session
144 static int destroy_one_session(char *name
)
148 ret
= destroy_session(name
);
151 ret
= find_session_name(name
);
153 /* Success, -1 means that the sesion is NOT found */
159 } else if (ret
< 0) {
160 if (ret
== -EEXIST
) {
161 printf("(session already exists) ");
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 ret
= destroy_one_session(OVERFLOW_SESSION_NAME
);
209 printf("Session destroyed with %s\n", OVERFLOW_SESSION_NAME
);
213 /* Session list must be 0 */
214 assert(!session_list
->count
);
220 * This test is supposed to fail at the second create call. If so, return 0 for
221 * test success, else -1.
223 static int two_session_same_name(void)
227 ret
= create_one_session(SESSION1
, PATH1
);
233 ret
= create_one_session(SESSION1
, PATH1
);
243 int main(int argc
, char **argv
)
247 struct ltt_session
*iter
, *tmp
;
251 printf("\nTesting Sessions:\n-----------\n");
253 session_list
= get_session_list();
254 if (session_list
== NULL
) {
258 printf("Create 1 session %s: ", SESSION1
);
259 ret
= create_one_session(SESSION1
, PATH1
);
265 printf("Validating created session %s: ", SESSION1
);
266 tmp
= find_session_by_name(SESSION1
);
270 /* Basic init session values */
271 assert(tmp
->kernel_session
== NULL
);
272 assert(tmp
->ust_trace_count
== 0);
273 assert(strlen(tmp
->path
));
274 assert(strlen(tmp
->name
));
280 printf("Destroy 1 session %s: ", SESSION1
);
281 ret
= destroy_one_session(SESSION1
);
287 printf("Two session with same name: ");
288 ret
= two_session_same_name();
294 empty_session_list();
296 printf("Fuzzing create_session arguments: ");
297 ret
= fuzzing_create_args();
303 printf("Fuzzing destroy_session argument: ");
304 ret
= fuzzing_destroy_args();
310 printf("Creating %d sessions: ", MAX_SESSIONS
);
311 for (i
= 0; i
< MAX_SESSIONS
; i
++) {
312 tmp_name
= get_random_string();
313 ret
= create_one_session(tmp_name
, PATH1
);
315 printf("session %d (name: %s) creation failed\n", i
, tmp_name
);
322 printf("Destroying %d sessions: ", MAX_SESSIONS
);
323 for (i
= 0; i
< MAX_SESSIONS
; i
++) {
324 cds_list_for_each_entry_safe(iter
, tmp
, &session_list
->head
, list
) {
325 ret
= destroy_one_session(iter
->name
);
327 printf("session %d (name: %s) creation failed\n", i
, iter
->name
);
334 /* Session list must be 0 */
335 assert(!session_list
->count
);
This page took 0.036394 seconds and 4 git commands to generate.