Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Ensure that task_listen works on asynchronous mailboxes (fix #40)
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 28 Feb 2016 21:41:16 +0000 (22:41 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 28 Feb 2016 21:45:57 +0000 (22:45 +0100)
- Clearly, nobody tested this before. Sorry for the delay in investiguating
- Also add a test case (written by Guillaume in the bug report)

.gitignore
src/msg/msg_gos.cpp
teshsuite/msg/listen_async/CMakeLists.txt [new file with mode: 0644]
teshsuite/msg/listen_async/listen_async.c [new file with mode: 0644]
teshsuite/msg/listen_async/listen_async.tesh [new file with mode: 0644]
tools/cmake/DefinePackages.cmake

index 4d9f154..f7dcfda 100644 (file)
@@ -281,6 +281,7 @@ teshsuite/msg/host_on_off/host_on_off
 teshsuite/msg/host_on_off/host_on_off_recv
 teshsuite/msg/host_on_off/host_on_off_wait
 teshsuite/msg/host_on_off_processes/host_on_off_processes
 teshsuite/msg/host_on_off/host_on_off_recv
 teshsuite/msg/host_on_off/host_on_off_wait
 teshsuite/msg/host_on_off_processes/host_on_off_processes
+teshsuite/msg/listen_async/listen_async
 teshsuite/msg/pid/pid
 teshsuite/msg/process_join/process_join
 teshsuite/msg/process/process
 teshsuite/msg/pid/pid
 teshsuite/msg/process_join/process_join
 teshsuite/msg/process/process
index 426f25a..cf71980 100644 (file)
@@ -1,9 +1,9 @@
-/* Copyright (c) 2004-2015. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2004-2016. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
+#include "src/simix/smx_private.h" /* MSG_task_listen looks inside the rdv directly. Not clean. */
 #include "msg_private.h"
 #include "mc/mc.h"
 #include "xbt/log.h"
 #include "msg_private.h"
 #include "mc/mc.h"
 #include "xbt/log.h"
@@ -826,7 +826,8 @@ msg_error_t MSG_task_send_with_timeout_bounded(msg_task_t task, const char *alia
  */
 int MSG_task_listen(const char *alias)
 {
  */
 int MSG_task_listen(const char *alias)
 {
-  return !MSG_mailbox_is_empty(MSG_mailbox_get_by_alias(alias));
+  smx_rdv_t rdv = MSG_mailbox_get_by_alias(alias);
+  return !MSG_mailbox_is_empty(rdv) || (rdv->permanent_receiver && xbt_fifo_size(rdv->done_comm_fifo)!=0);
 }
 
 /** \ingroup msg_task_usage
 }
 
 /** \ingroup msg_task_usage
diff --git a/teshsuite/msg/listen_async/CMakeLists.txt b/teshsuite/msg/listen_async/CMakeLists.txt
new file mode 100644 (file)
index 0000000..8749c40
--- /dev/null
@@ -0,0 +1,7 @@
+add_executable       (listen_async listen_async.c)
+target_link_libraries(listen_async simgrid)
+
+set(tesh_files    ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/listen_async.tesh  PARENT_SCOPE)
+set(teshsuite_src ${teshsuite_src} ${CMAKE_CURRENT_SOURCE_DIR}/listen_async.c     PARENT_SCOPE)
+
+ADD_TESH_FACTORIES(tesh-msg-listen-async "thread;ucontext;raw" --setenv srcdir=${CMAKE_CURRENT_SOURCE_DIR} --cd ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/listen_async.tesh)
diff --git a/teshsuite/msg/listen_async/listen_async.c b/teshsuite/msg/listen_async/listen_async.c
new file mode 100644 (file)
index 0000000..d32852b
--- /dev/null
@@ -0,0 +1,50 @@
+/* Bug report: https://github.com/mquinson/simgrid/issues/40
+ * 
+ * Task.listen used to be on async mailboxes as it always returned false.
+ * This occures in Java and C, but is only tested here in C.
+ */
+
+#include <stdio.h>
+#include "simgrid/msg.h"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
+
+static int server(int argc, char *argv[])
+{
+   msg_task_t task =  MSG_task_create("a", 0, 0, (char*)"Some data");
+   MSG_task_isend(task, "mailbox");
+   
+   xbt_assert(MSG_task_listen("mailbox")); // True (1)
+   XBT_INFO("Task listen works on regular mailboxes");
+   task = NULL;
+   MSG_task_receive(&task, "mailbox");
+   xbt_assert(!strcmp("Some data", MSG_task_get_data(task)), "Data received: %s", (char*)MSG_task_get_data(task));
+   MSG_task_destroy(task);
+   XBT_INFO("Data successfully received from regular mailbox");
+   
+   MSG_mailbox_set_async("mailbox2");
+   task = MSG_task_create("b", 0, 0, (char*)"More data");
+   MSG_task_isend(task, "mailbox2");
+   
+   xbt_assert(MSG_task_listen("mailbox2")); // used to break.
+   XBT_INFO("Task listen works on asynchronous mailboxes");
+   task = NULL;
+   MSG_task_receive(&task, "mailbox2");
+   xbt_assert(!strcmp("More data", MSG_task_get_data(task)));
+   MSG_task_destroy(task);
+   XBT_INFO("Data successfully received from asynchronous mailbox");
+   
+   return 0;
+}
+
+
+int main(int argc, char *argv[])
+{
+   MSG_init(&argc, argv);
+   xbt_assert(argc==2);
+   MSG_create_environment(argv[1]);
+   MSG_process_create("test", server, NULL, MSG_host_by_name("Tremblay"));
+   MSG_main();
+   
+   return 0;
+}
diff --git a/teshsuite/msg/listen_async/listen_async.tesh b/teshsuite/msg/listen_async/listen_async.tesh
new file mode 100644 (file)
index 0000000..c92957e
--- /dev/null
@@ -0,0 +1,6 @@
+$ ./listen_async ${srcdir:=.}/../../../examples/platforms/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [  0.000000] (1:test@Tremblay) Task listen works on regular mailboxes
+> [  0.000195] (1:test@Tremblay) Data successfully received from regular mailbox
+> [  0.000195] (1:test@Tremblay) Task listen works on asynchronous mailboxes
+> [  0.000195] (1:test@Tremblay) Data successfully received from asynchronous mailbox
+> [  0.000195] (0:maestro@) Variable 3 still in system when freing it: this may be a bug
index 2726313..a02f7d3 100644 (file)
@@ -1037,6 +1037,7 @@ set(CMAKEFILES_TXT
   teshsuite/msg/get_sender/CMakeLists.txt
   teshsuite/msg/host_on_off/CMakeLists.txt
   teshsuite/msg/host_on_off_processes/CMakeLists.txt
   teshsuite/msg/get_sender/CMakeLists.txt
   teshsuite/msg/host_on_off/CMakeLists.txt
   teshsuite/msg/host_on_off_processes/CMakeLists.txt
+  teshsuite/msg/listen_async/CMakeLists.txt
   teshsuite/msg/pid/CMakeLists.txt
   teshsuite/msg/process/CMakeLists.txt
   teshsuite/msg/process_join/CMakeLists.txt
   teshsuite/msg/pid/CMakeLists.txt
   teshsuite/msg/process/CMakeLists.txt
   teshsuite/msg/process_join/CMakeLists.txt