X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=tests%2Ftest_sessions.c;h=5b17e63911eeb8c45fdd05723978d79eae209313;hp=f3ffe6a43932d8b03ca8c833bcce7753b077da27;hb=daf282ab93462198c6acd16b4aa624635df1bea5;hpb=63371d1e4ff3148287a04e14b468c4234e3d0182 diff --git a/tests/test_sessions.c b/tests/test_sessions.c index f3ffe6a43..5b17e6391 100644 --- a/tests/test_sessions.c +++ b/tests/test_sessions.c @@ -24,8 +24,12 @@ #include #include #include +#include -#include "ltt-sessiond/session.h" +#include + +#include +#include "utils.h" #define SESSION1 "test1" @@ -115,8 +119,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) { @@ -127,8 +131,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; @@ -140,14 +144,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; @@ -155,11 +163,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; @@ -170,19 +173,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; } @@ -198,17 +201,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); @@ -249,64 +246,70 @@ int main(int argc, char **argv) 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; } - printf("Success\n"); + 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_trace_count == 0); assert(strlen(tmp->path)); assert(strlen(tmp->name)); - lock_session(tmp); - unlock_session(tmp); + session_lock(tmp); + session_unlock(tmp); - printf("Success\n"); + 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; } - printf("Success\n"); + PRINT_OK(); printf("Two session with same name: "); + fflush(stdout); ret = two_session_same_name(); if (ret < 0) { return -1; } - printf("Success\n"); + PRINT_OK(); empty_session_list(); printf("Fuzzing create_session arguments: "); + fflush(stdout); ret = fuzzing_create_args(); if (ret < 0) { return -1; } - printf("Success\n"); + PRINT_OK(); printf("Fuzzing destroy_session argument: "); + fflush(stdout); ret = fuzzing_destroy_args(); if (ret < 0) { return -1; } - printf("Success\n"); + PRINT_OK(); printf("Creating %d sessions: ", MAX_SESSIONS); + fflush(stdout); for (i = 0; i < MAX_SESSIONS; i++) { tmp_name = get_random_string(); ret = create_one_session(tmp_name, PATH1); @@ -316,19 +319,20 @@ int main(int argc, char **argv) } free(tmp_name); } - printf("Success\n"); + 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; } } } - printf("Success\n"); + PRINT_OK(); /* Session list must be 0 */ assert(!session_list->count);