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 /* This path will NEVER be created in this test */
39 #define PATH1 "/tmp/.test-junk-lttng"
41 #define MAX_SESSIONS 10000
42 #define RANDOM_STRING_LEN 11
44 /* Number of TAP tests in this file */
47 static struct ltt_session_list
*session_list
;
50 int lttng_opt_quiet
= 1;
51 int lttng_opt_verbose
= 0;
53 int ust_consumerd32_fd
;
54 int ust_consumerd64_fd
;
56 static const char alphanum
[] =
58 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
59 "abcdefghijklmnopqrstuvwxyz";
60 static char random_string
[RANDOM_STRING_LEN
];
63 * Return random string of 10 characters.
66 static char *get_random_string(void)
70 for (i
= 0; i
< RANDOM_STRING_LEN
- 1; i
++) {
71 random_string
[i
] = alphanum
[rand() % (sizeof(alphanum
) - 1)];
74 random_string
[RANDOM_STRING_LEN
- 1] = '\0';
80 * Return 0 if session name is found, else -1
82 static int find_session_name(char *name
)
84 struct ltt_session
*iter
;
86 cds_list_for_each_entry(iter
, &session_list
->head
, list
) {
87 if (strcmp(iter
->name
, name
) == 0) {
95 static int session_list_count(void)
98 struct ltt_session
*iter
;
100 cds_list_for_each_entry(iter
, &session_list
->head
, list
) {
107 * Empty session list manually.
109 static void empty_session_list(void)
111 struct ltt_session
*iter
, *tmp
;
113 cds_list_for_each_entry_safe(iter
, tmp
, &session_list
->head
, list
) {
114 cds_list_del(&iter
->list
);
118 /* Session list must be 0 */
119 assert(!session_list_count());
123 * Test creation of 1 session
125 static int create_one_session(char *name
, char *path
)
129 ret
= session_create(name
, path
, geteuid(), getegid());
130 if (ret
== LTTNG_OK
) {
132 ret
= find_session_name(name
);
134 /* Session not found by name */
135 printf("session not found after creation\n");
142 if (ret
== LTTNG_ERR_EXIST_SESS
) {
143 printf("(session already exists) ");
152 * Test deletion of 1 session
154 static int destroy_one_session(struct ltt_session
*session
)
158 ret
= session_destroy(session
);
160 if (ret
== LTTNG_OK
) {
162 if (session
== NULL
) {
165 ret
= find_session_name(session
->name
);
167 /* Success, -1 means that the sesion is NOT found */
179 * This test is supposed to fail at the second create call. If so, return 0 for
180 * test success, else -1.
182 static int two_session_same_name(void)
185 struct ltt_session
*sess
;
187 ret
= create_one_session(SESSION1
, PATH1
);
193 sess
= session_find_by_name(SESSION1
);
203 void test_session_list(void)
205 session_list
= session_get_list();
206 ok(session_list
!= NULL
, "Session list: not NULL");
209 void test_create_one_session(void)
211 ok(create_one_session(SESSION1
, PATH1
) == 0,
212 "Create session: %s",
216 void test_validate_session(void)
218 struct ltt_session
*tmp
;
220 tmp
= session_find_by_name(SESSION1
);
223 "Validating session: session found");
225 ok(tmp
->kernel_session
== NULL
&&
228 "Validating session: basic sanity check");
234 void test_destroy_session(void)
236 struct ltt_session
*tmp
;
238 tmp
= session_find_by_name(SESSION1
);
241 "Destroying session: session found");
243 ok(destroy_one_session(tmp
) == 0,
244 "Destroying session: %s destroyed",
248 void test_duplicate_session(void)
250 ok(two_session_same_name() == 0,
251 "Duplicate session creation");
254 void test_bogus_session_param(void)
256 ok(create_one_session(NULL
, NULL
) < 0,
257 "Create session with bogus param: NULL, NULL should fail");
259 ok(create_one_session(NULL
, PATH1
) < 0,
260 "Create session with bogus param: NULL, %s should fail",
263 ok(session_list_count() == 0,
264 "Create session with bogus param: session list empty");
267 void test_large_session_number(void)
269 int ret
, i
, failed
= 0;
270 struct ltt_session
*iter
, *tmp
;
272 for (i
= 0; i
< MAX_SESSIONS
; i
++) {
273 char *tmp_name
= get_random_string();
274 ret
= create_one_session(tmp_name
, PATH1
);
276 diag("session %d (name: %s) creation failed", i
, tmp_name
);
282 "Large sessions number: created %u sessions",
287 for (i
= 0; i
< MAX_SESSIONS
; i
++) {
288 cds_list_for_each_entry_safe(iter
, tmp
, &session_list
->head
, list
) {
289 ret
= destroy_one_session(iter
);
291 diag("session %d (name: %s) destroy failed", i
, iter
->name
);
297 ok(failed
== 0 && session_list_count() == 0,
298 "Large sessions number: destroyed %u sessions",
302 int main(int argc
, char **argv
)
304 plan_tests(NUM_TESTS
);
306 diag("Sessions unit tests");
310 test_create_one_session();
312 test_validate_session();
314 test_destroy_session();
316 test_duplicate_session();
318 empty_session_list();
320 test_bogus_session_param();
322 test_large_session_number();
324 return exit_status();
This page took 0.040296 seconds and 4 git commands to generate.