XEngineCrossingTests.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Threading;
  29. using Nini.Config;
  30. using NUnit.Framework;
  31. using OpenMetaverse;
  32. using OpenSim.Framework;
  33. using OpenSim.Region.CoreModules.Framework.EntityTransfer;
  34. using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
  35. using OpenSim.Region.Framework.Scenes;
  36. using OpenSim.Region.ScriptEngine.Shared;
  37. using OpenSim.Tests.Common;
  38. namespace OpenSim.Region.ScriptEngine.XEngine.Tests
  39. {
  40. /// <summary>
  41. /// XEngine tests connected with crossing scripts between regions.
  42. /// </summary>
  43. [TestFixture]
  44. public class XEngineCrossingTests : OpenSimTestCase
  45. {
  46. [TestFixtureSetUp]
  47. public void FixtureInit()
  48. {
  49. // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
  50. Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
  51. }
  52. [TestFixtureTearDown]
  53. public void TearDown()
  54. {
  55. // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
  56. // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
  57. // tests really shouldn't).
  58. Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
  59. }
  60. /// <summary>
  61. /// Test script state preservation when a script crosses between regions on the same simulator.
  62. /// </summary>
  63. [Test]
  64. public void TestScriptCrossOnSameSimulator()
  65. {
  66. TestHelpers.InMethod();
  67. // TestHelpers.EnableLogging();
  68. UUID userId = TestHelpers.ParseTail(0x1);
  69. int sceneObjectIdTail = 0x2;
  70. EntityTransferModule etmA = new EntityTransferModule();
  71. EntityTransferModule etmB = new EntityTransferModule();
  72. LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule();
  73. XEngine xEngineA = new XEngine();
  74. XEngine xEngineB = new XEngine();
  75. xEngineA.DebugLevel = 1;
  76. xEngineB.DebugLevel = 1;
  77. IConfigSource configSource = new IniConfigSource();
  78. IConfig startupConfig = configSource.AddConfig("Startup");
  79. startupConfig.Set("DefaultScriptEngine", "XEngine");
  80. startupConfig.Set("TrustBinaries", "true");
  81. IConfig xEngineConfig = configSource.AddConfig("XEngine");
  82. xEngineConfig.Set("Enabled", "true");
  83. xEngineConfig.Set("StartDelay", "0");
  84. // These tests will not run with AppDomainLoading = true, at least on mono. For unknown reasons, the call
  85. // to AssemblyResolver.OnAssemblyResolve fails.
  86. xEngineConfig.Set("AppDomainLoading", "false");
  87. IConfig modulesConfig = configSource.AddConfig("Modules");
  88. modulesConfig.Set("EntityTransferModule", etmA.Name);
  89. modulesConfig.Set("SimulationServices", lscm.Name);
  90. SceneHelpers sh = new SceneHelpers();
  91. TestScene sceneA = sh.SetupScene("sceneA", TestHelpers.ParseTail(0x100), 1000, 1000, configSource);
  92. TestScene sceneB = sh.SetupScene("sceneB", TestHelpers.ParseTail(0x200), 1000, 999, configSource);
  93. SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, configSource, lscm);
  94. SceneHelpers.SetupSceneModules(sceneA, configSource, etmA, xEngineA);
  95. SceneHelpers.SetupSceneModules(sceneB, configSource, etmB, xEngineB);
  96. sceneA.StartScripts();
  97. sceneB.StartScripts();
  98. SceneObjectGroup soSceneA = SceneHelpers.AddSceneObject(sceneA, 1, userId, "so1-", sceneObjectIdTail);
  99. soSceneA.AbsolutePosition = new Vector3(128, 10, 20);
  100. string soSceneAName = soSceneA.Name;
  101. string scriptItemSceneAName = "script1";
  102. // CREATE SCRIPT TODO
  103. InventoryItemBase scriptItemSceneA = new InventoryItemBase();
  104. // itemTemplate.ID = itemId;
  105. scriptItemSceneA.Name = scriptItemSceneAName;
  106. scriptItemSceneA.Folder = soSceneA.UUID;
  107. scriptItemSceneA.InvType = (int)InventoryType.LSL;
  108. AutoResetEvent chatEvent = new AutoResetEvent(false);
  109. OSChatMessage messageReceived = null;
  110. sceneA.EventManager.OnChatFromWorld += (s, m) => { messageReceived = m; chatEvent.Set(); };
  111. sceneA.RezNewScript(userId, scriptItemSceneA,
  112. @"integer c = 0;
  113. default
  114. {
  115. state_entry()
  116. {
  117. llSay(0, ""Script running"");
  118. }
  119. changed(integer change)
  120. {
  121. llSay(0, ""Changed"");
  122. }
  123. touch_start(integer n)
  124. {
  125. c = c + 1;
  126. llSay(0, (string)c);
  127. }
  128. }");
  129. chatEvent.WaitOne(60000);
  130. Assert.That(messageReceived, Is.Not.Null, "No chat message received.");
  131. Assert.That(messageReceived.Message, Is.EqualTo("Script running"));
  132. {
  133. // XXX: Should not be doing this so directly. Should call some variant of EventManager.touch() instead.
  134. DetectParams[] det = new DetectParams[1];
  135. det[0] = new DetectParams();
  136. det[0].Key = userId;
  137. det[0].Populate(sceneA);
  138. EventParams ep = new EventParams("touch_start", new Object[] { new LSL_Types.LSLInteger(1) }, det);
  139. messageReceived = null;
  140. chatEvent.Reset();
  141. xEngineA.PostObjectEvent(soSceneA.LocalId, ep);
  142. chatEvent.WaitOne(60000);
  143. Assert.That(messageReceived.Message, Is.EqualTo("1"));
  144. }
  145. AutoResetEvent chatEventB = new AutoResetEvent(false);
  146. sceneB.EventManager.OnChatFromWorld += (s, m) => { messageReceived = m; chatEventB.Set(); };
  147. messageReceived = null;
  148. chatEventB.Reset();
  149. // Cross with a negative value
  150. soSceneA.AbsolutePosition = new Vector3(128, -10, 20);
  151. chatEventB.WaitOne(60000);
  152. Assert.That(messageReceived, Is.Not.Null, "No Changed message received.");
  153. Assert.That(messageReceived.Message, Is.Not.Null, "Changed message without content");
  154. Assert.That(messageReceived.Message, Is.EqualTo("Changed"));
  155. // TEST sending event to moved prim and output
  156. {
  157. SceneObjectGroup soSceneB = sceneB.GetSceneObjectGroup(soSceneAName);
  158. TaskInventoryItem scriptItemSceneB = soSceneB.RootPart.Inventory.GetInventoryItem(scriptItemSceneAName);
  159. // XXX: Should not be doing this so directly. Should call some variant of EventManager.touch() instead.
  160. DetectParams[] det = new DetectParams[1];
  161. det[0] = new DetectParams();
  162. det[0].Key = userId;
  163. det[0].Populate(sceneB);
  164. EventParams ep = new EventParams("touch_start", new Object[] { new LSL_Types.LSLInteger(1) }, det);
  165. Thread.Sleep(250); // wait for other change messages to pass
  166. messageReceived = null;
  167. chatEventB.Reset();
  168. xEngineB.PostObjectEvent(soSceneB.LocalId, ep);
  169. chatEventB.WaitOne(60000);
  170. Assert.That(messageReceived.Message, Is.EqualTo("2"));
  171. }
  172. }
  173. }
  174. }