#include <string.h>
#include <unistd.h>
#include <time.h>
+#include <sys/types.h>
+
+#include <bin/lttng-sessiond/session.h>
+#include <common/sessiond-comm/sessiond-comm.h>
-#include "ltt-sessiond/session.h"
#include "utils.h"
#define SESSION1 "test1"
#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
"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;
}
/*
{
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) {
/* Success */
return 0;
}
- } else if (ret < 0) {
- if (ret == -EEXIST) {
+ } else {
+ if (ret == LTTCOMM_EXIST_SESS) {
printf("(session already exists) ");
}
return -1;
/*
* 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;
/* Fail */
return -1;
}
- } else if (ret < 0) {
- if (ret == -EEXIST) {
- printf("(session already exists) ");
- }
- return -1;
}
return 0;
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;
}
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);
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;
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;
empty_session_list();
printf("Fuzzing create_session arguments: ");
+ fflush(stdout);
ret = fuzzing_create_args();
if (ret < 0) {
return -1;
PRINT_OK();
printf("Fuzzing destroy_session argument: ");
+ fflush(stdout);
ret = fuzzing_destroy_args();
if (ret < 0) {
return -1;
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);
+
+ if ((i % 1000) == 0) {
+ fprintf(stdout, "%d..", i);
+ fflush(stdout);
+ }
}
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;