aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-02-07 17:44:37 +0000
committerJustin Clark-Casey (justincc)2012-02-07 17:44:37 +0000
commit038d1bf742ba4f95ca8a83b27f6fefb755485524 (patch)
treeec03beab5a4c0a3afd75b685d629f9d82d4199b9 /OpenSim/Region/ScriptEngine
parentRevert my two quick fixes for the lag issue and put in the real fix, which (diff)
downloadopensim-SC_OLD-038d1bf742ba4f95ca8a83b27f6fefb755485524.zip
opensim-SC_OLD-038d1bf742ba4f95ca8a83b27f6fefb755485524.tar.gz
opensim-SC_OLD-038d1bf742ba4f95ca8a83b27f6fefb755485524.tar.bz2
opensim-SC_OLD-038d1bf742ba4f95ca8a83b27f6fefb755485524.tar.xz
Add a regression test to compile and start a script. Remove Path.GetDirectoryName when getting assembly loading path in Compiler.CompileFromDotNetText().
The Path.GetDirectoryName call in Compiler.CompileFromDotNetText is unnecessary since AppDomain.CurrentDomain.BaseDirectory is always a directory. Later path concatenation is already done by Path.Combine() which handles any trailing slash. Removing Path.GetDirectoryName() will not affect the runtime but allows NUnit to work since it doesn't add a trailing slash to AppDomain.CurrentDomain.BaseDirectory.
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/AssemblyResolver.cs4
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs6
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs10
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/Tests/XEngineTest.cs96
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs23
5 files changed, 113 insertions, 26 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/AssemblyResolver.cs b/OpenSim/Region/ScriptEngine/Shared/AssemblyResolver.cs
index 130e197..e35f79f 100644
--- a/OpenSim/Region/ScriptEngine/Shared/AssemblyResolver.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/AssemblyResolver.cs
@@ -44,7 +44,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
44 string dirName = myDomain.FriendlyName; 44 string dirName = myDomain.FriendlyName;
45 string ScriptEnginesPath = myDomain.SetupInformation.PrivateBinPath; 45 string ScriptEnginesPath = myDomain.SetupInformation.PrivateBinPath;
46 46
47 string[] pathList = new string[] {"bin", ScriptEnginesPath, 47 string[] pathList = new string[] {"", "bin", ScriptEnginesPath,
48 Path.Combine(ScriptEnginesPath, dirName)}; 48 Path.Combine(ScriptEnginesPath, dirName)};
49 49
50 string assemblyName = args.Name; 50 string assemblyName = args.Name;
@@ -56,6 +56,8 @@ namespace OpenSim.Region.ScriptEngine.Shared
56 string path = Path.Combine(Directory.GetCurrentDirectory(), 56 string path = Path.Combine(Directory.GetCurrentDirectory(),
57 Path.Combine(s, assemblyName))+".dll"; 57 Path.Combine(s, assemblyName))+".dll";
58 58
59// Console.WriteLine("Trying to resolve {0}", path);
60
59 if (File.Exists(path)) 61 if (File.Exists(path))
60 return Assembly.LoadFrom(path); 62 return Assembly.LoadFrom(path);
61 } 63 }
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs
index b1fb6c2..8b88588 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs
@@ -28,12 +28,16 @@
28using System; 28using System;
29using System.IO; 29using System.IO;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Reflection;
32using log4net;
31using Tools; 33using Tools;
32 34
33namespace OpenSim.Region.ScriptEngine.Shared.CodeTools 35namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
34{ 36{
35 public class CSCodeGenerator : ICodeConverter 37 public class CSCodeGenerator : ICodeConverter
36 { 38 {
39// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
40
37 private SYMBOL m_astRoot = null; 41 private SYMBOL m_astRoot = null;
38 private Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> m_positionMap; 42 private Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> m_positionMap;
39 private int m_indentWidth = 4; // for indentation 43 private int m_indentWidth = 4; // for indentation
@@ -87,6 +91,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
87 /// <returns>String containing the generated C# code.</returns> 91 /// <returns>String containing the generated C# code.</returns>
88 public string Convert(string script) 92 public string Convert(string script)
89 { 93 {
94// m_log.DebugFormat("[CS CODE GENERATOR]: Converting to C#\n{0}", script);
95
90 m_warnings.Clear(); 96 m_warnings.Clear();
91 ResetCounters(); 97 ResetCounters();
92 Parser p = new LSLSyntax(new yyLSLSyntax(), new ErrorHandler(true)); 98 Parser p = new LSLSyntax(new yyLSLSyntax(), new ErrorHandler(true));
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
index 734d4d5..c10143b 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
@@ -291,6 +291,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
291 public void PerformScriptCompile(string Script, string asset, UUID ownerUUID, 291 public void PerformScriptCompile(string Script, string asset, UUID ownerUUID,
292 out string assembly, out Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap) 292 out string assembly, out Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap)
293 { 293 {
294// m_log.DebugFormat("[Compiler]: Compiling script\n{0}", Script);
295
294 linemap = null; 296 linemap = null;
295 m_warnings.Clear(); 297 m_warnings.Clear();
296 298
@@ -357,6 +359,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
357 if (Script.StartsWith("//yp", true, CultureInfo.InvariantCulture)) 359 if (Script.StartsWith("//yp", true, CultureInfo.InvariantCulture))
358 language = enumCompileType.yp; 360 language = enumCompileType.yp;
359 361
362// m_log.DebugFormat("[Compiler]: Compile language is {0}", language);
363
360 if (!AllowedCompilers.ContainsKey(language.ToString())) 364 if (!AllowedCompilers.ContainsKey(language.ToString()))
361 { 365 {
362 // Not allowed to compile to this language! 366 // Not allowed to compile to this language!
@@ -417,7 +421,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
417 } 421 }
418 422
419 assembly = CompileFromDotNetText(compileScript, language, asset, assembly); 423 assembly = CompileFromDotNetText(compileScript, language, asset, assembly);
420 return;
421 } 424 }
422 425
423 public string[] GetWarnings() 426 public string[] GetWarnings()
@@ -491,6 +494,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
491 /// <returns>Filename to .dll assembly</returns> 494 /// <returns>Filename to .dll assembly</returns>
492 internal string CompileFromDotNetText(string Script, enumCompileType lang, string asset, string assembly) 495 internal string CompileFromDotNetText(string Script, enumCompileType lang, string asset, string assembly)
493 { 496 {
497// m_log.DebugFormat("[Compiler]: Compiling to assembly\n{0}", Script);
498
494 string ext = "." + lang.ToString(); 499 string ext = "." + lang.ToString();
495 500
496 // Output assembly name 501 // Output assembly name
@@ -531,8 +536,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
531 536
532 parameters.IncludeDebugInformation = true; 537 parameters.IncludeDebugInformation = true;
533 538
534 string rootPath = 539 string rootPath = AppDomain.CurrentDomain.BaseDirectory;
535 Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
536 540
537 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, 541 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
538 "OpenSim.Region.ScriptEngine.Shared.dll")); 542 "OpenSim.Region.ScriptEngine.Shared.dll"));
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 f11987e..c68f03f 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -680,6 +680,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine
680 680
681 public void OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine, int stateSource) 681 public void OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine, int stateSource)
682 { 682 {
683// m_log.DebugFormat(
684// "[XEngine]: OnRezScript event triggered for script {0}, startParam {1}, postOnRez {2}, engine {3}, stateSource {4}, script\n{5}",
685// itemID, startParam, postOnRez, engine, stateSource, script);
686
683 if (script.StartsWith("//MRM:")) 687 if (script.StartsWith("//MRM:"))
684 return; 688 return;
685 689
@@ -761,6 +765,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
761 m_CompileDict[itemID] = 0; 765 m_CompileDict[itemID] = 0;
762 } 766 }
763 767
768// m_log.DebugFormat("[XEngine]: Added script {0} to compile queue", itemID);
769
764 if (m_CurrentCompile == null) 770 if (m_CurrentCompile == null)
765 { 771 {
766 // NOTE: Although we use a lockless queue, the lock here 772 // NOTE: Although we use a lockless queue, the lock here
@@ -822,6 +828,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
822 bool postOnRez = (bool)p[4]; 828 bool postOnRez = (bool)p[4];
823 StateSource stateSource = (StateSource)p[5]; 829 StateSource stateSource = (StateSource)p[5];
824 830
831// m_log.DebugFormat("[XEngine]: DoOnRezScript called for script {0}", itemID);
832
825 lock (m_CompileDict) 833 lock (m_CompileDict)
826 { 834 {
827 if (!m_CompileDict.ContainsKey(itemID)) 835 if (!m_CompileDict.ContainsKey(itemID))
@@ -870,7 +878,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
870 { 878 {
871 try 879 try
872 { 880 {
873 lock (m_AddingAssemblies) 881 lock (m_AddingAssemblies)
874 { 882 {
875 m_Compiler.PerformScriptCompile(script, assetID.ToString(), item.OwnerID, out assembly, out linemap); 883 m_Compiler.PerformScriptCompile(script, assetID.ToString(), item.OwnerID, out assembly, out linemap);
876 if (!m_AddingAssemblies.ContainsKey(assembly)) { 884 if (!m_AddingAssemblies.ContainsKey(assembly)) {
@@ -922,6 +930,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
922 } 930 }
923 catch (Exception e) 931 catch (Exception e)
924 { 932 {
933// m_log.ErrorFormat("[XEngine]: Exception when rezzing script {0}{1}", e.Message, e.StackTrace);
934
925 // try 935 // try
926 // { 936 // {
927 if (!m_ScriptErrors.ContainsKey(itemID)) 937 if (!m_ScriptErrors.ContainsKey(itemID))
@@ -1132,7 +1142,6 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1132 handlerObjectRemoved(part.UUID); 1142 handlerObjectRemoved(part.UUID);
1133 } 1143 }
1134 1144
1135
1136 ScriptRemoved handlerScriptRemoved = OnScriptRemoved; 1145 ScriptRemoved handlerScriptRemoved = OnScriptRemoved;
1137 if (handlerScriptRemoved != null) 1146 if (handlerScriptRemoved != null)
1138 handlerScriptRemoved(itemID); 1147 handlerScriptRemoved(itemID);
@@ -1381,6 +1390,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1381 string path = Path.Combine(Directory.GetCurrentDirectory(), 1390 string path = Path.Combine(Directory.GetCurrentDirectory(),
1382 Path.Combine(s, assemblyName))+".dll"; 1391 Path.Combine(s, assemblyName))+".dll";
1383 1392
1393// Console.WriteLine("[XEngine]: Trying to resolve {0}", path);
1394
1384 if (File.Exists(path)) 1395 if (File.Exists(path))
1385 return Assembly.LoadFrom(path); 1396 return Assembly.LoadFrom(path);
1386 } 1397 }
@@ -1863,16 +1874,24 @@ namespace OpenSim.Region.ScriptEngine.XEngine
1863 1874
1864 public void SuspendScript(UUID itemID) 1875 public void SuspendScript(UUID itemID)
1865 { 1876 {
1877// m_log.DebugFormat("[XEngine]: Received request to suspend script with ID {0}", itemID);
1878
1866 IScriptInstance instance = GetInstance(itemID); 1879 IScriptInstance instance = GetInstance(itemID);
1867 if (instance != null) 1880 if (instance != null)
1868 instance.Suspend(); 1881 instance.Suspend();
1882// else
1883// m_log.DebugFormat("[XEngine]: Could not find script with ID {0} to resume", itemID);
1869 } 1884 }
1870 1885
1871 public void ResumeScript(UUID itemID) 1886 public void ResumeScript(UUID itemID)
1872 { 1887 {
1888// m_log.DebugFormat("[XEngine]: Received request to resume script with ID {0}", itemID);
1889
1873 IScriptInstance instance = GetInstance(itemID); 1890 IScriptInstance instance = GetInstance(itemID);
1874 if (instance != null) 1891 if (instance != null)
1875 instance.Resume(); 1892 instance.Resume();
1893// else
1894// m_log.DebugFormat("[XEngine]: Could not find script with ID {0} to resume", itemID);
1876 } 1895 }
1877 } 1896 }
1878} \ No newline at end of file 1897} \ No newline at end of file