From: Martin Quinson Date: Sun, 28 Feb 2016 21:41:16 +0000 (+0100) Subject: Ensure that task_listen works on asynchronous mailboxes (fix #40) X-Git-Tag: v3_13~639 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/a9950e96250eb4d483964721e1d83aa9c63960e9 Ensure that task_listen works on asynchronous mailboxes (fix #40) - Clearly, nobody tested this before. Sorry for the delay in investiguating - Also add a test case (written by Guillaume in the bug report) --- diff --git a/.gitignore b/.gitignore index 4d9f15423e..f7dcfda410 100644 --- a/.gitignore +++ b/.gitignore @@ -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/listen_async/listen_async teshsuite/msg/pid/pid teshsuite/msg/process_join/process_join teshsuite/msg/process/process diff --git a/src/msg/msg_gos.cpp b/src/msg/msg_gos.cpp index 426f25aa5f..cf719803e8 100644 --- a/src/msg/msg_gos.cpp +++ b/src/msg/msg_gos.cpp @@ -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. */ +#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" @@ -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) { - 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 diff --git a/teshsuite/msg/listen_async/CMakeLists.txt b/teshsuite/msg/listen_async/CMakeLists.txt new file mode 100644 index 0000000000..8749c404ed --- /dev/null +++ b/teshsuite/msg/listen_async/CMakeLists.txt @@ -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 index 0000000000..d32852bf96 --- /dev/null +++ b/teshsuite/msg/listen_async/listen_async.c @@ -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 +#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 index 0000000000..c92957eee5 --- /dev/null +++ b/teshsuite/msg/listen_async/listen_async.tesh @@ -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 diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 27263131f1..a02f7d3a37 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -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/listen_async/CMakeLists.txt teshsuite/msg/pid/CMakeLists.txt teshsuite/msg/process/CMakeLists.txt teshsuite/msg/process_join/CMakeLists.txt