From: Frederic Suter Date: Mon, 27 Mar 2017 08:16:07 +0000 (+0200) Subject: tesh conversion X-Git-Tag: v3.16~443 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/2748fc363dd4fe709089d1ec51c38db3fe2ca26a tesh conversion add Mailbox::listen() and this_actor::isend() in the process --- diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index 713127f8d4..2196eadc55 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -306,6 +306,8 @@ namespace this_actor { */ XBT_PUBLIC(void) send(MailboxPtr chan, void* payload, double simulatedSize); + XBT_PUBLIC(void) isend(MailboxPtr chan, void* payload, double simulatedSize); + /** @brief Returns the PID of the current actor. */ XBT_PUBLIC(int) pid(); diff --git a/include/simgrid/s4u/Mailbox.hpp b/include/simgrid/s4u/Mailbox.hpp index 9d52198b07..bd0a479215 100644 --- a/include/simgrid/s4u/Mailbox.hpp +++ b/include/simgrid/s4u/Mailbox.hpp @@ -132,6 +132,9 @@ public: /** Returns whether the mailbox contains queued communications */ bool empty(); + /** Check if there is a communication going on in a mailbox. */ + bool listen(); + /** Gets the first element in the queue (without dequeuing it), or nullptr if none is there */ smx_activity_t front(); diff --git a/src/msg/msg_gos.cpp b/src/msg/msg_gos.cpp index 8fc4a95001..7d5000821b 100644 --- a/src/msg/msg_gos.cpp +++ b/src/msg/msg_gos.cpp @@ -848,8 +848,7 @@ msg_error_t MSG_task_send_with_timeout_bounded(msg_task_t task, const char *alia int MSG_task_listen(const char *alias) { simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(alias); - return !mbox->empty() || - (mbox->getImpl()->permanent_receiver && !mbox->getImpl()->done_comm_queue.empty()); + return mbox->listen() ? 1 : 0; } /** \ingroup msg_task_usage diff --git a/src/s4u/s4u_actor.cpp b/src/s4u/s4u_actor.cpp index f16cabf607..c1c7ed280a 100644 --- a/src/s4u/s4u_actor.cpp +++ b/src/s4u/s4u_actor.cpp @@ -190,6 +190,11 @@ void send(MailboxPtr chan, void* payload, double simulatedSize) c.wait(); } +void isend(MailboxPtr chan, void* payload, double simulatedSize) +{ + Comm::send_async(chan, payload, simulatedSize); +} + int pid() { return SIMIX_process_self()->pid; diff --git a/src/s4u/s4u_mailbox.cpp b/src/s4u/s4u_mailbox.cpp index b2cbb4de69..2e6ad2c88a 100644 --- a/src/s4u/s4u_mailbox.cpp +++ b/src/s4u/s4u_mailbox.cpp @@ -41,6 +41,11 @@ bool Mailbox::empty() return pimpl_->comm_queue.empty(); } +bool Mailbox::listen() +{ + return !this->empty() || (pimpl_->permanent_receiver && !pimpl_->done_comm_queue.empty()); +} + smx_activity_t Mailbox::front() { return pimpl_->comm_queue.empty() ? nullptr : pimpl_->comm_queue.front(); diff --git a/teshsuite/msg/CMakeLists.txt b/teshsuite/msg/CMakeLists.txt index 28cdd2cf51..d7e61e4f71 100644 --- a/teshsuite/msg/CMakeLists.txt +++ b/teshsuite/msg/CMakeLists.txt @@ -1,5 +1,5 @@ # C examples -foreach(x get_sender host_on_off host_on_off_recv host_on_off_processes host_on_off_wait listen_async +foreach(x get_sender host_on_off host_on_off_recv host_on_off_processes host_on_off_wait storage_client_server trace_integration) add_executable (${x} ${x}/${x}.c) target_link_libraries(${x} simgrid) @@ -34,7 +34,7 @@ set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/trace_integration ${CMAKE_CURRENT_SOURCE_DIR}/trace_integration/test-hbp1-c1s1-c3s2.xml ${CMAKE_CURRENT_SOURCE_DIR}/trace_integration/test-hbp2.5-hbp1.5.xml PARENT_SCOPE) -foreach(x get_sender host_on_off host_on_off_processes host_on_off_recv host_on_off_wait listen_async +foreach(x get_sender host_on_off host_on_off_processes host_on_off_recv host_on_off_wait storage_client_server task_destroy_cancel trace_integration) ADD_TESH_FACTORIES(tesh-msg-${x} "thread;boost;ucontext;raw" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/msg/${x} --cd ${CMAKE_BINARY_DIR}/teshsuite/msg/${x} ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/${x}/${x}.tesh) endforeach() diff --git a/teshsuite/msg/listen_async/listen_async.c b/teshsuite/msg/listen_async/listen_async.c deleted file mode 100644 index 10c97d7a77..0000000000 --- a/teshsuite/msg/listen_async/listen_async.c +++ /dev/null @@ -1,48 +0,0 @@ -/* Bug report: https://github.com/simgrid/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 "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 deleted file mode 100644 index c92957eee5..0000000000 --- a/teshsuite/msg/listen_async/listen_async.tesh +++ /dev/null @@ -1,6 +0,0 @@ -$ ./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/teshsuite/s4u/CMakeLists.txt b/teshsuite/s4u/CMakeLists.txt index 12c25fe335..06301505b5 100644 --- a/teshsuite/s4u/CMakeLists.txt +++ b/teshsuite/s4u/CMakeLists.txt @@ -1,4 +1,4 @@ -foreach(x actor concurrent_rw pid) +foreach(x actor concurrent_rw listen_async pid) add_executable (${x} ${x}/${x}.cpp) target_link_libraries(${x} simgrid) set_target_properties(${x} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${x}) @@ -11,6 +11,6 @@ set(teshsuite_src ${teshsuite_src} PARENT_SCOPE) set(tesh_files ${tesh_files} PARENT_SCOPE) set(xml_files ${xml_files} PARENT_SCOPE) -foreach(x actor concurrent_rw pid) +foreach(x actor concurrent_rw listen_async pid) ADD_TESH_FACTORIES(tesh-s4u-${x} "thread;boost;ucontext;raw" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x} --cd ${CMAKE_BINARY_DIR}/teshsuite/s4u/${x} ${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x}/${x}.tesh) endforeach() diff --git a/teshsuite/s4u/listen_async/listen_async.cpp b/teshsuite/s4u/listen_async/listen_async.cpp new file mode 100644 index 0000000000..4948ed418e --- /dev/null +++ b/teshsuite/s4u/listen_async/listen_async.cpp @@ -0,0 +1,49 @@ +/* Bug report: https://github.com/simgrid/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 "simgrid/s4u.hpp" + +XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example"); + +static void server() +{ + simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName("mailbox"); + + simgrid::s4u::this_actor::isend(mailbox, xbt_strdup("Some data"), 0); + + xbt_assert(mailbox->listen()); // True (1) + XBT_INFO("Task listen works on regular mailboxes"); + char* res = static_cast(simgrid::s4u::this_actor::recv(mailbox)); + + xbt_assert(!strcmp("Some data", res), "Data received: %s", res); + XBT_INFO("Data successfully received from regular mailbox"); + xbt_free(res); + + simgrid::s4u::MailboxPtr mailbox2 = simgrid::s4u::Mailbox::byName("mailbox2"); + mailbox2->setReceiver(simgrid::s4u::Actor::self()); + + simgrid::s4u::this_actor::isend(mailbox2, xbt_strdup("More data"), 0); + + xbt_assert(mailbox2->listen()); // used to break. + XBT_INFO("Task listen works on asynchronous mailboxes"); + + res = static_cast(simgrid::s4u::this_actor::recv(mailbox2)); + xbt_assert(!strcmp("More data", res)); + xbt_free(res); + + XBT_INFO("Data successfully received from asynchronous mailbox"); +} + +int main(int argc, char* argv[]) +{ + simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv); + e->loadPlatform(argv[1]); + + simgrid::s4u::Actor::createActor("test", simgrid::s4u::Host::by_name("Tremblay"), server); + + e->run(); + return 0; +} diff --git a/teshsuite/s4u/listen_async/listen_async.tesh b/teshsuite/s4u/listen_async/listen_async.tesh new file mode 100644 index 0000000000..184718e296 --- /dev/null +++ b/teshsuite/s4u/listen_async/listen_async.tesh @@ -0,0 +1,6 @@ +$ ./listen_async ${srcdir:=.}/../../../examples/platforms/small_platform.xml "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n" +> [ 0.000000] (test@Tremblay) Task listen works on regular mailboxes +> [ 0.000195] (test@Tremblay) Data successfully received from regular mailbox +> [ 0.000195] (test@Tremblay) Task listen works on asynchronous mailboxes +> [ 0.000195] (test@Tremblay) Data successfully received from asynchronous mailbox +> [ 0.000195] (maestro@) Variable 3 still in system when freing it: this may be a bug