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 <bin/lttng-sessiond/ust-app.h>
33 #include <common/sessiond-comm/sessiond-comm.h>
34 #include <common/common.h>
36 #define SESSION1 "test1"
38 #define MAX_SESSIONS 10000
39 #define RANDOM_STRING_LEN 11
41 /* Number of TAP tests in this file */
44 static struct ltt_session_list
*session_list
;
47 int lttng_opt_quiet
= 1;
48 int lttng_opt_verbose
= 0;
51 int ust_consumerd32_fd
;
52 int ust_consumerd64_fd
;
54 static const char alphanum
[] =
56 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
57 "abcdefghijklmnopqrstuvwxyz";
58 static char random_string
[RANDOM_STRING_LEN
];
61 * Return random string of 10 characters.
64 static char *get_random_string(void)
68 for (i
= 0; i
< RANDOM_STRING_LEN
- 1; i
++) {
69 random_string
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
72 random_string
[RANDOM_STRING_LEN
- 1] = '\0';
78 * Return 0 if session name is found, else -1
80 static int find_session_name(char *name
)
82 struct ltt_session
*iter
;
84 cds_list_for_each_entry(iter
, &session_list
->head
, list
) {
85 if (strcmp(iter
->name
, name
) == 0) {
93 static int session_list_count(void)
96 struct ltt_session
*iter
;
98 cds_list_for_each_entry(iter
, &session_list
->head
, list
) {
105 * Empty session list manually.
107 static void empty_session_list(void)
109 struct ltt_session
*iter
, *tmp
;
111 cds_list_for_each_entry_safe(iter
, tmp
, &session_list
->head
, list
) {
112 cds_list_del(&iter
->list
);
116 /* Session list must be 0 */
117 assert(!session_list_count());
121 * Test creation of 1 session
123 static int create_one_session(char *name
)
127 ret
= session_create(name
, geteuid(), getegid());
128 if (ret
== LTTNG_OK
) {
130 ret
= find_session_name(name
);
132 /* Session not found by name */
133 printf("session not found after creation\n");
140 if (ret
== LTTNG_ERR_EXIST_SESS
) {
141 printf("(session already exists) ");
150 * Test deletion of 1 session
152 static int destroy_one_session(struct ltt_session
*session
)
155 char session_name
[NAME_MAX
];
157 strncpy(session_name
, session
->name
, sizeof(session
->name
));
158 session_name
[sizeof(session_name
) - 1] = '\0';
160 ret
= session_destroy(session
);
161 if (ret
== LTTNG_OK
) {
162 ret
= find_session_name(session_name
);
164 /* Success, -1 means that the sesion is NOT found */
176 * This test is supposed to fail at the second create call. If so, return 0 for
177 * test success, else -1.
179 static int two_session_same_name(void)
182 struct ltt_session
*sess
;
184 ret
= create_one_session(SESSION1
);
190 sess
= session_find_by_name(SESSION1
);
200 void test_session_list(void)
202 session_list
= session_get_list();
203 ok(session_list
!= NULL
, "Session list: not NULL");
206 void test_create_one_session(void)
208 ok(create_one_session(SESSION1
) == 0,
209 "Create session: %s",
213 void test_validate_session(void)
215 struct ltt_session
*tmp
;
217 tmp
= session_find_by_name(SESSION1
);
220 "Validating session: session found");
222 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
) < 0,
253 "Create session with bogus param: NULL should fail");
255 ok(session_list_count() == 0,
256 "Create session with bogus param: session list empty");
259 void test_large_session_number(void)
261 int ret
, i
, failed
= 0;
262 struct ltt_session
*iter
, *tmp
;
264 for (i
= 0; i
< MAX_SESSIONS
; i
++) {
265 char *tmp_name
= get_random_string();
266 ret
= create_one_session(tmp_name
);
268 diag("session %d (name: %s) creation failed", i
, tmp_name
);
274 "Large sessions number: created %u sessions",
279 for (i
= 0; i
< MAX_SESSIONS
; i
++) {
280 cds_list_for_each_entry_safe(iter
, tmp
, &session_list
->head
, list
) {
281 ret
= destroy_one_session(iter
);
283 diag("session %d destroy failed", i
);
289 ok(failed
== 0 && session_list_count() == 0,
290 "Large sessions number: destroyed %u sessions",
294 int main(int argc
, char **argv
)
296 plan_tests(NUM_TESTS
);
298 diag("Sessions unit tests");
302 test_create_one_session();
304 test_validate_session();
306 test_destroy_session();
308 test_duplicate_session();
310 empty_session_list();
312 test_bogus_session_param();
314 test_large_session_number();
316 return exit_status();
This page took 0.036815 seconds and 5 git commands to generate.