Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Ansi C declaration of the variables (at the beginning of the blocks)
[simgrid.git] / src / dynar_unit.c
index b7e9209..7c451b5 100644 (file)
@@ -8,17 +8,18 @@
 /* GENERATED FILE, DO NOT EDIT */
 /*******************************/
 
-# 623 "xbt/dynar.c" 
+# 728 "xbt/dynar.c" 
 
 #define NB_ELEM 5000
 
 XBT_LOG_EXTERNAL_CATEGORY(xbt_dyn);
 XBT_LOG_DEFAULT_CATEGORY(xbt_dyn);
 
-XBT_TEST_UNIT("int",test_dynar_int,"Dyars of integers") {
+XBT_TEST_UNIT("int",test_dynar_int,"Dynars of integers") {
    /* Vars_decl [doxygen cruft] */
    xbt_dynar_t d;
-   int i,cpt,cursor;
+   int i,cpt;
+   unsigned int cursor;
    int *iptr;
    
    xbt_test_add0("==== Traverse the empty dynar");
@@ -158,10 +159,13 @@ XBT_TEST_UNIT("int",test_dynar_int,"Dyars of integers") {
    xbt_dynar_free(&d);
    xbt_dynar_free(&d);
 }
-
-XBT_TEST_UNIT("double",test_dynar_double,"Dyars of doubles") {
+/*******************************************************************************/
+/*******************************************************************************/
+/*******************************************************************************/
+XBT_TEST_UNIT("double",test_dynar_double,"Dynars of doubles") {
    xbt_dynar_t d;
-   int cpt,cursor;
+   int cpt;
+   unsigned int cursor;
    double d1,d2;
    
    xbt_test_add0("==== Traverse the empty dynar");
@@ -276,15 +280,19 @@ static void free_string(void *d){
   free(*(void**)d);
 }
 
+/*******************************************************************************/
+/*******************************************************************************/
+/*******************************************************************************/
 XBT_TEST_UNIT("string",test_dynar_string,"Dyars of strings") {
    xbt_dynar_t d;
    int cpt;
+   unsigned int iter;
    char buf[1024];
    char *s1,*s2;
    
    xbt_test_add0("==== Traverse the empty dynar");
    d=xbt_dynar_new(sizeof(char *),&free_string);
-   xbt_dynar_foreach(d,cpt,s1){
+   xbt_dynar_foreach(d,iter,s1){
      xbt_test_assert0(FALSE,
                  "Damnit, there is something in the empty dynar");
    }
@@ -335,8 +343,8 @@ XBT_TEST_UNIT("string",test_dynar_string,"Dyars of strings") {
      xbt_dynar_unshift(d,&s1);
    }
    /* 2. Traverse the dynar with the macro */
-   xbt_dynar_foreach(d,cpt,s1) {
-     sprintf(buf,"%d",NB_ELEM - cpt -1);
+   xbt_dynar_foreach(d,iter,s1) {
+     sprintf(buf,"%d",NB_ELEM - iter -1);
      xbt_test_assert2 (!strcmp(buf,s1),
            "The retrieved value is not the same than the injected one (%s!=%s)",
               buf,s1);
@@ -413,6 +421,54 @@ XBT_TEST_UNIT("string",test_dynar_string,"Dyars of strings") {
    }
    xbt_dynar_free(&d); /* end_of_doxygen */
 }
+
+
+/*******************************************************************************/
+/*******************************************************************************/
+/*******************************************************************************/
+#include "xbt/synchro.h"
+static void pusher_f(void *a) {
+   xbt_dynar_t d=(xbt_dynar_t)a;
+   int i;
+   for (i=0; i<500; i++) {
+      xbt_dynar_push(d,&i);
+   }
+}
+static void poper_f(void *a) {
+   xbt_dynar_t d=(xbt_dynar_t)a;
+   int i;
+   int data;
+   xbt_ex_t e;
+   
+   for (i=0; i<500; i++) {
+      TRY {     
+        xbt_dynar_pop(d,&data);
+      } CATCH(e) {
+        if (e.category == bound_error) {
+           xbt_ex_free(e);
+           i--;
+        } else {
+           RETHROW;
+        }
+      }
+   }
+}
+
+   
+XBT_TEST_UNIT("synchronized int",test_dynar_sync_int,"Synchronized dynars of integers") {
+   /* Vars_decl [doxygen cruft] */
+   xbt_dynar_t d;
+   xbt_thread_t pusher,poper;
+   
+   xbt_test_add0("==== Have a pusher and a popper on the dynar");
+   d=xbt_dynar_new_sync(sizeof(int),NULL);
+   pusher = xbt_thread_create("pusher",pusher_f,d);
+   poper = xbt_thread_create("poper",poper_f,d);
+   xbt_thread_join(pusher);
+   xbt_thread_join(poper);
+   xbt_dynar_free(&d);
+}
+
 /*******************************/
 /* GENERATED FILE, DO NOT EDIT */
 /*******************************/