Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Lua: add a test to check that global values are correctly duplicated
authorChristophe Thiéry <christopho128@gmail.com>
Mon, 3 Oct 2011 08:50:40 +0000 (10:50 +0200)
committerChristophe Thiéry <christopho128@gmail.com>
Mon, 3 Oct 2011 08:50:40 +0000 (10:50 +0200)
buildtools/Cmake/AddTests.cmake
examples/lua/state_cloner/deployment_duplicated_globals.xml [new file with mode: 0644]
examples/lua/state_cloner/duplicated_globals.lua [new file with mode: 0644]
examples/lua/state_cloner/duplicated_globals.tesh [new file with mode: 0644]

index 298258f..1d1033e 100644 (file)
@@ -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 (file)
index 0000000..aca6202
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
+<platform version="3">
+  <process host="Tremblay" function="set_global_string">
+    <argument value="Calling set_global_string() from Tremblay"/>
+  </process>
+  <process host="Bourassa" function="replace">
+    <argument value="Calling replace() from Bourassa"/>
+  </process>
+  <process host="Jupiter" function="please_dont_replace_me">
+    <argument value="Calling please_dont_replace_me() from Jupiter"/>
+  </process>
+</platform>
diff --git a/examples/lua/state_cloner/duplicated_globals.lua b/examples/lua/state_cloner/duplicated_globals.lua
new file mode 100644 (file)
index 0000000..d4c2331
--- /dev/null
@@ -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 (file)
index 0000000..c8029d7
--- /dev/null
@@ -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'