diff options
Diffstat (limited to 'OpenSim/Tests/Torture/ScriptTortureTests.cs')
-rw-r--r-- | OpenSim/Tests/Torture/ScriptTortureTests.cs | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/OpenSim/Tests/Torture/ScriptTortureTests.cs b/OpenSim/Tests/Torture/ScriptTortureTests.cs new file mode 100644 index 0000000..24f278f --- /dev/null +++ b/OpenSim/Tests/Torture/ScriptTortureTests.cs | |||
@@ -0,0 +1,168 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Diagnostics; | ||
31 | using System.Reflection; | ||
32 | using System.Threading; | ||
33 | using log4net; | ||
34 | using Nini.Config; | ||
35 | using NUnit.Framework; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Region.CoreModules.Scripting.WorldComm; | ||
39 | using OpenSim.Region.Framework.Interfaces; | ||
40 | using OpenSim.Region.Framework.Scenes; | ||
41 | using OpenSim.Region.ScriptEngine.XEngine; | ||
42 | using OpenSim.Tests.Common; | ||
43 | using OpenSim.Tests.Common.Mock; | ||
44 | |||
45 | namespace OpenSim.Tests.Torture | ||
46 | { | ||
47 | /// <summary> | ||
48 | /// Script torture tests | ||
49 | /// </summary> | ||
50 | /// <remarks> | ||
51 | /// Don't rely on the numbers given by these tests - they will vary a lot depending on what is already cached, | ||
52 | /// how much memory is free, etc. In some cases, later larger tests will apparently take less time than smaller | ||
53 | /// earlier tests. | ||
54 | /// </remarks> | ||
55 | [TestFixture] | ||
56 | public class ScriptTortureTests | ||
57 | { | ||
58 | private TestScene m_scene; | ||
59 | private XEngine m_xEngine; | ||
60 | private AutoResetEvent m_chatEvent = new AutoResetEvent(false); | ||
61 | |||
62 | private int m_expectedChatMessages; | ||
63 | private List<OSChatMessage> m_osChatMessagesReceived = new List<OSChatMessage>(); | ||
64 | |||
65 | [SetUp] | ||
66 | public void Init() | ||
67 | { | ||
68 | //AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory + "/bin"); | ||
69 | // Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory); | ||
70 | m_xEngine = new XEngine(); | ||
71 | |||
72 | // Necessary to stop serialization complaining | ||
73 | WorldCommModule wcModule = new WorldCommModule(); | ||
74 | |||
75 | IniConfigSource configSource = new IniConfigSource(); | ||
76 | |||
77 | IConfig startupConfig = configSource.AddConfig("Startup"); | ||
78 | startupConfig.Set("DefaultScriptEngine", "XEngine"); | ||
79 | |||
80 | IConfig xEngineConfig = configSource.AddConfig("XEngine"); | ||
81 | xEngineConfig.Set("Enabled", "true"); | ||
82 | |||
83 | // These tests will not run with AppDomainLoading = true, at least on mono. For unknown reasons, the call | ||
84 | // to AssemblyResolver.OnAssemblyResolve fails. | ||
85 | xEngineConfig.Set("AppDomainLoading", "false"); | ||
86 | |||
87 | m_scene = new SceneHelpers().SetupScene("My Test", UUID.Random(), 1000, 1000, configSource); | ||
88 | SceneHelpers.SetupSceneModules(m_scene, configSource, m_xEngine, wcModule); | ||
89 | |||
90 | m_scene.EventManager.OnChatFromWorld += OnChatFromWorld; | ||
91 | m_scene.StartScripts(); | ||
92 | } | ||
93 | |||
94 | [TearDown] | ||
95 | public void TearDown() | ||
96 | { | ||
97 | m_scene.Close(); | ||
98 | m_scene = null; | ||
99 | GC.Collect(); | ||
100 | GC.WaitForPendingFinalizers(); | ||
101 | } | ||
102 | |||
103 | [Test] | ||
104 | public void TestCompileAndStart100Scripts() | ||
105 | { | ||
106 | TestHelpers.InMethod(); | ||
107 | log4net.Config.XmlConfigurator.Configure(); | ||
108 | |||
109 | TestCompileAndStartScripts(100); | ||
110 | } | ||
111 | |||
112 | private void TestCompileAndStartScripts(int scriptsToCreate) | ||
113 | { | ||
114 | UUID userId = TestHelpers.ParseTail(0x1); | ||
115 | |||
116 | m_expectedChatMessages = scriptsToCreate; | ||
117 | int startingObjectIdTail = 0x100; | ||
118 | |||
119 | GC.Collect(); | ||
120 | |||
121 | for (int idTail = startingObjectIdTail;idTail < startingObjectIdTail + scriptsToCreate; idTail++) | ||
122 | { | ||
123 | AddObjectAndScript(idTail, userId); | ||
124 | } | ||
125 | |||
126 | m_chatEvent.WaitOne(40000 + scriptsToCreate * 1000); | ||
127 | |||
128 | Assert.That(m_osChatMessagesReceived.Count, Is.EqualTo(m_expectedChatMessages)); | ||
129 | |||
130 | foreach (OSChatMessage msg in m_osChatMessagesReceived) | ||
131 | Assert.That( | ||
132 | msg.Message, | ||
133 | Is.EqualTo("Script running"), | ||
134 | string.Format( | ||
135 | "Message from {0} was {1} rather than {2}", msg.SenderUUID, msg.Message, "Script running")); | ||
136 | } | ||
137 | |||
138 | private void AddObjectAndScript(int objectIdTail, UUID userId) | ||
139 | { | ||
140 | // UUID itemId = TestHelpers.ParseTail(0x3); | ||
141 | string itemName = string.Format("AddObjectAndScript() Item for object {0}", objectIdTail); | ||
142 | |||
143 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId, "AddObjectAndScriptPart_", objectIdTail); | ||
144 | m_scene.AddNewSceneObject(so, true); | ||
145 | |||
146 | InventoryItemBase itemTemplate = new InventoryItemBase(); | ||
147 | // itemTemplate.ID = itemId; | ||
148 | itemTemplate.Name = itemName; | ||
149 | itemTemplate.Folder = so.UUID; | ||
150 | itemTemplate.InvType = (int)InventoryType.LSL; | ||
151 | |||
152 | m_scene.RezNewScript(userId, itemTemplate); | ||
153 | } | ||
154 | |||
155 | private void OnChatFromWorld(object sender, OSChatMessage oscm) | ||
156 | { | ||
157 | // Console.WriteLine("Got chat [{0}]", oscm.Message); | ||
158 | |||
159 | lock (m_osChatMessagesReceived) | ||
160 | { | ||
161 | m_osChatMessagesReceived.Add(oscm); | ||
162 | |||
163 | if (m_osChatMessagesReceived.Count == m_expectedChatMessages) | ||
164 | m_chatEvent.Set(); | ||
165 | } | ||
166 | } | ||
167 | } | ||
168 | } \ No newline at end of file | ||