From 047ca9a2a6c647c2cc014d53460b8c359b3238c7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Christophe=20Thi=C3=A9ry?= Date: Mon, 3 Oct 2011 10:50:40 +0200 Subject: [PATCH 1/1] Lua: add a test to check that global values are correctly duplicated --- buildtools/Cmake/AddTests.cmake | 2 + .../deployment_duplicated_globals.xml | 13 ++++++ .../lua/state_cloner/duplicated_globals.lua | 44 +++++++++++++++++++ .../lua/state_cloner/duplicated_globals.tesh | 11 +++++ 4 files changed, 70 insertions(+) create mode 100644 examples/lua/state_cloner/deployment_duplicated_globals.xml create mode 100644 examples/lua/state_cloner/duplicated_globals.lua create mode 100644 examples/lua/state_cloner/duplicated_globals.tesh diff --git a/buildtools/Cmake/AddTests.cmake b/buildtools/Cmake/AddTests.cmake index 298258fb60..1d1033ec8c 100644 --- a/buildtools/Cmake/AddTests.cmake +++ b/buildtools/Cmake/AddTests.cmake @@ -379,10 +379,12 @@ ENDIF(HAVE_TRACING) # Lua examples if(HAVE_LUA) +ADD_TEST(lua-duplicated-globals ${CMAKE_BINARY_DIR}/bin/tesh --cd ${CMAKE_HOME_DIRECTORY}/examples/lua/state_cloner duplicated_globals.tesh) ADD_TEST(lua-masterslave ${CMAKE_BINARY_DIR}/bin/tesh --cd ${CMAKE_HOME_DIRECTORY}/examples/lua/masterslave master_slave.tesh) ADD_TEST(lua-mult-matrix ${CMAKE_BINARY_DIR}/bin/tesh --cd ${CMAKE_HOME_DIRECTORY}/examples/lua/multi_matrix mult_matrix.tesh) ADD_TEST(lua-masterslave-bypass ${CMAKE_BINARY_DIR}/bin/tesh --cd ${CMAKE_HOME_DIRECTORY}/examples/lua/console master_slave_bypass.tesh) ADD_TEST(lua-msg-masterslave-console ${CMAKE_BINARY_DIR}/bin/tesh --cd ${CMAKE_BINARY_DIR}/examples/msg/masterslave --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/msg/masterslave ${CMAKE_HOME_DIRECTORY}/examples/msg/masterslave/masterslave_console.tesh) +set_tests_properties(lua-duplicated-globals PROPERTIES ENVIRONMENT "LUA_CPATH=${CMAKE_BINARY_DIR}/examples/lua/?.so") set_tests_properties(lua-masterslave PROPERTIES ENVIRONMENT "LUA_CPATH=${CMAKE_BINARY_DIR}/examples/lua/?.so") set_tests_properties(lua-mult-matrix PROPERTIES ENVIRONMENT "LUA_CPATH=${CMAKE_BINARY_DIR}/examples/lua/?.so") set_tests_properties(lua-masterslave-bypass PROPERTIES ENVIRONMENT "LUA_CPATH=${CMAKE_BINARY_DIR}/examples/lua/?.so") diff --git a/examples/lua/state_cloner/deployment_duplicated_globals.xml b/examples/lua/state_cloner/deployment_duplicated_globals.xml new file mode 100644 index 0000000000..aca62021da --- /dev/null +++ b/examples/lua/state_cloner/deployment_duplicated_globals.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/examples/lua/state_cloner/duplicated_globals.lua b/examples/lua/state_cloner/duplicated_globals.lua new file mode 100644 index 0000000000..d4c2331290 --- /dev/null +++ b/examples/lua/state_cloner/duplicated_globals.lua @@ -0,0 +1,44 @@ +-- This code creates 3 simgrid processes and verifies that the global values +-- in each Lua world are correctly cloned from maestro and become different + +require("simgrid") + +global_string = "A global string set by maestro" + +-- Assigns to the global string the first argument and prints it +function set_global_string(...) + + global_string = arg[1] + simgrid.info("Changing the global string") + print_global() +end + +-- Replaces the function please_dont_change_me() by set_global_string() +-- and calls it +function replace(...) + + simgrid.info("Overwriting function please_dont_replace_me()") + please_dont_replace_me = set_global_string + please_dont_replace_me(...) +end + +-- Show a hello message and prints the global string +function please_dont_replace_me(...) + + simgrid.info("Hello from please_dont_replace_me(). I'm lucky, I still exist in this state.") + print_global() +end + +-- Prints the value of global_string +function print_global() + + simgrid.info("Global string is '"..global_string.."'") +end + +print_global() + +simgrid.platform("../../msg/small_platform.xml") +simgrid.application("deployment_duplicated_globals.xml") +simgrid.run() +simgrid.clean() + diff --git a/examples/lua/state_cloner/duplicated_globals.tesh b/examples/lua/state_cloner/duplicated_globals.tesh new file mode 100644 index 0000000000..c8029d71d9 --- /dev/null +++ b/examples/lua/state_cloner/duplicated_globals.tesh @@ -0,0 +1,11 @@ +# Checks that global values are correctly duplicated in Lua processes + +$ lua duplicated_globals.lua +> [0.000000] [lua/INFO] Global string is 'A global string set by maestro' +> [Tremblay:set_global_string:(1) 0.000000] [lua/INFO] Changing the global string +> [Tremblay:set_global_string:(1) 0.000000] [lua/INFO] Global string is 'Calling set_global_string() from Tremblay' +> [Bourassa:replace:(2) 0.000000] [lua/INFO] Overwriting function please_dont_replace_me() +> [Bourassa:replace:(2) 0.000000] [lua/INFO] Changing the global string +> [Bourassa:replace:(2) 0.000000] [lua/INFO] Global string is 'Calling replace() from Bourassa' +> [Jupiter:please_dont_replace_me:(3) 0.000000] [lua/INFO] Hello from please_dont_replace_me(). I'm lucky, I still exist in this state. +> [Jupiter:please_dont_replace_me:(3) 0.000000] [lua/INFO] Global string is 'A global string set by maestro' -- 2.20.1