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>
31 #include <bin/lttng-sessiond/session.h>
32 #include <common/sessiond-comm/sessiond-comm.h>
33 #include <common/common.h>
35 #define SESSION1 "test1"
37 /* This path will NEVER be created in this test */
38 #define PATH1 "/tmp/.test-junk-lttng"
40 #define MAX_SESSIONS 10000
41 #define RANDOM_STRING_LEN 11
43 /* Number of TAP tests in this file */
46 static struct ltt_session_list
*session_list
;
49 int lttng_opt_quiet
= 1;
50 int lttng_opt_verbose
= 0;
52 static const char alphanum
[] =
54 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
55 "abcdefghijklmnopqrstuvwxyz";
56 static char random_string
[RANDOM_STRING_LEN
];
59 * Return random string of 10 characters.
62 static char *get_random_string(void)
66 for (i
= 0; i
< RANDOM_STRING_LEN
- 1; i
++) {
67 random_string
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
70 random_string
[RANDOM_STRING_LEN
- 1] = '\0';
76 * Return 0 if session name is found, else -1
78 static int find_session_name(char *name
)
80 struct ltt_session
*iter
;
82 cds_list_for_each_entry(iter
, &session_list
->head
, list
) {
83 if (strcmp(iter
->name
, name
) == 0) {
91 static int session_list_count(void)
94 struct ltt_session
*iter
;
96 cds_list_for_each_entry(iter
, &session_list
->head
, list
) {
103 * Empty session list manually.
105 static void empty_session_list(void)
107 struct ltt_session
*iter
, *tmp
;
109 cds_list_for_each_entry_safe(iter
, tmp
, &session_list
->head
, list
) {
110 cds_list_del(&iter
->list
);
114 /* Session list must be 0 */
115 assert(!session_list_count());
119 * Test creation of 1 session
121 static int create_one_session(char *name
, char *path
)
125 ret
= session_create(name
, path
, geteuid(), getegid());
126 if (ret
== LTTNG_OK
) {
128 ret
= find_session_name(name
);
130 /* Session not found by name */
131 printf("session not found after creation\n");
138 if (ret
== LTTNG_ERR_EXIST_SESS
) {
139 printf("(session already exists) ");
148 * Test deletion of 1 session
150 static int destroy_one_session(struct ltt_session
*session
)
154 ret
= session_destroy(session
);
156 if (ret
== LTTNG_OK
) {
158 if (session
== NULL
) {
161 ret
= find_session_name(session
->name
);
163 /* Success, -1 means that the sesion is NOT found */
175 * This test is supposed to fail at the second create call. If so, return 0 for
176 * test success, else -1.
178 static int two_session_same_name(void)
181 struct ltt_session
*sess
;
183 ret
= create_one_session(SESSION1
, PATH1
);
189 sess
= session_find_by_name(SESSION1
);
199 void test_session_list(void)
201 session_list
= session_get_list();
202 ok(session_list
!= NULL
, "Session list: not NULL");
205 void test_create_one_session(void)
207 ok(create_one_session(SESSION1
, PATH1
) == 0,
208 "Create session: %s",
212 void test_validate_session(void)
214 struct ltt_session
*tmp
;
216 tmp
= session_find_by_name(SESSION1
);
219 "Validating session: session found");
221 ok(tmp
->kernel_session
== NULL
&&
224 "Validating session: basic sanity check");
230 void test_destroy_session(void)
232 struct ltt_session
*tmp
;
234 tmp
= session_find_by_name(SESSION1
);
237 "Destroying session: session found");
239 ok(destroy_one_session(tmp
) == 0,
240 "Destroying session: %s destroyed",
244 void test_duplicate_session(void)
246 ok(two_session_same_name() == 0,
247 "Duplicate session creation");
250 void test_bogus_session_param(void)
252 ok(create_one_session(NULL
, NULL
) < 0,
253 "Create session with bogus param: NULL, NULL should fail");
255 ok(create_one_session(NULL
, PATH1
) < 0,
256 "Create session with bogus param: NULL, %s should fail",
259 ok(session_list_count() == 0,
260 "Create session with bogus param: session list empty");
263 void test_large_session_number(void)
265 int ret
, i
, failed
= 0;
266 struct ltt_session
*iter
, *tmp
;
268 for (i
= 0; i
< MAX_SESSIONS
; i
++) {
269 char *tmp_name
= get_random_string();
270 ret
= create_one_session(tmp_name
, PATH1
);
272 diag("session %d (name: %s) creation failed", i
, tmp_name
);
278 "Large sessions number: created %u sessions",
283 for (i
= 0; i
< MAX_SESSIONS
; i
++) {
284 cds_list_for_each_entry_safe(iter
, tmp
, &session_list
->head
, list
) {
285 ret
= destroy_one_session(iter
);
287 diag("session %d (name: %s) destroy failed", i
, iter
->name
);
293 ok(failed
== 0 && session_list_count() == 0,
294 "Large sessions number: destroyed %u sessions",
298 int main(int argc
, char **argv
)
300 diag("Sessions unit tests");
302 plan_tests(NUM_TESTS
);
306 test_create_one_session();
308 test_validate_session();
310 test_destroy_session();
312 test_duplicate_session();
314 empty_session_list();
316 test_bogus_session_param();
318 test_large_session_number();
320 return exit_status();
This page took 0.04972 seconds and 5 git commands to generate.