X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=tests%2Ftest_sessions.c;h=5faf64f27f7d60ea27176a6da17ed4d1808a60b6;hp=f99d2a462d6f69999c1bce5a2f0ebd14f7b94eb3;hb=c9e326131856d96e03bc19f74e4ea39709b52ae5;hpb=0177d773712c6d6b11e395708ae2cc686d6917a4 diff --git a/tests/test_sessions.c b/tests/test_sessions.c index f99d2a462..5faf64f27 100644 --- a/tests/test_sessions.c +++ b/tests/test_sessions.c @@ -24,8 +24,11 @@ #include #include #include +#include + +#include +#include -#include "ltt-sessiond/session.h" #include "utils.h" #define SESSION1 "test1" @@ -34,6 +37,7 @@ #define PATH1 "/tmp/.test-junk-lttng" #define MAX_SESSIONS 10000 +#define RANDOM_STRING_LEN 11 /* * String of 263 caracters. NAME_MAX + "OVERFLOW". If OVERFLOW appears in the @@ -58,22 +62,23 @@ static const char alphanum[] = "0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"; +static char random_string[RANDOM_STRING_LEN]; /* * Return random string of 10 characters. + * Not thread-safe. */ static char *get_random_string(void) { int i; - char *str = malloc(11); - for (i = 0; i < 10; i++) { - str[i] = alphanum[rand() % (sizeof(alphanum) - 1)]; + for (i = 0; i < RANDOM_STRING_LEN - 1; i++) { + random_string[i] = alphanum[rand() % (sizeof(alphanum) - 1)]; } - str[10] = '\0'; + random_string[RANDOM_STRING_LEN - 1] = '\0'; - return str; + return random_string; } /* @@ -116,8 +121,8 @@ static int create_one_session(char *name, char *path) { int ret; - ret = create_session(name, path); - if (ret >= 0) { + ret = session_create(name, path, geteuid(), getegid()); + if (ret == LTTCOMM_OK) { /* Validate */ ret = find_session_name(name); if (ret < 0) { @@ -128,8 +133,8 @@ static int create_one_session(char *name, char *path) /* Success */ return 0; } - } else if (ret < 0) { - if (ret == -EEXIST) { + } else { + if (ret == LTTCOMM_EXIST_SESS) { printf("(session already exists) "); } return -1; @@ -141,14 +146,18 @@ static int create_one_session(char *name, char *path) /* * Test deletion of 1 session */ -static int destroy_one_session(char *name) +static int destroy_one_session(struct ltt_session *session) { int ret; - ret = destroy_session(name); - if (ret == 1) { + ret = session_destroy(session); + + if (ret == LTTCOMM_OK) { /* Validate */ - ret = find_session_name(name); + if (session == NULL) { + return 0; + } + ret = find_session_name(session->name); if (ret < 0) { /* Success, -1 means that the sesion is NOT found */ return 0; @@ -156,11 +165,6 @@ static int destroy_one_session(char *name) /* Fail */ return -1; } - } else if (ret < 0) { - if (ret == -EEXIST) { - printf("(session already exists) "); - } - return -1; } return 0; @@ -171,19 +175,19 @@ static int fuzzing_create_args(void) int ret; ret = create_one_session(NULL, NULL); - if (ret >= 0) { + if (ret > 0) { printf("Session created with (null),(null)\n"); return -1; } ret = create_one_session(NULL, PATH1); - if (ret >= 0) { + if (ret > 0) { printf("Session created with (null), %s)\n", PATH1); return -1; } ret = create_one_session(SESSION1, NULL); - if (ret >= 0) { + if (ret > 0) { printf("Session created with %s, (null)\n", SESSION1); return -1; } @@ -199,17 +203,11 @@ static int fuzzing_destroy_args(void) int ret; ret = destroy_one_session(NULL); - if (ret >= 0) { + if (ret > 0) { printf("Session destroyed with (null)\n"); return -1; } - ret = destroy_one_session(OVERFLOW_SESSION_NAME); - if (ret >= 0) { - printf("Session destroyed with %s\n", OVERFLOW_SESSION_NAME); - return -1; - } - /* Session list must be 0 */ assert(!session_list->count); @@ -243,19 +241,19 @@ static int two_session_same_name(void) int main(int argc, char **argv) { int ret, i; - char *tmp_name; struct ltt_session *iter, *tmp; srand(time(NULL)); printf("\nTesting Sessions:\n-----------\n"); - session_list = get_session_list(); + session_list = session_get_list(); if (session_list == NULL) { return -1; } printf("Create 1 session %s: ", SESSION1); + fflush(stdout); ret = create_one_session(SESSION1, PATH1); if (ret < 0) { return -1; @@ -263,28 +261,30 @@ int main(int argc, char **argv) PRINT_OK(); printf("Validating created session %s: ", SESSION1); - tmp = find_session_by_name(SESSION1); + fflush(stdout); + tmp = session_find_by_name(SESSION1); if (tmp == NULL) { return -1; } /* Basic init session values */ assert(tmp->kernel_session == NULL); - assert(tmp->ust_session_list.count == 0); assert(strlen(tmp->path)); assert(strlen(tmp->name)); - lock_session(tmp); - unlock_session(tmp); + session_lock(tmp); + session_unlock(tmp); PRINT_OK(); printf("Destroy 1 session %s: ", SESSION1); - ret = destroy_one_session(SESSION1); + fflush(stdout); + ret = destroy_one_session(tmp); if (ret < 0) { return -1; } PRINT_OK(); printf("Two session with same name: "); + fflush(stdout); ret = two_session_same_name(); if (ret < 0) { return -1; @@ -294,6 +294,7 @@ int main(int argc, char **argv) empty_session_list(); printf("Fuzzing create_session arguments: "); + fflush(stdout); ret = fuzzing_create_args(); if (ret < 0) { return -1; @@ -301,6 +302,7 @@ int main(int argc, char **argv) PRINT_OK(); printf("Fuzzing destroy_session argument: "); + fflush(stdout); ret = fuzzing_destroy_args(); if (ret < 0) { return -1; @@ -308,21 +310,23 @@ int main(int argc, char **argv) PRINT_OK(); printf("Creating %d sessions: ", MAX_SESSIONS); + fflush(stdout); for (i = 0; i < MAX_SESSIONS; i++) { - tmp_name = get_random_string(); + char *tmp_name = get_random_string(); + ret = create_one_session(tmp_name, PATH1); if (ret < 0) { printf("session %d (name: %s) creation failed\n", i, tmp_name); return -1; } - free(tmp_name); } PRINT_OK(); printf("Destroying %d sessions: ", MAX_SESSIONS); + fflush(stdout); for (i = 0; i < MAX_SESSIONS; i++) { cds_list_for_each_entry_safe(iter, tmp, &session_list->head, list) { - ret = destroy_one_session(iter->name); + ret = destroy_one_session(iter); if (ret < 0) { printf("session %d (name: %s) creation failed\n", i, iter->name); return -1;