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 <bin/lttng-sessiond/session.h>
30 #include <common/sessiond-comm/sessiond-comm.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
40 #define RANDOM_STRING_LEN 11
43 * String of 263 caracters. NAME_MAX + "OVERFLOW". If OVERFLOW appears in the
44 * session name, we have a problem.
48 #define OVERFLOW_SESSION_NAME \
49 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \
50 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \
51 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \
52 "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc" \
55 static struct ltt_session_list
*session_list
;
58 int lttng_opt_quiet
= 1;
59 int lttng_opt_verbose
= 0;
61 static const char alphanum
[] =
63 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
64 "abcdefghijklmnopqrstuvwxyz";
65 static char random_string
[RANDOM_STRING_LEN
];
68 * Return random string of 10 characters.
71 static char *get_random_string(void)
75 for (i
= 0; i
< RANDOM_STRING_LEN
- 1; i
++) {
76 random_string
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
79 random_string
[RANDOM_STRING_LEN
- 1] = '\0';
85 * Return 0 if session name is found, else -1
87 static int find_session_name(char *name
)
89 struct ltt_session
*iter
;
91 cds_list_for_each_entry(iter
, &session_list
->head
, list
) {
92 if (strcmp(iter
->name
, name
) == 0) {
100 static int session_list_count(void)
103 struct ltt_session
*iter
;
105 cds_list_for_each_entry(iter
, &session_list
->head
, list
) {
112 * Empty session list manually.
114 static void empty_session_list(void)
116 struct ltt_session
*iter
, *tmp
;
118 cds_list_for_each_entry_safe(iter
, tmp
, &session_list
->head
, list
) {
119 cds_list_del(&iter
->list
);
123 /* Session list must be 0 */
124 assert(!session_list_count());
128 * Test creation of 1 session
130 static int create_one_session(char *name
, char *path
)
134 ret
= session_create(name
, path
, geteuid(), getegid());
135 if (ret
== LTTCOMM_OK
) {
137 ret
= find_session_name(name
);
139 /* Session not found by name */
140 printf("session not found after creation\n");
147 if (ret
== LTTCOMM_EXIST_SESS
) {
148 printf("(session already exists) ");
157 * Test deletion of 1 session
159 static int destroy_one_session(struct ltt_session
*session
)
163 ret
= session_destroy(session
);
165 if (ret
== LTTCOMM_OK
) {
167 if (session
== NULL
) {
170 ret
= find_session_name(session
->name
);
172 /* Success, -1 means that the sesion is NOT found */
183 static int fuzzing_create_args(void)
187 ret
= create_one_session(NULL
, NULL
);
189 printf("Session created with (null),(null)\n");
193 ret
= create_one_session(NULL
, PATH1
);
195 printf("Session created with (null), %s)\n", PATH1
);
199 /* Session list must be 0 */
200 assert(!session_list_count());
205 static int fuzzing_destroy_args(void)
209 ret
= destroy_one_session(NULL
);
211 printf("Session destroyed with (null)\n");
215 /* Session list must be 0 */
216 assert(!session_list_count());
222 * This test is supposed to fail at the second create call. If so, return 0 for
223 * test success, else -1.
225 static int two_session_same_name(void)
228 struct ltt_session
*sess
;
230 ret
= create_one_session(SESSION1
, PATH1
);
236 sess
= session_find_by_name(SESSION1
);
246 int main(int argc
, char **argv
)
249 struct ltt_session
*iter
, *tmp
;
253 printf("\nTesting Sessions:\n-----------\n");
255 session_list
= session_get_list();
256 if (session_list
== NULL
) {
260 printf("Create 1 session %s: ", SESSION1
);
262 ret
= create_one_session(SESSION1
, PATH1
);
268 printf("Validating created session %s: ", SESSION1
);
270 tmp
= session_find_by_name(SESSION1
);
274 /* Basic init session values */
275 assert(tmp
->kernel_session
== NULL
);
276 assert(strlen(tmp
->path
));
277 assert(strlen(tmp
->name
));
283 printf("Destroy 1 session %s: ", SESSION1
);
285 ret
= destroy_one_session(tmp
);
291 printf("Two session with same name: ");
293 ret
= two_session_same_name();
299 empty_session_list();
301 printf("Fuzzing create_session arguments: ");
303 ret
= fuzzing_create_args();
309 printf("Fuzzing destroy_session argument: ");
311 ret
= fuzzing_destroy_args();
317 printf("Creating %d sessions: ", MAX_SESSIONS
);
319 for (i
= 0; i
< MAX_SESSIONS
; i
++) {
320 char *tmp_name
= get_random_string();
322 ret
= create_one_session(tmp_name
, PATH1
);
324 printf("session %d (name: %s) creation failed\n", i
, tmp_name
);
328 if ((i
% 1000) == 0) {
329 fprintf(stdout
, "%d..", i
);
335 printf("Destroying %d sessions: ", MAX_SESSIONS
);
337 for (i
= 0; i
< MAX_SESSIONS
; i
++) {
338 cds_list_for_each_entry_safe(iter
, tmp
, &session_list
->head
, list
) {
339 ret
= destroy_one_session(iter
);
341 printf("session %d (name: %s) creation failed\n", i
, iter
->name
);
348 /* Session list must be 0 */
349 assert(!session_list_count());
This page took 0.035586 seconds and 4 git commands to generate.