Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 22 Apr 2012 19:18:42 +0000 (21:18 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 22 Apr 2012 19:18:42 +0000 (21:18 +0200)
24 files changed:
buildtools/Cmake/DefinePackages.cmake
doc/gtut-tour.doc
examples/msg/chord/chord.c
examples/msg/mc/CMakeLists.txt
examples/msg/mc/bugged1_for_liveness.c [moved from examples/msg/mc/bugged1_liveness.c with 90% similarity]
examples/msg/mc/bugged1_while_liveness.c [new file with mode: 0644]
examples/msg/mc/bugged2_liveness.c
examples/msg/mc/test_snapshot.c [new file with mode: 0644]
examples/msg/mc/test_snapshot.h [new file with mode: 0644]
include/xbt/cunit.h
src/instr/jedule/jedule_sd_binding.c
src/mc/memory_map.c
src/simix/smx_private.h
src/surf/network_gtnets.c
src/surf/network_ns3.c
src/surf/network_ns3_private.h
src/surf/storage_private.h
src/surf/surf_routing_dijkstra.c
src/xbt/cunit.c
src/xbt/graph.c
src/xbt/mmalloc/mm_diff.c
src/xbt/xbt_str.c
tools/doxygen/doxygen_postprocesser.pl
tools/sg_unit_extractor.pl

index aa9961d..45da846 100644 (file)
@@ -17,23 +17,18 @@ set(EXTRA_DIST
        src/xbt/backtrace_dummy.c
        src/xbt/setset_private.h
        src/xbt/automatonparse_promela.c
-       src/xbt/mmalloc/attach.c
-       src/xbt/mmalloc/detach.c        
-       src/xbt/mmalloc/keys.c
-       src/xbt/mmalloc/mcalloc.c
        src/xbt/mmalloc/mfree.c
-       src/xbt/mmalloc/mm_legacy.c             
-       src/xbt/mmalloc/mm.c
        src/xbt/mmalloc/mmalloc.c
-       src/xbt/mmalloc/mmap-sup.c
-       src/xbt/mmalloc/mmcheck.c
-       src/xbt/mmalloc/mmemalign.c
-       src/xbt/mmalloc/mmprivate.h
-       src/xbt/mmalloc/mmstats.c
-       src/xbt/mmalloc/mmtrace.c
-       src/xbt/mmalloc/mrealloc.c
-       src/xbt/mmalloc/mvalloc.c
-       src/xbt/mmalloc/sbrk-sup.c
+       src/xbt/mmalloc/mmalloc.info
+       src/xbt/mmalloc/mmalloc.texi
+       src/xbt/mmalloc/mm.c
+    src/xbt/mmalloc/mm_diff.c
+       src/xbt/mmalloc/mm_legacy.c
+       src/xbt/mmalloc/mm_module.c
+       src/xbt/mmalloc/mmorecore.c
+       src/xbt/mmalloc/mmprivate.h             
+       src/xbt/mmalloc/mmtrace.awk
+       src/xbt/mmalloc/mrealloc.c      
        src/xbt/mmalloc/test/mmalloc_test.c
        src/xbt/datadesc/ddt_parse.yy.l
        src/xbt/datadesc/ddt_parse.yy.h
@@ -95,6 +90,15 @@ set(EXTRA_DIST
        examples/gras/ping/ping.h
        examples/gras/console/ping.h
        examples/gras/mmrpc/mmrpc.h
+       
+    examples/msg/mc/parserPromela.yacc
+    examples/msg/mc/parserPromela.lex
+    examples/msg/mc/automaton.h
+    examples/msg/mc/bugged1_liveness.h
+    examples/msg/mc/centralized_liveness.h
+    examples/msg/mc/automatonparse_promela.h
+    examples/msg/mc/bugged2_liveness.h
+    examples/msg/mc/y.tab.h
 
        tools/gras/gras_stub_generator.h
        tools/tesh/run_context.h  
@@ -570,6 +574,8 @@ endif(${HAVE_LUA})
 file(GLOB_RECURSE examples_to_install_in_doc
 "examples/*.c"
 "examples/*.h"
+"examples/*yacc"
+"examples/*lex"
 "examples/*.cxx"
 "examples/*.hpp"
 "examples/*.rb"
@@ -578,8 +584,6 @@ file(GLOB_RECURSE examples_to_install_in_doc
 "examples/*.xml"
 "examples/*README"
 )
-
-
     
 set(DOC_SOURCES
        doc/install.doc
index 57b1320..0288a1c 100644 (file)
@@ -21,7 +21,7 @@ all features available in GRAS.
       DOXYGEN_NAVBAR_CHILD "Recapping part 1"=GRAS_tut_tour_message_recaping.html
       DOXYGEN_NAVBAR_CHILD "12: Static data definition"=GRAS_tut_tour_staticstruct.html
       DOXYGEN_NAVBAR_CHILD "13: Pointers definition"=GRAS_tut_tour_pointers.html
-      DOXYGEN_NAVBAR_CHILD "14: Dynars definition"=GRAS_tut_tour_dynars.html
+      DOXYGEN_NAVBAR_CHILD "14: Dynars definition"=GRAS_tut_tour_dynar.html
       DOXYGEN_NAVBAR_CHILD "15: Manual data definition"=GRAS_tut_tour_manualdatadef.html
       DOXYGEN_NAVBAR_CHILD "16: Advanced data definition"=GRAS_tut_tour_exchangecb.html
     --> \endhtmlonly
index b112874..d9f9995 100644 (file)
@@ -42,7 +42,7 @@ extern long int smx_total_comms;
 /**
  * Finger element.
  */
-typedef struct finger {
+typedef struct s_finger {
   int id;
   char mailbox[MAILBOX_NAME_SIZE]; // string representation of the id
 } s_finger_t, *finger_t;
@@ -50,7 +50,7 @@ typedef struct finger {
 /**
  * Node data.
  */
-typedef struct node {
+typedef struct s_node {
   int id;                                 // my id
   char mailbox[MAILBOX_NAME_SIZE];        // my mailbox name (string representation of the id)
   s_finger_t *fingers;                    // finger table, of size nb_bits (fingers[0] is my successor)
@@ -77,7 +77,7 @@ typedef enum {
 /**
  * Data attached with the tasks sent and received
  */
-typedef struct task_data {
+typedef struct s_task_data {
   e_task_type_t type;                     // type of task
   int request_id;                         // id paramater (used by some types of tasks)
   int request_finger;                     // finger parameter (used by some types of tasks)
@@ -323,8 +323,8 @@ int node(int argc, char *argv[])
 
   if (join_success) {
     while (MSG_get_clock() < init_time + deadline
-//     && MSG_get_clock() < node.last_change_date + 1000
-       && MSG_get_clock() < max_simulation_time) {
+//      && MSG_get_clock() < node.last_change_date + 1000
+        && MSG_get_clock() < max_simulation_time) {
 
       if (node.comm_receive == NULL) {
         task_received = NULL;
@@ -347,10 +347,10 @@ int node(int argc, char *argv[])
           check_predecessor(&node);
           next_check_predecessor_date = MSG_get_clock() + periodic_check_predecessor_delay;
         }
-       else if (MSG_get_clock() >= next_lookup_date) {
-         random_lookup(&node);
-         next_lookup_date = MSG_get_clock() + periodic_lookup_delay;
-       }
+        else if (MSG_get_clock() >= next_lookup_date) {
+          random_lookup(&node);
+          next_lookup_date = MSG_get_clock() + periodic_lookup_delay;
+        }
         else {
           // nothing to do: sleep for a while
           MSG_process_sleep(5);
@@ -415,7 +415,7 @@ static void handle_task(node_t node, m_task_t task) {
         task_data->answer_id = node->fingers[0].id;
         XBT_DEBUG("Sending back a 'Find Successor Answer' to %s (mailbox %s): the successor of %d is %d",
             task_data->issuer_host_name,
-           task_data->answer_to,
+            task_data->answer_to,
             task_data->request_id, task_data->answer_id);
         MSG_task_dsend(task, task_data->answer_to, task_free);
       }
@@ -552,7 +552,7 @@ static void quit_notify(node_t node, int to)
   if (to == 1) {    // notify my successor
     to_mailbox = node->fingers[0].mailbox;
     XBT_INFO("Telling my Successor %d about my departure via mailbox %s",
-         node->fingers[0].id, to_mailbox);
+          node->fingers[0].id, to_mailbox);
     req_data->type = TASK_PREDECESSOR_LEAVING;
   }
   else if (to == -1) {    // notify my predecessor
@@ -563,7 +563,7 @@ static void quit_notify(node_t node, int to)
 
     to_mailbox = node->pred_mailbox;
     XBT_INFO("Telling my Predecessor %d about my departure via mailbox %s",
-         node->pred_id, to_mailbox);
+          node->pred_id, to_mailbox);
     req_data->type = TASK_SUCCESSOR_LEAVING;
   }
   m_task_t task = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, req_data);
@@ -638,22 +638,22 @@ static int remote_find_successor(node_t node, int ask_to, int id)
         XBT_DEBUG("Failed to receive the answer to my 'Find Successor' request (task %p): %d",
                   task_sent, (int)res);
         stop = 1;
-       MSG_comm_destroy(node->comm_receive);
-       node->comm_receive = NULL;
+        MSG_comm_destroy(node->comm_receive);
+        node->comm_receive = NULL;
       }
       else {
         m_task_t task_received = MSG_comm_get_task(node->comm_receive);
         XBT_DEBUG("Received a task (%p)", task_received);
         task_data_t ans_data = MSG_task_get_data(task_received);
 
-       if (MC_IS_ENABLED) {
-         MC_assert(task_received == task_sent);
-       }
+        if (MC_IS_ENABLED) {
+          MC_assert(task_received == task_sent);
+        }
 
         if (task_received != task_sent) {
           // this is not the expected answer
-         MSG_comm_destroy(node->comm_receive);
-         node->comm_receive = NULL;
+          MSG_comm_destroy(node->comm_receive);
+          node->comm_receive = NULL;
           handle_task(node, task_received);
         }
         else {
@@ -662,8 +662,8 @@ static int remote_find_successor(node_t node, int ask_to, int id)
               ans_data->request_id, task_received, id, ans_data->answer_id);
           successor = ans_data->answer_id;
           stop = 1;
-         MSG_comm_destroy(node->comm_receive);
-         node->comm_receive = NULL;
+          MSG_comm_destroy(node->comm_receive);
+          node->comm_receive = NULL;
           task_free(task_received);
         }
       }
@@ -717,22 +717,22 @@ static int remote_get_predecessor(node_t node, int ask_to)
 
       if (res != MSG_OK) {
         XBT_DEBUG("Failed to receive the answer to my 'Get Predecessor' request (task %p): %d",
-                  task_sent, (int)res);
+            task_sent, (int)res);
         stop = 1;
-       MSG_comm_destroy(node->comm_receive);
-       node->comm_receive = NULL;
+        MSG_comm_destroy(node->comm_receive);
+        node->comm_receive = NULL;
       }
       else {
         m_task_t task_received = MSG_comm_get_task(node->comm_receive);
         task_data_t ans_data = MSG_task_get_data(task_received);
 
-       if (MC_IS_ENABLED) {
-         MC_assert(task_received == task_sent);
-       }
+        if (MC_IS_ENABLED) {
+          MC_assert(task_received == task_sent);
+        }
 
         if (task_received != task_sent) {
-         MSG_comm_destroy(node->comm_receive);
-         node->comm_receive = NULL;
+          MSG_comm_destroy(node->comm_receive);
+          node->comm_receive = NULL;
           handle_task(node, task_received);
         }
         else {
@@ -740,8 +740,8 @@ static int remote_get_predecessor(node_t node, int ask_to)
               task_received, ask_to, ans_data->answer_id);
           predecessor_id = ans_data->answer_id;
           stop = 1;
-         MSG_comm_destroy(node->comm_receive);
-         node->comm_receive = NULL;
+          MSG_comm_destroy(node->comm_receive);
+          node->comm_receive = NULL;
           task_free(task_received);
         }
       }
@@ -903,11 +903,11 @@ int main(int argc, char *argv[])
 
       length = strlen("-timeout=");
       if (!strncmp(options[0], "-timeout=", length) && strlen(options[0]) > length) {
-       timeout = atoi(options[0] + length);
-       XBT_DEBUG("Set timeout to %d", timeout);
+        timeout = atoi(options[0] + length);
+        XBT_DEBUG("Set timeout to %d", timeout);
       }
       else {
-       xbt_die("Invalid chord option '%s'", options[0]);
+        xbt_die("Invalid chord option '%s'", options[0]);
       }
     }
     options++;
index 82578b9..eb78400 100644 (file)
@@ -9,11 +9,11 @@ add_executable(bugged2_stateful bugged2_stateful.c)
 add_executable(bugged2     bugged2.c)
 add_executable(bugged3    bugged3.c)
 add_executable(random_test random_test.c)
-add_executable(bugged1_liveness automaton.c automatonparse_promela.c bugged1_liveness.c)
+add_executable(bugged1_for_liveness automaton.c automatonparse_promela.c bugged1_for_liveness.c)
+add_executable(bugged1_while_liveness automaton.c automatonparse_promela.c bugged1_while_liveness.c)
 add_executable(bugged2_liveness automaton.c automatonparse_promela.c bugged2_liveness.c)
 add_executable(centralized_liveness automaton.c automatonparse_promela.c centralized_liveness.c)
-
-
+add_executable(test_snapshot automaton.c automatonparse_promela.c test_snapshot.c)
 
 target_link_libraries(centralized simgrid m )
 target_link_libraries(bugged1     simgrid m )
@@ -22,6 +22,8 @@ target_link_libraries(bugged2_stateful simgrid m)
 target_link_libraries(bugged2     simgrid m )
 target_link_libraries(bugged3     simgrid m )
 target_link_libraries(random_test     simgrid m )
-target_link_libraries(bugged1_liveness     simgrid m )
+target_link_libraries(bugged1_for_liveness     simgrid m )
+target_link_libraries(bugged1_while_liveness     simgrid m )
 target_link_libraries(bugged2_liveness     simgrid m )
-target_link_libraries(centralized_liveness     simgrid m )
\ No newline at end of file
+target_link_libraries(centralized_liveness     simgrid m )
+target_link_libraries(test_snapshot     simgrid m )
similarity index 90%
rename from examples/msg/mc/bugged1_liveness.c
rename to examples/msg/mc/bugged1_for_liveness.c
index 3d051c9..b45f9ce 100644 (file)
@@ -1,6 +1,6 @@
 /***************** Centralized Mutual Exclusion Algorithm *********************/
 /* This example implements a centralized mutual exclusion algorithm.          */
-/* CS requests of client 2 not satisfied                                      */
+/* CS requests of client 1 not satisfied                                      */
 /* LTL property checked : G(r->F(cs)); (r=request of CS, cs=CS ok)            */
 /******************************************************************************/
 
@@ -12,9 +12,9 @@
 #include "y.tab.c"
 
 #define AMOUNT_OF_CLIENTS 2
-#define CS_PER_PROCESS 1
+#define CS_PER_PROCESS 2
 
-XBT_LOG_NEW_DEFAULT_CATEGORY(example_liveness_with_cycle, "my log messages");
+XBT_LOG_NEW_DEFAULT_CATEGORY(bugged1_liveness, "my log messages");
 
 
 int r=0; 
@@ -44,7 +44,7 @@ int coordinator(int argc, char *argv[])
         XBT_INFO("CS already used. Queue the request of client %d", atoi(req) +1);
         xbt_dynar_push(requests, &req);
       } else {                  // can serve it immediatly
-       if(strcmp(req, "1") == 0){
+       if(strcmp(req, "2") == 0){
          m_task_t answer = MSG_task_create("grant", 0, 1000, NULL);
          MSG_task_send(answer, req);
          CS_used = 1;
@@ -56,7 +56,7 @@ int coordinator(int argc, char *argv[])
         XBT_INFO("CS release. Grant to queued requests (queue size: %lu)", xbt_dynar_length(requests));
         char *req ;
        xbt_dynar_get_cpy(requests, (xbt_dynar_length(requests) - 1), &req);
-       if(strcmp(req, "1") == 0){
+       if(strcmp(req, "2") == 0){
          xbt_dynar_pop(requests, &req);
          MSG_task_send(MSG_task_create("grant", 0, 1000, NULL), req);
          todo--;
@@ -85,13 +85,13 @@ int client(int argc, char *argv[])
   char *my_mailbox = bprintf("%s", argv[1]);
   int i;
 
-  // request the CS 4 times, sleeping a bit in between
+  // request the CS (CS_PER_PROCESS times), sleeping a bit in between
   for (i = 0; i < CS_PER_PROCESS; i++) {
       
     XBT_INFO("Ask the request");
     MSG_task_send(MSG_task_create("request", 0, 1000, my_mailbox), "coordinator");
 
-    if(strcmp(my_mailbox, "2") == 0){
+    if(strcmp(my_mailbox, "1") == 0){
       r = 1;
       cs = 0;
       XBT_DEBUG("Propositions changed : r=1, cs=0");
@@ -102,7 +102,7 @@ int client(int argc, char *argv[])
     MSG_task_receive(&grant, my_mailbox);
     const char *kind = MSG_task_get_name(grant);
 
-    if((strcmp(my_mailbox, "2") == 0) && (strcmp("grant", kind) == 0)){
+    if((strcmp(my_mailbox, "1") == 0) && (strcmp("grant", kind) == 0)){
       cs = 1;
       r = 0;
       XBT_DEBUG("Propositions changed : r=0, cs=1");
@@ -116,7 +116,7 @@ int client(int argc, char *argv[])
 
     MSG_process_sleep(my_pid);
     
-    if(strcmp(my_mailbox, "2") == 0){
+    if(strcmp(my_mailbox, "1") == 0){
       cs=0;
       r=0;
       XBT_DEBUG("Propositions changed : r=0, cs=0");
diff --git a/examples/msg/mc/bugged1_while_liveness.c b/examples/msg/mc/bugged1_while_liveness.c
new file mode 100644 (file)
index 0000000..95b6e5b
--- /dev/null
@@ -0,0 +1,137 @@
+/***************** Centralized Mutual Exclusion Algorithm *********************/
+/* This example implements a centralized mutual exclusion algorithm.          */
+/* CS requests of client 1 not satisfied                                      */
+/* LTL property checked : G(r->F(cs)); (r=request of CS, cs=CS ok)            */
+/******************************************************************************/
+
+#include "msg/msg.h"
+#include "mc/mc.h"
+#include "xbt/automaton.h"
+#include "xbt/automatonparse_promela.h"
+#include "bugged1_liveness.h"
+#include "y.tab.c"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(bugged1_liveness, "my log messages");
+
+int r=0; 
+int cs=0;
+
+int predR(){
+  return r;
+}
+
+int predCS(){
+  return cs;
+}
+
+
+int coordinator(int argc, char *argv[])
+{
+  xbt_dynar_t requests = xbt_dynar_new(sizeof(char *), NULL);   // dynamic vector storing requests (which are char*)
+  int CS_used = 0;              // initially the CS is idle
+  while (1) {
+    m_task_t task = NULL;
+    MSG_task_receive(&task, "coordinator");
+    const char *kind = MSG_task_get_name(task); //is it a request or a release?
+    if (!strcmp(kind, "request")) {     // that's a request
+      char *req = MSG_task_get_data(task);
+      if (CS_used) {            // need to push the request in the vector
+        XBT_INFO("CS already used. Queue the request of client %d", atoi(req) +1);
+        xbt_dynar_push(requests, &req);
+      } else {                  // can serve it immediatly
+       if(strcmp(req, "2") == 0){
+         m_task_t answer = MSG_task_create("grant", 0, 1000, NULL);
+         MSG_task_send(answer, req);
+         CS_used = 1;
+         XBT_INFO("CS idle. Grant immediatly");
+       }
+      }
+    } else {                    // that's a release. Check if someone was waiting for the lock
+      if (xbt_dynar_length(requests) > 0) {
+        XBT_INFO("CS release. Grant to queued requests (queue size: %lu)", xbt_dynar_length(requests));
+        char *req ;
+       xbt_dynar_get_cpy(requests, (xbt_dynar_length(requests) - 1), &req);
+       if(strcmp(req, "2") == 0){
+         xbt_dynar_pop(requests, &req);
+         MSG_task_send(MSG_task_create("grant", 0, 1000, NULL), req);
+       }else{
+         xbt_dynar_pop(requests, &req);
+         MSG_task_send(MSG_task_create("notgrant", 0, 1000, NULL), req);
+         CS_used = 0;
+       }
+      } else {                  // nobody wants it
+        XBT_INFO("CS release. resource now idle");
+        CS_used = 0;
+      }
+    }
+    MSG_task_destroy(task);
+  }
+  return 0;
+}
+
+int client(int argc, char *argv[])
+{
+  int my_pid = MSG_process_get_PID(MSG_process_self());
+
+  char *my_mailbox = bprintf("%s", argv[1]);
+
+  // request the CS, sleeping a bit in between
+  while(1) {
+      
+    XBT_INFO("Ask the request");
+    MSG_task_send(MSG_task_create("request", 0, 1000, my_mailbox), "coordinator");
+
+    if(strcmp(my_mailbox, "1") == 0){
+      r = 1;
+      cs = 0;
+      XBT_DEBUG("Propositions changed : r=1, cs=0");
+    }
+
+    // wait the answer
+    m_task_t grant = NULL;
+    MSG_task_receive(&grant, my_mailbox);
+    const char *kind = MSG_task_get_name(grant);
+
+    if((strcmp(my_mailbox, "1") == 0) && (strcmp("grant", kind) == 0)){
+      cs = 1;
+      r = 0;
+      XBT_DEBUG("Propositions changed : r=0, cs=1");
+    }
+
+
+    MSG_task_destroy(grant);
+    XBT_INFO("%s got the answer. Sleep a bit and release it", argv[1]);
+    MSG_process_sleep(1);
+    MSG_task_send(MSG_task_create("release", 0, 1000, NULL), "coordinator");
+
+    MSG_process_sleep(my_pid);
+    
+    if(strcmp(my_mailbox, "1") == 0){
+      cs=0;
+      r=0;
+      XBT_DEBUG("Propositions changed : r=0, cs=0");
+    }
+    
+  }
+
+  return 0;
+}
+
+int main(int argc, char *argv[])
+{
+  init();
+  yyparse();
+  automaton = get_automaton();
+  xbt_new_propositional_symbol(automaton,"r", &predR); 
+  xbt_new_propositional_symbol(automaton,"cs", &predCS); 
+  
+  MSG_global_init(&argc, argv);
+  MSG_create_environment("../msg_platform.xml");
+  MSG_function_register("coordinator", coordinator);
+  MSG_function_register("client", client);
+  MSG_launch_application("deploy_bugged1_liveness.xml");
+  MSG_main_liveness(automaton, argv[0]);
+
+  return 0;
+}
index 9842999..15467be 100644 (file)
@@ -11,7 +11,7 @@
 #include "bugged2_liveness.h"
 #include "y.tab.c"
 
-XBT_LOG_NEW_DEFAULT_CATEGORY(example_liveness_with_cycle, "my log messages");
+XBT_LOG_NEW_DEFAULT_CATEGORY(bugged2_liveness, "my log messages");
 
 char* buffer;
 
@@ -87,6 +87,7 @@ int producer(int argc, char *argv[])
     const char *mess = "message";
 
     pready = 1;
+    XBT_INFO("pready = 1");
     
     /* CS request */
     XBT_INFO("Producer ask the request");
@@ -101,6 +102,7 @@ int producer(int argc, char *argv[])
     buffer = strdup(mess);
 
     produce = 1;
+    XBT_INFO("produce = 1");
 
     /* CS release */
     MSG_task_send(MSG_task_create("release", 0, 1000, my_mailbox), "coordinator");
@@ -108,6 +110,8 @@ int producer(int argc, char *argv[])
     produce = 0;
     pready = 0;
 
+    XBT_INFO("pready et produce = 0");
+
   }
 
   return 0;
@@ -128,6 +132,7 @@ int consumer(int argc, char *argv[])
     MSG_task_send(MSG_task_create("request", 0, 1000, my_mailbox), "coordinator");
 
     cready = 1;
+    XBT_INFO("cready = 1");
 
     /* Wait the answer */
     m_task_t grant = NULL;
@@ -139,10 +144,12 @@ int consumer(int argc, char *argv[])
     mess = strdup(buffer);
     buffer[0] = '\0'; 
 
-     /* Display message */
+    /* Display message */
     XBT_INFO("Message : %s", mess);
-    if(strcmp(mess, "") != 0)
+    if(strcmp(mess, "") != 0){
       consume = 1;
+      XBT_INFO("consume = 1");
+    }
 
     /* CS release */
     MSG_task_send(MSG_task_create("release", 0, 1000, my_mailbox), "coordinator");
@@ -152,6 +159,8 @@ int consumer(int argc, char *argv[])
     consume = 0;
     cready = 0;
 
+    XBT_INFO("cready et consume = 0");
+
   }
 
   return 0;
diff --git a/examples/msg/mc/test_snapshot.c b/examples/msg/mc/test_snapshot.c
new file mode 100644 (file)
index 0000000..fad4288
--- /dev/null
@@ -0,0 +1,147 @@
+#include "msg/msg.h"
+#include "mc/mc.h"
+#include "xbt/automaton.h"
+#include "xbt/automatonparse_promela.h"
+#include "test_snapshot.h"
+#include "y.tab.c"
+#include <stdlib.h>
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(test_snapshot, "my log messages");
+
+int r=0; 
+int cs=0;
+
+int i = 1;
+xbt_dynar_t d1 = NULL;
+xbt_dynar_t d2 = NULL;
+char *c1;
+
+int predR(){
+  return r;
+}
+
+int predCS(){
+  return cs;
+}
+
+void check(){
+  XBT_INFO("*** Check ***"); 
+  if(d1!=NULL){
+    XBT_INFO("Dynar d1 (%p -> %p) length : %lu", &d1, d1, xbt_dynar_length(d1));
+    unsigned int cursor = 0;
+    char *elem;
+    xbt_dynar_foreach(d1, cursor, elem){
+      XBT_INFO("Elem in dynar d1 : %s", elem);
+    }
+  }else{
+    XBT_INFO("Dynar d1 NULL");
+  }
+  if(d2!=NULL){
+    XBT_INFO("Dynar d2 (%p -> %p) length : %lu", &d2, d2, xbt_dynar_length(d2));
+    unsigned int cursor = 0;
+    char *elem;
+    xbt_dynar_foreach(d2, cursor, elem){
+      XBT_INFO("Elem in dynar d2 : %s", elem);
+    }
+  }else{
+    XBT_INFO("Dynar d2 NULL");
+  }
+}
+
+
+int coordinator(int argc, char *argv[])
+{
+
+  while(i>0){
+
+    m_task_t task = NULL;
+    MSG_task_receive(&task, "coordinator");
+    const char *kind = MSG_task_get_name(task);
+
+    //check();
+
+    if (!strcmp(kind, "request")) { 
+      char *req = MSG_task_get_data(task);
+      m_task_t answer = MSG_task_create("received", 0, 1000, NULL);
+      MSG_task_send(answer, req); 
+    }else{
+      XBT_INFO("End of coordinator");
+    }
+
+  }
+
+  return 0;
+}
+
+int client(int argc, char *argv[])
+{
+  int my_pid = MSG_process_get_PID(MSG_process_self());
+
+  char *my_mailbox = bprintf("%s", argv[1]);
+
+  while(i>0){
+
+    XBT_INFO("Ask the request");
+    MSG_task_send(MSG_task_create("request", 0, 1000, my_mailbox), "coordinator");
+
+    r = 1;
+
+    check();
+
+    // wait the answer
+    m_task_t task = NULL;
+    MSG_task_receive(&task, my_mailbox);
+    MSG_task_destroy(task);
+
+    check();
+    XBT_INFO("*** Update ***"); 
+    xbt_dynar_reset(d1);
+    free(c1);
+    xbt_dynar_free(&d1);
+    d2 = xbt_dynar_new(sizeof(char *), NULL);
+    XBT_INFO("Dynar d2 : %p -> %p", &d2, d2);
+    char *c2 = strdup("boooooooo");
+    xbt_dynar_push(d2, &c2);
+
+    cs = 1;
+
+    check();
+    MSG_process_sleep(1);
+    MSG_task_send(MSG_task_create("release", 0, 1000, NULL), "coordinator");
+
+    check();
+
+    MSG_process_sleep(my_pid);
+
+    i--;
+  }
+    
+  return 0;
+}
+
+int main(int argc, char *argv[])
+{
+
+  d1 = xbt_dynar_new(sizeof(char *), NULL);
+  XBT_DEBUG("Dynar d1 : %p -> %p", &d1, d1);
+  c1 = strdup("coucou");
+  xbt_dynar_push(d1, &c1);
+  xbt_dynar_push(d1, &c1);
+
+  init();
+  yyparse();
+  automaton = get_automaton();
+  xbt_new_propositional_symbol(automaton,"r", &predR); 
+  xbt_new_propositional_symbol(automaton,"cs", &predCS); 
+  
+  MSG_global_init(&argc, argv);
+  MSG_create_environment("../msg_platform.xml");
+  MSG_function_register("coordinator", coordinator);
+  MSG_function_register("client", client);
+  MSG_launch_application("deploy_test_snapshot.xml");
+  MSG_main_liveness(automaton, argv[0]);
+
+  return 0;
+}
diff --git a/examples/msg/mc/test_snapshot.h b/examples/msg/mc/test_snapshot.h
new file mode 100644 (file)
index 0000000..118aaac
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef _TEST_SNAPSHOT_H
+#define _TEST_SNAPSHOT_H
+
+int yyparse(void);
+int yywrap(void);
+int yylex(void);
+
+int predCS(void);
+int predR(void);
+
+int coordinator(int argc, char *argv[]);
+int client(int argc, char *argv[]);
+
+void check(void);
+
+#endif 
index 9ed28ae..0cd6358 100644 (file)
@@ -51,7 +51,7 @@ XBT_PUBLIC(void) xbt_test_suite_push(xbt_test_suite_t suite,
  * * testname: if given, the test on which the directive acts. If not, acts on any tests.
  */
 
-XBT_PUBLIC(int) xbt_test_run(char *selection);
+XBT_PUBLIC(int) xbt_test_run(char *selection, int verbosity);
 /* Show information about the selection of tests */
 XBT_PUBLIC(void) xbt_test_dump(char *selection);
 /* Cleanup the mess */
index e5c51c6..e992795 100644 (file)
@@ -60,7 +60,7 @@ static void create_hierarchy(AS_t current_comp,
        unsigned int dynar_cursor;
        char *key;
        AS_t elem;
-       network_element_t network_elem;
+       sg_routing_edge_t network_elem;
 
        if(xbt_dict_is_empty(current_comp->routing_sons)) {
                // I am no AS
index b971a47..f3c410a 100644 (file)
@@ -33,14 +33,12 @@ memory_map_t get_memory_map(void)
   xbt_assert(fp,
               "Cannot open /proc/self/maps to investigate the memory map of the process. Please report this bug.");
 
-  //XBT_DEBUG("/proc/self/maps");
-
   ret = xbt_new0(s_memory_map_t, 1);
 
   /* Read one line at the time, parse it and add it to the memory map to be returned */
   while ((read = getline(&line, &n, fp)) != -1) {
 
-    XBT_DEBUG("%s", line);
+    //fprintf(stderr,"%s", line);
 
     /* Wipeout the new line character */
     line[read - 1] = '\0';
index 28cbd06..824239f 100644 (file)
@@ -64,7 +64,7 @@ typedef struct s_smx_file {
 
 typedef struct s_smx_stat {
   s_file_stat_t surf_stat;
-} s_smx_stat_t, *smx_stat_t;
+} s_smx_stat_t;
 
 /*********************************** Time ************************************/
 
index 7193b0d..27eb0cb 100644 (file)
@@ -438,7 +438,7 @@ static void surf_network_model_init_internal(void)
     xbt_die("Impossible to initialize GTNetS interface");
   }
 
-  routing_model_create(sizeof(network_link_GTNETS_t), NULL);
+  routing_model_create(NULL);
 }
 
 #ifdef HAVE_LATENCY_BOUND_TRACKING
index 5083d94..9248945 100644 (file)
@@ -366,7 +366,7 @@ void surf_network_model_init_NS3()
     xbt_die("Impossible to initialize NS3 interface");
   }
 
-  routing_model_create(sizeof(s_surf_ns3_link_t), NULL);
+  routing_model_create(NULL);
   define_callbacks_ns3();
 
   NS3_HOST_LEVEL = xbt_lib_add_level(host_lib,(void_f_pvoid_t)free_ns3_host);
index 544c210..9cd7c6d 100644 (file)
@@ -26,8 +26,8 @@ typedef struct surf_action_network_ns3 {
   s_surf_action_t generic_action;
 #ifdef HAVE_TRACING
   double last_sent;
-  network_element_t src_elm;
-  network_element_t dst_elm;
+  sg_routing_edge_t src_elm;
+  sg_routing_edge_t dst_elm;
 #endif //HAVE_TRACING
 } s_surf_action_network_ns3_t, *surf_action_network_ns3_t;
 
index c5ae4d2..c1b812b 100644 (file)
@@ -23,7 +23,7 @@ typedef struct s_mount {
 typedef struct surf_stat { /* file status structure */
   s_file_stat_t stat;
   /* possible additionnal fields (e.g., popularity, last access time to know whether the file is in cache, ...) */
-} s_surf_stat_t, *surf_stat_t;
+} s_surf_stat_t;
 
 typedef struct surf_file {
   char *name;
index 27c04b8..2d7b1dd 100644 (file)
@@ -56,8 +56,6 @@ static void graph_edge_data_free(void *e) // FIXME: useless code dupplication
   route_t e_route = (route_t) e;
   if (e_route) {
     xbt_dynar_free(&(e_route->link_list));
-    xbt_free(e_route->src_gateway);
-    xbt_free(e_route->dst_gateway);
     xbt_free(e_route);
   }
 }
index 4436ae5..a3798ee 100644 (file)
@@ -245,7 +245,7 @@ void xbt_test_suite_push(xbt_test_suite_t suite, const char *name,
 }
 
 /* run test one suite */
-static int xbt_test_suite_run(xbt_test_suite_t suite)
+static int xbt_test_suite_run(xbt_test_suite_t suite, int verbosity)
 {
   xbt_test_unit_t unit;
   xbt_test_test_t test;
@@ -324,7 +324,8 @@ static int xbt_test_suite_run(xbt_test_suite_t suite)
 
 
       /* Display whether this unit went well */
-      if (unit->test_failed > 0 || unit->test_expect) {
+      if (unit->test_failed > 0 || unit->test_expect ||
+          (verbosity && unit->nb_tests > 0)) {
         /* some tests failed (or were supposed to), so do detailed reporting of test case */
         if (unit->test_failed > 0) {
           fprintf(stderr, ".. failed\n");
@@ -612,7 +613,7 @@ void xbt_test_dump(char *selection)
   }
 }
 
-int xbt_test_run(char *selection)
+int xbt_test_run(char *selection, int verbosity)
 {
   apply_selection(selection);
 
@@ -623,7 +624,7 @@ int xbt_test_run(char *selection)
 
     /* Run all the suites */
     xbt_dynar_foreach(_xbt_test_suites, it_suite, suite)
-        xbt_test_suite_run(suite);
+      xbt_test_suite_run(suite, verbosity);
 
     /* Display some more statistics */
     fprintf(stderr, "\n\n TOTAL: Suites: %.0f%% ok (%d suites: ",
index fdf9f5f..61b8364 100644 (file)
@@ -140,35 +140,30 @@ void xbt_graph_free_graph(xbt_graph_t g,
                           void_f_pvoid_t edge_free_function,
                           void_f_pvoid_t graph_free_function)
 {
-  unsigned int cursor = 0;
-  xbt_node_t node = NULL;
-  xbt_edge_t edge = NULL;
+  unsigned int cursor;
+  xbt_node_t node;
+  xbt_edge_t edge;
 
+  xbt_dynar_foreach(g->edges, cursor, edge) {
+    if (edge_free_function)
+      edge_free_function(edge->data);
+    free(edge);
+  }
+  xbt_dynar_free(&(g->edges));
 
   xbt_dynar_foreach(g->nodes, cursor, node) {
     xbt_dynar_free(&(node->out));
     xbt_dynar_free(&(node->in));
     if (node_free_function)
       node_free_function(node->data);
+    free(node);
   }
-
-  xbt_dynar_foreach(g->edges, cursor, edge) {
-    if (edge_free_function)
-      edge_free_function(edge->data);
-  }
-
-  xbt_dynar_foreach(g->nodes, cursor, node)
-      free(node);
   xbt_dynar_free(&(g->nodes));
 
-  xbt_dynar_foreach(g->edges, cursor, edge)
-      free(edge);
-  xbt_dynar_free(&(g->edges));
   if (graph_free_function)
     graph_free_function(g->data);
   free(g);
   xbt_graph_parse_lex_destroy();
-  return;
 }
 
 
index e7e5114..1fdc5bd 100644 (file)
@@ -114,7 +114,7 @@ void mmalloc_backtrace_fragment_display(xbt_mheap_t mdp, size_t block, size_t fr
 int mmalloc_compare_heap(xbt_mheap_t mdp1, xbt_mheap_t mdp2){
 
   if(mdp1 == NULL && mdp2 == NULL){
-    XBT_DEBUG("Malloc descriptors null\n");
+    fprintf(stderr, "Malloc descriptors null\n");
     return 0;
   }
 
@@ -151,21 +151,18 @@ int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2){
   if(mdp1->heapsize != mdp2->heapsize){
     fprintf(stderr,"Different number of info entries\n");
     return 1;
-  }
-  
+  }  
 
   if(mdp1->heapbase != mdp2->heapbase){
     fprintf(stderr,"Different first block of the heap\n");
     return 1;
   }
 
-
   if(mdp1->heapindex != mdp2->heapindex){
     fprintf(stderr,"Different index for the heap table : %zu - %zu\n", mdp1->heapindex, mdp2->heapindex);
     return 1;
   }
 
-
   if(mdp1->base != mdp2->base){
     fprintf(stderr,"Different base address of the memory region\n");
     return 1;
@@ -205,6 +202,7 @@ int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2){
 
   int k;
   int distance = 0;
+  int pointer_align;
 
   /* Check busy blocks*/
 
@@ -231,13 +229,17 @@ int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2){
       } 
 
       if(memcmp(addr_block1, addr_block2, (mdp1->heapinfo[i].busy_block.busy_size)) != 0){
-       fprintf(stderr,"Different data in large block %zu (size = %zu (in blocks), busy_size = %zu (in bytes))\n", i, mdp1->heapinfo[i].busy_block.size, mdp1->heapinfo[i].busy_block.busy_size);
+       fprintf(stderr,"\nDifferent data in large block %zu (size = %zu (in blocks), busy_size = %zu (in bytes))\n", i, mdp1->heapinfo[i].busy_block.size, mdp1->heapinfo[i].busy_block.busy_size);
 
        /* Hamming distance on different blocks */
        distance = 0;
        for(k=0;k<mdp1->heapinfo[i].busy_block.busy_size;k++){
-         if(memcmp(((char *)addr_block1) + k, ((char *)addr_block2) + k, 1) != 0)
+         if(memcmp(((char *)addr_block1) + k, ((char *)addr_block2) + k, 1) != 0){
+           fprintf(stderr, "Different byte (offset=%d) (%p - %p) in block %zu\n", k, (char *)addr_block1 + k, (char *)addr_block2 + k, i); 
            distance++;
+           pointer_align = (k / sizeof(void*)) * sizeof(void*); 
+           fprintf(stderr, "Pointer address : %p - %p\n", *((void **)((char *)addr_block1 + pointer_align)), *((void **)((char *)addr_block2 + pointer_align)));
+         }
        }
 
        fprintf(stderr, "Hamming distance between blocks : %d\n", distance);
@@ -283,14 +285,19 @@ int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2){
            addr_frag1 = (char *)addr_block1 + (j * frag_size);
            addr_frag2 = (char *)addr_block2 + (j * frag_size);
 
+
            if(memcmp(addr_frag1, addr_frag2, mdp1->heapinfo[i].busy_frag.frag_size[j]) != 0){
-             fprintf(stderr,"Different data in fragment %zu (size = %zu, size used = %hu) in block %zu \n", j, frag_size, mdp1->heapinfo[i].busy_frag.frag_size[j], i);
+             fprintf(stderr,"\nDifferent data in fragment %zu (size = %zu, size used = %hu) in block %zu \n", j, frag_size, mdp1->heapinfo[i].busy_frag.frag_size[j], i);
 
              /* Hamming distance on different blocks */
              distance = 0;
              for(k=0;k<mdp1->heapinfo[i].busy_frag.frag_size[j];k++){
-               if(memcmp(((char *)addr_frag1) + k, ((char *)addr_frag2) + k, 1) != 0)
+               if(memcmp(((char *)addr_frag1) + k, ((char *)addr_frag2) + k, 1) != 0){
+                 fprintf(stderr, "Different byte (offset=%d) (%p - %p) in fragment %zu in block %zu\n", k, (char *)addr_frag1 + k, (char *)addr_frag2 + k, j, i); 
                  distance++;
+                 pointer_align = (k / sizeof(void*)) * sizeof(void*);
+                 fprintf(stderr, "Pointer address : %p - %p\n", *((void **)((char *)addr_frag1 + pointer_align)), *((void **)((char *)addr_frag2 + pointer_align)));
+               }
              }
 
              fprintf(stderr, "Hamming distance between fragments : %d\n", distance);
index 6d7a2e2..de49953 100644 (file)
@@ -573,146 +573,222 @@ long getline(char **buf, size_t * n, FILE * stream)
 
 /*
  * Diff related functions
+ *
+ * Implementation of the algorithm described in "An O(NP) Sequence Comparison
+ * Algorithm", by Sun Wu, Udi Manber, Gene Myers, and Webb Miller (Information
+ * Processing Letters 35(6):317-323, 1990), with the linear-space
+ * divide-and-conquer strategy described in "An O(ND) Difference Algorithm and
+ * Its Variations", by Eugene W. Myers (Algorithmica 1:251-266, 1986).
  */
-static XBT_INLINE void diff_push(xbt_dynar_t dyn, char prefix, const char *s)
-{
-  char *topush = bprintf("%c %s", prefix, s);
-  xbt_dynar_push(dyn, &topush);
-}
 
-static int diff_member(const char *s, xbt_dynar_t d, unsigned from, unsigned to)
+struct subsequence {
+    int x, y;                   /* starting coordinates */
+    int len;                    /* length */
+};
+
+static XBT_INLINE
+void diff_snake(const char *vec_a[], int a0, int len_a,
+                const char *vec_b[], int b0, int len_b,
+                struct subsequence *seqs, int *fp, int k, int limit)
 {
-  unsigned i;
-  for (i = from; i < to; i++)
-    if (!strcmp(s, xbt_dynar_get_as(d, i, char *)))
-      return 1;
-  return 0;
+  int record_seq;
+  int x, y;
+  int fp_left = fp[k - 1] + 1;
+  int fp_right = fp[k + 1];
+  if (fp_left > fp_right) {
+    x = fp_left;
+    record_seq = k - 1;
+  } else {
+    x = fp_right;
+    record_seq = k + 1;
+  }
+  y = x - k;
+  if (x + y <= limit) {
+    seqs[k].x = x;
+    seqs[k].y = y;
+    record_seq = k;
+  } else {
+    seqs[k] = seqs[record_seq];
+  }
+  while (x < len_a && y < len_b && !strcmp(vec_a[a0 + x], vec_b[b0 + y]))
+    ++x, ++y;
+  fp[k] = x;
+  if (record_seq == k)
+    seqs[k].len = x - seqs[k].x;
 }
 
-static void diff_easy_prefix(xbt_dynar_t res, xbt_dynar_t da, xbt_dynar_t db)
+/* Returns the length of a shortest edit script, and a common
+ * subsequence from the middle.
+ */
+static int diff_middle_subsequence(const char *vec_a[], int a0,  int len_a,
+                                   const char *vec_b[], int b0,  int len_b,
+                                   struct subsequence *subseq,
+                                   struct subsequence *seqs, int *fp)
 {
-  while (xbt_dynar_length(da) > 0 && xbt_dynar_length(db) > 0) {
-    char *sa = xbt_dynar_getfirst_as(da, char *);
-    char *sb = xbt_dynar_getfirst_as(db, char *);
-
-    if (!strcmp(sa, sb)) {
-      /* sa == sb */
-      diff_push(res, ' ', sa);
-      xbt_dynar_shift(da, NULL);
-      xbt_dynar_shift(db, NULL);
-    } else if (!diff_member(sa, db, 1, xbt_dynar_length(db))) {
-      /* sa not in db */
-      diff_push(res, '-', sa);
-      xbt_dynar_shift(da, NULL);
-    } else if (!diff_member(sb, da, 1, xbt_dynar_length(da))) {
-      /* sb not in da */
-      diff_push(res, '+', sb);
-      xbt_dynar_shift(db, NULL);
-    } else {
-      /* sa in db, and sb in da: cannot go further */
-      return;
-    }
+  const int delta = len_a - len_b;
+  const int limit = (len_a + len_b) / 2;
+  int kmin;
+  int kmax;
+  int k;
+  int p = -1;
+
+  if (delta >= 0) {
+    kmin = 0;
+    kmax = delta;
+  } else {
+    kmin = delta;
+    kmax = 0;
   }
+  for (k = kmin; k <= kmax; k++)
+    fp[k] = -1;
+  do {
+    p++;
+    fp[kmin - p - 1] = fp[kmax + p + 1] = -1;
+    for (k = kmax + p; k > delta; k--)
+      diff_snake(vec_a, a0, len_a, vec_b, b0, len_b, seqs, fp, k, limit);
+    for (k = kmin - p; k <= delta; k++)
+      diff_snake(vec_a, a0, len_a, vec_b, b0, len_b, seqs, fp, k, limit);
+  } while (fp[delta] != len_a);
+
+  subseq->x = a0 + seqs[delta].x;
+  subseq->y = b0 + seqs[delta].y;
+  subseq->len = seqs[delta].len;
+  return abs(delta) + 2 * p;;
 }
 
-static void diff_easy_suffix(xbt_dynar_t res, xbt_dynar_t da, xbt_dynar_t db)
+/* Finds a longest common subsequence.
+ * Returns its length.
+ */
+static int diff_compute_lcs(const char *vec_a[], int a0, int len_a,
+                            const char *vec_b[], int b0, int len_b,
+                            xbt_dynar_t common_sequence,
+                            struct subsequence *seqs, int *fp)
 {
-  while (xbt_dynar_length(da) > 0 && xbt_dynar_length(db) > 0) {
-    char *sa = xbt_dynar_getlast_as(da, char *);
-    char *sb = xbt_dynar_getlast_as(db, char *);
-
-    if (!strcmp(sa, sb)) {
-      /* sa == sb */
-      diff_push(res, ' ', sa);
-      xbt_dynar_pop(da, NULL);
-      xbt_dynar_pop(db, NULL);
-    } else if (!diff_member(sb, da, 0, xbt_dynar_length(da) - 1)) {
-      /* sb not in da */
-      diff_push(res, '+', sb);
-      xbt_dynar_pop(db, NULL);
-    } else if (!diff_member(sa, db, 0, xbt_dynar_length(db) - 1)) {
-      /* sa not in db */
-      diff_push(res, '-', sa);
-      xbt_dynar_pop(da, NULL);
+  if (len_a > 0 && len_b > 0) {
+    struct subsequence subseq;
+    int ses_len = diff_middle_subsequence(vec_a, a0, len_a, vec_b, b0, len_b,
+                                          &subseq, seqs, fp);
+    int lcs_len = (len_a + len_b - ses_len) / 2;
+    if (lcs_len == 0) {
+      return 0;
+    } else if (ses_len > 1) {
+      int lcs_len1 = subseq.len;
+      if (lcs_len1 < lcs_len)
+        lcs_len1 += diff_compute_lcs(vec_a, a0, subseq.x - a0,
+                                     vec_b, b0, subseq.y - b0,
+                                     common_sequence, seqs, fp);
+      if (subseq.len > 0)
+        xbt_dynar_push(common_sequence, &subseq);
+      if (lcs_len1 < lcs_len) {
+        int u = subseq.x + subseq.len;
+        int v = subseq.y + subseq.len;
+        diff_compute_lcs(vec_a, u, a0 + len_a - u, vec_b, v, b0 + len_b - v,
+                         common_sequence, seqs, fp);
+      }
     } else {
-      /* sa in db, and sb in da: cannot go further */
-      return;
+      int len = MIN(len_a, len_b) - subseq.len;
+      if (subseq.x == a0 && subseq.y == b0) {
+        if (subseq.len > 0)
+          xbt_dynar_push(common_sequence, &subseq);
+        if (len > 0) {
+          struct subsequence subseq0 = {a0 + len_a - len,
+                                        b0 + len_b - len, len};
+          xbt_dynar_push(common_sequence, &subseq0);
+        }
+      } else {
+        if (len > 0) {
+          struct subsequence subseq0 = {a0, b0, len};
+          xbt_dynar_push(common_sequence, &subseq0);
+        }
+        if (subseq.len > 0)
+          xbt_dynar_push(common_sequence, &subseq);
+      }
     }
+    return lcs_len;
+  } else {
+    return 0;
   }
 }
 
-static XBT_INLINE int diff_get(xbt_matrix_t C, int i, int j)
+static int diff_member(const char *s, const char *vec[], int from, int to)
 {
-  return (i == -1 || j == -1) ? 0 : xbt_matrix_get_as(C, i, j, int);
+  for ( ; from < to ; from++)
+    if (!strcmp(s, vec[from]))
+      return 1;
+  return 0;
 }
 
-static xbt_matrix_t diff_build_LCS(xbt_dynar_t da, xbt_dynar_t db)
+/* Extract common prefix.
+ */
+static void diff_easy_prefix(const char *vec_a[], int *a0_p, int *len_a_p,
+                             const char *vec_b[], int *b0_p, int *len_b_p,
+                             xbt_dynar_t common_sequence)
 {
-  unsigned len_a = xbt_dynar_length(da);
-  unsigned len_b = xbt_dynar_length(db);
-  xbt_matrix_t C = xbt_matrix_new(len_a, len_b, sizeof(int), NULL);
-  int i, j;
-
-  /* Compute the LCS */
-  /*
-     function LCSLength(X[1..m], Y[1..n])
-       C = array(0..m, 0..n)
-       for i := 0..m
-         C[i,0] = 0
-       for j := 1..n
-         C[0,j] = 0
-       for i := 1..m
-         for j := 1..n
-           if X[i] = Y[j]
-             C[i,j] := C[i-1,j-1] + 1
-           else:
-             C[i,j] := max(C[i,j-1], C[i-1,j])
-       return C[m,n]
-   */
-  for (i = 0; i < len_a; i++)
-    for (j = 0; j < len_b; j++) {
-
-      if (!strcmp(xbt_dynar_get_as(da, i, char *),
-                  xbt_dynar_get_as(db, j, char *)))
-        xbt_matrix_get_as(C, i, j, int) = diff_get(C, i - 1, j - 1) + 1;
-      else
-        xbt_matrix_get_as(C, i, j, int) = max(diff_get(C, i, j - 1),
-                                              diff_get(C, i - 1, j));
+  int a0 = *a0_p;
+  int b0 = *b0_p;
+  int len_a = *len_a_p;
+  int len_b = *len_b_p;
+
+  while (len_a > 0 && len_b > 0) {
+    struct subsequence subseq = {a0, b0, 0};
+    while (len_a > 0 && len_b > 0 && !strcmp(vec_a[a0], vec_b[b0])) {
+      a0++, len_a--;
+      b0++, len_b--;
+      subseq.len++;
     }
-  return C;
+    if (subseq.len > 0)
+      xbt_dynar_push(common_sequence, &subseq);
+    if (len_a > 0 && len_b > 0 &&
+        !diff_member(vec_a[a0], vec_b, b0 + 1, b0 + len_b)) {
+      a0++, len_a--;
+    } else {
+      break;
+    }
+  }
+
+  *a0_p = a0;
+  *b0_p = b0;
+  *len_a_p = len_a;
+  *len_b_p = len_b;
 }
 
-static void diff_build_diff(xbt_dynar_t res,
-                            xbt_matrix_t C,
-                            xbt_dynar_t da, xbt_dynar_t db, int i, int j)
+/* Extract common suffix.
+ */
+static void diff_easy_suffix(const char *vec_a[], int *a0_p, int *len_a_p,
+                             const char *vec_b[], int *b0_p, int *len_b_p,
+                             xbt_dynar_t common_suffix)
 {
-  /* Construct the diff
-     function printDiff(C[0..m,0..n], X[1..m], Y[1..n], i, j)
-       if i > 0 and j > 0 and X[i] = Y[j]
-         printDiff(C, X, Y, i-1, j-1)
-         print "  " + X[i]
-       else
-         if j > 0 and (i = 0 or C[i,j-1] >= C[i-1,j])
-           printDiff(C, X, Y, i, j-1)
-           print "+ " + Y[j]
-         else if i > 0 and (j = 0 or C[i,j-1] < C[i-1,j])
-           printDiff(C, X, Y, i-1, j)
-           print "- " + X[i]
-   */
-
-  if (i >= 0 && j >= 0 && !strcmp(xbt_dynar_get_as(da, i, char *),
-                                  xbt_dynar_get_as(db, j, char *))) {
-    diff_build_diff(res, C, da, db, i - 1, j - 1);
-    diff_push(res, ' ', xbt_dynar_get_as(da, i, char *));
-  } else if (j >= 0 &&
-             (i == -1 || diff_get(C, i, j - 1) >= diff_get(C, i - 1, j))) {
-    diff_build_diff(res, C, da, db, i, j - 1);
-    diff_push(res, '+', xbt_dynar_get_as(db, j, char *));
-  } else if (i >= 0 &&
-             (j == -1 || diff_get(C, i, j - 1) < diff_get(C, i - 1, j))) {
-    diff_build_diff(res, C, da, db, i - 1, j);
-    diff_push(res, '-', xbt_dynar_get_as(da, i, char *));
+  int a0 = *a0_p;
+  int b0 = *b0_p;
+  int len_a = *len_a_p;
+  int len_b = *len_b_p;
+
+  while (len_a > 0 && len_b > 0){
+    struct subsequence subseq;
+    subseq.len = 0;
+    while (len_a > 0 && len_b > 0 &&
+           !strcmp(vec_a[a0 + len_a - 1], vec_b[b0 + len_b - 1])) {
+      len_a--;
+      len_b--;
+      subseq.len++;
+    }
+    if (subseq.len > 0) {
+      subseq.x = a0 + len_a;
+      subseq.y = b0 + len_b;
+      xbt_dynar_push(common_suffix, &subseq);
+    }
+    if (len_a > 0 && len_b > 0 &&
+        !diff_member(vec_b[b0 + len_b - 1], vec_a, a0, a0 + len_a - 1)) {
+      len_b--;
+    } else {
+      break;
+    }
   }
+
+  *a0_p = a0;
+  *b0_p = b0;
+  *len_a_p = len_a;
+  *len_b_p = len_b;
 }
 
 /** @brief Compute the unified diff of two strings */
@@ -720,14 +796,19 @@ char *xbt_str_diff(const char *a, const char *b)
 {
   xbt_dynar_t da = xbt_str_split(a, "\n");
   xbt_dynar_t db = xbt_str_split(b, "\n");
-  xbt_matrix_t C;
+  xbt_dynar_t common_sequence, common_suffix;
+  size_t len;
+  const char **vec_a, **vec_b;
+  int a0, b0;
+  int len_a, len_b;
+  int max;
+  int *fp_base, *fp;
+  struct subsequence *seqs_base, *seqs;
+  struct subsequence subseq;
   xbt_dynar_t diff;
-  xbt_dynar_t diff2;
   char *res;
-  size_t len;
-
-  diff = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
-  diff2 = xbt_dynar_new(sizeof(char *), NULL);
+  int x, y;
+  unsigned s;
 
   /* Clean empty lines at the end of da and db */
   len = strlen(a);
@@ -737,30 +818,64 @@ char *xbt_str_diff(const char *a, const char *b)
   if (len > 0 && b[len - 1] == '\n')
     xbt_dynar_pop(db, NULL);
 
-  /* Extract the easy suffix, do it before extracting the prefix,
-   * as xbt_dynar_pop costs less than xbt_dynar_shift */
-  diff_easy_suffix(diff2, da, db);
+  /* Various initializations */
+  /* Assume that dynar's content is contiguous */
+  a0 = 0;
+  len_a = xbt_dynar_length(da);
+  vec_a = len_a ? xbt_dynar_get_ptr(da, 0) : NULL;
+  b0 = 0;
+  len_b = xbt_dynar_length(db);
+  vec_b = len_b ? xbt_dynar_get_ptr(db, 0) : NULL;
+  max = MAX(len_a, len_b) + 1;
+  fp_base = xbt_new(int, 2 * max + 1);
+  fp = fp_base + max;           /* indexes in [-max..max] */
+  seqs_base = xbt_new(struct subsequence, 2 * max + 1);
+  seqs = seqs_base + max;       /* indexes in [-max..max] */
+  common_sequence = xbt_dynar_new(sizeof(struct subsequence), NULL);
+  common_suffix = xbt_dynar_new(sizeof(struct subsequence), NULL);
+
+  /* Add a sentinel a the end of the sequence */
+  subseq.x = len_a;
+  subseq.y = len_b;
+  subseq.len = 0;
+  xbt_dynar_push(common_suffix, &subseq);
+
+  /* Compute the Longest Common Subsequence */
+  diff_easy_prefix(vec_a, &a0, &len_a, vec_b, &b0, &len_b, common_sequence);
+  diff_easy_suffix(vec_a, &a0, &len_a, vec_b, &b0, &len_b, common_suffix);
+  diff_compute_lcs(vec_a, a0, len_a, vec_b, b0, len_b, common_sequence, seqs, fp);
+  while (!xbt_dynar_is_empty(common_suffix)) {
+    xbt_dynar_pop(common_suffix, &subseq);
+    xbt_dynar_push(common_sequence, &subseq);
+  }
 
-  /* Extract the easy prefix */
-  diff_easy_prefix(diff, da, db);
+  /* Build a Shortest Edit Script, and the final result */
+  diff = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
+  x = 0;
+  y = 0;
+  xbt_dynar_foreach(common_sequence, s, subseq) {
+    while (x < subseq.x) {
+      char *topush = bprintf("- %s", vec_a[x++]);
+      xbt_dynar_push_as(diff, char*, topush);
+    }
+    while (y < subseq.y) {
+      char *topush = bprintf("+ %s", vec_b[y++]);
+      xbt_dynar_push_as(diff, char*, topush);
+    }
+    while (x < subseq.x + subseq.len) {
+      char *topush = bprintf("  %s", vec_a[x++]);
+      xbt_dynar_push_as(diff, char*, topush);
+      y++;
+    }
+  }
+  res = xbt_str_join(diff, "\n");
 
-  /* Compute the diff for the remaining */
-  C = diff_build_LCS(da, db);
-  diff_build_diff(diff, C, da, db,
-                  xbt_dynar_length(da) - 1, xbt_dynar_length(db) - 1);
-  xbt_matrix_free(C);
+  xbt_free(fp_base);
+  xbt_free(seqs_base);
   xbt_dynar_free(&db);
   xbt_dynar_free(&da);
-
-  /* Add the easy suffix, in reverse order */
-  while (!xbt_dynar_is_empty(diff2)) {
-    char *topush = xbt_dynar_pop_as(diff2, char *);
-    xbt_dynar_push(diff, &topush);
-  }
-  xbt_dynar_free(&diff2);
-
-  /* Build the final result */
-  res = xbt_str_join(diff, "\n");
+  xbt_dynar_free(&common_sequence);
+  xbt_dynar_free(&common_suffix);
   xbt_dynar_free(&diff);
 
   return res;
index 7a41fb1..7d98a5e 100755 (executable)
@@ -11,7 +11,9 @@ my @extra_files = qw(html/index.html html/pages.html html/modules.html html/anno
 # GRAS tutorial
 map {push @extra_files, "html/GRAS_tut_$_.html"} qw (intro 
                                                      tour tour_install tour_setup tour_simpleexchange tour_args tour_callbacks tour_globals 
-                                                          tour_logs tour_timers tour_exceptions tour_rpc);
+                                                          tour_logs tour_timers tour_exceptions tour_simpledata tour_rpc tour_explicitwait
+                                                          tour_message_recaping tour_staticstruct tour_pointers tour_dynar 
+                                                          tour_manualdatadef tour_exchangecb);
 
 # GRAS examples
 map {push @extra_files, "html/GRAS_ex_$_.html"} qw (ping mmrpc token timer);
@@ -401,7 +403,8 @@ foreach my $file (@allfiles) {
              || $file =~ /^html\/modules.*/
              || $file =~ /^html\/annotated.*/
              || $file =~ /^html\/group__.*/
-             || $file =~ /^html\/functions.*/)
+             || $file =~ /^html\/functions.*/
+             || $file =~ /^html\/GRAS_tut_tour_.*/)
              {
                                $tmp_buff .= '      <div class="tabs_group_use">'."\n";
                                $tmp_buff .= '          <ul class="tablist">'."\n";
@@ -436,7 +439,8 @@ foreach my $file (@allfiles) {
                      $tmp_buff =~ s/<li class="current">/<li>/g;
                      $tmp_buff =~ s/<li><a href="$filename.html">/<li class="current"><a href="$filename.html">/g;     
              }
-             if($file =~ /^html\/group__.*/)
+             if($file =~ /^html\/group__.*/
+             || $file =~ /^html\/GRAS_tut_tour_.*/)
              {
                $tmp_buff =~ s/<li><a href="modules.html">/<li class="current"><a href="modules.html">/g;
              }
@@ -445,7 +449,6 @@ foreach my $file (@allfiles) {
                $tmp_buff =~ s/<li><a href="annotated.html">/<li class="current"><a href="annotated.html">/g;
              }
              
-
              print TO $tmp_buff;             
              next;
     }
index 0aa5faf..66ef7d7 100755 (executable)
@@ -130,8 +130,10 @@ sub process_one($) {
 int main(int argc, char *argv[]) {
   xbt_test_suite_t suite; 
   char selection[1024];
-  int i;\n
-  int res;\n
+  int verbosity = 0;
+  int i;
+  int res;
+
   /* SGU: BEGIN SUITES DECLARATION */
   /* SGU: END SUITES DECLARATION */
       
@@ -148,14 +150,17 @@ int main(int argc, char *argv[]) {
           strcat(selection, \",\");
           strcat(selection, p);
         }
-      } else if (!strncmp(argv[i],\"--dump-only\",strlen(\"--dump-only\"))||
-                !strncmp(argv[i],\"--dump\",     strlen(\"--dump\"))) {
+      } else if (!strcmp(argv[i], \"--verbose\")) {
+        verbosity++;
+      } else if (!strcmp(argv[i], \"--dump-only\")||
+                 !strcmp(argv[i], \"--dump\")) {
         xbt_test_dump(selection);
         return 0;
-      } else if (!strncmp(argv[i],\"--help\",strlen(\"--help\"))) {
+      } else if (!strcmp(argv[i], \"--help\")) {
          printf(
              "Usage: testall [--help] [--tests=selection] [--dump-only]\\n\\n"
              "--help: display this help\\n"
+             "--verbose: print the name for each running test\\n"
              "--dump-only: don't run the tests, but display some debuging info about the tests\\n"
              "--tests=selection: Use argument to select which suites/units/tests to run\\n"
              "                   --tests can be used more than once, and selection may be a comma\\n"
@@ -180,7 +185,7 @@ int main(int argc, char *argv[]) {
     }
   /* Got all my tests to do */
       
-  res = xbt_test_run(selection);
+  res = xbt_test_run(selection, verbosity);
   xbt_test_exit();
   return res;
 }