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 <lttng-sessiond-comm.h>
31 #include <lttng-sessiond/session.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
42 * String of 263 caracters. NAME_MAX + "OVERFLOW". If OVERFLOW appears in the
43 * session name, we have a problem.
47 #define OVERFLOW_SESSION_NAME \
48 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \
49 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \
50 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \
51 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc" \
54 static struct ltt_session_list
*session_list
;
60 static const char alphanum
[] =
62 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
63 "abcdefghijklmnopqrstuvwxyz";
66 * Return random string of 10 characters.
68 static char *get_random_string(void)
71 char *str
= malloc(11);
73 for (i
= 0; i
< 10; i
++) {
74 str
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
83 * Return 0 if session name is found, else -1
85 static int find_session_name(char *name
)
87 struct ltt_session
*iter
;
89 cds_list_for_each_entry(iter
, &session_list
->head
, list
) {
90 if (strcmp(iter
->name
, name
) == 0) {
99 * Empty session list manually.
101 static void empty_session_list(void)
103 struct ltt_session
*iter
, *tmp
;
105 cds_list_for_each_entry_safe(iter
, tmp
, &session_list
->head
, list
) {
106 cds_list_del(&iter
->list
);
107 session_list
->count
--;
111 /* Session list must be 0 */
112 assert(!session_list
->count
);
116 * Test creation of 1 session
118 static int create_one_session(char *name
, char *path
)
122 ret
= session_create(name
, path
, geteuid(), getegid());
123 if (ret
== LTTCOMM_OK
) {
125 ret
= find_session_name(name
);
127 /* Session not found by name */
128 printf("session not found after creation\n");
135 if (ret
== LTTCOMM_EXIST_SESS
) {
136 printf("(session already exists) ");
145 * Test deletion of 1 session
147 static int destroy_one_session(struct ltt_session
*session
)
151 ret
= session_destroy(session
);
153 if (ret
== LTTCOMM_OK
) {
155 if (session
== NULL
) {
158 ret
= find_session_name(session
->name
);
160 /* Success, -1 means that the sesion is NOT found */
171 static int fuzzing_create_args(void)
175 ret
= create_one_session(NULL
, NULL
);
177 printf("Session created with (null),(null)\n");
181 ret
= create_one_session(NULL
, PATH1
);
183 printf("Session created with (null), %s)\n", PATH1
);
187 ret
= create_one_session(SESSION1
, NULL
);
189 printf("Session created with %s, (null)\n", SESSION1
);
193 /* Session list must be 0 */
194 assert(!session_list
->count
);
199 static int fuzzing_destroy_args(void)
203 ret
= destroy_one_session(NULL
);
205 printf("Session destroyed with (null)\n");
209 /* Session list must be 0 */
210 assert(!session_list
->count
);
216 * This test is supposed to fail at the second create call. If so, return 0 for
217 * test success, else -1.
219 static int two_session_same_name(void)
223 ret
= create_one_session(SESSION1
, PATH1
);
229 ret
= create_one_session(SESSION1
, PATH1
);
239 int main(int argc
, char **argv
)
243 struct ltt_session
*iter
, *tmp
;
247 printf("\nTesting Sessions:\n-----------\n");
249 session_list
= session_get_list();
250 if (session_list
== NULL
) {
254 printf("Create 1 session %s: ", SESSION1
);
256 ret
= create_one_session(SESSION1
, PATH1
);
262 printf("Validating created session %s: ", SESSION1
);
264 tmp
= session_find_by_name(SESSION1
);
268 /* Basic init session values */
269 assert(tmp
->kernel_session
== NULL
);
270 assert(strlen(tmp
->path
));
271 assert(strlen(tmp
->name
));
277 printf("Destroy 1 session %s: ", SESSION1
);
279 ret
= destroy_one_session(tmp
);
285 printf("Two session with same name: ");
287 ret
= two_session_same_name();
293 empty_session_list();
295 printf("Fuzzing create_session arguments: ");
297 ret
= fuzzing_create_args();
303 printf("Fuzzing destroy_session argument: ");
305 ret
= fuzzing_destroy_args();
311 printf("Creating %d sessions: ", MAX_SESSIONS
);
313 for (i
= 0; i
< MAX_SESSIONS
; i
++) {
314 tmp_name
= get_random_string();
315 ret
= create_one_session(tmp_name
, PATH1
);
317 printf("session %d (name: %s) creation failed\n", i
, tmp_name
);
324 printf("Destroying %d sessions: ", MAX_SESSIONS
);
326 for (i
= 0; i
< MAX_SESSIONS
; i
++) {
327 cds_list_for_each_entry_safe(iter
, tmp
, &session_list
->head
, list
) {
328 ret
= destroy_one_session(iter
);
330 printf("session %d (name: %s) creation failed\n", i
, iter
->name
);
337 /* Session list must be 0 */
338 assert(!session_list
->count
);
This page took 0.047436 seconds and 4 git commands to generate.