Fix: test: session list count cannot use "count" unique id
[lttng-tools.git] / tests / test_sessions.c
index f444e30438bb3aeff3a3d9ee54531788b40aeb79..c7dd32036655f4203619ebd735ef620d16dad40a 100644 (file)
@@ -37,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
 static struct ltt_session_list *session_list;
 
 /* For lttngerr.h */
-int opt_quiet = 1;
-int opt_verbose = 0;
+int lttng_opt_quiet = 1;
+int lttng_opt_verbose = 0;
 
 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;
 }
 
 /*
@@ -95,6 +97,17 @@ static int find_session_name(char *name)
        return -1;
 }
 
+static int session_list_count(void)
+{
+       int count = 0;
+       struct ltt_session *iter;
+
+       cds_list_for_each_entry(iter, &session_list->head, list) {
+               count++;
+       }
+       return count;
+}
+
 /*
  * Empty session list manually.
  */
@@ -104,12 +117,11 @@ static void empty_session_list(void)
 
        cds_list_for_each_entry_safe(iter, tmp, &session_list->head, list) {
                cds_list_del(&iter->list);
-               session_list->count--;
                free(iter);
        }
 
        /* Session list must be 0 */
-       assert(!session_list->count);
+       assert(!session_list_count());
 }
 
 /*
@@ -191,7 +203,7 @@ static int fuzzing_create_args(void)
        }
 
        /* Session list must be 0 */
-       assert(!session_list->count);
+       assert(!session_list_count());
 
        return 0;
 }
@@ -207,7 +219,7 @@ static int fuzzing_destroy_args(void)
        }
 
        /* Session list must be 0 */
-       assert(!session_list->count);
+       assert(!session_list_count());
 
        return 0;
 }
@@ -239,7 +251,6 @@ 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));
@@ -311,13 +322,18 @@ int main(int argc, char **argv)
        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();
 
@@ -335,7 +351,7 @@ int main(int argc, char **argv)
        PRINT_OK();
 
        /* Session list must be 0 */
-       assert(!session_list->count);
+       assert(!session_list_count());
 
        /* Success */
        return 0;
This page took 0.025549 seconds and 4 git commands to generate.