# 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")
--- /dev/null
+<?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>
--- /dev/null
+-- 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()
+
--- /dev/null
+# 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'