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.
26 #include <sys/types.h>
30 #include <bin/lttng-sessiond/session.h>
31 #include <bin/lttng-sessiond/ust-app.h>
32 #include <common/sessiond-comm/sessiond-comm.h>
33 #include <common/common.h>
35 #define SESSION1 "test1"
37 #define MAX_SESSIONS 10000
38 #define RANDOM_STRING_LEN 11
40 /* Number of TAP tests in this file */
43 static struct ltt_session_list
*session_list
;
46 int lttng_opt_quiet
= 1;
47 int lttng_opt_verbose
= 0;
50 int ust_consumerd32_fd
;
51 int ust_consumerd64_fd
;
53 static const char alphanum
[] =
55 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
56 "abcdefghijklmnopqrstuvwxyz";
57 static char random_string
[RANDOM_STRING_LEN
];
60 * Return random string of 10 characters.
63 static char *get_random_string(void)
67 for (i
= 0; i
< RANDOM_STRING_LEN
- 1; i
++) {
68 random_string
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
71 random_string
[RANDOM_STRING_LEN
- 1] = '\0';
77 * Return 0 if session name is found, else -1
79 static int find_session_name(char *name
)
81 struct ltt_session
*iter
;
83 cds_list_for_each_entry(iter
, &session_list
->head
, list
) {
84 if (strcmp(iter
->name
, name
) == 0) {
92 static int session_list_count(void)
95 struct ltt_session
*iter
;
97 cds_list_for_each_entry(iter
, &session_list
->head
, list
) {
104 * Empty session list manually.
106 static void empty_session_list(void)
108 struct ltt_session
*iter
, *tmp
;
110 cds_list_for_each_entry_safe(iter
, tmp
, &session_list
->head
, list
) {
111 session_destroy(iter
);
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
)
125 ret
= session_create(name
, 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
)
153 char session_name
[NAME_MAX
];
155 strncpy(session_name
, session
->name
, sizeof(session
->name
));
156 session_name
[sizeof(session_name
) - 1] = '\0';
158 ret
= session_destroy(session
);
159 if (ret
== LTTNG_OK
) {
160 ret
= find_session_name(session_name
);
162 /* Success, -1 means that the sesion is NOT found */
174 * This test is supposed to fail at the second create call. If so, return 0 for
175 * test success, else -1.
177 static int two_session_same_name(void)
180 struct ltt_session
*sess
;
182 ret
= create_one_session(SESSION1
);
188 sess
= session_find_by_name(SESSION1
);
198 void test_session_list(void)
200 session_list
= session_get_list();
201 ok(session_list
!= NULL
, "Session list: not NULL");
204 void test_create_one_session(void)
206 ok(create_one_session(SESSION1
) == 0,
207 "Create session: %s",
211 void test_validate_session(void)
213 struct ltt_session
*tmp
;
215 tmp
= session_find_by_name(SESSION1
);
218 "Validating session: session found");
220 ok(tmp
->kernel_session
== NULL
&&
222 "Validating session: basic sanity check");
228 void test_destroy_session(void)
230 struct ltt_session
*tmp
;
232 tmp
= session_find_by_name(SESSION1
);
235 "Destroying session: session found");
237 ok(destroy_one_session(tmp
) == 0,
238 "Destroying session: %s destroyed",
242 void test_duplicate_session(void)
244 ok(two_session_same_name() == 0,
245 "Duplicate session creation");
248 void test_bogus_session_param(void)
250 ok(create_one_session(NULL
) < 0,
251 "Create session with bogus param: NULL should fail");
253 ok(session_list_count() == 0,
254 "Create session with bogus param: session list empty");
257 void test_large_session_number(void)
259 int ret
, i
, failed
= 0;
260 struct ltt_session
*iter
, *tmp
;
262 for (i
= 0; i
< MAX_SESSIONS
; i
++) {
263 char *tmp_name
= get_random_string();
264 ret
= create_one_session(tmp_name
);
266 diag("session %d (name: %s) creation failed", i
, tmp_name
);
272 "Large sessions number: created %u sessions",
277 for (i
= 0; i
< MAX_SESSIONS
; i
++) {
278 cds_list_for_each_entry_safe(iter
, tmp
, &session_list
->head
, list
) {
279 ret
= destroy_one_session(iter
);
281 diag("session %d destroy failed", i
);
287 ok(failed
== 0 && session_list_count() == 0,
288 "Large sessions number: destroyed %u sessions",
292 int main(int argc
, char **argv
)
294 plan_tests(NUM_TESTS
);
296 diag("Sessions unit tests");
300 test_create_one_session();
302 test_validate_session();
304 test_destroy_session();
306 test_duplicate_session();
308 empty_session_list();
310 test_bogus_session_param();
312 test_large_session_number();
314 return exit_status();
This page took 0.040817 seconds and 4 git commands to generate.