VectorRenderModuleStressTests.cs 4.7 KB

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