OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
VectorRenderModuleStressTests.cs
Go to the documentation of this file.
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.IO;
31 using System.Linq;
32 using System.Reflection;
33 using System.Threading;
34 using log4net.Config;
35 using NUnit.Framework;
36 using OpenMetaverse;
37 using OpenMetaverse.Assets;
38 using OpenSim.Framework;
39 using OpenSim.Region.CoreModules.Scripting.DynamicTexture;
40 using OpenSim.Region.CoreModules.Scripting.VectorRender;
41 using OpenSim.Region.Framework.Scenes;
42 using OpenSim.Region.Framework.Scenes.Serialization;
43 using OpenSim.Tests.Common;
44 
45 namespace OpenSim.Tests.Stress
46 {
47  [TestFixture]
49  {
50  public Scene Scene { get; private set; }
51  public DynamicTextureModule Dtm { get; private set; }
52  public VectorRenderModule Vrm { get; private set; }
53 
54  private void SetupScene(bool reuseTextures)
55  {
56  Scene = new SceneHelpers().SetupScene();
57 
58  Dtm = new DynamicTextureModule();
59  Dtm.ReuseTextures = reuseTextures;
60 
61  Vrm = new VectorRenderModule();
62 
63  SceneHelpers.SetupSceneModules(Scene, Dtm, Vrm);
64  }
65 
66  [Test]
68  {
69  int threads = 4;
70  TestHelpers.InMethod();
71 
72  SetupScene(false);
73 
74  List<Drawer> drawers = new List<Drawer>();
75 
76  for (int i = 0; i < threads; i++)
77  {
78  Drawer d = new Drawer(this, i);
79  drawers.Add(d);
80  Console.WriteLine("Starting drawer {0}", i);
81  Util.FireAndForget(o => d.Draw(), null, "VectorRenderModuleStressTests.TestConcurrentRepeatedDraw");
82  }
83 
84  Thread.Sleep(10 * 60 * 1000);
85 
86  drawers.ForEach(d => d.Ready = false);
87  drawers.ForEach(d => Console.WriteLine("Drawer {0} drew {1} textures", d.Number, d.Pass + 1));
88  }
89 
90  class Drawer
91  {
92  public int Number { get; private set; }
93  public int Pass { get; private set; }
94  public bool Ready { get; set; }
95 
96  private VectorRenderModuleStressTests m_tests;
97 
98  public Drawer(VectorRenderModuleStressTests tests, int number)
99  {
100  m_tests = tests;
101  Number = number;
102  Ready = true;
103  }
104 
105  public void Draw()
106  {
107  SceneObjectGroup so = SceneHelpers.AddSceneObject(m_tests.Scene);
108 
109  while (Ready)
110  {
111  UUID originalTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID;
112 
113  // Ensure unique text
114  string text = string.Format("{0:D2}{1}", Number, Pass);
115 
116  m_tests.Dtm.AddDynamicTextureData(
117  m_tests.Scene.RegionInfo.RegionID,
118  so.UUID,
119  m_tests.Vrm.GetContentType(),
120  string.Format("PenColour BLACK; MoveTo 40,220; FontSize 32; Text {0};", text),
121  "",
122  0);
123 
124  Assert.That(originalTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID));
125 
126  Pass++;
127  }
128  }
129  }
130  }
131 }
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60
Interactive OpenSim region server
Definition: OpenSim.cs:55