浏览代码

Updating tests which were not ported properly from SimViz repo.

/fix-editor-pause
Jon Hogins 5 年前
当前提交
46510192
共有 13 个文件被更改,包括 195 次插入54 次删除
  1. 36
      com.unity.perception/Tests/Runtime/GroundTruthTests/BoundingBox2DTests.cs
  2. 6
      com.unity.perception/Tests/Runtime/GroundTruthTests/Main Camera.prefab
  3. 4
      com.unity.perception/Tests/Runtime/GroundTruthTests/ObjectCountTests.cs
  4. 12
      com.unity.perception/Tests/Runtime/GroundTruthTests/SimulationManagerTests.cs
  5. 6
      com.unity.perception/Tests/Runtime/GroundTruthTests/SimulationManager_SensorSchedulingTests.cs
  6. 2
      com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationGroundTruthTests.cs
  7. 37
      com.unity.perception/Tests/Runtime/GroundTruthTests/GroundTruthTestBase.cs
  8. 112
      com.unity.perception/Tests/Runtime/GroundTruthTests/PerceptionCameraIntegrationTests.cs
  9. 3
      com.unity.perception/Tests/Runtime/GroundTruthTests/PerceptionCameraIntegrationTests.cs.meta
  10. 31
      com.unity.perception/Tests/Runtime/GroundTruthTests/PassTestBase.cs
  11. 0
      /com.unity.perception/Tests/Runtime/GroundTruthTests/GroundTruthTestBase.cs.meta
  12. 0
      /com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationGroundTruthTests.cs.meta
  13. 0
      /com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationGroundTruthTests.cs

36
com.unity.perception/Tests/Runtime/GroundTruthTests/BoundingBox2DTests.cs


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Perception;
using UnityEngine.Perception.Sensors;
using UnityEngine.TestTools;

[TestFixture]
public class BoundingBox2DTests : PassTestBase
public class BoundingBox2DTests : GroundTruthTestBase
{
public class ProducesCorrectBoundingBoxesData
{

public BoundingBoxOrigin boundingBoxOrigin;
public ProducesCorrectBoundingBoxesData(uint[] data, RenderedObjectInfo[] boundingBoxesExpected, uint[] classCountsExpected, int stride, string name)
public ProducesCorrectBoundingBoxesData(uint[] data, RenderedObjectInfo[] boundingBoxesExpected, uint[] classCountsExpected, int stride, BoundingBoxOrigin boundingBoxOrigin, string name)
{
this.data = data;
this.boundingBoxesExpected = boundingBoxesExpected;

this.boundingBoxOrigin = boundingBoxOrigin;
}
public override string ToString()

0
},
2,
BoundingBoxOrigin.BottomLeft,
"SimpleBox");
yield return new ProducesCorrectBoundingBoxesData(
new uint[]

1
},
3,
BoundingBoxOrigin.BottomLeft,
"WithGaps");
yield return new ProducesCorrectBoundingBoxesData(
new uint[]

1
},
3,
BoundingBoxOrigin.BottomLeft,
yield return new ProducesCorrectBoundingBoxesData(
new uint[]
{
0, 0,
0, 0,
0, 1
}, new[]
{
new RenderedObjectInfo()
{
boundingBox = new Rect(1, 0, 1, 1),
instanceId = 1,
labelId = 0,
pixelCount = 1
},
}, new uint[]
{
1,
0
},
2,
BoundingBoxOrigin.TopLeft,
"TopLeft");
}
[UnityTest]

var dataNativeArray = new NativeArray<uint>(producesCorrectBoundingBoxesData.data, Allocator.Persistent);
renderedObjectInfoGenerator.Compute(dataNativeArray, producesCorrectBoundingBoxesData.stride, BoundingBoxOrigin.BottomLeft, out var boundingBoxes, out var classCounts, Allocator.Temp);
renderedObjectInfoGenerator.Compute(dataNativeArray, producesCorrectBoundingBoxesData.stride, producesCorrectBoundingBoxesData.boundingBoxOrigin, out var boundingBoxes, out var classCounts, Allocator.Temp);
CollectionAssert.AreEqual(producesCorrectBoundingBoxesData.boundingBoxesExpected, boundingBoxes.ToArray());
CollectionAssert.AreEqual(producesCorrectBoundingBoxesData.classCountsExpected, classCounts.ToArray());

6
com.unity.perception/Tests/Runtime/GroundTruthTests/Main Camera.prefab


references:
version: 1
00000000:
type: {class: InstanceSegmentationPass, ns: UnityEngine.Perception.Sensors, asm: Unity.Perception.GroundTruth}
type: {class: InstanceSegmentationPass, ns: UnityEngine.SimViz.Sensors, asm: Unity.SimViz.GroundTruth}
data:
name: Custom Pass
enabled: 1

idStart: 1
idStep: 1
00000001:
type: {class: SemanticSegmentationPass, ns: UnityEngine.Perception.Sensors, asm: Unity.Perception.GroundTruth}
type: {class: SemanticSegmentationPass, ns: UnityEngine.SimViz.Sensors, asm: Unity.SimViz.GroundTruth}
data:
name: Custom Pass
enabled: 1

labelingConfiguration: {fileID: 11400000, guid: 16a81d3f01f4f4345b113509e93fdab6,
type: 2}
00000002:
type: {class: LabelHistogramPass, ns: UnityEngine.Perception.Sensors, asm: Unity.Perception.GroundTruth}
type: {class: LabelHistogramPass, ns: UnityEngine.SimViz.Sensors, asm: Unity.SimViz.GroundTruth}
data:
name: Custom Pass
enabled: 1

4
com.unity.perception/Tests/Runtime/GroundTruthTests/ObjectCountTests.cs


//Graphics issues with OpenGL Linux Editor. https://jira.unity3d.com/browse/AISV-422
[UnityPlatform(exclude = new[] {RuntimePlatform.LinuxEditor, RuntimePlatform.LinuxPlayer})]
[TestFixture]
class ObjectCountTests : PassTestBase
class ObjectCountTests : GroundTruthTestBase
public IEnumerator LabeledObjectHistogramPassProducesCorrectValuesWithChangingObjects()
public IEnumerator ProducesCorrectValuesWithChangingObjects()
{
var label = "label";
var labelingConfiguration = ScriptableObject.CreateInstance<LabelingConfiguration>();

12
com.unity.perception/Tests/Runtime/GroundTruthTests/SimulationManagerTests.cs


[TestFixture]
public class SimulationManagerTests
{
[TearDown]
public void TearDown()
{
SimulationManager.ResetSimulation();
Time.timeScale = 1;
//Manager.Instance.Shutdown();
if (Directory.Exists(SimulationManager.OutputDirectory))
Directory.Delete(SimulationManager.OutputDirectory, true);
//Manager.Instance.Start();
}
[Test]
public void RegisterSensor_ReportsProperJson()
{

6
com.unity.perception/Tests/Runtime/GroundTruthTests/SimulationManager_SensorSchedulingTests.cs


timeScale * period,
timeScale * period
};
for (int i = 0; i < deltaTimeSamplesExpected.Length; i++)
float[] deltaTimeSamples = new float[deltaTimeSamplesExpected.Length];
for (int i = 0; i < deltaTimeSamples.Length; i++)
{
yield return null;
Assert.AreEqual(deltaTimeSamplesExpected[i], Time.deltaTime, 0.0001f);

period,
period
};
for (int i = 0; i < deltaTimeSamplesExpected.Length; i++)
float[] deltaTimeSamples = new float[deltaTimeSamplesExpected.Length];
for (int i = 0; i < deltaTimeSamples.Length; i++)
{
Time.timeScale = newTimeScalesPerFrame[i];
yield return null;

2
com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationGroundTruthTests.cs


//Graphics issues with OpenGL Linux Editor. https://jira.unity3d.com/browse/AISV-422
[UnityPlatform(exclude = new[] {RuntimePlatform.LinuxEditor, RuntimePlatform.LinuxPlayer})]
public class SegmentationPassTests : PassTestBase
public class SegmentationPassTests : GroundTruthTestBase
{
// A UnityTest behaves like a coroutine in Play Mode. In Edit Mode you can use
// `yield return null;` to skip a frame.

37
com.unity.perception/Tests/Runtime/GroundTruthTests/GroundTruthTestBase.cs


using System;
using System.Collections.Generic;
using System.IO;
using NUnit.Framework;
using Unity.Simulation;
using UnityEngine;
using UnityEngine.Perception;
using Object = UnityEngine.Object;
namespace GroundTruthTests
{
public class GroundTruthTestBase
{
List<GameObject> objectsToDestroy = new List<GameObject>();
[TearDown]
public void TearDown()
{
foreach (var o in objectsToDestroy)
Object.DestroyImmediate(o);
objectsToDestroy.Clear();
SimulationManager.ResetSimulation();
Time.timeScale = 1;
if (Directory.Exists(SimulationManager.OutputDirectory))
Directory.Delete(SimulationManager.OutputDirectory, true);
}
public void AddTestObjectForCleanup(GameObject @object) => objectsToDestroy.Add(@object);
public void DestroyTestObject(GameObject @object)
{
Object.DestroyImmediate(@object);
objectsToDestroy.Remove(@object);
}
}
}

112
com.unity.perception/Tests/Runtime/GroundTruthTests/PerceptionCameraIntegrationTests.cs


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using NUnit.Framework;
using Unity.Collections;
using UnityEngine;
using UnityEngine.Perception;
using UnityEngine.Perception.Sensors;
using UnityEngine.TestTools;
using Object = UnityEngine.Object;
namespace GroundTruthTests
{
#if HDRP_PRESENT
[Ignore("Ignoring in HDRP because of a rendering issue in the first frame. See issue AISV-455.")]
#endif
public class PerceptionCameraIntegrationTests : GroundTruthTestBase
{
[UnityTest]
[UnityPlatform(RuntimePlatform.LinuxPlayer, RuntimePlatform.WindowsPlayer)]
public IEnumerator EnableBoundingBoxes_GeneratesCorrectDataset()
{
//set resolution to ensure we don't have rounding in rendering leading to bounding boxes to change height/width
Screen.SetResolution(400, 400, false);
//give the screen a chance to resize
yield return null;
var jsonExpected = $@" {{
""label_id"": 0,
""label_name"": ""label"",
""instance_id"": 1,
""x"": 0.0,
""y"": {Screen.height / 4:F1},
""width"": {Screen.width:F1},
""height"": {Screen.height / 2:F1}
}}";
var labelingConfiguration = CreateLabelingConfiguration();
var camera = SetupCamera(labelingConfiguration, pc =>
{
pc.produceBoundingBoxAnnotations = true;
});
var plane = TestHelper.CreateLabeledPlane();
AddTestObjectForCleanup(plane);
//a plane is 10x10 by default, so scale it down to be 10x1 to cover the center half of the image
plane.transform.localScale = new Vector3(10f, -1f, .1f);
yield return null;
SimulationManager.ResetSimulation();
var capturesPath = Path.Combine(SimulationManager.OutputDirectory, "captures_000.json");
var capturesJson = File.ReadAllText(capturesPath);
StringAssert.Contains(jsonExpected, capturesJson);
}
[UnityTest]
public IEnumerator EnableSemanticSegmentation_GeneratesCorrectDataset()
{
var labelingConfiguration = CreateLabelingConfiguration();
SetupCamera(labelingConfiguration, pc => pc.produceSegmentationImages = true);
string expectedImageFilename = $"segmentation_{Time.frameCount}.png";
this.AddTestObjectForCleanup(TestHelper.CreateLabeledPlane());
yield return null;
SimulationManager.ResetSimulation();
var capturesPath = Path.Combine(SimulationManager.OutputDirectory, "captures_000.json");
var capturesJson = File.ReadAllText(capturesPath);
var imagePath = Path.Combine("SemanticSegmentation", expectedImageFilename).Replace(@"\", @"\\");
StringAssert.Contains(imagePath, capturesJson);
}
static LabelingConfiguration CreateLabelingConfiguration()
{
var label = "label";
var labelingConfiguration = ScriptableObject.CreateInstance<LabelingConfiguration>();
labelingConfiguration.LabelingConfigurations = new List<LabelingConfigurationEntry>
{
new LabelingConfigurationEntry
{
label = label,
value = 500
}
};
return labelingConfiguration;
}
GameObject SetupCamera(LabelingConfiguration labelingConfiguration, Action<PerceptionCamera> initPerceptionCamera)
{
var cameraObject = new GameObject();
cameraObject.SetActive(false);
var camera = cameraObject.AddComponent<Camera>();
camera.orthographic = true;
camera.orthographicSize = 1;
var perceptionCamera = cameraObject.AddComponent<PerceptionCamera>();
perceptionCamera.produceSegmentationImages = false;
perceptionCamera.produceVisiblePixelsMetric = false;
perceptionCamera.produceBoundingBoxAnnotations = false;
perceptionCamera.produceObjectCountAnnotations = false;
perceptionCamera.captureRgbImages = false;
perceptionCamera.LabelingConfiguration = labelingConfiguration;
initPerceptionCamera(perceptionCamera);
cameraObject.SetActive(true);
AddTestObjectForCleanup(cameraObject);
return cameraObject;
}
}
}

3
com.unity.perception/Tests/Runtime/GroundTruthTests/PerceptionCameraIntegrationTests.cs.meta


fileFormatVersion: 2
guid: f83408fe81fd4168a740139c98a38cfe
timeCreated: 1586791038

31
com.unity.perception/Tests/Runtime/GroundTruthTests/PassTestBase.cs


using System;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.Perception;
using Object = UnityEngine.Object;
namespace GroundTruthTests
{
public class PassTestBase
{
List<GameObject> objectsToDestroy = new List<GameObject>();
[TearDown]
public void TearDown()
{
foreach (var o in objectsToDestroy)
Object.DestroyImmediate(o);
objectsToDestroy.Clear();
SimulationManager.ResetSimulation();
}
public void AddTestObjectForCleanup(GameObject @object) => objectsToDestroy.Add(@object);
public void DestroyTestObject(GameObject @object)
{
Object.DestroyImmediate(@object);
objectsToDestroy.Remove(@object);
}
}
}

/com.unity.perception/Tests/Runtime/GroundTruthTests/PassTestBase.cs.meta → /com.unity.perception/Tests/Runtime/GroundTruthTests/GroundTruthTestBase.cs.meta

/com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationPassTests.cs.meta → /com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationGroundTruthTests.cs.meta

/com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationPassTests.cs → /com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationGroundTruthTests.cs

正在加载...
取消
保存