f3ffe6a43932d8b03ca8c833bcce7753b077da27
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"
30 #define SESSION1 "test1"
32 /* This path will NEVER be created in this test */
33 #define PATH1 "/tmp/.test-junk-lttng"
35 #define MAX_SESSIONS 10000
38 * String of 263 caracters. NAME_MAX + "OVERFLOW". If OVERFLOW appears in the
39 * session name, we have a problem.
43 #define OVERFLOW_SESSION_NAME \
44 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \
45 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \
46 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \
47 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc" \
50 static struct ltt_session_list
*session_list
;
56 static const char alphanum
[] =
58 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
59 "abcdefghijklmnopqrstuvwxyz";
62 * Return random string of 10 characters.
64 static char *get_random_string(void)
67 char *str
= malloc(11);
69 for (i
= 0; i
< 10; i
++) {
70 str
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
79 * Return 0 if session name is found, else -1
81 static int find_session_name(char *name
)
83 struct ltt_session
*iter
;
85 cds_list_for_each_entry(iter
, &session_list
->head
, list
) {
86 if (strcmp(iter
->name
, name
) == 0) {
95 * Empty session list manually.
97 static void empty_session_list(void)
99 struct ltt_session
*iter
, *tmp
;
101 cds_list_for_each_entry_safe(iter
, tmp
, &session_list
->head
, list
) {
102 cds_list_del(&iter
->list
);
103 session_list
->count
--;
107 /* Session list must be 0 */
108 assert(!session_list
->count
);
112 * Test creation of 1 session
114 static int create_one_session(char *name
, char *path
)
118 ret
= create_session(name
, path
);
121 ret
= find_session_name(name
);
123 /* Session not found by name */
124 printf("session not found after creation\n");
130 } else if (ret
< 0) {
131 if (ret
== -EEXIST
) {
132 printf("(session already exists) ");
141 * Test deletion of 1 session
143 static int destroy_one_session(char *name
)
147 ret
= destroy_session(name
);
150 ret
= find_session_name(name
);
152 /* Success, -1 means that the sesion is NOT found */
158 } else if (ret
< 0) {
159 if (ret
== -EEXIST
) {
160 printf("(session already exists) ");
168 static int fuzzing_create_args(void)
172 ret
= create_one_session(NULL
, NULL
);
174 printf("Session created with (null),(null)\n");
178 ret
= create_one_session(NULL
, PATH1
);
180 printf("Session created with (null), %s)\n", PATH1
);
184 ret
= create_one_session(SESSION1
, NULL
);
186 printf("Session created with %s, (null)\n", SESSION1
);
190 /* Session list must be 0 */
191 assert(!session_list
->count
);
196 static int fuzzing_destroy_args(void)
200 ret
= destroy_one_session(NULL
);
202 printf("Session destroyed with (null)\n");
206 ret
= destroy_one_session(OVERFLOW_SESSION_NAME
);
208 printf("Session destroyed with %s\n", OVERFLOW_SESSION_NAME
);
212 /* Session list must be 0 */
213 assert(!session_list
->count
);
219 * This test is supposed to fail at the second create call. If so, return 0 for
220 * test success, else -1.
222 static int two_session_same_name(void)
226 ret
= create_one_session(SESSION1
, PATH1
);
232 ret
= create_one_session(SESSION1
, PATH1
);
242 int main(int argc
, char **argv
)
246 struct ltt_session
*iter
, *tmp
;
250 printf("\nTesting Sessions:\n-----------\n");
252 session_list
= get_session_list();
253 if (session_list
== NULL
) {
257 printf("Create 1 session %s: ", SESSION1
);
258 ret
= create_one_session(SESSION1
, PATH1
);
264 printf("Validating created session %s: ", SESSION1
);
265 tmp
= find_session_by_name(SESSION1
);
269 /* Basic init session values */
270 assert(tmp
->kernel_session
== NULL
);
271 assert(tmp
->ust_trace_count
== 0);
272 assert(strlen(tmp
->path
));
273 assert(strlen(tmp
->name
));
279 printf("Destroy 1 session %s: ", SESSION1
);
280 ret
= destroy_one_session(SESSION1
);
286 printf("Two session with same name: ");
287 ret
= two_session_same_name();
293 empty_session_list();
295 printf("Fuzzing create_session arguments: ");
296 ret
= fuzzing_create_args();
302 printf("Fuzzing destroy_session argument: ");
303 ret
= fuzzing_destroy_args();
309 printf("Creating %d sessions: ", MAX_SESSIONS
);
310 for (i
= 0; i
< MAX_SESSIONS
; i
++) {
311 tmp_name
= get_random_string();
312 ret
= create_one_session(tmp_name
, PATH1
);
314 printf("session %d (name: %s) creation failed\n", i
, tmp_name
);
321 printf("Destroying %d sessions: ", MAX_SESSIONS
);
322 for (i
= 0; i
< MAX_SESSIONS
; i
++) {
323 cds_list_for_each_entry_safe(iter
, tmp
, &session_list
->head
, list
) {
324 ret
= destroy_one_session(iter
->name
);
326 printf("session %d (name: %s) creation failed\n", i
, iter
->name
);
333 /* Session list must be 0 */
334 assert(!session_list
->count
);
This page took 0.034406 seconds and 3 git commands to generate.