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.iar_mods
parent
130b1c0665
commit
038d1bf742
|
@ -267,10 +267,8 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
/// <returns></returns>
|
||||
public void CreateScriptInstance(TaskInventoryItem item, int startParam, bool postOnRez, string engine, int stateSource)
|
||||
{
|
||||
// m_log.InfoFormat(
|
||||
// "[PRIM INVENTORY]: " +
|
||||
// "Starting script {0}, {1} in prim {2}, {3}",
|
||||
// item.Name, item.ItemID, Name, UUID);
|
||||
// m_log.DebugFormat("[PRIM INVENTORY]: Starting script {0} {1} in prim {2} {3} in {4}",
|
||||
// item.Name, item.ItemID, m_part.Name, m_part.UUID, m_part.ParentGroup.Scene.RegionInfo.RegionName);
|
||||
|
||||
if (!m_part.ParentGroup.Scene.Permissions.CanRunScript(item.ItemID, m_part.UUID, item.OwnerID))
|
||||
return;
|
||||
|
@ -299,8 +297,7 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
if (null == asset)
|
||||
{
|
||||
m_log.ErrorFormat(
|
||||
"[PRIM INVENTORY]: " +
|
||||
"Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found",
|
||||
"[PRIM INVENTORY]: Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found",
|
||||
item.Name, item.ItemID, m_part.AbsolutePosition,
|
||||
m_part.ParentGroup.Scene.RegionInfo.RegionName, item.AssetID);
|
||||
}
|
||||
|
@ -400,8 +397,7 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
CreateScriptInstance(item, startParam, postOnRez, engine, stateSource);
|
||||
else
|
||||
m_log.ErrorFormat(
|
||||
"[PRIM INVENTORY]: " +
|
||||
"Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}",
|
||||
"[PRIM INVENTORY]: Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}",
|
||||
itemId, m_part.Name, m_part.UUID,
|
||||
m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
|||
string dirName = myDomain.FriendlyName;
|
||||
string ScriptEnginesPath = myDomain.SetupInformation.PrivateBinPath;
|
||||
|
||||
string[] pathList = new string[] {"bin", ScriptEnginesPath,
|
||||
string[] pathList = new string[] {"", "bin", ScriptEnginesPath,
|
||||
Path.Combine(ScriptEnginesPath, dirName)};
|
||||
|
||||
string assemblyName = args.Name;
|
||||
|
@ -56,6 +56,8 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
|||
string path = Path.Combine(Directory.GetCurrentDirectory(),
|
||||
Path.Combine(s, assemblyName))+".dll";
|
||||
|
||||
// Console.WriteLine("Trying to resolve {0}", path);
|
||||
|
||||
if (File.Exists(path))
|
||||
return Assembly.LoadFrom(path);
|
||||
}
|
||||
|
|
|
@ -28,12 +28,16 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using log4net;
|
||||
using Tools;
|
||||
|
||||
namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
||||
{
|
||||
public class CSCodeGenerator : ICodeConverter
|
||||
{
|
||||
// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private SYMBOL m_astRoot = null;
|
||||
private Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> m_positionMap;
|
||||
private int m_indentWidth = 4; // for indentation
|
||||
|
@ -87,6 +91,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
|||
/// <returns>String containing the generated C# code.</returns>
|
||||
public string Convert(string script)
|
||||
{
|
||||
// m_log.DebugFormat("[CS CODE GENERATOR]: Converting to C#\n{0}", script);
|
||||
|
||||
m_warnings.Clear();
|
||||
ResetCounters();
|
||||
Parser p = new LSLSyntax(new yyLSLSyntax(), new ErrorHandler(true));
|
||||
|
|
|
@ -291,6 +291,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
|||
public void PerformScriptCompile(string Script, string asset, UUID ownerUUID,
|
||||
out string assembly, out Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap)
|
||||
{
|
||||
// m_log.DebugFormat("[Compiler]: Compiling script\n{0}", Script);
|
||||
|
||||
linemap = null;
|
||||
m_warnings.Clear();
|
||||
|
||||
|
@ -357,6 +359,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
|||
if (Script.StartsWith("//yp", true, CultureInfo.InvariantCulture))
|
||||
language = enumCompileType.yp;
|
||||
|
||||
// m_log.DebugFormat("[Compiler]: Compile language is {0}", language);
|
||||
|
||||
if (!AllowedCompilers.ContainsKey(language.ToString()))
|
||||
{
|
||||
// Not allowed to compile to this language!
|
||||
|
@ -417,7 +421,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
|||
}
|
||||
|
||||
assembly = CompileFromDotNetText(compileScript, language, asset, assembly);
|
||||
return;
|
||||
}
|
||||
|
||||
public string[] GetWarnings()
|
||||
|
@ -491,6 +494,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
|||
/// <returns>Filename to .dll assembly</returns>
|
||||
internal string CompileFromDotNetText(string Script, enumCompileType lang, string asset, string assembly)
|
||||
{
|
||||
// m_log.DebugFormat("[Compiler]: Compiling to assembly\n{0}", Script);
|
||||
|
||||
string ext = "." + lang.ToString();
|
||||
|
||||
// Output assembly name
|
||||
|
@ -531,8 +536,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
|
|||
|
||||
parameters.IncludeDebugInformation = true;
|
||||
|
||||
string rootPath =
|
||||
Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
|
||||
string rootPath = AppDomain.CurrentDomain.BaseDirectory;
|
||||
|
||||
parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
|
||||
"OpenSim.Region.ScriptEngine.Shared.dll"));
|
||||
|
|
|
@ -27,44 +27,100 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Nini.Config;
|
||||
using NUnit.Framework;
|
||||
using OpenSim.Tests.Common.Mock;
|
||||
using OpenSim.Region.Framework.Scenes;
|
||||
using OpenMetaverse;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.CoreModules.Scripting.WorldComm;
|
||||
using OpenSim.Region.Framework.Scenes;
|
||||
using OpenSim.Region.Framework.Interfaces;
|
||||
using OpenSim.Tests.Common;
|
||||
using OpenSim.Tests.Common.Mock;
|
||||
|
||||
namespace OpenSim.Region.ScriptEngine.XEngine.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Scene presence tests
|
||||
/// XEngine tests.
|
||||
/// </summary>
|
||||
/// Commented out XEngineTests that don't do anything
|
||||
/*
|
||||
[TestFixture]
|
||||
public class XEngineTest
|
||||
{
|
||||
public Scene scene;
|
||||
|
||||
public static Random random;
|
||||
public TestClient testclient;
|
||||
//TestCommunicationsManager cm;
|
||||
private TestScene m_scene;
|
||||
private XEngine m_xEngine;
|
||||
private AutoResetEvent m_chatEvent = new AutoResetEvent(false);
|
||||
private OSChatMessage m_osChatMessageReceived;
|
||||
|
||||
[TestFixtureSetUp]
|
||||
public void Init()
|
||||
{
|
||||
TestCommunicationsManager cm = new TestCommunicationsManager();
|
||||
scene = SceneSetupHelpers.SetupScene("My Test", UUID.Random(), 1000, 1000, cm);
|
||||
random = new Random();
|
||||
//AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory + "/bin");
|
||||
// Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory);
|
||||
m_xEngine = new XEngine();
|
||||
|
||||
// Necessary to stop serialization complaining
|
||||
WorldCommModule wcModule = new WorldCommModule();
|
||||
|
||||
IniConfigSource configSource = new IniConfigSource();
|
||||
|
||||
IConfig startupConfig = configSource.AddConfig("Startup");
|
||||
startupConfig.Set("DefaultScriptEngine", "XEngine");
|
||||
|
||||
IConfig xEngineConfig = configSource.AddConfig("XEngine");
|
||||
xEngineConfig.Set("Enabled", "true");
|
||||
|
||||
// These tests will not run with AppDomainLoading = true, at least on mono. For unknown reasons, the call
|
||||
// to AssemblyResolver.OnAssemblyResolve fails.
|
||||
xEngineConfig.Set("AppDomainLoading", "false");
|
||||
|
||||
m_scene = SceneHelpers.SetupScene("My Test", UUID.Random(), 1000, 1000, null, configSource);
|
||||
SceneHelpers.SetupSceneModules(m_scene, configSource, m_xEngine, wcModule);
|
||||
m_scene.StartScripts();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test compilation and starting of a script.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is a less than ideal regression test since it involves an asynchronous operation (in this case,
|
||||
/// compilation of the script).
|
||||
/// </remarks>
|
||||
[Test]
|
||||
public void T001_XStart()
|
||||
public void TestCompileAndStartScript()
|
||||
{
|
||||
INonSharedRegionModule xengine = new XEngine();
|
||||
SceneSetupHelpers.SetupSceneModules(scene, new IniConfigSource(), xengine);
|
||||
xengine.RegionLoaded(scene);
|
||||
TestHelpers.InMethod();
|
||||
// log4net.Config.XmlConfigurator.Configure();
|
||||
|
||||
UUID userId = TestHelpers.ParseTail(0x1);
|
||||
// UUID objectId = TestHelpers.ParseTail(0x2);
|
||||
// UUID itemId = TestHelpers.ParseTail(0x3);
|
||||
string itemName = "TestStartScript() Item";
|
||||
|
||||
SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, "TestStartScriptPart_", 0x100);
|
||||
m_scene.AddNewSceneObject(so, true);
|
||||
|
||||
InventoryItemBase itemTemplate = new InventoryItemBase();
|
||||
// itemTemplate.ID = itemId;
|
||||
itemTemplate.Name = itemName;
|
||||
itemTemplate.Folder = so.UUID;
|
||||
itemTemplate.InvType = (int)InventoryType.LSL;
|
||||
|
||||
m_scene.EventManager.OnChatFromWorld += OnChatFromWorld;
|
||||
|
||||
m_scene.RezNewScript(userId, itemTemplate);
|
||||
|
||||
m_chatEvent.WaitOne(60000);
|
||||
|
||||
Assert.That(m_osChatMessageReceived, Is.Not.Null, "No chat message received in TestStartScript()");
|
||||
Assert.That(m_osChatMessageReceived.Message, Is.EqualTo("Script running"));
|
||||
}
|
||||
|
||||
private void OnChatFromWorld(object sender, OSChatMessage oscm)
|
||||
{
|
||||
// Console.WriteLine("Got chat [{0}]", oscm.Message);
|
||||
|
||||
m_osChatMessageReceived = oscm;
|
||||
m_chatEvent.Set();
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
|
@ -680,6 +680,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
|||
|
||||
public void OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine, int stateSource)
|
||||
{
|
||||
// m_log.DebugFormat(
|
||||
// "[XEngine]: OnRezScript event triggered for script {0}, startParam {1}, postOnRez {2}, engine {3}, stateSource {4}, script\n{5}",
|
||||
// itemID, startParam, postOnRez, engine, stateSource, script);
|
||||
|
||||
if (script.StartsWith("//MRM:"))
|
||||
return;
|
||||
|
||||
|
@ -761,6 +765,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
|||
m_CompileDict[itemID] = 0;
|
||||
}
|
||||
|
||||
// m_log.DebugFormat("[XEngine]: Added script {0} to compile queue", itemID);
|
||||
|
||||
if (m_CurrentCompile == null)
|
||||
{
|
||||
// NOTE: Although we use a lockless queue, the lock here
|
||||
|
@ -822,6 +828,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
|||
bool postOnRez = (bool)p[4];
|
||||
StateSource stateSource = (StateSource)p[5];
|
||||
|
||||
// m_log.DebugFormat("[XEngine]: DoOnRezScript called for script {0}", itemID);
|
||||
|
||||
lock (m_CompileDict)
|
||||
{
|
||||
if (!m_CompileDict.ContainsKey(itemID))
|
||||
|
@ -870,7 +878,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
|||
{
|
||||
try
|
||||
{
|
||||
lock (m_AddingAssemblies)
|
||||
lock (m_AddingAssemblies)
|
||||
{
|
||||
m_Compiler.PerformScriptCompile(script, assetID.ToString(), item.OwnerID, out assembly, out linemap);
|
||||
if (!m_AddingAssemblies.ContainsKey(assembly)) {
|
||||
|
@ -922,6 +930,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// m_log.ErrorFormat("[XEngine]: Exception when rezzing script {0}{1}", e.Message, e.StackTrace);
|
||||
|
||||
// try
|
||||
// {
|
||||
if (!m_ScriptErrors.ContainsKey(itemID))
|
||||
|
@ -1132,7 +1142,6 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
|||
handlerObjectRemoved(part.UUID);
|
||||
}
|
||||
|
||||
|
||||
ScriptRemoved handlerScriptRemoved = OnScriptRemoved;
|
||||
if (handlerScriptRemoved != null)
|
||||
handlerScriptRemoved(itemID);
|
||||
|
@ -1381,6 +1390,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
|||
string path = Path.Combine(Directory.GetCurrentDirectory(),
|
||||
Path.Combine(s, assemblyName))+".dll";
|
||||
|
||||
// Console.WriteLine("[XEngine]: Trying to resolve {0}", path);
|
||||
|
||||
if (File.Exists(path))
|
||||
return Assembly.LoadFrom(path);
|
||||
}
|
||||
|
@ -1863,16 +1874,24 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
|||
|
||||
public void SuspendScript(UUID itemID)
|
||||
{
|
||||
// m_log.DebugFormat("[XEngine]: Received request to suspend script with ID {0}", itemID);
|
||||
|
||||
IScriptInstance instance = GetInstance(itemID);
|
||||
if (instance != null)
|
||||
instance.Suspend();
|
||||
// else
|
||||
// m_log.DebugFormat("[XEngine]: Could not find script with ID {0} to resume", itemID);
|
||||
}
|
||||
|
||||
public void ResumeScript(UUID itemID)
|
||||
{
|
||||
// m_log.DebugFormat("[XEngine]: Received request to resume script with ID {0}", itemID);
|
||||
|
||||
IScriptInstance instance = GetInstance(itemID);
|
||||
if (instance != null)
|
||||
instance.Resume();
|
||||
// else
|
||||
// m_log.DebugFormat("[XEngine]: Could not find script with ID {0} to resume", itemID);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -88,9 +88,27 @@ namespace OpenSim.Tests.Common
|
|||
/// <param name="id">ID of the region</param>
|
||||
/// <param name="x">X co-ordinate of the region</param>
|
||||
/// <param name="y">Y co-ordinate of the region</param>
|
||||
/// <param name="cm">This should be the same if simulating two scenes within a standalone</param>
|
||||
/// <param name="cache"></param>
|
||||
/// <returns></returns>
|
||||
public static TestScene SetupScene(string name, UUID id, uint x, uint y, CoreAssetCache cache)
|
||||
public static TestScene SetupScene(
|
||||
string name, UUID id, uint x, uint y, CoreAssetCache cache)
|
||||
{
|
||||
return SetupScene(name, id, x, y, cache, new IniConfigSource());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set up a scene. If it's more then one scene, use the same CommunicationsManager to link regions
|
||||
/// or a different, to get a brand new scene with new shared region modules.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the region</param>
|
||||
/// <param name="id">ID of the region</param>
|
||||
/// <param name="x">X co-ordinate of the region</param>
|
||||
/// <param name="y">Y co-ordinate of the region</param>
|
||||
/// <param name="cache"></param>
|
||||
/// <param name="configSource"></param>
|
||||
/// <returns></returns>
|
||||
public static TestScene SetupScene(
|
||||
string name, UUID id, uint x, uint y, CoreAssetCache cache, IConfigSource configSource)
|
||||
{
|
||||
Console.WriteLine("Setting up test scene {0}", name);
|
||||
|
||||
|
@ -106,7 +124,6 @@ namespace OpenSim.Tests.Common
|
|||
|
||||
ISimulationDataService simDataService = OpenSim.Server.Base.ServerUtils.LoadPlugin<ISimulationDataService>("OpenSim.Tests.Common.dll", null);
|
||||
IEstateDataService estateDataService = null;
|
||||
IConfigSource configSource = new IniConfigSource();
|
||||
|
||||
TestScene testScene = new TestScene(
|
||||
regInfo, acm, scs, simDataService, estateDataService, null, false, configSource, null);
|
||||
|
|
Loading…
Reference in New Issue