From c4830be809e3969945e79f543151a676bbc12a1f Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 28 Jun 2022 22:07:02 +0200 Subject: [PATCH] Add a TESH for the new sthread feature --- examples/sthread/CMakeLists.txt | 4 +++- examples/sthread/pthread-mutex-simple.c | 9 ++++----- examples/sthread/pthread-mutex-simple.tesh | 7 +++++++ src/sthread/sthread.c | 1 - src/sthread/sthread_impl.cpp | 7 ++++--- 5 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 examples/sthread/pthread-mutex-simple.tesh diff --git a/examples/sthread/CMakeLists.txt b/examples/sthread/CMakeLists.txt index d5473021a4..784b55af44 100644 --- a/examples/sthread/CMakeLists.txt +++ b/examples/sthread/CMakeLists.txt @@ -13,10 +13,12 @@ foreach(x target_link_libraries(pthread-${x} PRIVATE Threads::Threads) add_dependencies(tests pthread-${x}) + ADD_TESH_FACTORIES(pthread-${x} "^thread" --setenv LD_PRELOAD=${CMAKE_BINARY_DIR}/lib/libsthread.so --cd ${CMAKE_BINARY_DIR}/examples/sthread ${CMAKE_CURRENT_SOURCE_DIR}/pthread-${x}.tesh) endif() -# set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/pthread-${x}.tesh) + set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/pthread-${x}.tesh) set(examples_src ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/pthread-${x}.c) + endforeach() # Regular sthread examples: test the internal interface for debugging purpose diff --git a/examples/sthread/pthread-mutex-simple.c b/examples/sthread/pthread-mutex-simple.c index abe582d5f0..b59214f2a6 100644 --- a/examples/sthread/pthread-mutex-simple.c +++ b/examples/sthread/pthread-mutex-simple.c @@ -10,6 +10,7 @@ static void* thread1_fun(void* ignore) pthread_mutex_lock(&mutex); pthread_mutex_unlock(&mutex); + fprintf(stderr, "The first thread is terminating.\n"); return NULL; } static void* thread2_fun(void* ignore) @@ -17,23 +18,21 @@ static void* thread2_fun(void* ignore) pthread_mutex_lock(&mutex); pthread_mutex_unlock(&mutex); + fprintf(stderr, "The second thread is terminating.\n"); return NULL; } int main(int argc, char* argv[]) { - fprintf(stderr, "User main is starting\n"); - pthread_mutex_init(&mutex, NULL); pthread_t thread1, thread2; pthread_create(&thread1, NULL, thread1_fun, NULL); - fprintf(stderr, "here\n"); pthread_create(&thread2, NULL, thread2_fun, NULL); - fprintf(stderr, "there\n"); + fprintf(stderr, "All threads are started.\n"); pthread_join(thread1, NULL); pthread_join(thread2, NULL); - fprintf(stderr, "User main is done\n"); + fprintf(stderr, "User's main is terminating.\n"); return 0; } diff --git a/examples/sthread/pthread-mutex-simple.tesh b/examples/sthread/pthread-mutex-simple.tesh new file mode 100644 index 0000000000..00827cbed4 --- /dev/null +++ b/examples/sthread/pthread-mutex-simple.tesh @@ -0,0 +1,7 @@ +$ ./pthread-mutex-simple +> [0.000000] [sthread/INFO] Starting the simulation. +> The first thread is terminating. +> All threads are started. +> The second thread is terminating. +> User's main is terminating. +> [0.000000] [sthread/INFO] All threads exited. Terminating the simulation. \ No newline at end of file diff --git a/src/sthread/sthread.c b/src/sthread/sthread.c index dd9a67c198..666cb36c74 100644 --- a/src/sthread/sthread.c +++ b/src/sthread/sthread.c @@ -211,7 +211,6 @@ int __libc_start_main(int (*main)(int, char**, char**), int argc, char** argv, i /* Find the real __libc_start_main()... */ typeof(&__libc_start_main) orig = dlsym(RTLD_NEXT, "__libc_start_main"); - fprintf(stderr, "__libc_start_main\n"); /* ... and call it with our custom main function */ return orig(main_hook, argc, argv, init, fini, rtld_fini, stack_end); } diff --git a/src/sthread/sthread_impl.cpp b/src/sthread/sthread_impl.cpp index 19a19b80b8..1780543ad0 100644 --- a/src/sthread/sthread_impl.cpp +++ b/src/sthread/sthread_impl.cpp @@ -30,7 +30,7 @@ int sthread_main(int argc, char** argv, char** envp, int (*raw_main)(int, char** std::ostringstream id; id << std::this_thread::get_id(); - XBT_INFO("sthread main() is starting in thread %s", id.str().c_str()); + XBT_DEBUG("sthread main() is starting in thread %s", id.str().c_str()); sg4::Engine e(&argc, argv); auto* zone = sg4::create_full_zone("world"); @@ -41,8 +41,9 @@ int sthread_main(int argc, char** argv, char** envp, int (*raw_main)(int, char** sthread_enable(); sg4::ActorPtr main_actor = sg4::Actor::create("tid 0", lilibeth, raw_main, argc, argv, envp); - XBT_INFO("sthread main() is launching the simulation"); + XBT_INFO("Starting the simulation."); sg4::Engine::get_instance()->run(); + XBT_INFO("All threads exited. Terminating the simulation."); return 0; } @@ -67,7 +68,7 @@ int sthread_create(unsigned long int* thread, const /*pthread_attr_t*/ void* att { static int TID = 0; TID++; - XBT_INFO("Create thread %d", TID); + XBT_VERB("Create thread %d", TID); int rank = 0; #if HAVE_SMPI if (SMPI_is_inited()) -- 2.20.1