aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/XEngine
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/XEngine')
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs96
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs22
2 files changed, 97 insertions, 21 deletions
diff --git a/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs
index b635d5c..7d7bd82 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs
@@ -27,44 +27,100 @@
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Threading;
30using Nini.Config; 31using Nini.Config;
31using NUnit.Framework; 32using NUnit.Framework;
32using OpenSim.Tests.Common.Mock;
33using OpenSim.Region.Framework.Scenes;
34using OpenMetaverse; 33using OpenMetaverse;
34using OpenSim.Framework;
35using OpenSim.Region.CoreModules.Scripting.WorldComm;
36using OpenSim.Region.Framework.Scenes;
35using OpenSim.Region.Framework.Interfaces; 37using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Tests.Common;
39using OpenSim.Tests.Common.Mock;
36 40
37namespace OpenSim.Region.ScriptEngine.XEngine.Tests 41namespace OpenSim.Region.ScriptEngine.XEngine.Tests
38{ 42{
39 /// <summary> 43 /// <summary>
40 /// Scene presence tests 44 /// XEngine tests.
41 /// </summary> 45 /// </summary>
42 /// Commented out XEngineTests that don't do anything
43 /*
44 [TestFixture] 46 [TestFixture]
45 public class XEngineTest 47 public class XEngineTest
46 { 48 {
47 public Scene scene; 49 private TestScene m_scene;
48 50 private XEngine m_xEngine;
49 public static Random random; 51 private AutoResetEvent m_chatEvent = new AutoResetEvent(false);
50 public TestClient testclient; 52 private OSChatMessage m_osChatMessageReceived;
51 //TestCommunicationsManager cm;
52 53
53 [TestFixtureSetUp] 54 [TestFixtureSetUp]
54 public void Init() 55 public void Init()
55 { 56 {
56 TestCommunicationsManager cm = new TestCommunicationsManager(); 57 //AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory + "/bin");
57 scene = SceneSetupHelpers.SetupScene("My Test", UUID.Random(), 1000, 1000, cm); 58// Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory);
58 random = new Random(); 59 m_xEngine = new XEngine();
60
61 // Necessary to stop serialization complaining
62 WorldCommModule wcModule = new WorldCommModule();
63
64 IniConfigSource configSource = new IniConfigSource();
65
66 IConfig startupConfig = configSource.AddConfig("Startup");
67 startupConfig.Set("DefaultScriptEngine", "XEngine");
68
69 IConfig xEngineConfig = configSource.AddConfig("XEngine");
70 xEngineConfig.Set("Enabled", "true");
71
72 // These tests will not run with AppDomainLoading = true, at least on mono. For unknown reasons, the call
73 // to AssemblyResolver.OnAssemblyResolve fails.
74 xEngineConfig.Set("AppDomainLoading", "false");
75
76 m_scene = SceneHelpers.SetupScene("My Test", UUID.Random(), 1000, 1000, null, configSource);
77 SceneHelpers.SetupSceneModules(m_scene, configSource, m_xEngine, wcModule);
78 m_scene.StartScripts();
59 } 79 }
60 80
81 /// <summary>
82 /// Test compilation and starting of a script.
83 /// </summary>
84 /// <remarks>
85 /// This is a less than ideal regression test since it involves an asynchronous operation (in this case,
86 /// compilation of the script).
87 /// </remarks>
61 [Test] 88 [Test]
62 public void T001_XStart() 89 public void TestCompileAndStartScript()
63 { 90 {
64 INonSharedRegionModule xengine = new XEngine(); 91 TestHelpers.InMethod();
65 SceneSetupHelpers.SetupSceneModules(scene, new IniConfigSource(), xengine); 92// log4net.Config.XmlConfigurator.Configure();
66 xengine.RegionLoaded(scene); 93
94 UUID userId = TestHelpers.ParseTail(0x1);
95// UUID objectId = TestHelpers.ParseTail(0x2);
96// UUID itemId = TestHelpers.ParseTail(0x3);
97 string itemName = "TestStartScript() Item";
98
99 SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, "TestStartScriptPart_", 0x100);
100 m_scene.AddNewSceneObject(so, true);
101
102 InventoryItemBase itemTemplate = new InventoryItemBase();
103// itemTemplate.ID = itemId;
104 itemTemplate.Name = itemName;
105 itemTemplate.Folder = so.UUID;
106 itemTemplate.InvType = (int)InventoryType.LSL;
107
108 m_scene.EventManager.OnChatFromWorld += OnChatFromWorld;
109
110 m_scene.RezNewScript(userId, itemTemplate);
111
112 m_chatEvent.WaitOne(60000);
113
114 Assert.That(m_osChatMessageReceived, Is.Not.Null, "No chat message received in TestStartScript()");
115 Assert.That(m_osChatMessageReceived.Message, Is.EqualTo("Script running"));
116 }
117
118 private void OnChatFromWorld(object sender, OSChatMessage oscm)
119 {
120// Console.WriteLine("Got chat [{0}]", oscm.Message);
121
122 m_osChatMessageReceived = oscm;
123 m_chatEvent.Set();
67 } 124 }
68 } 125 }
69 */ 126} \ No newline at end of file
70}
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 084ef48..02d47bd 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -747,6 +747,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine
747 747
748 public void OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine, int stateSource) 748 public void OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine, int stateSource)
749 { 749 {
750// m_log.DebugFormat(
751// "[XEngine]: OnRezScript event triggered for script {0}, startParam {1}, postOnRez {2}, engine {3}, stateSource {4}, script\n{5}",
752// itemID, startParam, postOnRez, engine, stateSource, script);
753
750 if (script.StartsWith("//MRM:")) 754 if (script.StartsWith("//MRM:"))
751 return; 755 return;
752 756
@@ -828,6 +832,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
828 m_CompileDict[itemID] = 0; 832 m_CompileDict[itemID] = 0;
829 } 833 }
830 834
835// m_log.DebugFormat("[XEngine]: Added script {0} to compile queue", itemID);
836
831 if (m_CurrentCompile == null) 837 if (m_CurrentCompile == null)
832 { 838 {
833 // NOTE: Although we use a lockless queue, the lock here 839 // NOTE: Although we use a lockless queue, the lock here
@@ -889,6 +895,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
889 bool postOnRez = (bool)p[4]; 895 bool postOnRez = (bool)p[4];
890 StateSource stateSource = (StateSource)p[5]; 896 StateSource stateSource = (StateSource)p[5];
891 897
898// m_log.DebugFormat("[XEngine]: DoOnRezScript called for script {0}", itemID);
899
892 lock (m_CompileDict) 900 lock (m_CompileDict)
893 { 901 {
894 if (!m_CompileDict.ContainsKey(itemID)) 902 if (!m_CompileDict.ContainsKey(itemID))
@@ -937,7 +945,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
937 { 945 {
938 try 946 try
939 { 947 {
940 lock (m_AddingAssemblies) 948 lock (m_AddingAssemblies)
941 { 949 {
942 m_Compiler.PerformScriptCompile(script, assetID.ToString(), item.OwnerID, out assembly, out linemap); 950 m_Compiler.PerformScriptCompile(script, assetID.ToString(), item.OwnerID, out assembly, out linemap);
943 if (!m_AddingAssemblies.ContainsKey(assembly)) { 951 if (!m_AddingAssemblies.ContainsKey(assembly)) {
@@ -989,6 +997,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
989 } 997 }
990 catch (Exception e) 998 catch (Exception e)
991 { 999 {
1000// m_log.ErrorFormat("[XEngine]: Exception when rezzing script {0}{1}", e.Message, e.StackTrace);
1001
992 // try 1002 // try
993 // { 1003 // {
994 if (!m_ScriptErrors.ContainsKey(itemID)) 1004 if (!m_ScriptErrors.ContainsKey(itemID))
@@ -1464,6 +1474,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1464 string path = Path.Combine(Directory.GetCurrentDirectory(), 1474 string path = Path.Combine(Directory.GetCurrentDirectory(),
1465 Path.Combine(s, assemblyName))+".dll"; 1475 Path.Combine(s, assemblyName))+".dll";
1466 1476
1477// Console.WriteLine("[XEngine]: Trying to resolve {0}", path);
1478
1467 if (File.Exists(path)) 1479 if (File.Exists(path))
1468 return Assembly.LoadFrom(path); 1480 return Assembly.LoadFrom(path);
1469 } 1481 }
@@ -1949,16 +1961,24 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1949 1961
1950 public void SuspendScript(UUID itemID) 1962 public void SuspendScript(UUID itemID)
1951 { 1963 {
1964// m_log.DebugFormat("[XEngine]: Received request to suspend script with ID {0}", itemID);
1965
1952 IScriptInstance instance = GetInstance(itemID); 1966 IScriptInstance instance = GetInstance(itemID);
1953 if (instance != null) 1967 if (instance != null)
1954 instance.Suspend(); 1968 instance.Suspend();
1969// else
1970// m_log.DebugFormat("[XEngine]: Could not find script with ID {0} to resume", itemID);
1955 } 1971 }
1956 1972
1957 public void ResumeScript(UUID itemID) 1973 public void ResumeScript(UUID itemID)
1958 { 1974 {
1975// m_log.DebugFormat("[XEngine]: Received request to resume script with ID {0}", itemID);
1976
1959 IScriptInstance instance = GetInstance(itemID); 1977 IScriptInstance instance = GetInstance(itemID);
1960 if (instance != null) 1978 if (instance != null)
1961 instance.Resume(); 1979 instance.Resume();
1980// else
1981// m_log.DebugFormat("[XEngine]: Could not find script with ID {0} to resume", itemID);
1962 } 1982 }
1963 1983
1964 public bool HasScript(UUID itemID, out bool running) 1984 public bool HasScript(UUID itemID, out bool running)