29 using System.Collections.Generic;
30 using System.Threading;
32 using NUnit.Framework;
34 using OpenSim.Framework;
35 using OpenSim.Region.CoreModules.Scripting.WorldComm;
36 using OpenSim.Region.Framework.Scenes;
37 using OpenSim.Region.Framework.Interfaces;
38 using OpenSim.Region.ScriptEngine.XEngine;
39 using OpenSim.Tests.Common;
52 private AutoResetEvent m_chatEvent;
53 private AutoResetEvent m_stoppedEvent;
60 private int m_chatMessagesReceived;
65 private int m_chatMessagesThreshold;
70 m_osChatMessageReceived = null;
71 m_chatMessagesReceived = 0;
72 m_chatMessagesThreshold = 0;
73 m_chatEvent =
new AutoResetEvent(
false);
74 m_stoppedEvent =
new AutoResetEvent(
false);
79 m_xEngine.DebugLevel = 1;
81 IniConfigSource configSource =
new IniConfigSource();
83 IConfig startupConfig = configSource.AddConfig(
"Startup");
84 startupConfig.Set(
"DefaultScriptEngine",
"XEngine");
86 IConfig xEngineConfig = configSource.AddConfig(
"XEngine");
87 xEngineConfig.Set(
"Enabled",
"true");
88 xEngineConfig.Set(
"StartDelay",
"0");
92 xEngineConfig.Set(
"AppDomainLoading",
"false");
94 xEngineConfig.Set(
"ScriptStopStrategy",
"co-op");
97 xEngineConfig.Set(
"ScriptDelayFactor", 0);
100 xEngineConfig.Set(
"WriteScriptSourceToDebugFile",
true);
107 xEngineConfig.Set(
"WaitForEventCompletionOnScriptStop", 120000);
109 m_scene =
new SceneHelpers().SetupScene(
"My Test", TestHelpers.ParseTail(0x9999), 1000, 1000, configSource);
110 SceneHelpers.SetupSceneModules(m_scene, configSource, m_xEngine);
111 m_scene.StartScripts();
124 TestHelpers.InMethod();
132 llSay(0, ""Thin Lizzy"");
143 TestHelpers.InMethod();
152 for (i = 0; i <= 1; i++) llSay(0, ""Iter "" + (string)i);
156 TestSingleStatementNoStop(script);
162 TestHelpers.InMethod();
171 llSay(0, ""Thin Lizzy"");
173 for (i = 0; i < 2147483647; i++) llSay(0, ""Iter "" + (string)i);
183 TestHelpers.InMethod();
192 llSay(0, ""Thin Lizzy"");
194 for (i = 0; i < 2147483647; i++)
196 llSay(0, ""Iter "" + (string)i);
207 TestHelpers.InMethod();
216 while (i < 2) llSay(0, ""Iter "" + (string)i++);
220 TestSingleStatementNoStop(script);
226 TestHelpers.InMethod();
235 llSay(0, ""Thin Lizzy"");
238 llSay(0, ""Iter "" + (string)i++);
248 TestHelpers.InMethod();
257 llSay(0, ""Thin Lizzy"");
261 llSay(0, ""Iter "" + (string)i++);
272 TestHelpers.InMethod();
282 do llSay(0, ""Iter "" + (string)i++);
287 TestSingleStatementNoStop(script);
293 TestHelpers.InMethod();
302 llSay(0, ""Thin Lizzy"");
304 do llSay(0, ""Iter "" + (string)i++);
315 TestHelpers.InMethod();
324 llSay(0, ""Thin Lizzy"");
328 llSay(0, ""Iter "" + (string)i++);
339 TestHelpers.InMethod();
340 TestHelpers.EnableLogging();
348 llSay(0, ""Thin Lizzy"");
351 llSay(0, ""Iter "" + (string)i++);
364 TestHelpers.InMethod();
373 llSay(0, ""Iter ufn1() "" + (string)i++);
382 llSay(0, ""Thin Lizzy"");
396 TestHelpers.InMethod();
405 llSay(0, ""Thin Lizzy"");
407 llSay(0, ""Iter"" + (string)i++);
408 default_event_state_entry();
415 private SceneObjectPart CreateScript(
string script,
string itemName, UUID userId)
421 = SceneHelpers.CreateSceneObject(1, userId, string.Format(
"Object for {0}", itemName), 0x100);
422 m_scene.AddNewSceneObject(so,
true);
426 itemTemplate.Name = itemName;
427 itemTemplate.Folder = so.UUID;
428 itemTemplate.InvType = (int)InventoryType.LSL;
430 m_scene.EventManager.OnChatFromWorld += OnChatFromWorld;
432 return m_scene.RezNewScript(userId, itemTemplate, script);
435 private void TestSingleStatementNoStop(
string script)
438 m_chatMessagesThreshold = 2;
440 UUID userId = TestHelpers.ParseTail(0x1);
443 string itemName =
"TestNoStop";
445 SceneObjectPart partWhereRezzed = CreateScript(script, itemName, userId);
448 m_chatEvent.WaitOne(60000);
450 if (m_osChatMessageReceived == null)
451 Assert.Fail(
"Script did not start");
453 Assert.That(m_chatMessagesReceived, Is.EqualTo(2));
456 TaskInventoryItem scriptItem = partWhereRezzed.Inventory.GetInventoryItem(itemName);
458 SceneObjectPartInventory.TryGetScriptInstanceRunning(m_scene, scriptItem, out running), Is.True);
459 Assert.That(running, Is.True);
462 private void TestStop(
string script)
465 m_chatMessagesThreshold = 1;
467 UUID userId = TestHelpers.ParseTail(0x1);
470 string itemName =
"TestStop";
472 SceneObjectPart partWhereRezzed = CreateScript(script, itemName, userId);
473 TaskInventoryItem rezzedItem = partWhereRezzed.Inventory.GetInventoryItem(itemName);
476 m_chatEvent.WaitOne(60000);
478 if (m_osChatMessageReceived != null)
479 Console.WriteLine(
"Script started with message [{0}]", m_osChatMessageReceived.Message);
481 Assert.Fail(
"Script did not start");
489 new Thread(() => { m_xEngine.StopScript(rezzedItem.ItemID); m_stoppedEvent.Set(); }).Start();
491 if (!m_stoppedEvent.WaitOne(30000))
492 Assert.Fail(
"Script did not co-operatively stop.");
495 TaskInventoryItem scriptItem = partWhereRezzed.Inventory.GetInventoryItem(itemName);
497 SceneObjectPartInventory.TryGetScriptInstanceRunning(m_scene, scriptItem, out running), Is.True);
498 Assert.That(running, Is.False);
501 private void OnChatFromWorld(
object sender,
OSChatMessage oscm)
503 Console.WriteLine(
"Got chat [{0}]", oscm.Message);
504 m_osChatMessageReceived = oscm;
506 if (++m_chatMessagesReceived >= m_chatMessagesThreshold)
508 m_scene.EventManager.OnChatFromWorld -= OnChatFromWorld;
void TestStopOnLongSingleStatementWhileLoop()
void TestStopOnLongCompoundStatementWhileLoop()
void TestNoStopOnSingleStatementDoWhileLoop()
void TestStopOnLongCompoundStatementForLoop()
void TestStopOnInfiniteManualEventCallLoop()
void TestStopOnLongSleep()
Test co-operative termination on derez of an object containing a script with a long-running event...
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
Represents an item in a task inventory
void TestNoStopOnSingleStatementWhileLoop()
void TestStopOnLongCompoundStatementDoWhileLoop()
Inventory Item - contains all the properties associated with an individual inventory piece...
void TestStopOnInfiniteJumpLoop()
void TestStopOnInfiniteUserFunctionCallLoop()
Helpers for setting up scenes.
void TestStopOnLongSingleStatementForLoop()
Interactive OpenSim region server
Test that co-operative script thread termination is working correctly.
void TestStopOnLongSingleStatementDoWhileLoop()
void TestNoStopOnSingleStatementForLoop()