VectorRenderModuleStressTests.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. using System;
  28. using System.Collections.Generic;
  29. using System.IO;
  30. using System.Linq;
  31. using System.Reflection;
  32. using System.Threading;
  33. using log4net.Config;
  34. using NUnit.Framework;
  35. using OpenMetaverse;
  36. using OpenMetaverse.Assets;
  37. using OpenSim.Framework;
  38. using OpenSim.Region.CoreModules.Scripting.DynamicTexture;
  39. using OpenSim.Region.CoreModules.Scripting.VectorRender;
  40. using OpenSim.Region.Framework.Scenes;
  41. using OpenSim.Region.Framework.Scenes.Serialization;
  42. using OpenSim.Tests.Common;
  43. using OpenSim.Tests.Common.Mock;
  44. namespace OpenSim.Tests.Stress
  45. {
  46. [TestFixture]
  47. public class VectorRenderModuleStressTests : OpenSimTestCase
  48. {
  49. public Scene Scene { get; private set; }
  50. public DynamicTextureModule Dtm { get; private set; }
  51. public VectorRenderModule Vrm { get; private set; }
  52. private void SetupScene(bool reuseTextures)
  53. {
  54. Scene = new SceneHelpers().SetupScene();
  55. Dtm = new DynamicTextureModule();
  56. Dtm.ReuseTextures = reuseTextures;
  57. Vrm = new VectorRenderModule();
  58. SceneHelpers.SetupSceneModules(Scene, Dtm, Vrm);
  59. }
  60. [Test]
  61. public void TestConcurrentRepeatedDraw()
  62. {
  63. int threads = 4;
  64. TestHelpers.InMethod();
  65. SetupScene(false);
  66. List<Drawer> drawers = new List<Drawer>();
  67. for (int i = 0; i < threads; i++)
  68. {
  69. Drawer d = new Drawer(this, i);
  70. drawers.Add(d);
  71. Console.WriteLine("Starting drawer {0}", i);
  72. Util.FireAndForget(o => d.Draw());
  73. }
  74. Thread.Sleep(10 * 60 * 1000);
  75. drawers.ForEach(d => d.Ready = false);
  76. drawers.ForEach(d => Console.WriteLine("Drawer {0} drew {1} textures", d.Number, d.Pass + 1));
  77. }
  78. class Drawer
  79. {
  80. public int Number { get; private set; }
  81. public int Pass { get; private set; }
  82. public bool Ready { get; set; }
  83. private VectorRenderModuleStressTests m_tests;
  84. public Drawer(VectorRenderModuleStressTests tests, int number)
  85. {
  86. m_tests = tests;
  87. Number = number;
  88. Ready = true;
  89. }
  90. public void Draw()
  91. {
  92. SceneObjectGroup so = SceneHelpers.AddSceneObject(m_tests.Scene);
  93. while (Ready)
  94. {
  95. UUID originalTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID;
  96. // Ensure unique text
  97. string text = string.Format("{0:D2}{1}", Number, Pass);
  98. m_tests.Dtm.AddDynamicTextureData(
  99. m_tests.Scene.RegionInfo.RegionID,
  100. so.UUID,
  101. m_tests.Vrm.GetContentType(),
  102. string.Format("PenColour BLACK; MoveTo 40,220; FontSize 32; Text {0};", text),
  103. "",
  104. 0);
  105. Assert.That(originalTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID));
  106. Pass++;
  107. }
  108. }
  109. }
  110. }
  111. }